docs: Phase 116 DONE

Phase 116 完了ドキュメント化

## 更新内容

### Phase 116 README
- 背景: LLVM fragile pattern(keep+call merge)
- 実装内容: fixture, VM smoke, LLVM EXE smoke
- 検証コマンド
- 技術的詳細: JoinIR Pattern 1, PHI接続
- Lessons Learned: Box-First原則, Fail-Fast原則

### 10-Now.md
- Phase 116 完了エントリ追加
- 入口: `docs/development/current/main/phases/phase-116/README.md`

### 01-JoinIR-Selfhost-INDEX.md
- Phase 116 を JoinIR Phase リストに追加
- 番号の重複を修正(18-27に整理)

## 成果物

 片側元値保持、片側call結果のmergeパターンをVM/LLVM両方で固定
 output_validator.sh, llvm_exe_runner.sh 活用で統一的なテスト基盤
 回帰防止: Phase 115 維持確認

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-18 02:39:44 +09:00
parent ed38aa820a
commit 8440550b2f
3 changed files with 144 additions and 9 deletions

View File

@ -68,17 +68,19 @@ JoinIR の箱構造と責務、ループ/if の lowering パターンを把握
- `docs/development/current/main/phases/phase-114/README.md`
17. Phase 115: if-only call result merge parity関数呼び出し結果 merge
- `docs/development/current/main/phases/phase-115/README.md`
18. Phase 104: loop(true) break-only digitsVM + LLVM EXE
18. Phase 116: if-only keep+call merge parity片側元値保持、片側 call merge
- `docs/development/current/main/phases/phase-116/README.md`
19. Phase 104: loop(true) break-only digitsVM + LLVM EXE
- `docs/development/current/main/phases/phase-104/README.md`
19. Phase 107: json_cur find_balanced_* depth scanVM + LLVM EXE
20. Phase 107: json_cur find_balanced_* depth scanVM + LLVM EXE
- `docs/development/current/main/phases/phase-107/README.md`
20. Phase 108: Pattern2 policy router SSOT入口の薄さを固定
21. Phase 108: Pattern2 policy router SSOT入口の薄さを固定
- `docs/development/current/main/phases/phase-108/README.md`
21. Phase 109: error_tags hints SSOTFail-Fast + hint の語彙固定)
22. Phase 109: error_tags hints SSOTFail-Fast + hint の語彙固定)
- `docs/development/current/main/phases/phase-109/README.md`
22. MIR BuilderContext 分割の入口)
23. MIR BuilderContext 分割の入口)
- `src/mir/builder/README.md`
23. Scope/BindingIdshadowing・束縛同一性の段階移行
24. Scope/BindingIdshadowing・束縛同一性の段階移行
- `docs/development/current/main/phase73-scope-manager-design.md`
- `docs/development/current/main/PHASE_74_SUMMARY.md`
- `docs/development/current/main/PHASE_75_SUMMARY.md`
@ -86,16 +88,16 @@ JoinIR の箱構造と責務、ループ/if の lowering パターンを把握
- `docs/development/current/main/phase78-bindingid-promoted-carriers.md`
- `docs/development/current/main/phase80-bindingid-p3p4-plan.md`P3/P4 への配線計画)
- `docs/development/current/main/phase81-pattern2-exitline-contract.md`promoted carriers の ExitLine 契約検証)
22. Boxification feedbackPhase 7885 の振り返りと Phase 86 推奨)
25. Boxification feedbackPhase 7885 の振り返りと Phase 86 推奨)
- `docs/development/current/main/phase78-85-boxification-feedback.md`
23. Phase 86: Carrier Init Builder + Error Tags ✅
26. Phase 86: Carrier Init Builder + Error Tags ✅
- **Status**: COMPLETE (2025-12-13)
- **Modules**:
- `src/mir/builder/control_flow/joinir/merge/carrier_init_builder.rs` (+8 tests)
- `src/mir/join_ir/lowering/error_tags.rs` (+5 tests)
- **Achievements**: SSOT 確立CarrierInit → ValueId 生成統一、エラータグ中央化、DebugOutputBox 完全移行)
- **Impact**: 987/987 tests PASS, +13 unit tests, Single Responsibility validated
24. Phase 87: LLVM Exe Line SSOT ✅
27. Phase 87: LLVM Exe Line SSOT ✅
- **Status**: COMPLETE (2025-12-13)
- **SSOT**: `tools/build_llvm.sh` - Single pipeline for .hako → executable
- **Deliverables**:

View File

@ -1,5 +1,14 @@
# Self Current Task — Now (main)
## 2025-12-18Phase 116 完了 ✅
**Phase 116: if-only keep+call merge parity**
- if-only で片側が元値保持、片側が call 結果のパターンを VM/LLVM で固定
- Fixture: phase116_if_only_keep_plus_call_min.hako (expected: 10, 2)
- Smoke: VM + LLVM EXE parity 検証済み
- 回帰: Phase 115 維持確認
- 入口: `docs/development/current/main/phases/phase-116/README.md`
## 2025-12-18Phase 115 完了 ✅
**Phase 115: if-only call result merge parity**

View File

@ -0,0 +1,124 @@
# Phase 116: if-only keep+call merge parity
**Status**: ✅ DONE
**Date**: 2025-12-18
## 背景
LLVMバックエンドで壊れやすいパターンの固定: 片側が元値保持、片側がcall結果のmerge。
### 問題のパターン
```hako
fn f(x) { return x + 1 }
fn g(flag) {
local v = 10
if flag == 1 { v = f(1) }
// else側は暗黙的にv=10を保持
print(v)
}
g(0) // → 10 (元値保持)
g(1) // → 2 (f(1) = 1+1 = 2)
```
- **then側**: call結果でvを更新 (`v = f(1)`)
- **else側**: 元の値を保持 (`v = 10`)
- **merge地点**: 2つの異なるソース元値 vs call結果からのPHI
## 実装内容
### 1. テストフィクスチャ
**ファイル**: `apps/tests/phase116_if_only_keep_plus_call_min.hako`
最小限のケース:
- `g(0)``10` (元値保持)
- `g(1)``2` (call結果)
### 2. VM smoke test
**ファイル**: `tools/smokes/v2/profiles/integration/apps/phase116_if_only_keep_plus_call_vm.sh`
- `output_validator.sh` を使用して数値2行 `10\n2` を検証
- 実行条件: `NYASH_DISABLE_PLUGINS=1 HAKO_JOINIR_STRICT=1`
### 3. LLVM EXE smoke test
**ファイル**: `tools/smokes/v2/profiles/integration/apps/phase116_if_only_keep_plus_call_llvm_exe.sh`
- `llvm_exe_runner.sh` を利用plugin dlopen/cache/build-all SSOT
- `llvm_exe_build_and_run_numeric_smoke` で出力検証(`10\n2`
## 検証コマンド
```bash
# VM smoke test
bash tools/smokes/v2/profiles/integration/apps/phase116_if_only_keep_plus_call_vm.sh
# LLVM EXE smoke test
bash tools/smokes/v2/profiles/integration/apps/phase116_if_only_keep_plus_call_llvm_exe.sh
# 回帰テスト (Phase 115)
bash tools/smokes/v2/profiles/integration/apps/phase115_if_only_call_merge_llvm_exe.sh
```
## 技術的詳細
### JoinIR Pattern
このケースは **Pattern 1 (Simple If)** として処理される:
```
entry_block:
v = 10
if flag == 1 goto then_block else exit_block
then_block:
v = f(1)
goto exit_block
exit_block:
v_merged = PHI [v=10 from entry, v=f(1) from then]
print(v_merged)
```
### PHI接続の重要性
- **entry → exit**: 元値 (`10`) を直接伝播
- **then → exit**: call結果 (`f(1)`) を伝播
- **PHI**: 2つの異なる型のソース変数 vs call結果を正しくmerge
LLVM IRでは、これらが適切な型で統一される必要がある。
## 期待される効果
1. **LLVM安定性向上**: keep+call mergeパターンの回帰を防止
2. **PHI生成品質**: 異なるソースタイプのmerge処理の検証
3. **パリティ保証**: VM/LLVM両方で同じ動作を保証
## 関連Phase
- **Phase 115**: if-only call result merge (両側がcall)
- **Phase 114**: if-only PHI minimal (基本的なPHI)
- **Phase 33**: Box Theory Modularization (JoinIR architecture)
## Lessons Learned
### Box-First原則の適用
このPhaseでは、既存の箱化されたコンポーネントを活用:
-`output_validator.sh` による出力検証の統一
-`llvm_exe_runner.sh` によるLLVM実行の標準化
- ✅ テストインフラの再利用no reinvention
### Fail-Fast原則
- VM/LLVM両方でエラーを即座に検出
- `HAKO_JOINIR_STRICT=1` で厳密な検証を有効化
- フォールバック処理なし(エラーは明示的に失敗)
## Future Work
- **Phase 117+**: より複雑なmergeパターン両側keep、ネストしたcall等
- **最適化**: 元値保持の場合のPHI削減の可能性検討