Skip to content

ariglx-web: WebAssembly guests in the page (G2, third part) - #1245

Merged
transfix merged 1 commit into
masterfrom
feat/ariglx-web-wasm-guests
Nov 15, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/ariglx-web-wasm-guests

Conversation

@transfix

@transfix transfix commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

G2's third part (ARIADNE_SCRIPTING_HOSTS.md §8.5, §10): a document's wasm: block now runs in ariglx-web as it does in the native ariglx, on the browser's own WebAssembly. #1197 built the browser backend and #1206 the gas pass; this compiles them into the page and checks them in headless Chrome. What G2 has left is JSPI measured against Asyncify.

What it adds

  • The engine in the browser's ariglx. cvc_ariadne_wasm_host(ariglx ASYNC_LOAD) in the Emscripten branch of src/arigl/CMakeLists.txt. ariglx already makes the engine and registers it after Python (lend_python), so nothing in main.cpp changes.
  • The guest comes with the document. The page's fetcher (doc_fetch.cpp, document_references) follows a wasm: block's module, as it follows import: and load:: the module alone or the map's module:, top level only, and not a cvcpkg: package. It's data, so it isn't parsed for more names. AriadneDocFetch.ListsTheFilesADocumentNames covers it.
  • A guest over 8 MB loads. On the page's own thread, Chrome refuses new WebAssembly.Module for a module over 8 MB with a RangeError. It refuses new WebAssembly.Instance for one as large too, even when the module was compiled asynchronously. I probed headless Chrome 157: 7.9 MiB passes both, 8.1 MiB fails both.
    • browser_runtime.cpp still compiles synchronously first. On that RangeError it awaits WebAssembly.compile, then WebAssembly.instantiate for each instance, through EM_ASYNC_JS, and the document's load waits while the host's own Asyncify unwinds its stack.
    • So a small guest never pauses the page.
    • Only a host linked with Asyncify can wait. That's the new ASYNC_LOAD (CVC_ARIADNE_WASM_ASYNC_LOAD). Without it, such a guest fails to load and the error says why. ariadne_wasm_browser_test stays as it was.
  • ariglx_wasm_guests (built by name, not by the package) transforms the hosts' test guest (guest.wat: metered, then Asyncify) into <bin>/ariglx-wasm-guests, beside src/arigl/web/test/wasm's documents.
  • The smoke (arigl_web_smoke.mjs --wasmdocs DIR), two documents:
    • guest.ari: the guest fetched with the document, its ari_init at load, a call from init:, then on the first tick echo, nap (two yields, so the guest unwinds and later frames rewind it), a trap caught as a WasmError, and spin (24 million gas, 376 slices over several frames).
    • big.ari: big.wasm, which the smoke serves as the guest with a 9 MiB custom section after it, compiled and instantiated asynchronously.
    • The page keeps stderr in window.ariadneWeb.log, and the DSL's print writes to stdout, so each document reports through a small python: block. Both engines then run in one document, as ariglx registers them.
  • ci.yml's ariglx-web job builds ariglx_wasm_guests in the recipe's tree after the recipe's build and passes --wasmdocs, on wasm and wasm-mt. src/ariadne_wasm joins both legs' paths.
  • Docs: ARIADNE.md (the wasm: block in the browser) and the roadmap (§8.5's as-built, the §1 table, the G2 row).

How it was tested (Windows, sandipaws)

  • Browser: an ariglx-web tree configured as the recipe configures it (single-threaded wasm, the lean tier, emsdk 5.0.7, deps with python312 3.12.10+cvc.25, numpy and pillow-cp312), staged as the recipe stages it.
    • arigl_web_smoke.mjs --pydocs src/arigl/web/test/python --wasmdocs <bin>/ariglx-wasm-guests in headless Chrome 157: all 14 cases passed. That includes the two new ones:
      • ariglx-web: wasm booted yes, init early, echo 1 a, nap 7, boom trapped, spin done, running 4.5 s after navigation;
      • ariglx-web: wasm big guest booted yes, echo 2 b, get-x big, at 6.4 s.
    • The page's other cases still pass: the docset, the upload, numpy, expat/SHA-2, the console, a Python program, a raising block, Pillow.
  • Native, a static core tree (MSVC):
    • ariadne_doc_fetch_test: 9/9, including the new wasm: cases.
    • Both documents, without their Python report (that tree has no pycvc), run under arix with wasmtime and print the same two lines.
  • The padded guest is valid (V8), with the same imports and exports as the guest.
  • clang-format 18.1.8 on the changed lines: clean.

Not covered here

  • wasm-mt wasn't built locally. CI's wasm-mt leg runs both cases on the threaded page, served cross-origin isolated.
  • A guest over 8 MB loaded while Python is on the stack (a Python program's host.load) pauses the page under Python, which §5.3 otherwise avoids. The default link instruments those frames, so it's sound there. ASYNCIFY_REMOVE (fallback 1) would break it. The roadmap says so.
  • JSPI against Asyncify: the last part of G2.

A document's wasm: block now runs in ariglx-web as it does in the native
ariglx, on the browser's own WebAssembly.

- src/arigl/CMakeLists.txt: the browser's ariglx compiles the engine in,
  cvc_ariadne_wasm_host(ariglx ASYNC_LOAD). A new target,
  ariglx_wasm_guests (built by name, not by the package), transforms the
  hosts' test guest and copies src/arigl/web/test/wasm's documents beside
  it, for the browser smoke.
- doc_fetch.cpp: the page's fetcher follows a wasm: block's module (the
  module alone, or the map's module:; not a cvcpkg: package), so the guest
  comes with the document.
- browser_runtime.cpp: a guest the page won't compile on its own thread is
  compiled asynchronously. Chrome refuses new WebAssembly.Module for a
  module over 8 MB there with a RangeError, and new WebAssembly.Instance for
  one as large even when it was compiled asynchronously (headless Chrome
  157: 7.9 MiB passes both, 8.1 MiB fails both). On that refusal the
  backend awaits WebAssembly.compile, then WebAssembly.instantiate, through
  EM_ASYNC_JS, and the document's load waits. A small guest never pauses
  the page. Only a host linked with Asyncify can wait (cvc_ariadne_wasm_host's
  new ASYNC_LOAD); without it the load fails, saying why.
- arigl_web_smoke.mjs --wasmdocs: guest.ari (the guest fetched with the
  document, its ari_init, calls, a yield over two frames, spin's 24 million
  gas in 376 slices, a trap caught as a WasmError) and big.ari (the guest
  with a 9 MiB custom section, compiled and instantiated asynchronously).
  Each reports through a python: block's print to stderr: the page keeps
  stderr, and the DSL's print writes to stdout.
- ci.yml's ariglx-web job builds ariglx_wasm_guests in the recipe's tree
  and passes --wasmdocs, on wasm and wasm-mt; src/ariadne_wasm joins both
  legs' paths.
- Docs: ARIADNE.md (the wasm: block in the browser) and the roadmap
  (section 8.5's as-built, the G2 row). JSPI against Asyncify is what is
  left of G2.
@transfix
transfix enabled auto-merge (squash) November 15, 2026 05:43
@transfix
transfix merged commit 0fcbe98 into master Nov 15, 2026
29 checks passed
@transfix
transfix deleted the feat/ariglx-web-wasm-guests branch November 15, 2026 08:38
transfix added a commit that referenced this pull request Nov 15, 2026
No conflicts; #1245's ariglx-web WebAssembly guests touch no threading code.
transfix added a commit that referenced this pull request Nov 15, 2026
No conflicts. Master brings 26 commits (#1171, #1191, #1221, #1236,
#1245, #1248, #1250 and others); none adds a writable global, a function
static or a signal handler to the hosts or examples, and none touches
the allowlist.
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