Skip to content

Commit 9375cdb

Browse files
committed
docs(ffi): record the Wasm host imports json v0.4 adds
A Wasm module that imports json's externs (`use json::*`) now imports hpm_json_object_len and hpm_json_object_key as well: 13 hpm_json_* imports instead of 11, under the `json` module. A host supplying only the v0.3 set fails with a LinkError at instantiation (checked with Bun's WebAssembly on this commit). The spec now says so, and how a host can stub the two until hpm-json-rsr exports them. Answers the outside-diff finding on stdlib/json.affine in the CodeRabbit review of #798; the externs moved to this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
1 parent 9464efe commit 9375cdb

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎docs/specs/zig-ffi-patterns.adoc‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ pub extern fn hpm_json_free(val: HpmJsonValue) -> Int; // ownership: caller fr
213213
* `parse` returns `Option` because parsing can fail.
214214
* `free` discharges the host allocation; every successful `parse` is
215215
balanced by exactly one `free`.
216+
217+
*Wasm host import set (changed in json v0.4).* A Wasm module that brings in
218+
`json`'s externs, for example with `use json::*`, imports every
219+
`hpm_json_*` extern whether or not it calls one. v0.4 adds
220+
`hpm_json_object_len` and `hpm_json_object_key`, so the set grows from 11
221+
to 13. Compiled with `use json::*`, the imports appear under the `json`
222+
module (`json.hpm_json_object_len`, `json.hpm_json_object_key`), not under
223+
`env` as the generic description above says. A host that supplies only the
224+
v0.3 eleven fails to instantiate the module with a `LinkError`, before any
225+
code runs. Until `hpm-json-rsr` exports the two functions, such a host must
226+
stub them (`hpm_json_object_len` returning 0, `hpm_json_object_key`
227+
returning `None`), which makes `to_json` reject objects, or import `json`
228+
selectively (`use json::{encode_int}` imports only what it names).
216229
* No effect row: parsing a string is pure with respect to the affine
217230
effect lattice (the allocation is an implementation detail of the host).
218231

0 commit comments

Comments
 (0)