Repository navigation
ariadne: the script_engine interface (P1b), with Python moved onto it - #1091
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.
transfix
enabled auto-merge (squash)
November 9, 2026 07:23
This was referenced Nov 9, 2026
transfix
added a commit
that referenced
this pull request
Nov 9, 2026
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 script_engine interface (#1091) runs a scripting engine's activations as document processes (Runtime::start_process). Fitted to Stage 1b: - start_process submits to the document's scheduler (its isolated group's, else group 0), as submit_action does; master's executed on app.exec_scheduler() with a context made for the document's group. It is a host-thread call (assert_outside_pump). - An activation's natives run its language inline, charge the slice to current_process(), look up the document's functions and share a per-language frame budget: they stay on the host thread. New Runtime::require_host_thread(why) gives an isolated document a host affinity group, decided again as a late registration is (m3). AppRuntime::use_script_engine declares it; start_process declares it for a process with natives of its own (LaneProcess::extend) and refuses one while the document still runs in an `any` group. - ScriptLane::stop and running reach the document's group (current_group), not group 0. - Conflicts: ariadne.h's includes and forward declarations (both kept); ~AppRuntime unloads the engines first, then swaps the verb table out under its lock. Master's engine frame hooks landed in drain_end and its sweep change in sweep_actions. Tests: ScriptEngineTest.AnIsolatedDocumentThatUsesAnEngineRunsOnTheHostThread (failed on the plain merge: an `any` group, the activation in group 0, stop and running missing it) and AProcessWithNativesIsRefusedInAWorkersGroup. Docs: STATE_EXEC_THREADED.md (affinity, scripting engines, late registrations), ARIADNE.md, APP_API.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.
The
script_engineinterface from the scripting-hosts roadmap's P1b row (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md§10). It is the one prerequisite of G1 (WebAssembly guests on wasmtime) and of L1 (Lua). Python now runs on it, and what a document sees is unchanged.What's in core
inc/cvc/ariadne/script_engine.h+src/cvc/ariadne/script_engine.cpp, libpython-free:ScriptEngine:language(),has_module()for the<language>.<module>tokens,load_block(ScriptBlock, ScriptLane &, warnings), andunload(ScriptLane &).register_script_engineis process-wide. It makes the language a block key and makes its tokens hold. It replaces the token-onlyset_script_engine;has_script_engineandcapability_holdsnow read the registry.AppRuntime::use_script_engineis per runtime. Each load hands that engine's block to it after the parse, before the load hooks,requires:andinit:, which is where Python's load hook ran. From the second load on, the engine is unloaded first and its lane's hooks are dropped.ScriptBlock: what a block hands its engine. That is the language, the block as written, the document's path, directory and prefix, and the module (""until module blocks run).ScriptLane: one per runtime and engine. It is how the engine reaches the document, and it is the program lane's own surface (§8.6):export_function/export_async_function, the one registry (AppRuntime::register_function);start,stop,running;on_eventruns an action peron:event.on_frameruns a resident at the end of each drain, andon_watcha resident when a value under the prefix changed. Both keep one delivery in flight, so a slow one coalesces.sliced_task.h. Each is a process of the document's program lane, started through the newRuntime::start_process(LaneProcess).make_action_context), with the document's owner tag, chroot, channel policy, lock manager andfunctions:.ProgramLane::actionorresidentcaps fromariadne.limits.*. Its own caps only lower them.(script-step). Each step runs oneScriptActivation::step(ScriptSlice &)ofariadne.limits.<language>_slice_steps(64).finish,yield_frame,await(future), orcall(function, args).charge(steps)adds DSL steps (data steps) to the process, so the lane's step cap is the gas cap.callitself, as(apply f args)inside atry. So an engine reaches exactly what a DSL program there reaches (chroot,link:holes, locks), and a call that waits parks the process.ActivationOptions::may_callnarrows the calls; a refused name comes back as aPermissionError.ariadne.limits.<language>_frame_budget(0.008 s) of each frame. The frame comes from the newexec_frame(app), the pump clock the Runtimes share.AppRuntimealso gainsapp()andadd_warning(), so a hook that fails to start becomes a runtime warning.Python on it
src/ariadne_python/python_engine.cpp:PythonScriptEngineanswers the tokens and runs thepython:block inload_block, with the same code that ran it as a load hook.Engineregisters it at boot and unregisters it beforePy_FinalizeEx.attach()callsuse_script_engineinstead ofadd_load_hook.Host's hooks stayadd_frame_hook.Not in this PR
run -m,load:module blocks,--python-allow, and GRL-SNAM's ports.wasm_runtime, the guest ABI andwasm:;WasmError,ari_init's lane, the policy option, andpureexports.Tests
ariadne_script_engine_test(18 cases), a stub engine through all of it:on_donethat starts the next activation, step caps (lowered, never raised; a resident has no total), a yield, and the frame budget;NameError), andmay_call;stopand teardown;AriadneRequires.ScriptLanguageTokensHoldOnlyWithItsEnginenow registers a stub Python engine instead of callingset_script_engine.Local runs on Windows, MSVC 14.44, RelWithDebInfo, shared (
build-scriptengine):ariadne_script_engine_test: 18/18, and 18/18 on each of 30 repeats (the frame-budget case busy-waits).ariadne_requires_test: 20/20.ariadne_host_test: 57/57.arix_python_blockran its 5 cases.arix_python_program,arix_python_error,arix_python_interpreter,ari_python_needs_arix,ariglx_python_checkandariglx_python_program.ari_*andarigl_*ctests: 12/12.ariadne_runtime_test: 262/262, from a static Release build of this branch (ariadne_script_engine_test18/18 and requires 20/20 there too). Master's shared Windows builds no longer link this suite: gtest'sdeath_test_styleflag has been unresolved since 3320f18, which is unrelated to this PR.Docs
docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md:Merge note
#1081 (S1, arisrvx) touches the same lines of
python_engine.cpp(attach(), the constructor) and the hint string inrequires.cppand its test. Whichever lands second rebases. That PR's server branch keepsadd_load_hook(refuse_python_block), which still works besideuse_script_engine.