perf(semantic): single call to Function::bind for functions#18295
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors semantic scope handling for functions to reduce duplicate work and enable better inlining, while preserving existing binding semantics for function declarations vs expressions.
Changes:
- Introduces
SemanticBuilder::create_scopeto construct a scope (including unresolved reference stack management) without immediately entering it. - Updates
Visit for SemanticBuilder::enter_scopeto delegate tocreate_scope, preserving previous behavior. - Refactors
visit_functionto:- Apply strict mode flags once,
- Create the function scope once via
create_scope, - Call
Function::bindexactly once while maintaining the existing behavior of binding declarations in the parent scope and expressions in the function’s own scope.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2f58b37 to
d0f8dc7
Compare
|
Doesn't produce the desired perf improvement! 🤷 It makes the code more complicated, and has no apparent benefit, so closing. |

Previously
visit_functionhad 2 calls toFunction::bind- depending on whether function is a declaration or expression, we calledbindbefore or after entering the scope.Instead, only have 1 call to
Function::bindand enter the scope either before or after it depending on declaration/expression.The scope is created before call to
bindeither way, but we just change when we enter that scope depending on the function type.Hopefully this means that
Function::bindcan now be inlined intovisit_function.To facilitate this change, move the code for creating a scope out of
enter_scopeinto a new methodcreate_scope.create_scopecreates a scope but just doesn't enter it yet.