Repository navigation
Handle loop backedges across sibling scopes - #121
Merged
AjayBrahmakshatriya merged 1 commit intoSep 23, 2026
Merged
Conversation
Add a normalization pass that copies the continuation of a loop label into out-of-scope backedges, restoring the structure expected by the loop finder. Hoist declarations copied during normalization, retain labels with non-local users, and add sample67 regression coverage.
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
Fixes #119.
Loop backedges usually target a label in the current statement block or
one of its parent scopes. However, first-stage compiler optimizations
such as tail merging or loop rotation can place the label and backedge
in sibling scopes.
The existing loop finder cannot recognize this structure and may remove
the label while leaving its goto behind, producing invalid generated
code.
This PR adds a normalization pass before loop discovery. For each
sibling-scope backedge, the pass:
parent, restoring the structure expected by the loop finder.
return.
initializations on the original and copied execution paths.
cannot be normalized.
Declaration splitting helpers previously local to the for-loop finder
are moved into a shared utility for use by the normalization logic.
Tests
Added
sample67covering:Golden outputs are included for both normal variable extraction and
variable-name recovery.
Validated with:
make TEST=sample67 runmake BUILD_DIR=/tmp/buildit-varnames RECOVER_VAR_NAMES=1 TEST=sample67 run