Analysis: Follow state into the locals it is assigned to - #2289
Merged
Conversation
A template reads state and then names it something else. `<% total = @items.size %>` puts `@items` in `total`, and `<%= total %>` was attributed to nothing, so changing `@items` looked like it touched one node when it decides two. This is the same shape as a block parameter, which carries state under another name for as long as its block is open, and it is bound the same way. A local carries whatever its right hand side reads, which makes chains work without anything extra: `a = @items.size` then `b = a * 2` puts both `a` and `b` in reach of `@items`. Only the right hand side counts, so `@items == other` binds nothing, since a comparison assigns nothing. Scope is the block that made the assignment. A local first assigned inside a block is gone when the block closes, the way Ruby has it, so an alias set is snapshotted on entry and restored on exit instead of subtracting what was added. A partial's declared locals are its state, and `dependency_index` enumerated only instance variables and constants, so asking what a partial's `query` reaches returned nothing at all. They are enumerated now. All three languages, with the same five templates asserted in each. Rust and TypeScript reach the assignment through the prism node they already carry, and slice the right hand side by the offsets it gives them.
|
View your CI Pipeline Execution ↗ for commit 73127af
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request teaches the dependency analysis that a local assigned from a piece of state carries that state.
totalis@items, counted. Matching is by name, so nothing connected the two andtotalwas attributed to nothing, which meantherb dependenciesandherb actionview flowleft the paragraph out of what@itemsreaches.Follow up on #2288, which did the same for the names a block binds. This is the other way a state gets a second name.
An assignment binds the name only when its right hand side reads the state, and the name carries it for as long as the assignment is in scope.
acarries@itemsandbcarriesa, sobreaches back to@itemsthrough the chain.Three cases that look like assignments and are not:
<% other = 5 %>binds nothing, because nothing on the right reads the state.<% if total == @items.size %>is a comparison, andtotalis left alone.