## 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>
27 lines
552 B
Plaintext
27 lines
552 B
Plaintext
// Phase 33-19: Pattern B test - else-side continue
|
|
// Tests: if (cond) { body } else { continue }
|
|
// This should be normalized to: if (!cond) { continue } else { body }
|
|
|
|
static box Main {
|
|
main(args) {
|
|
local i = 0
|
|
local sum = 0
|
|
local M = 5
|
|
|
|
loop(i < M) {
|
|
i = i + 1
|
|
// Pattern B: Process when i != M, continue when i == M
|
|
if (i != M) {
|
|
sum = sum + i
|
|
} else {
|
|
continue
|
|
}
|
|
}
|
|
|
|
// Expected: sum = 1 + 2 + 3 + 4 = 10
|
|
// (i=5 is skipped by continue)
|
|
print(sum)
|
|
return 0
|
|
}
|
|
}
|