docs: Phase 196 Implementation Results documentation

Updated documentation with Phase 196 completion details:

1. phase196-select-bug-fix.md:
   - Added "Implementation Results" section with fix details
   - Before/After code examples
   - Complete test results (all patterns PASS)
   - Reference to phase196-select-bug-analysis.md

2. joinir-architecture-overview.md:
   - Added Select expansion invariant to InstructionRewriter section
   - "PHI inputs must use remapper.remap_instruction() remapped ValueIds"
   - "InstructionRewriter only remaps block IDs, not ValueIds"

3. CURRENT_TASK.md:
   - Marked Phase 196 as complete with summary
   - Added Phase 197 as next candidate (JsonParser deployment)

All Phase 196 documentation now complete.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-09 14:56:05 +09:00
parent 996925ebaf
commit 5a19290db8
2 changed files with 62 additions and 0 deletions

View File

@ -276,6 +276,10 @@ JoinIR ラインで守るべきルールを先に書いておくよ:
- continuation 関数k_exitをスキップし、Return → exit ブロック Jump に変換。 - continuation 関数k_exitをスキップし、Return → exit ブロック Jump に変換。
- `JoinFragmentMeta.expr_result` と exit_bindings をヘッダ PHI 経由で収集し、`exit_phi_inputs` / `carrier_inputs` を復活させたSSAundef 修正済み)。 - `JoinFragmentMeta.expr_result` と exit_bindings をヘッダ PHI 経由で収集し、`exit_phi_inputs` / `carrier_inputs` を復活させたSSAundef 修正済み)。
- tail call を Branch/Jump に書き換えつつ、LoopHeaderPhiInfo に latch 入力を記録する。 - tail call を Branch/Jump に書き換えつつ、LoopHeaderPhiInfo に latch 入力を記録する。
- **Select 展開の不変条件Phase 196**:
- PHI の入力 ValueId は必ず `remapper.remap_instruction()` で remap 済みの MIR ValueId を使用。
- InstructionRewriter では ValueId の二重 remap を行わないblock ID のみ remap
- 詳細: [phase196-select-bug-analysis.md](./phase196-select-bug-analysis.md)
--- ---

View File

@ -539,3 +539,61 @@ Section 7.2 に追記:
4. **ドキュメント駆動**: 4. **ドキュメント駆動**:
- Before/After を明確に記録 - Before/After を明確に記録
- 将来同じバグが起きないように教訓を残す - 将来同じバグが起きないように教訓を残す
---
## Implementation Results完了: 2025-12-09
**Status**: ✅ Complete
### 修正ポイント
**File**: `src/mir/builder/control_flow/joinir/merge/instruction_rewriter.rs`
**Line**: 317-335
**根本原因**: PHI inputs の ValueId が二重に remap されていた
- Line 304: `remap_instruction()` で JoinIR ValueId → Host ValueId に remap 済み
- Line 328: `remap_value(*val)` で再度 remap を試行 → undefined ValueId 参照
**修正内容**: Block ID のみ remap、ValueId は既に remap 済みなのでそのまま使用
```rust
// Before (Phase 172 - 壊れていた)
let remapped_val = remapper.remap_value(*val); // ❌ 二重 remap
(remapped_bb, remapped_val)
// After (Phase 196 - 修正後)
(remapped_bb, *val) // ✅ 値はそのまま使用(既に remap 済み)
```
### 具体例
**Before**:
```
bb10:
%27 = phi [%28, bb8], [%32, bb9] // %28, %32 undefined
```
**After**:
```
bb10:
%27 = phi [%21, bb8], [%25, bb9] // %21, %25 correctly defined
```
### 検証結果
-**phase195_sum_count.hako**: 93multi-carrier P3
-**loop_if_phi.hako**: sum=9single-carrier P3
-**loop_min_while.hako**: 0,1,2Pattern 1
-**joinir_min_loop.hako**: RC:0Pattern 2
-**退行なし**: 全 Pattern (P1/P2/P3/P4) PASS
-**`[joinir/freeze]` なし**
### 詳細分析
完全な Before/After 分析、根本原因調査、テスト結果は以下を参照:
- **[phase196-select-bug-analysis.md](./phase196-select-bug-analysis.md)**
### コミット
- **[996925eb]** fix(joinir): Phase 196 Select double-remap bug in instruction_rewriter