docs: add MIR13 mode doc and set PHI-off as default; bridge lowering split (if/loop/try); llvmlite resolver stabilization; curated runner default PHI-off; refresh CURRENT_TASK.md
This commit is contained in:
16
docs/development/current/self_current_task/00-Overview.md
Normal file
16
docs/development/current/self_current_task/00-Overview.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Self Current Task — Overview (main)
|
||||
|
||||
目的
|
||||
- main ブランチで Core‑13(MIR13)前提の制御フローを整備し、LLVM/Cranelift(EXE)/VM に綺麗に降ろす土台を完成させる。
|
||||
- 箱言語の既存命令セット(Branch/Jump/Phi 他)を活かし、continue/break を新命令なしで表現する。
|
||||
|
||||
前提と指針
|
||||
- MIR13 前提(純化モードを含む)。
|
||||
- ループは canonical 形(preheader → header → body → latch → header、exit は単一)。
|
||||
- continue/break は分岐のみで表現(continue→ヘッダ/ラッチ、break→単一 exit)。
|
||||
- Verifier(支配関係/SSA)緑を最優先。post‑terminated 後の emit 禁止、合流点を明確化。
|
||||
|
||||
スコープ外
|
||||
- 新規 MIR 命令の追加。
|
||||
- try/finally と continue/break の相互作用(次段)。
|
||||
|
||||
62
docs/development/current/self_current_task/10-Now.md
Normal file
62
docs/development/current/self_current_task/10-Now.md
Normal file
@ -0,0 +1,62 @@
|
||||
# Self Current Task — Now (main)
|
||||
|
||||
2025‑09‑08:現状と直近タスク(selfhosting)
|
||||
|
||||
## 🔴 重要:ループビルダーのバグ発見(詳細調査完了)
|
||||
|
||||
### 問題詳細
|
||||
- **症状**: dep_tree_min_string.nyashがVM実行でエラー `Invalid value: Value %57 not set`
|
||||
- **発生箇所**: `loop(i + m <= n) { if ... { return 1 } i = i + 1 }`のような構造
|
||||
|
||||
### 根本原因(深掘り調査結果)
|
||||
- **ループビルダーの致命的欠陥**: `build_statement`が親ビルダーに単純委譲するだけ
|
||||
```rust
|
||||
// src/mir/loop_builder.rs:397-399
|
||||
fn build_statement(&mut self, stmt: ASTNode) -> Result<ValueId, String> {
|
||||
self.parent_builder.build_expression(stmt) // スコープ管理が失われる!
|
||||
}
|
||||
```
|
||||
- **block_var_mapsの不完全性**: preheaderとlatchの2箇所しか保存しない
|
||||
- ループ内if文で生成される中間ブロックの変数状態が保存されない
|
||||
- 結果として変数の最終値が追跡できない
|
||||
|
||||
### 🎯 「箱を下に積む」解決策
|
||||
Nyashの開発哲学「Everything is Box」に従い、スコープも箱化する:
|
||||
|
||||
1. **ScopeBox構造の導入**
|
||||
```rust
|
||||
struct ScopeBox {
|
||||
block_id: BasicBlockId,
|
||||
variables: HashMap<String, ValueId>,
|
||||
parent: Option<Box<ScopeBox>>, // 親スコープへの参照
|
||||
}
|
||||
```
|
||||
|
||||
2. **全BasicBlockで変数スナップショットを保存**
|
||||
- ブロック遷移時に自動的に変数状態を箱として保存
|
||||
- 階層的な変数解決(現在の箱→親の箱→...)
|
||||
|
||||
3. **最小限の修正案**
|
||||
- `build_statement`でブロック遷移を検出し、変数マップを保存
|
||||
- phi node作成時に適切な箱から値を取得
|
||||
|
||||
## 進捗
|
||||
- MIR ビルダー(self_main)へ Loop CFG/continue/break を移植(単一 exit + 単一 backedge、post‑terminated 禁止)。
|
||||
- dep_tree(string最小版)の実装完了も、上記バグにより実行不可。
|
||||
|
||||
## 直近タスク(優先度順)
|
||||
1. **🔥 ループビルダーのバグ修正**(ブロッカー)
|
||||
- **推奨案**: 「箱を下に積む」アプローチで最小限の修正
|
||||
- `build_statement`を改修してブロック遷移検出
|
||||
- 各ブロックの変数状態を自動的に箱として保存
|
||||
- 実装工数: 中程度(既存構造を活用)
|
||||
- 代替案A: ループビルダーの根本的な再設計(工数大)
|
||||
- 代替案B: 一時的なワークアラウンド(dep_tree_min_string.nyashの書き換え)
|
||||
2. dep-tree 深さ1(直下 include)を children に反映(行ベースの素朴抽出、`//`/`#` 行コメントスキップ)。
|
||||
3. `make dep-tree` 結果の JSON 形を確認(先頭 `{`、必須キー、children のリーフが path のみ)。
|
||||
4. その後、深さ2→任意深さ(max-depth=64、visited)を段階的に解禁。
|
||||
|
||||
代表コマンド
|
||||
- ビルド: `cargo build --release`
|
||||
- 最小 dep-tree: `./target/release/nyash --backend vm apps/selfhost/tools/dep_tree_min_string.nyash`
|
||||
- 生成: `make dep-tree`(`tmp/deps.json`)
|
||||
@ -0,0 +1,9 @@
|
||||
# Self Current Task — Decisions (main)
|
||||
|
||||
2025‑09‑08
|
||||
- ループ制御は既存命令(Branch/Jump/Phi)で表現し、新命令は導入しない。
|
||||
- Builder に loop_ctx({head, exit})を導入し、continue/break を分岐で降ろす。
|
||||
- Verifier の支配関係/SSA を崩さないよう、単一 exit と post‑terminated 後の emit 禁止を徹底。
|
||||
- VInvoke(vector 経路)の戻り値は、短期は「既知メソッドの整数返り」を特例扱いで保持し、
|
||||
中期は nyash.toml の戻り型ヒント or NyRT シムの期待フラグで正道化。
|
||||
|
||||
15
docs/development/current/self_current_task/30-Backlog.md
Normal file
15
docs/development/current/self_current_task/30-Backlog.md
Normal file
@ -0,0 +1,15 @@
|
||||
# Self Current Task — Backlog (main)
|
||||
|
||||
短期
|
||||
- continue/break 降ろしの実装と単体/統合テストの追加。
|
||||
- Verifier の支配関係/SSA の確認強化(ループ exit 合流の一意性チェック)。
|
||||
- LLVM/Cranelift EXE スモーク(単純/ネスト/継続/脱出)。
|
||||
|
||||
中期
|
||||
- VInvoke(vector)戻り型の正道化(トムル記述 or NyRT 期待フラグ)。
|
||||
- ループ式として値を返す仕様が必要になった場合の設計(現状不要)。
|
||||
|
||||
周辺
|
||||
- selfhosting-dev への取り込みと Ny ツールでの continue/break 使用解禁。
|
||||
- docs 更新(言語ガイドに continue/break の記法・制約を明記)。
|
||||
|
||||
Reference in New Issue
Block a user