Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ insta = "1.48.0"
predicates = "3.1.4"
rstest = "0.26.1"
tempfile = "3.27.0"
wast = { version = "258.0.0", default-features = false, features = ["wasm-module"] }

[lints.rust]
unsafe_code = "forbid"
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/wasm-spec/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Official WebAssembly core-suite fixture

`i32-arithmetic.wast` is a bounded, checked-in slice of the official
WebAssembly core test suite. It is copied from
[`test/core/i32.wast`](https://github.com/WebAssembly/spec/blob/fc209c5ed8afc4dfeb9252024d217da3376c7a6f/test/core/i32.wast)
at source revision `fc209c5ed8afc4dfeb9252024d217da3376c7a6f`.

The slice covers signed i32 add, subtract, multiply, and divide, including
wraparound values and the official divide-by-zero and signed-overflow trap
assertions. It is intentionally not presented as the whole specification
suite: the current compiler can only execute the subset represented by this
fixture through its existing decode, translation, and pinned Luau runtime path.

`tests/wasm_spec.rs` parses this fixture with the `wast` parser, encodes each
module, sends it through `decode_module` and `translate_module`, and executes
the generated Luau with the pinned official Luau binary. The harness reports
passed, failed, and skipped-by-scope assertions separately. Return assertions
for unsupported shapes are skipped by scope; a trap assertion that cannot be
compiled or executed is a failure, never a pass.

At the current compiler revision this slice reports 17 passed and 4 failed:
the four failures are the deliberately exercised `div_s` trap assertions.
That red result is the regression signal for missing trap semantics, not a
reason to widen the fixture or count unsupported behavior as success.
36 changes: 36 additions & 0 deletions tests/fixtures/wasm-spec/core/i32-arithmetic.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;; This fixture is copied from the official WebAssembly core suite's i32.wast.
;; Keep the source revision and selected assertions documented alongside it.

(module
(func (export "add") (param $x i32) (param $y i32) (result i32) (i32.add (local.get $x) (local.get $y)))
(func (export "sub") (param $x i32) (param $y i32) (result i32) (i32.sub (local.get $x) (local.get $y)))
(func (export "mul") (param $x i32) (param $y i32) (result i32) (i32.mul (local.get $x) (local.get $y)))
(func (export "div_s") (param $x i32) (param $y i32) (result i32) (i32.div_s (local.get $x) (local.get $y)))
)

(assert_return (invoke "add" (i32.const 1) (i32.const 1)) (i32.const 2))
(assert_return (invoke "add" (i32.const -1) (i32.const 1)) (i32.const 0))
(assert_return (invoke "add" (i32.const 0x7fffffff) (i32.const 1)) (i32.const 0x80000000))
(assert_return (invoke "add" (i32.const 0x80000000) (i32.const -1)) (i32.const 0x7fffffff))

(assert_return (invoke "sub" (i32.const 1) (i32.const 1)) (i32.const 0))
(assert_return (invoke "sub" (i32.const 0x7fffffff) (i32.const -1)) (i32.const 0x80000000))
(assert_return (invoke "sub" (i32.const 0x80000000) (i32.const 1)) (i32.const 0x7fffffff))
(assert_return (invoke "sub" (i32.const 0x80000000) (i32.const 0x80000000)) (i32.const 0))

(assert_return (invoke "mul" (i32.const 1) (i32.const 1)) (i32.const 1))
(assert_return (invoke "mul" (i32.const -1) (i32.const -1)) (i32.const 1))
(assert_return (invoke "mul" (i32.const 0x10000000) (i32.const 4096)) (i32.const 0))
(assert_return (invoke "mul" (i32.const 0x80000000) (i32.const -1)) (i32.const 0x80000000))
(assert_return (invoke "mul" (i32.const 0x7fffffff) (i32.const -1)) (i32.const 0x80000001))
(assert_return (invoke "mul" (i32.const 0x01234567) (i32.const 0x76543210)) (i32.const 0x358e7470))

;; These trap assertions must fail until the generated helper models the
;; specification's divide-by-zero and signed-overflow traps.
(assert_trap (invoke "div_s" (i32.const 1) (i32.const 0)) "integer divide by zero")
(assert_trap (invoke "div_s" (i32.const 0) (i32.const 0)) "integer divide by zero")
(assert_trap (invoke "div_s" (i32.const 0x80000000) (i32.const -1)) "integer overflow")
(assert_trap (invoke "div_s" (i32.const 0x80000000) (i32.const 0)) "integer divide by zero")
(assert_return (invoke "div_s" (i32.const 1) (i32.const 1)) (i32.const 1))
(assert_return (invoke "div_s" (i32.const -5) (i32.const 2)) (i32.const -2))
(assert_return (invoke "div_s" (i32.const 5) (i32.const -2)) (i32.const -2))
Loading
Loading