Files
hakorune/docs/development/current/main/phases/README.md

48 lines
1.8 KiB
Markdown
Raw Normal View History

# Phase ドキュメント
このフォルダは、実装フェーズPhase 131, Phase 33 等)ごとの詳細記録を保管します。
## 現在の Phase
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>
2025-12-15 03:17:31 +09:00
- **Phase 132**: Exit Values Parity (VM == LLVM)
2025-12-15 18:49:08 +09:00
- **Phase 133**: Promoted carrier join_idTrim修正
- **Phase 134**: Plugin loader best-effort loading
- **Phase 135**: ConditionLoweringBox allocator SSOTValueId 衝突の根治)
feat(mir): Phase 136 P0 - ValueId allocator SSOT 徹底(関数内経路から value_gen.next() 掃討) ## Summary Eliminates remaining `value_gen.next()` calls from function-context code paths, unifying all ValueId allocation through `MirBuilder::next_value_id()` SSOT allocator. ## Changes ### 1. Fixed `new_typed_value()` (src/mir/builder.rs:1068) **Before**: `let id = self.value_gen.next();` (bypasses function context) **After**: `let id = self.next_value_id();` (respects function context) This is a public API used in function context, so must use SSOT allocator to avoid collisions with reserved PHI dsts and function params. ### 2. Fixed test code (src/mir/builder.rs) **test_shadowing_binding_restore** (lines 1161, 1171): - Simulates function scope with `push_lexical_scope()` - Changed to `builder.next_value_id()` for function scope simulation **test_valueid_binding_parallel_allocation** (lines 1196-1216): - Tests ValueId/BindingId independence - Changed to `builder.next_value_id()` with note that Module context fallback preserves test intent ### 3. Verified Module context fallbacks (OK, no change needed) These already check `current_function.is_some()` and use `value_gen.next()` only as Module context fallback: - `src/mir/builder/utils.rs:43` - next_value_id() SSOT implementation - `src/mir/builder/utils.rs:436` - pin_to_slot() - `src/mir/builder/utils.rs:467` - materialize_local() - `src/mir/utils/phi_helpers.rs:69` - insert_phi_unified() ## Verification ```bash rg -n "value_gen\.next\(" src/mir --type rust | grep -v "Module context" | grep -v "//" # Result: Only comments/docs remain ``` ## Acceptance ✅ cargo test --release --lib - 997 passed ✅ phase135_trim_mir_verify.sh - PASS ✅ phase132_exit_phi_parity.sh - 3/3 PASS ✅ All function-context `value_gen.next()` eliminated ## Effect - **Collision prevention**: No more ValueId collisions between function-level allocations and reserved PHI dsts - **SSOT compliance**: All ValueId allocation flows through single allocator - **Contract enforcement**: Phase 135 P1 contract_checks will catch violations immediately 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 19:37:30 +09:00
- **Phase 136**: ValueId allocator SSOT 徹底(残存 value_gen.next() 掃討)
## Phase フォルダ構成(推奨)
```
phases/phase-131/
├── README.md (Phase 全体概要)
├── 131-03-llvm-lowering-inventory.md (LLVM 部分のテスト・検証)
├── 131-11-case-c-summary.md (Case C 実装サマリー)
└── phase131-11-case-c-root-cause-analysis.md (根本原因分析)
```
## 参照方法
1. **現在の Phase を知りたい** → [../10-Now.md](../10-Now.md)
2. **該当 Phase を詳しく知りたい** → フォルダを開く
3. **設計背景を知りたい** → [../design/](../design/README.md)
4. **調査ログを見たい** → [../investigations/](../investigations/README.md)
## Phase 命名規則
- **ファイル名**: `phase-<N>-<title>/` (例: `phase-131/`)
- **文書名**: `<N>-<NN>-<topic>.md` (例: `131-11-case-c-summary.md`)
- Phase 番号で自然にソート可能
- 同一 Phase 内で段階的に追跡可能
## 作成ルールSSOT
詳しくは [../DOCS_LAYOUT.md](../DOCS_LAYOUT.md) を参照。
-**置き場所**: `phases/phase-<N>/` 配下のみ
-**内容**: Phase の実装記録・進捗・チェックリスト・検証結果
-**避けるべき**: 複数 Phase で参照される設計・アーキテクチャ(→ design/ へ)
---
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>
2025-12-15 03:17:31 +09:00
**最終更新**: 2025-12-15