Improve control flow analysis in function expressions#8849
Improve control flow analysis in function expressions#8849ahejlsberg merged 9 commits intomasterfrom
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 |
src/compiler/checker.ts
Outdated
| 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.
we already check this in getImmediatelyInvokedFunctionExpression
There was a problem hiding this comment.
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.
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.
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:
constlocals 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 capturedconstlocal will remain true (because theconstlocal can't be reassigned).Some examples:
Fixes #8381.