Skip to content

Commit 3456c6e

Browse files
authored
Monomorphize allocators for tsserver/public API, just like core compiler (microsoft#58045)
1 parent 39daa13 commit 3456c6e

File tree

114 files changed

+153
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+153
-352
lines changed

src/compiler/_namespaces/ts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export * from "../factory/nodeFactory";
2121
export * from "../factory/emitNode";
2222
export * from "../factory/emitHelpers";
2323
export * from "../factory/nodeTests";
24+
export * from "../factory/nodeChildren";
2425
export * from "../factory/utilities";
2526
export * from "../factory/utilitiesPublic";
2627
export * from "../parser";

src/compiler/factory/nodeChildren.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Node } from "../_namespaces/ts";
2+
3+
const nodeChildren = new WeakMap<Node, Node[] | undefined>();
4+
5+
/** @internal */
6+
export function getNodeChildren(node: Node): Node[] | undefined {
7+
return nodeChildren.get(node);
8+
}
9+
10+
/** @internal */
11+
export function setNodeChildren(node: Node, children: Node[]): Node[] {
12+
nodeChildren.set(node, children);
13+
return children;
14+
}
15+
16+
/** @internal */
17+
export function unsetNodeChildren(node: Node) {
18+
nodeChildren.delete(node);
19+
}

src/compiler/factory/nodeFactory.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ import {
387387
setEmitFlags,
388388
setIdentifierAutoGenerate,
389389
setIdentifierTypeArguments,
390+
setNodeChildren,
390391
setParent,
391392
setTextRange,
392393
ShorthandPropertyAssignment,
@@ -6210,7 +6211,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
62106211
// @api
62116212
function createSyntaxList(children: Node[]) {
62126213
const node = createBaseNode<SyntaxList>(SyntaxKind.SyntaxList);
6213-
node._children = children;
6214+
setNodeChildren(node, children);
62146215
return node;
62156216
}
62166217

src/compiler/parser.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ import {
387387
unescapeLeadingUnderscores,
388388
UnionOrIntersectionTypeNode,
389389
UnionTypeNode,
390+
unsetNodeChildren,
390391
UpdateExpression,
391392
VariableDeclaration,
392393
VariableDeclarationList,
@@ -10002,9 +10003,7 @@ namespace IncrementalParser {
1000210003

1000310004
// Ditch any existing LS children we may have created. This way we can avoid
1000410005
// moving them forward.
10005-
if (node._children) {
10006-
node._children = undefined;
10007-
}
10006+
unsetNodeChildren(node);
1000810007

1000910008
setTextRangePosEnd(node, node.pos + delta, node.end + delta);
1001010009

@@ -10160,7 +10159,7 @@ namespace IncrementalParser {
1016010159
const fullEnd = child.end;
1016110160
if (fullEnd >= changeStart) {
1016210161
child.intersectsChange = true;
10163-
child._children = undefined;
10162+
unsetNodeChildren(child);
1016410163

1016510164
// Adjust the pos or end (or both) of the intersecting element accordingly.
1016610165
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
@@ -10349,7 +10348,6 @@ namespace IncrementalParser {
1034910348

1035010349
export interface IncrementalNode extends Node, IncrementalElement {
1035110350
hasBeenIncrementallyParsed: boolean;
10352-
_children: Node[] | undefined;
1035310351
}
1035410352

1035510353
interface IncrementalNodeArray extends NodeArray<IncrementalNode>, IncrementalElement {

src/compiler/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9695,7 +9695,6 @@ export interface DiagnosticCollection {
96959695
// SyntaxKind.SyntaxList
96969696
export interface SyntaxList extends Node {
96979697
kind: SyntaxKind.SyntaxList;
9698-
_children: Node[];
96999698
}
97009699

97019700
// dprint-ignore

src/compiler/utilities.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ import {
188188
getLineStarts,
189189
getModeForUsageLocation,
190190
getNameOfDeclaration,
191+
getNodeChildren,
191192
getNormalizedAbsolutePath,
192193
getNormalizedPathComponents,
193194
getOwnKeys,
@@ -511,7 +512,6 @@ import {
511512
SymbolFlags,
512513
SymbolTable,
513514
SyntaxKind,
514-
SyntaxList,
515515
TaggedTemplateExpression,
516516
TemplateExpression,
517517
TemplateLiteral,
@@ -1162,8 +1162,11 @@ export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, inclu
11621162
// the syntax list itself considers them as normal trivia. Therefore if we simply skip
11631163
// trivia for the list, we may have skipped the JSDocComment as well. So we should process its
11641164
// first child to determine the actual position of its first token.
1165-
if (node.kind === SyntaxKind.SyntaxList && (node as SyntaxList)._children.length > 0) {
1166-
return getTokenPosOfNode((node as SyntaxList)._children[0], sourceFile, includeJsDoc);
1165+
if (node.kind === SyntaxKind.SyntaxList) {
1166+
const first = firstOrUndefined(getNodeChildren(node));
1167+
if (first) {
1168+
return getTokenPosOfNode(first, sourceFile, includeJsDoc);
1169+
}
11671170
}
11681171

11691172
return skipTrivia(
@@ -8155,6 +8158,7 @@ export interface ObjectAllocator {
81558158
}
81568159

81578160
function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
8161+
// Note: if modifying this, be sure to update SymbolObject in src/services/services.ts
81588162
this.flags = flags;
81598163
this.escapedName = name;
81608164
this.declarations = undefined;
@@ -8172,20 +8176,23 @@ function Symbol(this: Symbol, flags: SymbolFlags, name: __String) {
81728176
}
81738177

81748178
function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
8179+
// Note: if modifying this, be sure to update TypeObject in src/services/services.ts
81758180
this.flags = flags;
81768181
if (Debug.isDebugging || tracing) {
81778182
this.checker = checker;
81788183
}
81798184
}
81808185

81818186
function Signature(this: Signature, checker: TypeChecker, flags: SignatureFlags) {
8187+
// Note: if modifying this, be sure to update SignatureObject in src/services/services.ts
81828188
this.flags = flags;
81838189
if (Debug.isDebugging) {
81848190
this.checker = checker;
81858191
}
81868192
}
81878193

81888194
function Node(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
8195+
// Note: if modifying this, be sure to update NodeObject in src/services/services.ts
81898196
this.pos = pos;
81908197
this.end = end;
81918198
this.kind = kind;
@@ -8199,6 +8206,7 @@ function Node(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
81998206
}
82008207

82018208
function Token(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
8209+
// Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts
82028210
this.pos = pos;
82038211
this.end = end;
82048212
this.kind = kind;
@@ -8210,6 +8218,7 @@ function Token(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number)
82108218
}
82118219

82128220
function Identifier(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: number) {
8221+
// Note: if modifying this, be sure to update TokenOrIdentifierObject in src/services/services.ts
82138222
this.pos = pos;
82148223
this.end = end;
82158224
this.kind = kind;
@@ -8222,6 +8231,7 @@ function Identifier(this: Mutable<Node>, kind: SyntaxKind, pos: number, end: num
82228231
}
82238232

82248233
function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) {
8234+
// Note: if modifying this, be sure to update SourceMapSourceObject in src/services/services.ts
82258235
this.fileName = fileName;
82268236
this.text = text;
82278237
this.skipTrivia = skipTrivia || (pos => pos);

0 commit comments

Comments
 (0)