Files
hakorune/apps/tests/loop_continue_else_simple.hako

26 lines
542 B
Plaintext
Raw Permalink Normal View History

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>
2025-12-07 19:00:12 +09:00
// Phase 33-19: Pattern B test - else-side continue (simplified)
// Tests: if (cond) { body } else { continue }
// This version uses a hardcoded constant instead of variable M
static box Main {
main(args) {
local i = 0
local sum = 0
loop(i < 5) {
i = i + 1
// Pattern B: Process when i != 5, continue when i == 5
if (i != 5) {
sum = sum + i
} else {
continue
}
}
// Expected: sum = 1 + 2 + 3 + 4 = 10
// (i=5 is skipped by continue)
print(sum)
return 0
}
}