Skip to content

Commit

Permalink
Refactor wrapSymbolTrackerToReportForContext to improve perf
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Dec 13, 2022
1 parent d4c2ef3 commit afc0496
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 120 deletions.
287 changes: 187 additions & 100 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
BundleFileTextLikeKind,
CallExpression,
CallSignatureDeclaration,
canHaveLocals, CaseBlock,
canHaveLocals,
CaseBlock,
CaseClause,
CaseOrDefaultClause,
cast,
Expand Down Expand Up @@ -181,7 +182,8 @@ import {
getTransformers,
getTypeNode,
guessIndentation,
HasLocals, hasRecordedExternalHelpers,
HasLocals,
hasRecordedExternalHelpers,
HeritageClause,
Identifier,
idText,
Expand Down Expand Up @@ -412,7 +414,8 @@ import {
tracing,
TransformationResult,
transformNodes,
tryCast, tryParseRawSourceMap,
tryCast,
tryParseRawSourceMap,
TryStatement,
TupleTypeNode,
TypeAliasDeclaration,
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,13 @@ export interface Node extends ReadonlyTextRange {
/** @internal */ modifierFlagsCache: ModifierFlags;
/** @internal */ readonly transformFlags: TransformFlags; // Flags for transforms
/** @internal */ id?: NodeId; // Unique id (used to look up NodeLinks)
readonly parent: Node; // Parent node (initialized by binding)
readonly parent: Node; // Parent node (initialized by binding)
/** @internal */ original?: Node; // The original node if this is an updated node.

/** @internal */ emitNode?: EmitNode; // Associated EmitNode (initialized by transforms)
// NOTE: `symbol` and `localSymbol` have been moved to `Declaration`
// `locals` and `nextContainer` have been moved to `LocalsContainer`
// `flowNode` has been moved to `FlowContainer`
// see: https://github.com/microsoft/TypeScript/pull/51682
}

export interface JSDocContainer extends Node {
Expand Down Expand Up @@ -5381,7 +5384,7 @@ export interface SymbolWalker {

// This was previously deprecated in our public API, but is still used internally
/** @internal */
export interface SymbolWriter extends SymbolTracker {
export interface SymbolWriter {
writeKeyword(text: string): void;
writeOperator(text: string): void;
writePunctuation(text: string): void;
Expand Down
8 changes: 0 additions & 8 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,6 @@ function createSingleLineStringWriter(): EmitTextWriter {
increaseIndent: noop,
decreaseIndent: noop,
clear: () => str = "",
trackSymbol: () => false,
reportInaccessibleThisError: noop,
reportInaccessibleUniqueSymbolError: noop,
reportPrivateInBaseOfClassExpression: noop,
};
}

Expand Down Expand Up @@ -5325,10 +5321,6 @@ export function createTextWriter(newLine: string): EmitTextWriter {
hasTrailingComment: () => hasTrailingComment,
hasTrailingWhitespace: () => !!output.length && isWhiteSpaceLike(output.charCodeAt(output.length - 1)),
clear: reset,
reportInaccessibleThisError: noop,
reportPrivateInBaseOfClassExpression: noop,
reportInaccessibleUniqueSymbolError: noop,
trackSymbol: () => false,
writeKeyword: write,
writeOperator: write,
writeParameter: write,
Expand Down
2 changes: 1 addition & 1 deletion src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
const printer = createPrinter(options);

return usingSingleLineStringWriter(writer => {
const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags, writer);
const typeNode = checker.typeToTypeNode(type, /*enclosingDeclaration*/ undefined, flags);
Debug.assertIsDefined(typeNode, "should always get typenode");
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ file, writer);
});
Expand Down
5 changes: 0 additions & 5 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ import {
nodeIsMissing,
nodeIsPresent,
nodeIsSynthesized,
noop,
normalizePath,
NoSubstitutionTemplateLiteral,
notImplemented,
Expand Down Expand Up @@ -2721,10 +2720,6 @@ function getDisplayPartWriter(): DisplayPartsSymbolWriter {
increaseIndent: () => { indent++; },
decreaseIndent: () => { indent--; },
clear: resetWriter,
trackSymbol: () => false,
reportInaccessibleThisError: noop,
reportInaccessibleUniqueSymbolError: noop,
reportPrivateInBaseOfClassExpression: noop,
};

function writeIndent() {
Expand Down

0 comments on commit afc0496

Please sign in to comment.