-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Improve control flow analysis in function expressions #8849
Conversation
@mhegazy @vladima @rbuckton My latest commit optimizes the critical code paths in the binder for a bind time reduction of about 10%. Specifically, the |
Turns out there were more opportunities for optimization in the binder. Bind time is now reduced by 25% compared to the original code. Latest gains come from completely circumventing |
const restTypes: Type[] = []; | ||
for (let i = indexOfParameter; i < iife.arguments.length; i++) { | ||
restTypes.push(getTypeOfExpression(iife.arguments[i])); | ||
if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already check this in getImmediatelyInvokedFunctionExpression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll remove it.
👍 |
hasExplicitReturn = false; | ||
currentFlow = { flags: FlowFlags.Start }; | ||
if (containerFlags & ContainerFlags.IsControlFlowContainer) { | ||
const saveCurrentFlow = currentFlow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you also need to save/restore the currentTrueTarget
and currentFalseTarget
flow labels here? I see that they are tracked in bindConditionalExpressionFlow
and bindPrefixUnaryExpressionFlow
, but what happens when one branch of the condition contains an IIFE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there's no need to save those. They're only used when a conditional operator is immediately contained in a conditional statement, and they're saved and restored at that point.
This PR improves control flow analysis as follows:
const
locals are in effect within nested function expressions and arrow functions. Although it is not known when (or even whether) a function expression or arrow function will be invoked, it is known that once proven true a type guard for a capturedconst
local will remain true (because theconst
local can't be reassigned).Some examples:
Fixes #8381.