Expand description
Per-function WebAssembly lowering: a region of VM bytecode (&[Op], a register machine)
→ a WebAssembly function (a stack machine with i64 locals).
§Control flow
VM bytecode uses absolute jumps; WebAssembly has only structured control flow. The
lowering splits the region into basic blocks and emits the standard dispatch loop:
a loop wrapping blocks nested one-per-basic-block, with a br_table on a “next
block” local at the bottom. Each block runs its arithmetic, then sets the next-block
index and re-dispatches (br to the loop) — or returns. This translates any
reducible (and irreducible) control flow correctly, not just recognized patterns.
§Eligibility (Phase 6 deopt-at-concurrency, mirrored)
Only integer regions are emitted: const/move/arith/compare/jump/return. Any op outside
that set — every concurrency / channel / networking op included — makes
compile_region_to_wasm return None, so the region stays on the bytecode tier (a
yield-free emitted module by construction, exactly like the native backend’s deny-list).
This is the byte emitter both the browser WASM-JIT tier (super::region_jit) and the
direct AOT backend consume; it depends only on super::encode, not on the wasm-jit
feature.
Functions§
- compile_
function_ to_ wasm - Lower function
fiof a compiled program to a WebAssembly module — the integration entry the VM’s tier-up uses. A function’s body lives in the sharedprogram.codefrom itsentry_pcuntil the next function’s entry (or the program end), with absolute jump targets; this extracts that slice and rebases every jump into the region-local 0-based spacecompile_region_to_wasmexpects. ReturnsNone(stay on bytecode) if the body leaves the integer fragment or a jump escapes the function. - compile_
region_ to_ wasm - Lower an integer region to a WebAssembly module exporting one function
fofnum_paramsi64parameters returningi64. VM registers map 1:1 to WASM locals (0..num_paramsparams,num_params..num_regsdeclared i64 locals); one extra i32 local at indexnum_regsis the dispatch “next block” index.