feat(joinir): Phase 33-19 ContinueBranchNormalizer for unified continue handling
## Problem
Pattern 4 (loop with continue) needs to handle both:
- if (cond) { continue } (then-continue)
- if (cond) { body } else { continue } (else-continue)
Previously, else-continue patterns required separate handling, preventing unified processing.
## Solution
### 1. ContinueBranchNormalizer Implementation
New file: `src/mir/join_ir/lowering/continue_branch_normalizer.rs`
- Detects: `if (cond) { body } else { continue }`
- Transforms to: `if (!cond) { continue } else { body }`
- Enables uniform Pattern 4 handling of all continue patterns
- No-op for other if statements
### 2. Pattern 4 Integration
- Normalize loop body before lowering (line 140)
- Use normalized body for carrier analysis (line 169)
- Preserves existing then-continue patterns
### 3. Carrier Filtering Enhancement
Lines 171-178: Only treat updated variables as carriers
- Fixes: Constant variables (M, args) no longer misidentified as carriers
- Enables: Condition-only variables without carrier slot overhead
### 4. LoopUpdateAnalyzer Enhancement
- Recursively scan if-else branches for carrier updates
- Correctly detect updates in normalized code
## Test Results
✅ Pattern 3 (If PHI): sum=9
✅ Pattern 4 (Then-continue): 25 (1+3+5+7+9)
✅ Pattern 4 (Else-continue): New test cases added
✅ No SSA-undef errors
✅ Carrier filtering works correctly
## Files Changed
- New: continue_branch_normalizer.rs (comprehensive implementation + tests)
- Modified: pattern4_with_continue.rs (integrated normalizer)
- Modified: loop_update_analyzer.rs (recursive branch scanning)
- Modified: lowering/mod.rs (module export)
- Added: 3 test cases (then/else continue patterns)
## Impact
This enables JsonParserBox / trim and other continue-heavy loops to work with
JoinIR Phase 4 lowering, paving the way for Phase 166/170 integration.
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -23,6 +23,7 @@ pub mod bool_expr_lowerer; // Phase 168: Boolean expression lowering for complex
|
||||
pub mod carrier_info; // Phase 196: Carrier metadata for loop lowering
|
||||
pub mod common;
|
||||
pub mod condition_to_joinir; // Phase 169: JoinIR condition lowering helper
|
||||
pub mod continue_branch_normalizer; // Phase 33-19: Continue branch normalization for Pattern B
|
||||
pub mod loop_update_analyzer; // Phase 197: Update expression analyzer for carrier semantics
|
||||
pub mod loop_update_summary; // Phase 170-C-2: Update pattern summary for shape detection
|
||||
pub mod exit_args_resolver;
|
||||
|
||||
Reference in New Issue
Block a user