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

67 lines
2.9 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.

# Phase31.3 — Selfhost LoopForm 実装計画Hakorne Script
目的
- Rust 側で安定化した LoopFormBoxヘッダ/条件/ボディ/ラッチ/出口の正規形を、SelfhostHakorne Scriptにも導入し、IR/MIR/VM の“ループの顔”を一本化する。
- PHI の生成位置・支配関係・continue/break の意味論をドキュメントスモークで固定し、FailFast を徹底する。
範囲
- Selfhost VM/Builder/Emitter の最小セットwhile/continue/break/if 内分岐)。
- 依存箱LoopCarrierAnalyzerBox, PhiBuilderBox, LoopTraceBoxの薄実装または委譲。
- LLVM ハーネスはパリティ確認のみ(機能追加なし)。
非対象(本フェーズ外)
- for/foreach 糖衣の拡張(次期)
- 例外伝播/tryfinally のループ内整合(次期)
受け入れ基準Definition of Done
- MIR 形状
- Loop は Header/Cond/Body/Latch/Exit を持つ単純 CFG に正規化。
- PHI はブロック先頭のみ。Exit の ret 値は Exit 内定義または ExitPHI を必須。
- 継続/脱出
- continue は Latch に、break は Exit にジャンプ。PHI 入力は continue/break を統合。
- FailFast
- 未定義のレガシー命令BoxCall/ExternCall/NewBox/Print/旧Loop 等)は Verifier が拒否。
- パリティ
- VM↔LLVM で代表ループwhile/continue/break/分岐)出力が一致(数本)。
- スモーク
- quick/integration で緑Loop 関連。MIR スナップショットで PHI 形状を固定。
参考(最小 MIR 形状スナップショット)
```
{
"functions": [
{ "name": "main",
"blocks": [
{"id": 0, "instructions": [
{"op":"jump", "target": 1}
]},
{"id": 1, "instructions": [
{"op":"phi", "dst": 10, "values": [{"block":0,"value":1},{"block":2,"value":11}]},
{"op":"branch", "cond": 3, "then": 2, "else": 3}
]},
{"id": 2, "instructions": [
{"op":"jump", "target": 1}
]},
{"id": 3, "instructions": [
{"op":"phi", "dst": 20, "values": [{"block":1,"value":10},{"block":2,"value":12}]},
{"op":"ret", "value": 20}
]}
]
}
]
}
```
要点
- ヘッダ/Exit の先頭にのみ `op:"phi"` が現れる。
- `ret.value` は Exit 内で定義された `dst`(例では `20`)を参照する。
進め方(小さく段階導入)
- P1: LoopFormBox の最小実装構造生成ExitPHI 生成)
- P2: continue/break の値スナップショット統合if 内分岐の merge 処理
- P3: Verifier 強化Exit 支配PHI 先頭限定Latch→Header のみ許可)
- P4: Selfhost Compiler への接続while 糖衣→LoopForm 降下)+ Env Gate 撤退既定ON
関連ドキュメント
- call 統一: `docs/reference/mir/call-unified.md`
- 旧ループ撤退: `docs/private/roadmap/phases/phase-31.2/`