📚 Phase 11 documentation: Everything is Box × MIR15 revolution

Key updates:
- Document MIR 26→15 instruction reduction plan (transitioning status)
- Add Core-15 target instruction set in INSTRUCTION_SET.md
- Save AI conference analyses validating Box Theory and 15-instruction design
- Create MIR annotation system proposal for optimization hints
- Update SKIP_PHASE_10_DECISION.md with LLVM direct migration rationale

Technical insights:
- RefNew/RefGet/RefSet can be eliminated through Box unification
- GC/sync/async all achievable with 15 core instructions
- BoxCall lowering can automatically insert GC barriers
- 2-3x performance improvement expected with LLVM
- Build time reduction 50%, binary size reduction 40%

Status: Design complete, implementation pending
This commit is contained in:
Moe Charm
2025-08-31 03:03:04 +09:00
parent 1812cda7d5
commit b003bdf25b
50 changed files with 2621 additions and 136 deletions

View File

@ -505,3 +505,15 @@ NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 NYASH_JIT_HOSTCALL=1 NYASH_JIT_STATS=1 \
- 分岐条件はb1化i64の場合は !=0 で正規化)
- 直線if/elseでのreturnをJITで実行副作用は未対応のためVMへ
- PHIは将来の`NYASH_JIT_PHI_MIN=1`で最小導入予定
#### 予約シンボルRuntime/GC 橋渡し)
- `nyash.rt.checkpoint`(セーフポイント)
- JIT: no-op スタブを登録済み(将来のスケジューラ/GC連携用
- AOT: `nyrt` が同名シンボルをエクスポート(`#[export_name]`)。リンク済み
- トレース: `NYASH_RUNTIME_CHECKPOINT_TRACE=1` でstderrに到達ログ
- `nyash.gc.barrier_write`(書き込みバリア)
- JIT: no-op スタブを登録済み将来のインクリメンタルGC向けフック
- AOT: `nyrt` が同名シンボルをエクスポート(`#[export_name]`
- トレース: `NYASH_GC_BARRIER_TRACE=1` でstderrに到達ログ
メモ: 現時点では両シンボルとも副作用なしno-op。MIR側では `Safepoint``ExternCall(env.runtime.checkpoint)` へ段階移行中です。

View File

@ -1,11 +1,21 @@
# Nyash MIR Instruction Set (Canonical 26)
# Nyash MIR Instruction Set (Canonical 26 → migrating to Core-15)
Status: Canonical (Source of Truth)
Status: Canonical (Source of Truth) — transitioning
Last Updated: 2025-08-25
この文書はNyashのMIR命令セットの唯一の参照26命令だよ。実装は常にこの一覧に一致し、総数はテストで26に固定する
この文書はNyashのMIR命令セットの唯一の参照現状は26命令だよ。Core-15 への段階移行を進めており、安定次第この文書を15命令へ更新し、テスト固定数も切り替える移行中は26を維持
注意: Debug/Nop/Safepointはビルドモードでの降格用メタ命令であり、コア26命令には数えない。
注意: Debug/Nop/Safepointはビルドモードでの降格用メタ命令であり、コア命令には数えない。
Transition Note
- Builder/Rewrite/JIT は既に以下の統合を段階適用中
- TypeCheck/Cast → TypeOp
- WeakNew/WeakLoad → WeakRef
- BarrierRead/BarrierWrite → Barrier
- Print → ExternCall(env.console.log)Deprecated
- VM/JIT の代表的な Core-15 カバー手順は `docs/reference/mir/MIR15_COVERAGE_CHECKLIST.md` を参照。
- Core-15 安定後に本ドキュメントの「Core Instructions」を15命令へ更新し、マッピング表を併記する。
## Core Instructions26
- Const
@ -30,11 +40,24 @@ Last Updated: 2025-08-25
- RefGet
- RefSet
- Await
- Print
- PrintDeprecated: ビルダーは発行しない。代わりに `ExternCall env.console.log` を使用)
- TypeOpTypeCheck/Cast統合
- WeakRefWeakNew/WeakLoad統合
- BarrierRead/Write統合
## Core-15Target; 移行中の最小コア)
- 基本演算(5): Const, UnaryOp, BinOp, Compare, TypeOp
- メモリ(2): Load, Store
- 制御(4): Branch, Jump, Return, Phi
- Box(3): NewBox, BoxCall, PluginInvoke
- 配列(2): ArrayGet, ArraySet
- 外部(1): ExternCall
Notes
- Print/Debug/Safepointはメタ/Extern化Print→ExternCall
- WeakRef/Barrier は統合済み旧WeakNew/WeakLoad/BarrierRead/WriteはRewriteで互換
- Call は BoxCall/PluginInvoke へ集約通常の関数呼び出しは将来Box化方針のもと整理
## Meta (降格対象; カウント外)
- Debug
- Nop

View File

@ -0,0 +1,43 @@
# MIR Core (~15) Coverage Checklist
Goal: Verify that the core MIR set executes correctly across VM and JIT (exe), then proceed to LLVM.
Target instructions (representative core):
- Basics: Const, UnaryOp, BinOp, Compare, TypeOp
- Memory: Load, Store
- Control: Branch, Jump, Return, Phi
- Box: NewBox, BoxCall, PluginInvoke
- Arrays: ArrayGet, ArraySet
- External: ExternCall
How to verify
- VM path
- Run representative examples or unit snippets via `--backend vm`.
- Enable VM stats for visibility: `NYASH_VM_STATS=1`
- JIT (compiler-only, exe emission where applicable)
- Enable JIT compile path and hostcall: `NYASH_JIT_EXEC=1 NYASH_JIT_THRESHOLD=1 NYASH_JIT_HOSTCALL=1`
- For PHI minimal path tests: `NYASH_JIT_PHI_MIN=1`
- Optional DOT/trace: `NYASH_JIT_DUMP=1` and/or `NYASH_JIT_EVENTS_COMPILE=1`
Quick smoke
- Build: `cargo build --release --features cranelift-jit`
- Run: `tools/mir15_smoke.sh release`
- Policy: Core-1 is required green; hostcall-based cases are optional (fallback allowed).
Suggested minimal scenarios
- Const/Return: function returns 0/1/42.
- BinOp/Compare: arithmetic and boolean conditions.
- Branch/Jump/Phi: single-diamond if/else with merging value.
- Load/Store: local slot store → load (VM) and JIT local slots (lower/core) coverage.
- TypeOp: `is`/`as` via builder emits TypeOp.
- NewBox/BoxCall: call basic methods (e.g., StringBox.length, IntegerBox.get via PluginInvoke where applicable).
- PluginInvoke/by-name: `nyash.handle.of` + invoke name path.
- Arrays: len/get/set/push hostcalls (JIT: handle-based externs wired).
- ExternCall: `env.console.log`, `env.debug.trace`, `env.runtime.checkpoint`.
Notes
- Debug/Safepoint/Future/Await are rewritable via env toggles; core stays focused on the above.
- JIT direct path is read-only; mutating ops should fallback or be whitelisted accordingly.
Once coverage is green on VM and JIT, proceed to LLVM feature work (inkwell-backed) following docs in execution-backends.