Docs: VM BoxCall vtable/PIC overview\n- VM_README: method_id slots, universal thunks, mono-PIC直呼び\n- Phase notes: progress includes direct-call and next steps

This commit is contained in:
Moe Charm
2025-08-26 22:37:15 +09:00
parent d46176de49
commit 90b9ab3a16
2 changed files with 27 additions and 1 deletions

View File

@ -51,6 +51,31 @@ NYASH_VM_STATS=1 NYASH_VM_STATS_JSON=1 ./target/debug/nyash --backend vm program
- 反復タイムアウト: `local_tests/socket_repeated_timeouts.nyash``acceptTimeout/recvTimeout` の連続ケース確認 - 反復タイムアウト: `local_tests/socket_repeated_timeouts.nyash``acceptTimeout/recvTimeout` の連続ケース確認
- BoxCallデバッグ: `NYASH_VM_DEBUG_BOXCALL=1` でBoxCallの受け手型・引数型・処理経路enter/fastpath/unified・結果型をstderr出力 - BoxCallデバッグ: `NYASH_VM_DEBUG_BOXCALL=1` でBoxCallの受け手型・引数型・処理経路enter/fastpath/unified・結果型をstderr出力
- 例: `NYASH_VM_DEBUG_BOXCALL=1 ./target/release/nyash --backend vm local_tests/test_vm_array_getset.nyash` - 例: `NYASH_VM_DEBUG_BOXCALL=1 ./target/release/nyash --backend vm local_tests/test_vm_array_getset.nyash`
## 🔧 BoxCallの統一経路Phase 9.79b
### method_idスロットによるBoxCall
- Builderが受け手型を推論できる場合、`BoxCall`に数値`method_id`(スロット)を付与。
- 低スロットはユニバーサル予約0=toString, 1=type, 2=equals, 3=clone
- ユーザー定義Boxは宣言時にインスタンスメソッドへスロットを4番から順に予約決定論的
### VMの実行経路thunk + PIC
- ユニバーサルスロット0..3はVMのfast-path thunkで即時処理。
- toString/type/equals/cloneの4種は受け手`VMValue`から直接評価。
- それ以外は以下の順で処理:
1. Mono-PICモーフィックPIC直呼び: 受け手型×methodまたはmethod_idのキーでホットサイトを判定し、
`InstanceBox`は関数名キャッシュを使って `{Class}.{method}/{arity}` を直接呼び出す(閾値=8
2. 既存経路: `InstanceBox`はMIR関数へCall、それ以外は各Boxのメソッドディスパッチへフォールバック。
環境変数(デバッグ):
```bash
NYASH_VM_DEBUG_BOXCALL=1 # BoxCallの入出力と処理経路を出力
NYASH_VM_PIC_DEBUG=1 # PICヒットのしきい値通過時にログ
```
今後の拡張:
- 一般`method_id`(ユーザー/ビルトイン/プラグインに対するvtableスロット→thunk直呼び。
- PICのキャッシュ無効化型versionと多相PICへの拡張Phase 10
- SocketBoxVM - SocketBoxVM
- 基本API: `bind/listen/accept/connect/read/write/close/isServer/isConnected` - 基本API: `bind/listen/accept/connect/read/write/close/isServer/isConnected`
- タイムアウト: `acceptTimeout(ms)` は接続なしで `void``recvTimeout(ms)` は空文字を返す - タイムアウト: `acceptTimeout(ms)` は接続なしで `void``recvTimeout(ms)` は空文字を返す

View File

@ -36,10 +36,11 @@ Progress: Fast-path thunks (universal slots) + PIC skeleton committed
- `MirInstruction::BoxCall` now carries optional `method_id` emitted by the builder when resolvable. - `MirInstruction::BoxCall` now carries optional `method_id` emitted by the builder when resolvable.
- Added monomorphic PIC skeleton: per-(receiver type, method_id/name) hit counters in the VM. - Added monomorphic PIC skeleton: per-(receiver type, method_id/name) hit counters in the VM.
- Minimal tests: verify fast-path behavior for `type()` and `equals()`. - Minimal tests: verify fast-path behavior for `type()` and `equals()`.
- PIC direct-call (InstanceBox): after threshold (8 hits), call `{Class}.{method}/{arity}` directly via cache.
Next: Next:
- Threshold-based direct dispatch using per-site cache entries. - Threshold-based direct dispatch using per-site cache entries.
- Extend beyond universal slots to general `method_id`-resolved methods. - Extend beyond universal slots to general `method_id`-resolved methods (builtin/plugin + user) via vtable thunks.
## Non-Goals ## Non-Goals
- Polymorphic PIC (plan only) - Polymorphic PIC (plan only)