Phase 114 validates that if-only lowering correctly handles cases with: - Early return in the if-only branch - Post-if statements that execute on the else path - Different return values from each path Fixture: apps/tests/phase114_if_only_return_then_post_min.hako - Expected output: 7\n2 - f(1): condition true → early return 7 - f(0): condition false → x=1+1=2, return 2 Testing: - VM backend: phase114_if_only_return_then_post_vm.sh ✅ - LLVM EXE backend: phase114_if_only_return_then_post_llvm_exe.sh ✅ - Regression: Phase 103/113 maintained ✅ Implementation: No new code required - validates existing if-only exit line routing and post-if statement processing. Documentation: - docs/development/current/main/phases/phase-114/README.md - Updated: 10-Now.md, 01-JoinIR-Selfhost-INDEX.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 114: if-only return+post parity
Status: DONE
Background
Phase 114 extends if-only JoinIR lowering to support cases where:
- The if-only branch contains an early return
- Post-if statements exist after the if block
- The function eventually returns a value from the post-if path
This pattern is common in early-exit optimization code where certain conditions trigger an immediate return, while the normal flow continues with additional processing.
Test Fixture
File: apps/tests/phase114_if_only_return_then_post_min.hako
// Phase 114: if-only return+post parity
// Tests: early return in if-only with post-if statements
static box Main {
f(flag) {
local x = 1
if flag == 1 { return 7 }
x = x + 1
return x
}
main() {
print(f(1))
print(f(0))
return "OK"
}
}
Expected Output:
7
2
Logic:
f(1): condition true → early return 7f(0): condition false → x=1+1=2, return 2
Implementation
This pattern was already supported by the existing JoinIR if-only lowering infrastructure:
- If-select pattern recognition
- Early return handling via exit line routing
- Post-if statement processing in the else path
No new implementation was required - Phase 114 validates that this pattern works correctly in both VM and LLVM backends.
Testing
Smoke Tests
-
VM Backend:
tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_vm.shbash tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_vm.sh -
LLVM EXE Backend:
tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_llvm_exe.shbash tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_llvm_exe.sh
Both tests run with:
NYASH_DISABLE_PLUGINS=1(core path only)HAKO_JOINIR_STRICT=1(strict validation)
Regression Tests
Verified backward compatibility with:
- Phase 103: if-only early return (both branches return)
- Phase 113: if-only partial assign (one branch assigns)
All regression tests pass without modifications.
Verification Commands
# Quick VM test
bash tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_vm.sh
# Full LLVM EXE test (requires plugins)
bash tools/smokes/v2/profiles/integration/apps/phase114_if_only_return_then_post_llvm_exe.sh
# Regression verification
bash tools/smokes/v2/profiles/integration/apps/phase103_if_only_early_return_vm.sh
bash tools/smokes/v2/profiles/integration/apps/phase113_if_only_partial_assign_vm.sh
bash tools/smokes/v2/profiles/integration/apps/phase113_if_only_partial_assign_llvm_exe.sh
Architecture Notes
Pattern Coverage
Phase 114 completes the if-only pattern matrix:
| Pattern | Phase | Description |
|---|---|---|
| Both branches return early | Phase 103 | if flag { return A } else { return B } |
| One branch assigns, else implicit | Phase 113 | if flag { x = value } (else preserves x) |
| One branch returns early, else continues | Phase 114 | if flag { return A }; post-code; return B |
Box Theory Alignment
This implementation follows Box Theory modularization principles:
- Single responsibility: If-only lowering handles one pattern variation
- Separation of concerns: Exit line routing is independent from assignment merging
- Reusability: Post-if statement processing reuses existing boundary SSA infrastructure
- Fail-Fast: No fallback paths - pattern either matches or explicitly fails
Exit Line Routing
The key to Phase 114 is proper exit line routing:
- Early return: Creates an exit line directly to function return
- Post-if path: Continues to post-if statements, then returns
- No join point: The two paths never merge (one exits early)
This is handled by the existing ExitLineReconnector Box.