Skip to content

ariadne: the state imports and the volume writers (G1, eighth part) - #1135

Merged
transfix merged 2 commits into
masterfrom
feat/wasm-guests-8
Nov 11, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/wasm-guests-8

Conversation

@transfix

Copy link
Copy Markdown
Owner

G1, eighth part: a guest's state imports, a fast path beside call, and §8.4.1's volume writers (roadmap §8.4, §8.4.1, §8.6).

The problem

  • State went through call. A guest reached state only through call, which ends the guest's slice so the activation's loop can make the call. So every value read or written cost a round trip through the loop's own steps.
  • imports: miscounted writers. imports: sorted the state- functions into groups by name. So state-cas, state-swap, state-incr and the expiry setters counted as state.read, and imports: [state.read] let a guest write through them.
  • No volume writes. The writes of §8.4.1 (volume_write, volume_new) weren't there.

The fix

A fast path beside call. ScriptSlice::call_now(function, args):

  • calls a function the lane holds as a native, inside the slice, which goes on;
  • calls the same function call() would reach, in the same environment, so the chroot, the link: holes and may_call all apply;
  • runs the call's deep-data work to its end there (no deferral to the evaluator), counted to the process;
  • puts the value, or the exception the call raised, in the slice's reply, as call()'s reply would arrive. An interruption is thrown.

A name the lane holds otherwise (a document function, say) gets false back, and goes through call(). The fast path belongs to the core, so any engine can use it.

The state imports. Each one calls one of the lane's state natives through call_now:

Import Calls
state_get state-get
state_exists state-exists
state_children state-children
state_data_get state-data-get
state_set state-set
state_data_set state-data-set
state_delete state-delete
state_swap state-swap
state_incr state-incr
state_cas state-cas
  • Each takes its path as text and its values as CBOR. An empty value is nil, except that an empty state_incr delta means 1.
  • Each returns as call does, and costs a step.
  • GuestCall polls the call again in the same slice until the slice's budget is spent.

state.write lists its writers. They are state-set, state-set-tree, state-data-set, state-from-json, state-delete, state-cas, state-swap, state-incr, state-expire, state-expire-at, state-clear-expiry and state-sweep-expired. Every other state- function is state.read's. This applies to call and the state imports alike.

The volume writers, with the data.write group:

  • volume_write(h, x, y, z, nx, ny, nz, src, len) writes a box into the guest's own copy of the volume.
    • A volume anyone else may hold (the state tree, a renderer, another handle) is copied at its first write, and the handle names the copy. Its voxels copy on write.
    • So nothing else sees the write until the guest stores the handle with state_data_set.
    • A volume only the guest holds is written in place.
  • volume_new(spec, len) makes a zeroed volume from a CBOR map as data_info gives one (dims, voxel, bounds).
    • It counts against the call's allocation limit, as a native's allocation does.
    • It returns the new volume's handle. A handle's generation now stays below 2^31, so a handle is always positive as an i64.

Docs

  • script_engine.h (call_now) and wasm_engine.h (the state imports, the writers, state.write).
  • ARIADNE.md §9.6.
  • The scripting hosts roadmap:
    • a "G1's eighth part, built" bullet in §8.3;
    • §8.4's and §8.4.1's notes on what is built;
    • the G1 row.

Tests

ariadne_wasm_test, new:

  • TheStateImportsAreTheLanesStateFunctions: set, incr, get, cas, swap, children, exists and delete, all under the document's prefix.
  • ImportsNarrowTheStateImports: [state.read] lets readers through and refuses state_set, state_cas, and state-incr through call. With the old name-based grouping put back, it fails.
  • AStateImportCostsAStepWhereACallEndsTheSlice: 500 increments through the import fit under a 3000-step action cap; through call they don't. With call_now made to always decline (every state import then goes through call), this test fails alone and the other state tests pass, so the fallback works too.
  • AGuestWritesItsOwnCopyOfAVolume:
    • the node's volume is unchanged by a write, and the copy has it;
    • a new volume is written and stored;
    • a write after the store goes to a copy, which the stored volume doesn't see.
  • TheWritersRefuseWhatTheyCantDo: refusals for no data.write (PermissionError), past the allocation limit (MemoryError) and an unknown voxel type (ValueError).

ariadne_script_engine_test: AFailedEventLetsTheNextOneGo (#1129's) drains until both events are in, at most 10 drains. It asserted one drain, and failed once here when a slow first run spent the 8 ms frame budget on the first event.

Local, Windows static Release tree:

  • ariadne_wasm_test 27/27, ariadne_script_engine_test 30/30 and ariadne_runtime_test 262/262, three runs each.
  • the arix_wasm_block and ari_wasm_needs_arix ctests.
  • clang-format 18 on the changed lines (git clang-format --diff against the merge base): clean.

Left for G1

  • A host option for state_exec.policy, and pure exports on the read lane.
  • wasmtime in the arix / ariglx recipes.

A guest reached state only through call, which ends its slice for the
activation's loop to make the call: a round trip of the loop's own steps
per value read or written.

ScriptSlice::call_now is a fast path beside call(). It calls a function
the lane holds as a native, the one call() would reach in the same
environment and under the same narrowing, inside the slice, which goes
on. Its deep-data work runs to its end there, and what it raises is the
reply. A name the lane holds otherwise (a document function) is left to
call().

The wasm engine's state imports go through it: state_get, state_exists,
state_children, state_data_get, state_set, state_data_set, state_delete,
state_swap, state_incr and state_cas, each the path as text and its
values as CBOR, a step a call. imports: narrowed state- functions on
their names, so the atomics and the expiry setters counted as
state.read; the writers are now listed, and are state.write's.

The writers of section 8.4.1 come with the data.write group. volume_write
writes a box into the guest's own copy of a volume: one anyone else may
hold is copied at its first write, and the handle names the copy, so
nothing else changes until the guest stores it with state_data_set. One
only the guest holds is written in place. volume_new makes a volume from
data_info's map (dims, voxel, bounds), counted against the call's
allocation limit, and returns its handle, which is now always positive
as an i64.

AFailedEventLetsTheNextOneGo drains until both events are in: one drain
could leave the second to the next frame once the 8 ms frame budget was
spent on a slow first run.
@transfix
transfix enabled auto-merge (squash) November 11, 2026 03:46
@transfix
transfix merged commit 66febca into master Nov 11, 2026
13 of 33 checks passed
@transfix
transfix deleted the feat/wasm-guests-8 branch November 11, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant