Repository navigation
ariadne: WebAssembly guests natively on wasmtime (G1, first part) - #1093
Merged
Merged
Conversation
The seam G1 (WebAssembly guests on wasmtime) and L1 (Lua) plug into beside Python (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md 3.1, 8.3-8.7). - inc/cvc/ariadne/script_engine.h: ScriptEngine (language, has_module, load_block, unload), registered once per process by language (register_script_engine), which makes its block a key the loader keeps and its tokens hold; set_script_engine goes. ScriptBlock is what a block hands its engine: the block, the document's path, dir and prefix. - ScriptLane, one per runtime and engine (AppRuntime::use_script_engine): the document's function registry, activations, and hooks (an on: event as an action, every frame and a changed value as a resident, one in flight). - Activations run like sliced tasks: a process of the document's program lane (Runtime::start_process: its owner tag, chroot, channel policy, lock manager, functions: and ariadne.limits.* caps, which an activation may lower and never raise), a DSL loop around (script-step) that steps a ScriptActivation one slice at a time. A slice charges DSL steps, so the step cap is the gas cap; it may finish, yield the frame, await a future, or call any function the lane holds, which the loop applies in the process (narrowed by may_call). A language's activations share ariadne.limits.<language>_frame_budget (0.008 s) of each frame (exec_frame). - Python's engine is a ScriptEngine: it answers the tokens and runs the python: block in load_block, and attach() uses it instead of a load hook. What a document sees is unchanged. - Tests: ariadne_script_engine_test (a stub engine through all of it); the AriadneRequires token test through a stub Python engine.
A document's wasm: block runs a compiled plugin in arix and ariglx, as a ScriptEngine on P1b's interface (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md 8.2-8.7; ARIADNE.md 9.6). - src/ariadne_wasm: the runtime interface (guest_runtime.h) and its wasmtime backend, where each slice is one wasmtime_call_future_poll under a fuel yield interval and an import that waits is an async host function; a CBOR codec for DSL values; and the engine: the wasm: block (module, export, hooks, imports, limits, priority), an instance per document, _initialize, and the guest ABI (values as CBOR in the guest's memory, ari_alloc, the call, reply, yield and fail imports). - ScriptLane::export_activation: a function whose calls are activations the caller parks on (an async function whose work starts itself, so no pool thread, and the wait counts against the caller's caps), with -async futures. AppRuntime::register_async_work_function under it. ActivationOutcome keeps a failed step's exception, so it re-raises with its own class. - Fuel is charged as DSL steps (ariadne.limits.wasm_gas_per_step), under the action caps and the wasm frame budget; one activation per instance; a guest calling its own export is refused; imports: narrows its calls (state.read, state.write, msg, net, call). - WasmError joins the built-in classes (18), the wasm token and the loader's warning for a wasm: block on a host without guests. - arix and ariglx carry the engine where wasmtime's C API is found (-DARI_WITH_WASM / -DARIGL_WITH_WASM require it); CI's package-linux installs the cvcpkg wasmtime package. - Tests: ariadne_wasm_test (a WAT guest), the export_activation stub case, and the arix_wasm_block / ari_wasm_needs_arix ctests.
transfix
enabled auto-merge (squash)
November 9, 2026 09:11
transfix
added a commit
that referenced
this pull request
Nov 9, 2026
transfix
added a commit
that referenced
this pull request
Nov 9, 2026
Master's WebAssembly engine (#1093) adds async work functions (AppRuntime::register_async_work_function), which a script lane's export_activation uses: a program's call parks while an activation runs and finishes it. Fitted to Stage 1b: - AppRuntime: a seventh provider binds them, host_only, on the calling program's own host (*ictx.host), after the host's async functions as master's single provider bound them; their table is locked like the others and swapped out in ~AppRuntime. - export_activation finished its calls on app.exec_async_host(). A call made on an isolated document's group host and finished through group 0's host forgets it by a slot of the wrong host's list (it may drop another live call of group 0's). New async_host::starting() names the host whose call() runs a work's start on this thread; the export finishes through that host's finisher, which posts nothing once the host has shut down. - start_process loses the assert_outside_pump the last merge added: an exported call or an on: hook starts its activation from the calling step, on the host thread inside a pump of group 0 or a host group. Tests: ScriptEngineTest.AnIsolatedDocumentsExportedCallFinishesOnItsGroup and AsyncCalls.AStartSeesTheHostItWasMadeOn. The wrong-host finish is not visible through a public API, so the first passes on the plain merge too; it guards the path. Docs: STATE_EXEC_THREADED.md (the seventh provider, exported calls), ARIADNE.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1091 (base
feat/script-engine). Once #1091 merges, this branch is rebased onto master and retargeted there, and CI runs then. Its recipe CI is cancelled here so the queue isn't held up twice.G1, first part: WebAssembly guests natively on wasmtime, as a
ScriptEngineon #1091's interface (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md§8.2–8.7; the user-facing reference is ARIADNE.md §9.6).What's in it
src/ariadne_wasm/guest_runtime.h: §8.3's runtime interface. It compiles a module, instantiates it with the imports, starts an export call, and polls it a slice of fuel at a time, pausing in an import that waits.wasmtime_runtime.cpp: the wasmtime backend. Each slice is onewasmtime_call_future_pollon the guest's own stack, underwasmtime_context_fuel_async_yield_interval. A waiting import is an async host function whose continuation reports when the host has answered. The store's limiter caps memory.value_cbor.{h,cpp}: DSL values as CBOR. A closure, a native function or a host object doesn't cross (host objects are §8.4.1's handles, later).wasm_engine.{h,cpp}: the engine.wasm:block, and an instance per document, rebuilt at a reload._initializeruns at instantiation.(ptr, len)of its CBOR argument list and returnsptr << 32 | lenof its result. The guest exportsmemoryandari_alloc.ari:call(name, args) -> i64,reply(dst),yield()andfail(text).ScriptLane::export_activation. A call is an activation the caller parks on:async_work.startbegins the activation, which settles the call when it ends. So no pool thread is used, and the same path will work in single-threaded wasm.-asyncreturns a future.ActivationOutcomenow keeps a failed step's exception.AppRuntime::register_async_work_function.ariadne.limits.wasm_gas_per_step, 1000), so the action caps bound a guest.imports:narrows thecallimport by group (state.read,state.write,msg,net,call).WasmErrorjoins the built-in classes besidePythonError(18 now; two tests pinned the count, and the docs are updated). Thewasmtoken, and the loader's warning for awasm:block on a host without guests, are added too.arixandariglxcarry the engine where wasmtime's C API is found.-DARI_WITH_WASM/-DARIGL_WITH_WASMmake it required.package-linuxinstalls the cvcpkgwasmtimepackage, a prebuilt download, soariadne_wasm_testruns there.init:(which can't park, so they raiseRuntimeErrortoday);MemoryErrorat a refusedmemory.grow;ari_init, and a host option forstate_exec.policy;arix/ariglxcvcpkg recipes.Tests
Local runs, Windows, MSVC 14.44, static Release core tree plus
arix, with wasmtime 45.0.0+cvc.1 from cvcpkg:ariadne_wasm_test, 11/11 (×5 repeats), with a WAT guest:-asyncfuture, and_initialize;imports:narrowing;max_steps_exceededstops it at 5000;failasWasmError; a refused re-entry;on_tickhook;ariadne_script_engine_test19/19 (the newexport_activationcase: park,-async, the class kept,init:refused).ariadne_requires_test20/20.state_exec_exceptions_test25/25,state_exec_data_steps_test54/54,state_exec_codec_test73/73,ariadne_runtime_test262/262.arix_wasm_block(arix testwith 5 cases) andari_wasm_needs_arixpass.ariglx: its editedmain.cpppasses a syntax-only compile against the GL tree withCVC_ARIADNE_WASMon.ariglxitself wasn't built here, and the GL CI jobs don't install wasmtime yet.