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:
11
docs/development/current/llvm/00-Overview.md
Normal file
11
docs/development/current/llvm/00-Overview.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Self Current Task — Overview (llvm)
|
||||
|
||||
目的
|
||||
- LLVM AOT の Core‑13 前提化を完了し、VM と一致する代表ケースを安定化。
|
||||
- BitOps/Shift の構文着地に合わせ、AOT 側の IR 生成/実行互換を維持。
|
||||
|
||||
指針
|
||||
- Opaque Pointer 対応済(get_element_type 不使用)。
|
||||
- `env.box.new/_i64x` は NyRT shim に統一、引数は i64 正規化。
|
||||
- BinOp/Compare は i64/f64 必要分を網羅する。
|
||||
|
||||
17
docs/development/current/llvm/10-Now.md
Normal file
17
docs/development/current/llvm/10-Now.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Self Current Task — Now (llvm)
|
||||
|
||||
2025‑09‑08:現状と直近タスク
|
||||
- P0 完了(BitOps/Array/Echo/Map 緑)。
|
||||
- VInvoke(by‑name/by‑id vector) で戻り値マッピングの課題(ret_tag=3 でも 0 になる)。
|
||||
|
||||
直近タスク
|
||||
1) VInvoke 戻り値の短期特例:既知メソッド(例: MapBox.get)の整数返りは i64 として保持。
|
||||
2) by‑id vector(`nyash.plugin.invoke_tagged_v_i64`)も同様に統一。
|
||||
3) 受け入れ:
|
||||
- `NYASH_LLVM_VINVOKE_SMOKE=1` → `VInvokeRc: 42`
|
||||
- `NYASH_LLVM_VINVOKE_RET_SMOKE=1` → `Result: 42`
|
||||
|
||||
代表コマンド
|
||||
- `LLVM_SYS_180_PREFIX=$(llvm-config-18 --prefix) NYASH_LLVM_BITOPS_SMOKE=1 ./tools/llvm_smoke.sh release`
|
||||
- `NYASH_LLVM_VINVOKE_TRACE=1 NYASH_LLVM_VINVOKE_SMOKE=1 ./tools/llvm_smoke.sh release`
|
||||
|
||||
8
docs/development/current/llvm/20-Decisions.md
Normal file
8
docs/development/current/llvm/20-Decisions.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Self Current Task — Decisions (llvm)
|
||||
|
||||
2025‑09‑08
|
||||
- VInvoke(vector 経路)の戻り値:短期は既知メソッドの整数返りを i64 として保持(Unknown/Box でも整数扱いにする特例)。
|
||||
- 中期は正道へ:
|
||||
- nyash.toml に戻り型ヒント(primitive/handle/f64/bool)を追加し codegen に供給、または
|
||||
- NyRT シムに「期待戻り形式」フラグを追加し codegen から通知。
|
||||
|
||||
9
docs/development/current/llvm/30-Backlog.md
Normal file
9
docs/development/current/llvm/30-Backlog.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Self Current Task — Backlog (llvm)
|
||||
|
||||
短期
|
||||
- VInvoke(vector)の短期特例実装とスモーク更新(by‑name/by‑id 一致)。
|
||||
|
||||
中期
|
||||
- 正道化(戻り型ヒント or NyRT 期待フラグ)と IR 経路の統一。
|
||||
- AOT E2E 強化(plugins あり/なし両系統)。
|
||||
|
||||
16
docs/development/current/main/00-Overview.md
Normal file
16
docs/development/current/main/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 の相互作用(次段)。
|
||||
|
||||
25
docs/development/current/main/10-Now.md
Normal file
25
docs/development/current/main/10-Now.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Self Current Task — Now (main)
|
||||
|
||||
2025‑09‑08:現状と直近タスク
|
||||
- LLVM 側 P0 完了(BitOps/Array/Echo/Map 緑)。VInvoke(by‑name/by‑id vector) は戻り値マッピングの暫定課題を確認中(Decisions 参照)。
|
||||
- selfhosting-dev の作業を main に順次取り込み。VM/MIR 基盤は main で先に整える方針。
|
||||
|
||||
直近タスク(優先)
|
||||
1) continue/break の lowering(Builder 修正のみで表現)
|
||||
- ループ文脈スタック {head, exit} を導入。
|
||||
- continue に遭遇 → head(または latch)へ br を emit し終端。
|
||||
- break に遭遇 → exit へ br を emit し終端。
|
||||
- post‑terminated 後に emit しない制御を徹底。
|
||||
2) ループ CFG の厳密化
|
||||
- 単一 exit ブロックの徹底。
|
||||
- Phi はヘッダでキャリー変数を合流(SSA/支配関係が崩れない形)。
|
||||
3) 検証とスモーク
|
||||
- Verifier 緑(dominance/SSA)。
|
||||
- VM のループ代表(単純/ネスト/早期継続・脱出)。
|
||||
- LLVM/Cranelift EXE に綺麗に降りる(br/phi ベースで問題なし)。
|
||||
|
||||
代表コマンド(例)
|
||||
- ビルド: `cargo build --release`
|
||||
- LLVM smoke: `LLVM_SYS_180_PREFIX=$(llvm-config-18 --prefix) NYASH_LLVM_BITOPS_SMOKE=1 ./tools/llvm_smoke.sh release`
|
||||
- VInvoke 調査: `NYASH_LLVM_VINVOKE_TRACE=1 NYASH_LLVM_VINVOKE_SMOKE=1 ./tools/llvm_smoke.sh release`
|
||||
|
||||
9
docs/development/current/main/20-Decisions.md
Normal file
9
docs/development/current/main/20-Decisions.md
Normal file
@ -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/main/30-Backlog.md
Normal file
15
docs/development/current/main/30-Backlog.md
Normal file
@ -0,0 +1,15 @@
|
||||
# Self Current Task — Backlog (main)
|
||||
|
||||
短期
|
||||
- continue/break 降ろしの実装と単体/統合テストの追加。
|
||||
- Verifier の支配関係/SSA の確認強化(ループ exit 合流の一意性チェック)。
|
||||
- LLVM/Cranelift EXE スモーク(単純/ネスト/継続/脱出)。
|
||||
|
||||
中期
|
||||
- VInvoke(vector)戻り型の正道化(toml 記述 or NyRT 期待フラグ)。
|
||||
- ループ式として値を返す仕様が必要になった場合の設計(現状不要)。
|
||||
|
||||
周辺
|
||||
- selfhosting-dev への取り込みと Ny ツールでの continue/break 使用解禁。
|
||||
- docs 更新(言語ガイドに continue/break の記法・制約を明記)。
|
||||
|
||||
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 の記法・制約を明記)。
|
||||
|
||||
39
docs/development/current/selfhost/dep_tree_min_string.md
Normal file
39
docs/development/current/selfhost/dep_tree_min_string.md
Normal file
@ -0,0 +1,39 @@
|
||||
# Include-only Dependency Tree (Phase 0)
|
||||
|
||||
Goal
|
||||
- Build a dependency tree using only Ny (no Array/Map), scanning source text for `include "..."`, and output stable JSON.
|
||||
|
||||
Scope (Phase 0)
|
||||
- Only `include` is supported. `using/module/import` are out of scope.
|
||||
- Runner bridge: `NYASH_DEPS_JSON=<path>` is read and logged only (no behavior change).
|
||||
|
||||
Tool
|
||||
- `apps/selfhost/tools/dep_tree_min_string.nyash`
|
||||
- Recursively reads source files, scans for `include "path"` outside of strings and comments.
|
||||
- Comments: `//` and `#` (line comments) are ignored.
|
||||
- Strings: `"..."` with `\"` escapes are honored.
|
||||
- Cycles: detected via a simple stack string; when detected, the child appears as a leaf node with empty `includes`/`children`.
|
||||
|
||||
Output format
|
||||
```
|
||||
{ "version": 1,
|
||||
"root_path": "<entry>",
|
||||
"tree": {
|
||||
"path": "<file>", "includes": ["..."], "children": [ <node> ]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Acceptance criteria
|
||||
- Running `make dep-tree` produces `tmp/deps.json` whose first non-empty line starts with `{` and conforms to the format above.
|
||||
- The scanner does not pick includes inside strings or comments.
|
||||
- Cycles do not crash or loop; the repeated node is represented as a leaf.
|
||||
|
||||
Examples
|
||||
- Root: `apps/selfhost/smokes/dep_smoke_root.nyash` (includes `dep_smoke_child.nyash`)
|
||||
- Cycle: `apps/selfhost/smokes/dep_smoke_cycle_a.nyash` ↔ `dep_smoke_cycle_b.nyash`
|
||||
|
||||
Validation (examples)
|
||||
- `echo apps/selfhost/smokes/dep_smoke_root.nyash | ./target/release/nyash --backend vm apps/selfhost/tools/dep_tree_min_string.nyash`
|
||||
- `make dep-tree`
|
||||
|
||||
Reference in New Issue
Block a user