Commit 3110b49
authored
fix(codegen-deno): WASI stub in __as_wasmInstance — instantiate affinescript-produced wasm (#534)
## What
The Deno-ESM backend's `wasmInstance` lowering (`__as_wasmInstance` in
`lib/codegen_deno.ml`) instantiated with **no import object**:
```js
new WebAssembly.Instance(new WebAssembly.Module(bytes)).exports;
```
But every affinescript-produced wasm imports
`wasi_snapshot_preview1.fd_write`
**unconditionally** (even a trivial pure-integer module with no
print/panic
path), so the import-less call throws `WebAssembly.Instance(): Imports
argument
must be present and must be an object`. Net effect: the Deno-ESM backend
could
not load *any* affinescript-compiled wasm. The Node backend
(`codegen_node.ml:251-273`) already wires this stub — this gives the
Deno-ESM
backend the same one line:
```diff
const __as_wasmInstance = (bytes) =>
- new WebAssembly.Instance(new WebAssembly.Module(bytes)).exports;
+ new WebAssembly.Instance(new WebAssembly.Module(bytes),
+ { wasi_snapshot_preview1: { fd_write: () => 0 } }).exports;
```
## Regression test
`tests/codegen-deno/wasm_wasi_instance.{affine,harness.mjs}` — the
harness
hand-builds an 86-byte wasm that **imports**
`wasi_snapshot_preview1.fd_write`
(declared, never called) and exports `add(i32,i32)->i32`, then drives it
through
the `wasmInstance` lowering. It passes **only** when the stub is present
(without
it, instantiation throws). Mirrors the existing `wasm_call` fixture
(#414), which
used an import-free module and so never exercised this path.
## Validation
Built from source on this branch (`dune build`),
`./tools/run_codegen_deno_tests.sh`
green including the new fixture; `wasm_wasi_instance.harness.mjs OK`.
Separately
confirmed the bytes instantiate **with** the stub (`add(2,3)=5`) and
throw
**without** it.
## Why it matters
Unblocks the Deno-ESM differential-test path downstream — e.g.
`hyperpolymath/idaptik`'s evacuation of its ~87 `*_diff.ts` parity
harnesses to
AffineScript, which load affinescript-compiled co-processor wasm via
this
backend. (Verified end-to-end there: a from-source build with this fix
runs an
AffineScript harness GREEN 1309/1309.)
## Caveat
1 parent f3ef056 commit 3110b49
3 files changed
Lines changed: 58 additions & 1 deletion
File tree
- lib
- tests/codegen-deno
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments