Skip to main content

Module reactor

Module reactor 

Source
Expand description

Tier-2 reactor ABI for wasm32-unknown-unknown (Cloudflare Workers / V8 isolates). No WASI, no stdio/argv — the module exports functions a JS host calls over linear memory (docs/design/done/WASM_TIER2_PLAN.md A3):

plg_init (emitted by the generated module) → builds the Machine, hands it to plg_rt_set_machine plg_rt_alloc(len) → ptr host writes the query bytes here plg_rt_run_query(ptr,len,…) → u64 packed (len<<32 | ptr) of a JSON buffer plg_rt_free(ptr,len) host frees the result (or the query buffer)

JSON formatting and the query path are NOT duplicated here — both go through crate::core, the single I/O-free core the WASI shell shares.

§Concurrency contract (D3 / WASM.md finding #2)

One in-flight query per isolate. The program Machine is a single static; a V8 isolate is single-threaded, but one Worker can interleave async tasks, so the host must not call plg_rt_run_query again before the prior call returns. This matches typical Worker use (a request maps to a query) and avoids threading per-request state through the ABI.

Functions§

plg_rt_alloc
Allocate a host-writable buffer in linear memory (query in / result out).
plg_rt_free
Safety
plg_rt_run_query
Run one query (UTF-8 at qptr..qptr+qlen) and return packed (len << 32) | ptr of a JSON byte buffer the host reads then frees via plg_rt_free. The packed return assumes wasm32 (the pointer fits in the low 32 bits); wasm64 would need a wider/two-value result (WASM.md finding #7).
plg_rt_set_machine
Safety