Files
hakorune/docs/private/roadmap/phases/phase-31.3/PLAN.md

58 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# PLAN — Selfhost LoopForm 実装Phase31.3
## 0. 背景と狙い
- 既に Rust 側では LoopFormBox を標準化(ヘッダ/条件/ボディ/ラッチ/出口)。
- Selfhost 側も同形へ統一し、MIR 形状・Verifier・VM/LLVM パリティを一本化する。
## 1. 要件(技術)
- 形状: Header → Cond → Branch(Body/Exit), Body → Latch → Header, Exit → ret
- PHI: ブロック先頭のみ。ExitPHI は break/正常脱出の統合。
- continue: Latch へ。break: Exit へ。いずれも値スナップショットを ExitPHI 入力に追加。
- ret 支配: ret が参照する値は Exit 内定義 or ExitPHIFailFast
## 2. 箱設計(箱言語)
- LoopFormBox
- `new(preheader_bb) -> LoopFormBox`
- `build_loop(loop_builder, condition, preheader_vars, body) -> LoopStructure`
- LoopStructure
- `header_bb, condition_bb, body_bb, latch_bb, exit_bb`
- 依存 / 委譲
- LoopCarrierAnalyzerBox: ループキャリア変数preheader∩body assigns検出
- PhiBuilderBox: ExitPHI の一元生成
- LoopTraceBox: 最小トレース
## 3. 実装ステップ
- P1: 構造だけExitPHI 生成まで。continue/break は Latch/Exit へジャンプのみ。
- P2: continue/break のスナップショット統合。if 内分岐の merge 処理then/else から merge へ)。
- P3: Verifier 強化Exit 支配/PHI先頭限定/許可エッジ)+ MIR スナップショットテスト。
- P4: Selfhost Compilerwhile 糖衣の降下・接続。Gate 撤退既定ON
## 4. 失敗時方針FailFast
- 形状破れ(ヘッダ/ラッチ/出口欠落): 検出時に即エラー。
- PHI 不正(先頭以外/Incoming 欠落): Verifier で拒否。
- continue/break の未設定latch/exit 無): 検出時に即エラー。
## 5. ENV/Gate開発用
- `HAKO_USE_LOOPFORM_BOX=1`既定ON
- `HAKO_VERIFY_PHI_STRICT=1`dev/profile 限定)
- `HAKO_LOOP_TRACE=1`(最小トレース)
## 6. テスト(最低限)
- quick
- while 最小: 0→5 加算、最終結果
- continue: 3 をスキップ
- break: 3 で脱出
- if 内分岐continue/break 混在
- MIR スナップショット: ExitPHI 形状、ret 値支配
- integration
- VM↔LLVM パリティ: while/continue/break の代表
## 7. ロールアウト
- dev で Gate ON既定。quick/integration 緑維持で既定ON継続。
- 旧レガシー撤退済31.2)。影響点は Selfhost 側のみ。
## 8. リスクと対策
- 例外/throw が導入された後の整合 → 次フェーズで tryfinally ガードを設計。
- ループ内に複数の return → 現行仕様は Exit 統一。早期 return は禁止または正規化で Exit へ統一。