Files
hakorune/tools/selfhost/test_pattern3_if_phi_no_break.hako
nyash-codex 701f1fd650 feat(joinir): Phase 164 Pattern3 (If-Else PHI) validation complete
- Created 4 representative test cases for Pattern3 patterns:
  * test_pattern3_if_phi_no_break.hako - Core Pattern3 (if-else PHI, no break/continue)
  * test_pattern3_skip_whitespace.hako - Pattern3+break style (routed to Pattern2)
  * test_pattern3_trim_leading.hako - Pattern3+break style (routed to Pattern2)
  * test_pattern3_trim_trailing.hako - Pattern3+break style (routed to Pattern2)

- Validated Pattern3_WithIfPhi detection:
  * Pattern routing: Pattern3_WithIfPhi MATCHED confirmed
  * JoinIR lowering: 3 functions, 20 blocks → 8 blocks (successful)
  * [joinir/freeze] elimination: Complete (no errors on any test)

- Clarified pattern classification:
  * Pattern3_WithIfPhi handles if-else PHI without break/continue
  * Loops with "if-else PHI + break" are routed to Pattern2_WithBreak
  * Break takes priority over if-else PHI in pattern detection

- Cumulative achievement (Phase 162-164):
  * Pattern1: 6 loops working 
  * Pattern2: 5 loops working 
  * Pattern3 (no break): 1 loop working 
  * Pattern3+break (as Pattern2): 3 loops working 
  * Total: 15 loops covered, zero [joinir/freeze] errors

- Updated CURRENT_TASK.md with Phase 164 section and findings

Next: Phase 165 Pattern4 (continue) validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-06 16:22:38 +09:00

31 lines
891 B
Plaintext

// Phase 164: Test Pattern3 (If-Else PHI) without break
// Pattern3 is: if-else PHI with NO break, NO continue
// Example: Accumulate result with conditional assignment
// Simulates: loop(i < n) { if condition { result = f(result) } else { result = g(result) } i++ }
static box Main {
main(args) {
// Accumulate sum with conditional increment
// Pattern: if-else PHI where variable gets different values in both branches
local i = 0
local sum = 0
local n = 5
loop(i < n) {
// If-else PHI: sum gets different values in each branch
if i == 2 {
sum = sum + 10 // Branch 1: add 10
} else {
sum = sum + 1 // Branch 2: add 1
}
i = i + 1
}
// Output result
print("Pattern3 (If-Else PHI, no break) test")
print("Final sum: " + ("" + sum))
print("Expected: 1 + 1 + 10 + 1 + 1 = 14")
return 0
}
}