Skip to content

Make AST nodes monomorphic. #59190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2,533 changes: 1,474 additions & 1,059 deletions src/compiler/factory/nodeFactory.ts

Large diffs are not rendered by default.

1,371 changes: 1,330 additions & 41 deletions src/compiler/utilities.ts

Large diffs are not rendered by default.

66 changes: 44 additions & 22 deletions src/harness/harnessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,49 @@ export function sourceFileToJSON(file: ts.Node): string {
return ts.Debug.formatNodeFlags(f);
}

function addSerializableFlags(o: any, n: ts.Node) {
// Clear the flags that are produced by aggregating child values. That is ephemeral
// data we don't care about in the dump. We only care what the parser set directly
// on the AST.
let flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData);
if (ts.isIdentifier(n)) {
if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) {
o.hasExtendedUnicodeEscape = true;
flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape;
}
}
if (flags) {
o.flags = getNodeFlagName(flags);
}
}
function serializeNode(n: ts.Node): any {
const o: any = { kind: getKindName(n.kind) };
if (ts.containsParseError(n)) {
o.containsParseError = true;
}
let nodeData;
if (n instanceof ts.NodeImpl) {
nodeData = (n as any as ts.NodeImpl).data;
o.pos = n.pos;
o.end = n.end;
addSerializableFlags(o, n);
if (ts.isNodeKind(n.kind) || ts.isLiteralKind(n.kind)) {
o.modifierFlagsCache = n.modifierFlagsCache;
}
o.transformFlags = n.transformFlags;
if (n.kind === ts.SyntaxKind.Identifier) {
o.escapedText = n.escapedText;
}
if (n.jsDoc) {
o.jsDoc = n.jsDoc;
}
}
else {
nodeData = n;
}
if (!nodeData) return o;

for (const propertyName of Object.getOwnPropertyNames(n) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) {
for (const propertyName of Object.getOwnPropertyNames(nodeData) as readonly (keyof ts.SourceFile | keyof ts.Identifier | keyof ts.StringLiteral)[]) {
switch (propertyName) {
case "parent":
case "symbol":
Expand All @@ -198,29 +234,15 @@ export function sourceFileToJSON(file: ts.Node): string {
case "emitNode":
// Blocklist of items we never put in the baseline file.
break;

case "flags":
addSerializableFlags(o, nodeData);
break;
case "hasExtendedUnicodeEscape":
if ((n as any).hasExtendedUnicodeEscape) {
if (nodeData.hasExtendedUnicodeEscape) {
o.hasExtendedUnicodeEscape = true;
}
break;

case "flags":
// Clear the flags that are produced by aggregating child values. That is ephemeral
// data we don't care about in the dump. We only care what the parser set directly
// on the AST.
let flags = n.flags & ~(ts.NodeFlags.JavaScriptFile | ts.NodeFlags.HasAggregatedChildData);
if (ts.isIdentifier(n)) {
if (flags & ts.NodeFlags.IdentifierHasExtendedUnicodeEscape) {
o.hasExtendedUnicodeEscape = true;
flags &= ~ts.NodeFlags.IdentifierHasExtendedUnicodeEscape;
}
}
if (flags) {
o[propertyName] = getNodeFlagName(flags);
}
break;

case "parseDiagnostics":
o[propertyName] = convertDiagnostics((n as any)[propertyName]);
break;
Expand All @@ -239,7 +261,7 @@ export function sourceFileToJSON(file: ts.Node): string {
break;

default:
o[propertyName] = (n as any)[propertyName];
o[propertyName] = nodeData[propertyName];
}
}

Expand Down Expand Up @@ -319,8 +341,8 @@ function assertArrayStructuralEquals(array1: ts.NodeArray<ts.Node>, array2: ts.N
}

function findChildName(parent: any, child: any) {
for (const name in parent) {
if (ts.hasProperty(parent, name) && parent[name] === child) {
for (const name in parent.data) {
if (ts.hasProperty(parent.data, name) && parent[name] === child) {
return name;
}
}
Expand Down
Loading