Skip to content
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

Reduce polymorphism resulting from unstable Node shapes #51682

Merged
merged 11 commits into from
Dec 13, 2022
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ tests/cases/user/puppeteer/puppeteer
tests/cases/user/axios-src/axios-src
tests/cases/user/prettier/prettier
.eslintcache
*v8.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a question, if I may, what kind of tools you were using to investigate those things? I imagine that in the case of Nodes the issue was already known for some time but I wonder how I could test those things in my libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an internal tool I wrote to analyze log files generated by various V8 commandline options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Andarist One open source tool that might be of interest is https://github.com/thlorenz/deoptigate

258 changes: 138 additions & 120 deletions src/compiler/binder.ts

Large diffs are not rendered by default.

852 changes: 489 additions & 363 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BundleFileTextLikeKind,
CallExpression,
CallSignatureDeclaration,
canHaveLocals,
CaseBlock,
CaseClause,
CaseOrDefaultClause,
Expand Down Expand Up @@ -181,6 +182,7 @@ import {
getTransformers,
getTypeNode,
guessIndentation,
HasLocals,
hasRecordedExternalHelpers,
HeritageClause,
Identifier,
Expand Down Expand Up @@ -412,6 +414,7 @@ import {
tracing,
TransformationResult,
transformNodes,
tryCast,
tryParseRawSourceMap,
TryStatement,
TupleTypeNode,
Expand Down Expand Up @@ -2475,8 +2478,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
//

function emitPrivateIdentifier(node: PrivateIdentifier) {
const writeText = node.symbol ? writeSymbol : write;
writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol);
write(getTextOfNode(node, /*includeTrivia*/ false));
}


Expand Down Expand Up @@ -5656,9 +5658,9 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
/**
* Returns a value indicating whether a name is unique within a container.
*/
function isUniqueLocalName(name: string, container: Node): boolean {
for (let node = container; isNodeDescendantOf(node, container); node = node.nextContainer!) {
if (node.locals) {
function isUniqueLocalName(name: string, container: HasLocals | undefined): boolean {
for (let node = container; node && isNodeDescendantOf(node, container); node = node.nextContainer) {
if (canHaveLocals(node) && node.locals) {
const local = node.locals.get(escapeLeadingUnderscores(name));
// We conservatively include alias symbols to cover cases where they're emitted as locals
if (local && local.flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) {
Expand Down Expand Up @@ -5798,7 +5800,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) {
const name = getTextOfNode(node.name);
// Use module/enum name itself if it is unique, otherwise make a unique variation
return isUniqueLocalName(name, node) ? name : makeUniqueName(name, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ "");
return isUniqueLocalName(name, tryCast(node, canHaveLocals)) ? name : makeUniqueName(name, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ "");
}

/**
Expand Down
Loading