Repository navigation
Fix parsing of nested for-loops that re-iterate the outer collection - #341
Merged
Merged
Conversation
Closed
Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix nested loops failure in mean value calculation
Fix parsing of nested for-loops that re-iterate the outer collection
Oct 22, 2026
samwaseda
approved these changes
Oct 22, 2026
samwaseda
marked this pull request as ready for review
October 22, 2026 09:32
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #341 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 53 53
Lines 4135 4135
=======================================
Hits 4133 4133
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@liamhuber Maybe we should talk whether this is a valid way of using nested for loops, because we could also argue that |
Closed
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.
Summary
A for-loop nested inside another for-loop failed to parse when the inner loop iterated over the same collection as the outer one. The parser raised
KeyError: Symbol 'w' is not in scope:Related Issue(s)
Resolves the nested-loop failure reported in #340.
Backward Compatibility
No breaking changes. Previously, referencing the iterated collection inside its own loop body raised a
KeyError. It is now accepted. All existing unit tests pass.Detailed Description
Cause. When a for-loop body was forked, the iterated symbol
rwas renamed to the loop variablevandrwas dropped from the body's scope. An innerfor w in rthen could not findr, sowwas never registered.Changes in
parsers/for_parser.py:parse_for_nodekeeps the iterated collection's port (r) in the body scope alongside the loop variable, viaadded_symbols. The body can then useras a broadcast input whilevis scattered from the same for-node port._wire_inputsdedupes for-nodeinputs, sincercan now appear as both a broadcast and a scattered port.Resulting recipe. The outer for-node has inputs
[x, r]. Its body has inputs[x, r, v], withvfed fromras the scattered edge andrfed fromras the broadcast edge.Verification. The issue's workflow now parses and evaluates to
2.0, both called directly and via its recipe; I computed the expected value by hand. I added a regression test,TestNestedLoops, totests/integration/parsers/test_parsing_for_nodes.py. It checks the ports of both the outer and inner for-nodes.