feat(llvm): Phase 132 - Pattern 1 exit value parity fix + Box-First refactoring
## Phase 132: Exit PHI Value Parity Fix ### Problem Pattern 1 (Simple While) returned 0 instead of final loop variable value (3) - VM: RC: 3 ✅ (correct) - LLVM: Result: 0 ❌ (wrong) ### Root Cause (Two Layers) 1. **JoinIR/Boundary**: Missing exit_bindings → ExitLineReconnector not firing 2. **LLVM Python**: block_end_values snapshot dropping PHI values ### Fix **JoinIR** (simple_while_minimal.rs): - Jump(k_exit, [i_param]) passes exit value **Boundary** (pattern1_minimal.rs): - Added LoopExitBinding with carrier_name="i", role=LoopState - Enables ExitLineReconnector to update variable_map **LLVM** (block_lower.py): - Use predeclared_ret_phis for reliable PHI filtering - Protect builder.vmap PHIs from overwrites (SSOT principle) ### Result - ✅ VM: RC: 3 - ✅ LLVM: Result: 3 - ✅ VM/LLVM parity achieved ## Phase 132-Post: Box-First Refactoring ### Rust Side **JoinModule::require_function()** (mod.rs): - Encapsulate function search logic - 10 lines → 1 line (90% reduction) - Reusable for Pattern 2-5 ### Python Side **PhiManager Box** (phi_manager.py - new): - Centralized PHI lifecycle management - 47 lines → 8 lines (83% reduction) - SSOT: builder.vmap owns PHIs - Fail-Fast: No silent overwrites **Integration**: - LLVMBuilder: Added phi_manager - block_lower.py: Delegated to PhiManager - tagging.py: Register PHIs with manager ### Documentation **New Files**: - docs/development/architecture/exit-phi-design.md - docs/development/current/main/investigations/phase132-llvm-exit-phi-wrong-result.md - docs/development/current/main/phases/phase-132/ **Updated**: - docs/development/current/main/10-Now.md - docs/development/current/main/phase131-3-llvm-lowering-inventory.md ### Design Principles - Box-First: Logic encapsulated in classes/methods - SSOT: Single Source of Truth (builder.vmap for PHIs) - Fail-Fast: Early explicit failures, no fallbacks - Separation of Concerns: 3-layer architecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -12,9 +12,24 @@
|
||||
| B2 | `/tmp/case_b_simple.hako` | ✅ | ✅ | ✅ | **PASS** - Simple print(42) without loop works |
|
||||
| C | `apps/tests/llvm_stage3_loop_only.hako` | ✅ | ✅ | ⚠️ | **TAG-RUN** - Loop ok; print/concat path segfaults |
|
||||
|
||||
## Phase 132 Update (2025-12-15)
|
||||
|
||||
✅ **MAJOR FIX**: Exit PHI wrong result bug fixed!
|
||||
- **Issue**: Pattern 1 の `return i` が LLVM だけ 0 を返す(VM は 3)
|
||||
- **Test**: `/tmp/p1_return_i.hako` が VM/LLVM ともに 3 を返すようになった
|
||||
- **Root Cause (two-layer)**:
|
||||
- JoinIR/Boundary: exit 値が境界を通っていなかった(exit_bindings / Jump args)
|
||||
- LLVM Python: builder.vmap の PHI placeholder が上書きされ、`ret` が 0 を参照
|
||||
- **Fix**:
|
||||
- JoinIR/Boundary: Pattern 1 で exit 値を明示的に渡す + LoopExitBinding を境界へ設定
|
||||
- LLVM Python: `predeclared_ret_phis` で PHI 所有を追跡し、PHI placeholder を上書きしない
|
||||
- **Details**:
|
||||
- Investigation: [phase132-llvm-exit-phi-wrong-result.md](investigations/phase132-llvm-exit-phi-wrong-result.md)
|
||||
- Phase summary: [phases/phase-132/README.md](phases/phase-132/README.md)
|
||||
|
||||
## Root Causes Identified
|
||||
|
||||
### 1. TAG-EMIT: Loop PHI → Invalid LLVM IR (Case B)
|
||||
### 1. TAG-EMIT: Loop PHI → Invalid LLVM IR (Case B) ✅ FIXED (Phase 131-10)
|
||||
|
||||
**File**: `apps/tests/loop_min_while.hako`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user