Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1df98f9
Refactor node constructors in utilities to be classes
rbuckton Dec 15, 2022
3b862b6
Move services Node classes to compiler
rbuckton Dec 16, 2022
cadf6e8
Remove objectAllocator
rbuckton Dec 16, 2022
c6ffac9
Remove baseNodeFactory
rbuckton Dec 17, 2022
9f19e4c
Merge branch 'main' into no-objectAllocator
rbuckton Apr 5, 2024
a1da7e1
Move the rest of services's NodeObject to compiler
rbuckton Apr 5, 2024
1bb7e2f
Define concrete fields for known inputs
rbuckton Apr 5, 2024
1a48252
Run formatter
rbuckton Apr 5, 2024
15ad90e
Fix lint warnings
rbuckton Apr 5, 2024
6caf908
Fixes and baseline updates
rbuckton Apr 5, 2024
77ac753
Migrate additional Node/Symbol/etc. methods from services to compiler
rbuckton Apr 6, 2024
2b58861
PR feedback
rbuckton Apr 6, 2024
33d6204
Switch back to instance-only 'kind' fields
rbuckton Apr 6, 2024
bb7688f
Base method and namespace cleanup
rbuckton Apr 12, 2024
dc35984
Simplify Debug.enableDebugInfo()
rbuckton Apr 12, 2024
4ce5648
Fix formatting
rbuckton Apr 12, 2024
42065d5
Add notes for possible future improvements for memory overhead
rbuckton Apr 12, 2024
90a5def
Update baselines
rbuckton Apr 15, 2024
d1ae0e8
Avoid mutating SymbolObject.prototype in services
rbuckton Apr 15, 2024
c0ce585
Shallow constructors for NodeObject et al.
rbuckton Apr 16, 2024
7160f82
Merge branch 'main' into no-objectAllocator
rbuckton Apr 17, 2024
1b39a6d
Remove unnecessary import alias for SymbolObject
rbuckton Apr 17, 2024
cf125da
Update classes to more closely align with recent changes to services
rbuckton Apr 17, 2024
b07f7da
Merge branch 'main' into no-objectAllocator
rbuckton Apr 17, 2024
74b510a
Update baselines
rbuckton Apr 18, 2024
9e56c70
Don't mutate SignatureObject from services
rbuckton Apr 18, 2024
1f0d71f
Fix format and lint
rbuckton Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/dtsBundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ function verifyMatchingSymbols(decl) {
* @param {ts.Symbol} moduleSymbol
*/
function emitAsNamespace(name, moduleSymbol) {
if (!(moduleSymbol.flags & ts.SymbolFlags.ValueModule)) debugger;
assert(moduleSymbol.flags & ts.SymbolFlags.ValueModule, "moduleSymbol is not a module");

scopeStack.push(new Map());
Expand Down
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.NodeConstructors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "../nodeConstructors";
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.ObjectConstructors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "../objectConstructors";
8 changes: 8 additions & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers";
export { moduleSpecifiers };
import * as performance from "./ts.performance";
export { performance };
/** @internal */
import * as NodeConstructors from "./ts.NodeConstructors";
/** @internal */
export { NodeConstructors };
/** @internal */
import * as ObjectConstructors from "./ts.ObjectConstructors";
/** @internal */
export { ObjectConstructors };
Comment thread
jakebailey marked this conversation as resolved.
Outdated
7 changes: 2 additions & 5 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ import {
NonNullChain,
NonNullExpression,
NumericLiteral,
objectAllocator,
ObjectLiteralExpression,
OptionalChain,
ParameterDeclaration,
Expand Down Expand Up @@ -310,6 +309,7 @@ import {
WhileStatement,
WithStatement,
} from "./_namespaces/ts";
import { SymbolObject as SymbolObject } from "./objectConstructors";
import * as performance from "./_namespaces/ts.performance";

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

let symbolCount = 0;

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

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

Symbol = objectAllocator.getSymbolConstructor();

// Attach debugging information if necessary
Debug.attachFlowNodeDebugInfo(unreachableFlow);
Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
Expand Down Expand Up @@ -610,7 +607,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

function createSymbol(flags: SymbolFlags, name: __String): Symbol {
symbolCount++;
return new Symbol(flags, name);
return new SymbolObject(flags, name);
}

function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags: SymbolFlags) {
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ import {
nullTransformationContext,
NumberLiteralType,
NumericLiteral,
objectAllocator,
ObjectBindingPattern,
ObjectFlags,
ObjectFlagsType,
Expand Down Expand Up @@ -1034,6 +1033,11 @@ import {
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";
import {
SignatureObject,
SymbolObject,
TypeObject,
} from "./objectConstructors";

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

const Symbol = objectAllocator.getSymbolConstructor();
const Type = objectAllocator.getTypeConstructor();
const Signature = objectAllocator.getSignatureConstructor();

let typeCount = 0;
let symbolCount = 0;
let totalInstantiationCount = 0;
Expand Down Expand Up @@ -2321,7 +2321,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function createSymbol(flags: SymbolFlags, name: __String, checkFlags?: CheckFlags) {
symbolCount++;
const symbol = new Symbol(flags | SymbolFlags.Transient, name) as TransientSymbol;
const symbol = new SymbolObject(flags | SymbolFlags.Transient, name) as Symbol as TransientSymbol;
symbol.links = new SymbolLinks() as TransientSymbolLinks;
symbol.links.checkFlags = checkFlags || CheckFlags.None;
return symbol;
Expand Down Expand Up @@ -5422,7 +5422,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function createType(flags: TypeFlags): Type {
const result = new Type(checker, flags);
const result = new TypeObject(checker, flags);
typeCount++;
result.id = typeCount;
tracing?.recordType(result);
Expand All @@ -5436,7 +5436,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function createOriginType(flags: TypeFlags): Type {
return new Type(checker, flags);
return new TypeObject(checker, flags);
}

function createIntrinsicType(kind: TypeFlags, intrinsicName: string, objectFlags = ObjectFlags.None): IntrinsicType {
Expand Down Expand Up @@ -12269,7 +12269,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
minArgumentCount: number,
flags: SignatureFlags
): Signature {
const sig = new Signature(checker, flags);
const sig = new SignatureObject(checker, flags);
sig.declaration = declaration;
sig.typeParameters = typeParameters;
sig.parameters = parameters;
Expand Down
26 changes: 18 additions & 8 deletions src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import {
NodeFlags,
nodeIsSynthesized,
noop,
objectAllocator,
ObjectFlags,
ObjectType,
RelationComparisonResult,
Expand All @@ -92,6 +91,17 @@ import {
VarianceFlags,
zipWith,
} from "./_namespaces/ts";
import {
SignatureObject,
SymbolObject,
TypeObject,
} from "./objectConstructors";
import {
IdentifierObject,
NodeObject,
SourceFileObject,
TokenObject,
} from "./nodeConstructors";

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

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

Object.defineProperties(objectAllocator.getTypeConstructor().prototype, {
Object.defineProperties(TypeObject.prototype, {
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
__tsDebuggerDisplay: {
value(this: Type) {
Expand Down Expand Up @@ -653,16 +663,16 @@ export namespace Debug {
},
});

Object.defineProperties(objectAllocator.getSignatureConstructor().prototype, {
Object.defineProperties(SignatureObject.prototype, {
__debugFlags: { get(this: Signature) { return formatSignatureFlags(this.flags); } },
__debugSignatureToString: { value(this: Signature) { return this.checker?.signatureToString(this); } }
});

const nodeConstructors = [
objectAllocator.getNodeConstructor(),
objectAllocator.getIdentifierConstructor(),
objectAllocator.getTokenConstructor(),
objectAllocator.getSourceFileConstructor()
NodeObject,
IdentifierObject,
TokenObject,
SourceFileObject
];

for (const ctor of nodeConstructors) {
Expand Down
30 changes: 12 additions & 18 deletions src/compiler/factory/baseNodeFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IdentifierObject, NodeObject, PrivateIdentifierObject, SourceFileObject, TokenObject } from "../nodeConstructors";
import {
Node,
objectAllocator,
SyntaxKind,
} from "../_namespaces/ts";

Expand All @@ -11,9 +11,9 @@ import {
* @internal
*/
export interface BaseNodeFactory {
createBaseSourceFileNode(kind: SyntaxKind): Node;
createBaseIdentifierNode(kind: SyntaxKind): Node;
createBasePrivateIdentifierNode(kind: SyntaxKind): Node;
createBaseSourceFileNode(): Node;
createBaseIdentifierNode(): Node;
createBasePrivateIdentifierNode(): Node;
createBaseTokenNode(kind: SyntaxKind): Node;
createBaseNode(kind: SyntaxKind): Node;
}
Expand All @@ -24,12 +24,6 @@ export interface BaseNodeFactory {
* @internal
*/
export function createBaseNodeFactory(): BaseNodeFactory {
let NodeConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
let TokenConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
let IdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
let PrivateIdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;
let SourceFileConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node;

return {
createBaseSourceFileNode,
createBaseIdentifierNode,
Expand All @@ -38,23 +32,23 @@ export function createBaseNodeFactory(): BaseNodeFactory {
createBaseNode
};

function createBaseSourceFileNode(kind: SyntaxKind): Node {
return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
function createBaseSourceFileNode(): Node {
return new SourceFileObject();
}

function createBaseIdentifierNode(kind: SyntaxKind): Node {
return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
function createBaseIdentifierNode(): Node {
return new IdentifierObject();
}

function createBasePrivateIdentifierNode(kind: SyntaxKind): Node {
return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
function createBasePrivateIdentifierNode(): Node {
return new PrivateIdentifierObject();
}

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

function createBaseNode(kind: SyntaxKind): Node {
return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
return new NodeObject(kind);
}
}
27 changes: 18 additions & 9 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ import {
nullNodeConverters,
nullParenthesizerRules,
NumericLiteral,
objectAllocator,
ObjectBindingPattern,
ObjectLiteralElementLike,
ObjectLiteralExpression,
Expand Down Expand Up @@ -468,6 +467,16 @@ import {
WithStatement,
YieldExpression,
} from "../_namespaces/ts";
// import {
// Node as NodeObject,
// Identifier as IdentifierObject,
// PrivateIdentifier as PrivateIdentifierObject,
// Token as TokenObject,
// SourceFile as SourceFileObject,
// } from "../nodeConstructors";
import {
SourceMapSourceObject as SourceMapSourceObject,
} from "../objectConstructors";

let nextAutoGenerateId = 0;

Expand Down Expand Up @@ -1151,7 +1160,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
//

function createBaseIdentifier(escapedText: __String, originalKeywordKind: SyntaxKind | undefined) {
const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable<Identifier>;
const node = baseFactory.createBaseIdentifierNode() as Mutable<Identifier>;
node.originalKeywordKind = originalKeywordKind;
node.escapedText = escapedText;
node.autoGenerate = undefined;
Expand Down Expand Up @@ -1248,7 +1257,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
}

function createBasePrivateIdentifier(escapedText: __String) {
const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable<PrivateIdentifier>;
const node = baseFactory.createBasePrivateIdentifierNode() as Mutable<PrivateIdentifier>;
node.escapedText = escapedText;
node.autoGenerate = undefined;
node.transformFlags |= TransformFlags.ContainsClassFields;
Expand Down Expand Up @@ -6024,7 +6033,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
endOfFileToken: EndOfFileToken,
flags: NodeFlags
) {
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
const node = baseFactory.createBaseSourceFileNode() as Mutable<SourceFile>;
node.statements = createNodeArray(statements);
node.endOfFileToken = endOfFileToken;
node.flags |= flags;
Expand Down Expand Up @@ -6107,7 +6116,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
function cloneSourceFileWorker(source: SourceFile) {
// TODO: This mechanism for cloning results in megamorphic property reads and writes. In future perf-related
// work, we should consider switching explicit property assignments instead of using `for..in`.
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
const node = baseFactory.createBaseSourceFileNode() as Mutable<SourceFile>;
node.flags |= source.flags & ~NodeFlags.Synthesized;
for (const p in source) {
if (hasProperty(node, p) || !hasProperty(source, p)) {
Expand Down Expand Up @@ -7387,9 +7396,9 @@ function makeSynthetic(node: Node) {
}

const syntheticFactory: BaseNodeFactory = {
createBaseSourceFileNode: kind => makeSynthetic(baseFactory.createBaseSourceFileNode(kind)),
createBaseIdentifierNode: kind => makeSynthetic(baseFactory.createBaseIdentifierNode(kind)),
createBasePrivateIdentifierNode: kind => makeSynthetic(baseFactory.createBasePrivateIdentifierNode(kind)),
createBaseSourceFileNode: () => makeSynthetic(baseFactory.createBaseSourceFileNode()),
createBaseIdentifierNode: () => makeSynthetic(baseFactory.createBaseIdentifierNode()),
createBasePrivateIdentifierNode: () => makeSynthetic(baseFactory.createBasePrivateIdentifierNode()),
createBaseTokenNode: kind => makeSynthetic(baseFactory.createBaseTokenNode(kind)),
createBaseNode: kind => makeSynthetic(baseFactory.createBaseNode(kind)),
};
Expand Down Expand Up @@ -7704,7 +7713,7 @@ let SourceMapSource: new (fileName: string, text: string, skipTrivia?: (pos: num
* Create an external source map source file reference
*/
export function createSourceMapSource(fileName: string, text: string, skipTrivia?: (pos: number) => number): SourceMapSource {
return new (SourceMapSource || (SourceMapSource = objectAllocator.getSourceMapSourceConstructor()))(fileName, text, skipTrivia);
return new SourceMapSourceObject(fileName, text, skipTrivia);
}

// Utilities
Expand Down
Loading