Skip to content

getSingleLineStringWriter: Use try-finally, and only one stringWriter#16751

Merged
4 commits merged into
masterfrom
singleLineStringWriter
Jul 13, 2017
Merged

getSingleLineStringWriter: Use try-finally, and only one stringWriter#16751
4 commits merged into
masterfrom
singleLineStringWriter

Conversation

@ghost

@ghost ghost commented Jun 26, 2017

Copy link
Copy Markdown
  • Failure to use try-with-resources can lead to state persisting after an exception. Could be the cause of this.
  • If we correctly clean up the StringWriter, then we should only need one global instance, not an array.

@ghost ghost force-pushed the singleLineStringWriter branch from 7ce90a2 to 6023898 Compare June 27, 2017 14:53
@ghost ghost force-pushed the singleLineStringWriter branch 2 times, most recently from 0c32972 to 9caaf17 Compare June 28, 2017 15:53
@ghost ghost force-pushed the singleLineStringWriter branch from 9caaf17 to 8ac59a9 Compare June 28, 2017 15:54

@sandersn sandersn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions about whether the affected functions can be called simultaneously.

Comment thread src/compiler/checker.ts
}

function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Declaration, flags?: TypeFormatFlags): string {
const writer = getSingleLineStringWriter();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it this is the only place that getSingleLineStringWriter was used? I wonder why it had the complex pooling behaviour then. Do you know whether it was used in more locations in the past?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these functions be called multiple times at once? In other words, do they each need to have their own copy of a string writer instead of a singleton?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would only happen if one of these 3 functions (symbolToString, signatureToString, typePredicateToString) called another one. I added an assert to prevent us from doing that.

@ghost ghost merged commit 9a3847f into master Jul 13, 2017
@ghost ghost deleted the singleLineStringWriter branch July 13, 2017 15:13
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants