Skip to content

Commit cadf6e8

Browse files
committed
Remove objectAllocator
1 parent 3b862b6 commit cadf6e8

File tree

100 files changed

+1540
-1551
lines changed

Some content is hidden

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

100 files changed

+1540
-1551
lines changed

scripts/dtsBundler.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ function verifyMatchingSymbols(decl) {
331331
* @param {ts.Symbol} moduleSymbol
332332
*/
333333
function emitAsNamespace(name, moduleSymbol) {
334+
if (!(moduleSymbol.flags & ts.SymbolFlags.ValueModule)) debugger;
334335
assert(moduleSymbol.flags & ts.SymbolFlags.ValueModule, "moduleSymbol is not a module");
335336

336337
scopeStack.push(new Map());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "../nodeConstructors";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "../objectConstructors";

src/compiler/_namespaces/ts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers";
7272
export { moduleSpecifiers };
7373
import * as performance from "./ts.performance";
7474
export { performance };
75+
/** @internal */
76+
import * as NodeConstructors from "./ts.NodeConstructors";
77+
/** @internal */
78+
export { NodeConstructors };
79+
/** @internal */
80+
import * as ObjectConstructors from "./ts.ObjectConstructors";
81+
/** @internal */
82+
export { ObjectConstructors };

src/compiler/binder.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ import {
249249
NonNullChain,
250250
NonNullExpression,
251251
NumericLiteral,
252-
objectAllocator,
253252
ObjectLiteralExpression,
254253
OptionalChain,
255254
ParameterDeclaration,
@@ -310,6 +309,7 @@ import {
310309
WhileStatement,
311310
WithStatement,
312311
} from "./_namespaces/ts";
312+
import { SymbolObject as SymbolObject } from "./objectConstructors";
313313
import * as performance from "./_namespaces/ts.performance";
314314

315315
/** @internal */
@@ -534,7 +534,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
534534

535535
let symbolCount = 0;
536536

537-
let Symbol: new (flags: SymbolFlags, name: __String) => Symbol;
538537
let classifiableNames: Set<__String>;
539538

540539
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
@@ -558,8 +557,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
558557
classifiableNames = new Set();
559558
symbolCount = 0;
560559

561-
Symbol = objectAllocator.getSymbolConstructor();
562-
563560
// Attach debugging information if necessary
564561
Debug.attachFlowNodeDebugInfo(unreachableFlow);
565562
Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
@@ -610,7 +607,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
610607

611608
function createSymbol(flags: SymbolFlags, name: __String): Symbol {
612609
symbolCount++;
613-
return new Symbol(flags, name);
610+
return new SymbolObject(flags, name);
614611
}
615612

616613
function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags: SymbolFlags) {

src/compiler/checker.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ import {
823823
nullTransformationContext,
824824
NumberLiteralType,
825825
NumericLiteral,
826-
objectAllocator,
827826
ObjectBindingPattern,
828827
ObjectFlags,
829828
ObjectFlagsType,
@@ -1034,6 +1033,11 @@ import {
10341033
} from "./_namespaces/ts";
10351034
import * as performance from "./_namespaces/ts.performance";
10361035
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";
1036+
import {
1037+
SignatureObject,
1038+
SymbolObject,
1039+
TypeObject,
1040+
} from "./objectConstructors";
10371041

10381042
const ambientModuleSymbolRegex = /^".+"$/;
10391043
const anon = "(anonymous)" as __String & string;
@@ -1379,10 +1383,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
13791383
let requestedExternalEmitHelpers: ExternalEmitHelpers;
13801384
let externalHelpersModule: Symbol;
13811385

1382-
const Symbol = objectAllocator.getSymbolConstructor();
1383-
const Type = objectAllocator.getTypeConstructor();
1384-
const Signature = objectAllocator.getSignatureConstructor();
1385-
13861386
let typeCount = 0;
13871387
let symbolCount = 0;
13881388
let totalInstantiationCount = 0;
@@ -2321,7 +2321,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
23212321

23222322
function createSymbol(flags: SymbolFlags, name: __String, checkFlags?: CheckFlags) {
23232323
symbolCount++;
2324-
const symbol = new Symbol(flags | SymbolFlags.Transient, name) as TransientSymbol;
2324+
const symbol = new SymbolObject(flags | SymbolFlags.Transient, name) as Symbol as TransientSymbol;
23252325
symbol.links = new SymbolLinks() as TransientSymbolLinks;
23262326
symbol.links.checkFlags = checkFlags || CheckFlags.None;
23272327
return symbol;
@@ -5422,7 +5422,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
54225422
}
54235423

54245424
function createType(flags: TypeFlags): Type {
5425-
const result = new Type(checker, flags);
5425+
const result = new TypeObject(checker, flags);
54265426
typeCount++;
54275427
result.id = typeCount;
54285428
tracing?.recordType(result);
@@ -5436,7 +5436,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
54365436
}
54375437

54385438
function createOriginType(flags: TypeFlags): Type {
5439-
return new Type(checker, flags);
5439+
return new TypeObject(checker, flags);
54405440
}
54415441

54425442
function createIntrinsicType(kind: TypeFlags, intrinsicName: string, objectFlags = ObjectFlags.None): IntrinsicType {
@@ -12269,7 +12269,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1226912269
minArgumentCount: number,
1227012270
flags: SignatureFlags
1227112271
): Signature {
12272-
const sig = new Signature(checker, flags);
12272+
const sig = new SignatureObject(checker, flags);
1227312273
sig.declaration = declaration;
1227412274
sig.typeParameters = typeParameters;
1227512275
sig.parameters = parameters;

src/compiler/debug.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import {
6868
NodeFlags,
6969
nodeIsSynthesized,
7070
noop,
71-
objectAllocator,
7271
ObjectFlags,
7372
ObjectType,
7473
RelationComparisonResult,
@@ -92,6 +91,17 @@ import {
9291
VarianceFlags,
9392
zipWith,
9493
} from "./_namespaces/ts";
94+
import {
95+
SignatureObject,
96+
SymbolObject,
97+
TypeObject,
98+
} from "./objectConstructors";
99+
import {
100+
IdentifierObject,
101+
NodeObject,
102+
SourceFileObject,
103+
TokenObject,
104+
} from "./nodeConstructors";
95105

96106
/** @internal */
97107
export enum LogLevel {
@@ -592,7 +602,7 @@ export namespace Debug {
592602
const weakNodeTextMap = new WeakMap<Node, string>();
593603

594604
// Add additional properties in debug mode to assist with debugging.
595-
Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, {
605+
Object.defineProperties(SymbolObject.prototype, {
596606
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
597607
__tsDebuggerDisplay: {
598608
value(this: Symbol) {
@@ -606,7 +616,7 @@ export namespace Debug {
606616
__debugFlags: { get(this: Symbol) { return formatSymbolFlags(this.flags); } }
607617
});
608618

609-
Object.defineProperties(objectAllocator.getTypeConstructor().prototype, {
619+
Object.defineProperties(TypeObject.prototype, {
610620
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
611621
__tsDebuggerDisplay: {
612622
value(this: Type) {
@@ -653,16 +663,16 @@ export namespace Debug {
653663
},
654664
});
655665

656-
Object.defineProperties(objectAllocator.getSignatureConstructor().prototype, {
666+
Object.defineProperties(SignatureObject.prototype, {
657667
__debugFlags: { get(this: Signature) { return formatSignatureFlags(this.flags); } },
658668
__debugSignatureToString: { value(this: Signature) { return this.checker?.signatureToString(this); } }
659669
});
660670

661671
const nodeConstructors = [
662-
objectAllocator.getNodeConstructor(),
663-
objectAllocator.getIdentifierConstructor(),
664-
objectAllocator.getTokenConstructor(),
665-
objectAllocator.getSourceFileConstructor()
672+
NodeObject,
673+
IdentifierObject,
674+
TokenObject,
675+
SourceFileObject
666676
];
667677

668678
for (const ctor of nodeConstructors) {
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { IdentifierObject, NodeObject, PrivateIdentifierObject, SourceFileObject, TokenObject } from "../nodeConstructors";
12
import {
23
Node,
3-
objectAllocator,
44
SyntaxKind,
55
} from "../_namespaces/ts";
66

@@ -11,9 +11,9 @@ import {
1111
* @internal
1212
*/
1313
export interface BaseNodeFactory {
14-
createBaseSourceFileNode(kind: SyntaxKind): Node;
15-
createBaseIdentifierNode(kind: SyntaxKind): Node;
16-
createBasePrivateIdentifierNode(kind: SyntaxKind): Node;
14+
createBaseSourceFileNode(): Node;
15+
createBaseIdentifierNode(): Node;
16+
createBasePrivateIdentifierNode(): Node;
1717
createBaseTokenNode(kind: SyntaxKind): Node;
1818
createBaseNode(kind: SyntaxKind): Node;
1919
}
@@ -24,12 +24,6 @@ export interface BaseNodeFactory {
2424
* @internal
2525
*/
2626
export function createBaseNodeFactory(): BaseNodeFactory {
27-
let NodeConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
28-
let TokenConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
29-
let IdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
30-
let PrivateIdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
31-
let SourceFileConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
32-
3327
return {
3428
createBaseSourceFileNode,
3529
createBaseIdentifierNode,
@@ -38,23 +32,23 @@ export function createBaseNodeFactory(): BaseNodeFactory {
3832
createBaseNode
3933
};
4034

41-
function createBaseSourceFileNode(kind: SyntaxKind): Node {
42-
return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
35+
function createBaseSourceFileNode(): Node {
36+
return new SourceFileObject();
4337
}
4438

45-
function createBaseIdentifierNode(kind: SyntaxKind): Node {
46-
return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
39+
function createBaseIdentifierNode(): Node {
40+
return new IdentifierObject();
4741
}
4842

49-
function createBasePrivateIdentifierNode(kind: SyntaxKind): Node {
50-
return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
43+
function createBasePrivateIdentifierNode(): Node {
44+
return new PrivateIdentifierObject();
5145
}
5246

5347
function createBaseTokenNode(kind: SyntaxKind): Node {
54-
return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
48+
return new TokenObject(kind);
5549
}
5650

5751
function createBaseNode(kind: SyntaxKind): Node {
58-
return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
52+
return new NodeObject(kind);
5953
}
6054
}

src/compiler/factory/nodeFactory.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ import {
337337
nullNodeConverters,
338338
nullParenthesizerRules,
339339
NumericLiteral,
340-
objectAllocator,
341340
ObjectBindingPattern,
342341
ObjectLiteralElementLike,
343342
ObjectLiteralExpression,
@@ -468,6 +467,16 @@ import {
468467
WithStatement,
469468
YieldExpression,
470469
} from "../_namespaces/ts";
470+
// import {
471+
// Node as NodeObject,
472+
// Identifier as IdentifierObject,
473+
// PrivateIdentifier as PrivateIdentifierObject,
474+
// Token as TokenObject,
475+
// SourceFile as SourceFileObject,
476+
// } from "../nodeConstructors";
477+
import {
478+
SourceMapSourceObject as SourceMapSourceObject,
479+
} from "../objectConstructors";
471480

472481
let nextAutoGenerateId = 0;
473482

@@ -1151,7 +1160,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11511160
//
11521161

11531162
function createBaseIdentifier(escapedText: __String, originalKeywordKind: SyntaxKind | undefined) {
1154-
const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable<Identifier>;
1163+
const node = baseFactory.createBaseIdentifierNode() as Mutable<Identifier>;
11551164
node.originalKeywordKind = originalKeywordKind;
11561165
node.escapedText = escapedText;
11571166
node.autoGenerate = undefined;
@@ -1248,7 +1257,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
12481257
}
12491258

12501259
function createBasePrivateIdentifier(escapedText: __String) {
1251-
const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable<PrivateIdentifier>;
1260+
const node = baseFactory.createBasePrivateIdentifierNode() as Mutable<PrivateIdentifier>;
12521261
node.escapedText = escapedText;
12531262
node.autoGenerate = undefined;
12541263
node.transformFlags |= TransformFlags.ContainsClassFields;
@@ -6024,7 +6033,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
60246033
endOfFileToken: EndOfFileToken,
60256034
flags: NodeFlags
60266035
) {
6027-
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
6036+
const node = baseFactory.createBaseSourceFileNode() as Mutable<SourceFile>;
60286037
node.statements = createNodeArray(statements);
60296038
node.endOfFileToken = endOfFileToken;
60306039
node.flags |= flags;
@@ -6107,7 +6116,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
61076116
function cloneSourceFileWorker(source: SourceFile) {
61086117
// TODO: This mechanism for cloning results in megamorphic property reads and writes. In future perf-related
61096118
// work, we should consider switching explicit property assignments instead of using `for..in`.
6110-
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
6119+
const node = baseFactory.createBaseSourceFileNode() as Mutable<SourceFile>;
61116120
node.flags |= source.flags & ~NodeFlags.Synthesized;
61126121
for (const p in source) {
61136122
if (hasProperty(node, p) || !hasProperty(source, p)) {
@@ -7387,9 +7396,9 @@ function makeSynthetic(node: Node) {
73877396
}
73887397

73897398
const syntheticFactory: BaseNodeFactory = {
7390-
createBaseSourceFileNode: kind => makeSynthetic(baseFactory.createBaseSourceFileNode(kind)),
7391-
createBaseIdentifierNode: kind => makeSynthetic(baseFactory.createBaseIdentifierNode(kind)),
7392-
createBasePrivateIdentifierNode: kind => makeSynthetic(baseFactory.createBasePrivateIdentifierNode(kind)),
7399+
createBaseSourceFileNode: () => makeSynthetic(baseFactory.createBaseSourceFileNode()),
7400+
createBaseIdentifierNode: () => makeSynthetic(baseFactory.createBaseIdentifierNode()),
7401+
createBasePrivateIdentifierNode: () => makeSynthetic(baseFactory.createBasePrivateIdentifierNode()),
73937402
createBaseTokenNode: kind => makeSynthetic(baseFactory.createBaseTokenNode(kind)),
73947403
createBaseNode: kind => makeSynthetic(baseFactory.createBaseNode(kind)),
73957404
};
@@ -7704,7 +7713,7 @@ let SourceMapSource: new (fileName: string, text: string, skipTrivia?: (pos: num
77047713
* Create an external source map source file reference
77057714
*/
77067715
export function createSourceMapSource(fileName: string, text: string, skipTrivia?: (pos: number) => number): SourceMapSource {
7707-
return new (SourceMapSource || (SourceMapSource = objectAllocator.getSourceMapSourceConstructor()))(fileName, text, skipTrivia);
7716+
return new SourceMapSourceObject(fileName, text, skipTrivia);
77087717
}
77097718

77107719
// Utilities

0 commit comments

Comments
 (0)