Repository navigation
feat(ir): move and splice statements, blocks and CFGs in Rewriter - #848
Open
alexcgatea wants to merge 5 commits into
Open
alexcgatea wants to merge 5 commits into
alexcgatea wants to merge 5 commits into
Conversation
Add replace_uses_if, replace_all_uses_except_stmt and replace_all_uses_except_stmts, which redirect only the use sites a predicate accepts. ReplacedUses is recorded only once the old value has no uses left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The event log now only grows while a Rewriter lives, so positions in events() stay valid. Tests track positions with an EventCursor helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves record MovedStatement; walk_mut rejects moving the visited statement in link-following orders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore/after Moves every non-terminator statement of a block next to an anchor and redirects its arguments; records SplicedBlock, which walk_mut checks. Drops the planned block move (step 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves every block of a CFG after an anchor block in another CFG; records SplicedCfg. walk_mut now records a VisitedPlace (block and CFG) before each visit to check splices against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Adds the
Rewriteroperations for code motion: moving statements, splicing a block's statements, and splicing a whole CFG. Walks now detect when the statement being visited is moved.New operations
replace_uses_if,replace_all_uses_except_stmt(s)replace_all_usesrestricted to selected use sitesmove_before/move_aftersplice_block_before/splice_block_aftersplice_cfg_afterEach records a new event (
MovedStatement,SplicedBlock,SplicedCfg). Moving a statement into its own bodies, or splicing a block or CFG into itself, is rejected (MovedIntoItself,SplicedIntoItself,CfgSplicedIntoItself).API changes
drain_eventsis replaced byinto_events(self), so the event log only grows while aRewriterlives, and positions in it stay valid.Walk safety
Moving or splicing the statement being visited breaks pre-order, post-order and BFS walks, which find the next statement through the visited one.
walk_mutnow checks theRewriter's event log after each visit (MovedStatement,SplicedBlock,SplicedCfg, compared against aVisitedPlacerecorded before the visit) and reportsWalkError::VisitedMoved. Reverse BFS orders, which build their order up front, still allow it. A loop driving a cursor by hand recordsVisitedPlace::of(stage, stmt)and the event-log length before each visit, and callsWalkOrder::check_not_moved_sinceitself.