[Feature] ADR-0026: lower native Wasm.Int64 and packed numeric-array intrinsics - #47
Open
harryprayiv wants to merge 26 commits into
Open
harryprayiv wants to merge 26 commits into
harryprayiv wants to merge 26 commits into
Conversation
added 25 commits
June 21, 2026 18:40
…as based on my fork instead of origin/main when I started the work. Codegen.purs was the file I needed to most carefully consider, requiring some surgery to resolve conflicts.
…module with both new I32Arrays, F64Arrays, and Int64
…ly provision everything rather than having to read documentation just to benchmark this module. DETERMINISM is the key to getting people to stop having the "it works on my computer" issue.
… dependency that I keep fighting)
Lower the wasm-base v0.2.0 primitives to native wasm: Wasm.Int64 (i64 scalar: bitwise/shift/rotate/compare, fromInt/fromHiLo/lowBits/hiBits) and the packed unboxed arrays Wasm.I32Array / Wasm.F64Array / Wasm.I64Array. Adds the I64 rep, four value types ($Int64/$I32Arr/$F64Arr/$I64Arr), the i64 Binaryen FFI, a compile-time rep-contract check, and e2e fixtures + CLI specs. Depends on wasm-base v0.2.0.
Collaborator
|
Hi, thank you for the pull request! While this PR was open, I merged some major changes into main.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Compiler support for the wasm-base v0.2.0 primitive families, lowered to native
wasm:
Wasm.Int64(ani64scalar) and the packed unboxed numeric arraysWasm.I32Array/Wasm.F64Array/Wasm.I64Array, so anInt/Number/Int64array carries no per-element box (unlikeWasm.Array's$Vals). Per-filedetail is in the commit.
What changed:
Intrinsics: theInt64*family (bitwise / shift / rotate / compare,fromInt/fromHiLo/lowBits/hiBits) and four constructors each forI32Array/F64Array/I64Array, withqualifiedIntrinsicresolutions. Allpure, so
checkWasmBaseCompatallowlists them off the same table.Lower.IR/Lower.Reps: a newI64rep; result/operand reps for every newintrinsic. Shift/rotate amounts are
i32(extended toi64in codegen),matching v0.2.0's
Intamount type.Codegen.RuntimeTypes: four value types appended at indices 8-11(
$I32Arr,$F64Arr,$Int64 = (struct i64),$I64Arr = (array (mut i64)));count, destructuring, and guard at 12.
Codegen.Value:boxInt64/unboxInt64Expr, wired intocoerce.Codegen.Prim: each op lowered inline;fromHiLozero-extends the low word bymasking (no
extend_i32_uis bound), arraySetre-yields the threaded array.Codegen: a compile-timecheckedPrimpost-check that the binaryen typegenPrimemits matches the declaredprimRep(O(1), separable from the feature).Binaryen.purs/Binaryen.js: the i64 FFI surface.Checklist
CI passing is enforced by the required
ci-gatestatus check, not by a box here.The items below are the human-judgment gates:
Test.E2E.Cli.Int64andTest.E2E.Cli.PackedArrays(both registered,routinely-run e2e lane) cover Int64 bitwise/shift/rotate/compare and
build/set/index/length + the zero-init contract for all three arrays. They import
the v0.2.0 primitives, so they cannot run in CI until that tag exists. Verified
locally with the pin pointed at my wasm-base fork; the suite passes and NIST SHA-3
vectors pass on wasm through a downstream Keccak built on these intrinsics.
new intrinsics are unreferenced by any existing code path, and the new types append
at indices 8-11 (0-7 unchanged), so every benchmark's compiled code is unchanged.
bench/snapshots/baseline.jsonleft untouched.$I32Arr,$F64Arr,$Int64,$I64Arrare all acyclic, each emitted as its own singleton rec group like theexisting value types; appending them doesn't perturb the other eight types'
canonical identity, so the ABI is unchanged and
runtime.watneeds no edit.$I32Arris structurally identical to$Bytesand canonicalises with it today;it's kept a distinct nominal type so a future packed-byte
$Strcan't alias it.Depends on
wasm-base v0.2.0 (
Wasm.Int64,Wasm.I32Array,Wasm.F64Array,Wasm.I64Array).The latest published wasm-base tag is v0.1.1, so I've pinned the additive next
version,
purs-wasm/purescript-wasm-base @ v0.2.0. That tag isn't cut yet; if you'drather it be a different number, tell me and I'll repoint the pin. (To avoid a
versioning mix-up I made myself: the
0.2.0inpurs-wasm/package.jsonis the CLIpackage's version, a separate line from the wasm-base library tag, which lives in
that repo's
spago.yaml.)Note for the maintainer
To turn CI green, wasm-base v0.2.0 needs to be tagged on
purs-wasmso the pinresolves. Happy to coordinate timing. If you'd like CI to exercise the suite on this
draft before the tag exists, I can temporarily point the pin at my wasm-base fork and
revert it to the canonical tag before merge. Marked draft until the dependency lands.