4.1 KiB
4.1 KiB
Phase 10.1 – Plugin Unification Path (MIR→JIT/AOT via C ABI)
This plan refines how we leverage the existing plugin system (BID-FFI) to unify JIT and AOT (EXE) paths using a single C ABI surface.
Goals
- Unify calls from JIT and AOT to the same C ABI (
nyrt_*/nyplug_*). - Convert builtin Boxes to Plugin Boxes in small steps (read-only first).
- Produce a minimal standalone EXE via static linking after unification.
Feasibility Summary
- JIT: emit calls to
extern "C"symbols (no change in semantics, only target). - AOT: emit
.owith unresolvednyrt_*/nyplug_*and link withlibnyrt.a+ plugin.a. - Compatibility: guard with
NYASH_USE_PLUGIN_BUILTINSand keep HostCall fallback.
Phase Breakdown
10.1: Plugin PoC + C ABI base (1 week)
- Deliverables:
- Minimal headers:
nyrt.h(runtime),nyplug_array.h(ArrayBox plugin). - ArrayBox as a plugin (
cdylib+staticlib), ABI version functions. - VM loader integration and
NYASH_USE_PLUGIN_BUILTINSswitch. - Smoke:
new/len/push/getworking via plugin.
- Minimal headers:
- DoD:
- Array plugin works on VM path; perf regression ≤10% on micro bench.
10.2: JIT Lowering unification (Array first) (1–1.5 weeks)
- Deliverables:
- IRBuilder:
emit_plugin_invoke(type_id, method_id, args, sig). - LowerCore BoxCall for Array routes to
plugin_invoke(events/stats intact). - Feature-flagged enablement:
NYASH_USE_PLUGIN_BUILTINS=1.
- IRBuilder:
- DoD:
- JIT execution of Array read/write (policy-constrained) via plugin path.
- Behavior parity with HostCall; no regressions on CI smoke.
10.2b: JIT Coverage Unblockers (0.5–1 week)
- Goal:
- Remove practical blockers so plugin_invoke can be exercised in typical Nyash functions and
.ocan be produced.
- Remove practical blockers so plugin_invoke can be exercised in typical Nyash functions and
- Deliverables:
- Lowering for
NewBoxof pluginized builtins → translatenew <Box>()to pluginbirth()viaemit_plugin_invoke(type_id, 0, argc=1 recvr-param)with appropriate handle threading. - Treat
Print/Debugas no-op/hostcall for v0 to avoid function-wide skip. - Keep conservative skip policy by default; document
NYASH_AOT_ALLOW_UNSUPPORTED=1for validation-only.oemission.
- Lowering for
- DoD:
- Minimal demo function with
String.length()compiled by JIT (Cranelift) and.oemitted. Plugin events visible under JIT.
- Minimal demo function with
10.3: Broaden plugin coverage + Compatibility (2 weeks)
- Targets: String/Integer/Bool/Map (read-only first).
- Deliverables:
- Pluginized Boxes and
plugin_invokelowering for BoxCall. - HostCall route retained; whitelist-driven co-existence.
- Added smoke and microbenches comparing HostCall vs Plugin.
- Pluginized Boxes and
- DoD:
- ≥5 builtin Boxes pluginized;
NYASH_USE_PLUGIN_BUILTINS=1green on smoke.
- ≥5 builtin Boxes pluginized;
10.4: AOT/EXE minimal pipeline (2–3 weeks)
- Deliverables:
- ObjectWriter path to emit
.owith unresolvednyrt_*/nyplug_*. libnyrt.aminimal runtime + selected plugin.a.- Link scripts and
nyc build-aotproof-of-concept. - Hello World-level standalone EXE on Linux/macOS.
- ObjectWriter path to emit
- DoD:
nyc build-aot <file.nyash> -o appruns without JIT/VM.- Basic debug info and minimal unwind.
10.5: Python Integration (moved; separate phase)
- Python work is deferred to 10.5 and builds on the plugin/AOT foundation.
Flags & Compatibility
NYASH_USE_PLUGIN_BUILTINS=1– enables plugin path for builtin Boxes.NYASH_JIT_HOSTCALL=1– preserves HostCall path for comparison.- Call conv alignment: x86_64 SysV, aarch64 AAPCS64, Win64.
- ABI version checks:
nyrt_abi_version(),nyplug_*_abi_version()hard-fail on mismatch.
Risks & Mitigations
- ABI drift: minimal headers + version checks.
- Linking complexity: start with the smallest set (Array/Print/GC-minimal), expand gradually.
- Performance: keep RO-first; benchmark and fall back to HostCall if needed.
- Windows linkage: prioritize Linux/macOS, then handle Win specifics in a follow-up task.
- JIT coverage: adopt staged lowering (NewBox→birth, Print/Debug no-op) to clear blockers; retain strict skip policy otherwise.
References
c_abi_unified_design.mdimplementation_steps.md../phase-10.5/(Python integration)
Everything is Plugin → unified paths for JIT and AOT.