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:
@ -1,5 +1,14 @@
|
||||
# Self Current Task — Now (main)
|
||||
|
||||
## 2025‑12‑15:Phase 132 完了 ✅
|
||||
|
||||
**Phase 132: LLVM Exit PHI=0 根治修正 完了!**
|
||||
- ループ exit PHI が 0 を返す問題を根治解決
|
||||
- 原因(2層): (1) JoinIR/Boundary が exit 値を境界に渡していない、(2) LLVM Python が PHI を落とす/上書きする
|
||||
- 修正: Pattern 1 で exit 値を明示的に渡す + `predeclared_ret_phis` 使用 + `builder.vmap` の PHI 保護
|
||||
- 結果: `/tmp/p1_return_i.hako` が 3 を返す(VM 一致)
|
||||
- 詳細: `investigations/phase132-llvm-exit-phi-wrong-result.md`
|
||||
|
||||
## 2025‑12‑14:現状サマリ
|
||||
|
||||
(補足)docs が増えて迷子になったときの「置き場所ルール(SSOT)」:
|
||||
@ -79,7 +88,8 @@
|
||||
- `docs/development/current/main/phase131-2-box-resolution-map.md`
|
||||
- LLVM(Python llvmlite)lowering の棚卸し(Phase 131-3..10):
|
||||
- `docs/development/current/main/phase131-3-llvm-lowering-inventory.md`
|
||||
- 状態: Case B(Pattern1/loop_min_while)は EMIT/LINK/RUN まで復旧済み。残りは Case C の JoinIR ループパターン穴。
|
||||
- 状態: Case B(Pattern1/loop_min_while)は EMIT/LINK/RUN まで復旧済み。Phase 132 で `return i` の VM/LLVM parity を固定。
|
||||
- Case C は別途 “Case C docs” を SSOT にして追跡する(状況は更新されるので、この箇所では断定しない)
|
||||
- Case C の調査と実装計画:
|
||||
- `docs/development/current/main/phase131-11-case-c-summary.md`
|
||||
- `docs/development/current/main/case-c-infinite-loop-analysis.md`
|
||||
|
||||
Reference in New Issue
Block a user