compiler: merge reactive scopes across const StoreLocal #29095
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@jbonta nerd-sniped me into making this optimization during conference prep, posting this as a PR now that keynote is over.
Consider these two cases:
Previously, the former would create two reactive scopes (one for
cb
, one for the div) while the latter would only have a single scope for thediv
and its inline callback. The reason we created separate scopes before is that there's aStoreLocal 'cb' = t0
instruction in-between, and i had conservatively implemented the merging pass to not allow intervening StoreLocal instructions.The observation is that intervening StoreLocals are fine if the assigned variable's last usage is the next scope. We already have a check that the intervening lvalues are last-used at/before the next scope, so it's trivial to extend this to support StoreLocal.
Note that we already don't merge scopes if there are intervening terminals, so we don't have to worry about things like conditional StoreLocal, conditional access of the resulting value, etc.