Skip to content

Verify which error the spec runner's error assertions actually got - #87

Merged
ziggy42 merged 13 commits into
mainfrom
fix/spec-runner-error-assertions
Aug 8, 2026
Merged

ziggy42 merged 13 commits into
mainfrom
fix/spec-runner-error-assertions

Conversation

@ziggy42

@ziggy42 ziggy42 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

The spec runner checked error assertions with err == nil, so a module
failing for entirely the wrong reason counted as a pass. Every assert_*
form now checks the reason wast2json recorded for it.

This is what PR #86 ran into: three of the four spec violations it fixed were
invisible because the runner could not observe them. Green did not mean
compliant.

What the check found

Nothing was wrongly accepted anywhere: all 5372 assertions already produced
an error. What they produced was often not the failure the spec describes.

Form Checked Reported the wrong reason
assert_trap 2408 25
assert_uninstantiable 34 0
assert_exhaustion 15 0
assert_unlinkable 83 83
assert_invalid 2146 1212
assert_malformed 719 631

Most of that is vocabulary — one rename accounts for 528 assertions. The
substantive findings:

  • call_indirect with an out-of-range index reported out of bounds table access. The spec separates this from the table accessor instructions, which
    keep that wording; call_indirect traps with undefined element.
  • INT_MIN / -1 reported integer divide overflow instead of the
    integer overflow the truncation traps already used.
  • Linking errors never distinguished an import that was missing from one
    present with the wrong type. Both conditions already had separate code paths.
  • memory.init and table.init checked their data or element segment
    before the memory or table the instruction addresses, so a module declaring
    neither blamed the segment.
  • Constant expressions reported a global that does not exist and a global
    that is mutable as the same failure.
  • One invalid limits covered the spec's page ceiling, the host's
    configured ceiling, and a minimum above the maximum. The spec ceiling is now
    checked separately, so a host configuring a lower one is not reported as a
    spec violation.
  • The parser surfaced a bare EOF for every way a read can run out. It now
    states which, and distinguishes a truncated instruction sequence from one
    merely missing its end opcode.
  • Limits flags and the function type prefix were read as plain bytes, so an
    over-long LEB128 encoding of either passed as valid.
  • Bit 6 of a memarg selects an explicit memory index, which only
    multi-memory allows. It was accepted unconditionally.

Matching

The expected reason is matched as a prefix ending at a word boundary, which is
what the suite requires of itself: bulk.wast expects the same call_indirect
trap as both uninitialized element 2 and uninitialized element, so no single
message can match both exactly. Epsilon keeps its detail as a suffix.

Four assertions cannot be satisfied from the binary a module was compiled to,
and are listed in the runner with the reason:

  • select.wast expects invalid result arity from (select (result) …), which
    wat2wasm compiles to a module byte-identical to the one the assertion before
    it expects to fail with type mismatch.
  • Three expect what the reference interpreter reports after reading past a
    section's declared size — binary.wast:93 says as much in a comment. Epsilon
    stops at the declared size, and that bound is what keeps a malformed module
    from reading beyond itself, so it was not relaxed to match.

Notes

Error strings changed across the parser, validator, and import linking. They
are unexported values, so nothing could have matched on them programmatically.

Five parser and validation tests asserted errors that gained a more precise
reason. One of them parsed a module with multi-memory off and validated it with
the option on; the new memarg check rejects that at parse time, so it now reads
the module under the config it validates it with.

The runner still skips the 1091 assert_malformed cases given as text-format
modules, which it cannot compile. That predates this change.

make fmt, make vet, make test-all and GOARCH=amd64 go test ./... pass.

🤖 Generated with Claude Code

ziggy42 added 13 commits August 2, 2026 17:43
The spec runner only checked that error assertions produced some error, so
a module trapping for entirely the wrong reason counted as a pass. Carry
wast2json's "text" field through and compare it against the trap message.

The expected reason is matched as a prefix ending at a word boundary,
which is the matching the reference interpreter performs: bulk.wast
expects the same call_indirect trap as both "uninitialized element 2" and
"uninitialized element", so no single message can match both exactly.

This surfaced two spec violations:

- call_indirect with an out-of-range table index reported "out of bounds
  table access". The spec distinguishes this from the table accessor
  instructions, which keep that wording; call_indirect traps with
  "undefined element".
- Dividing the most negative integer by -1 reported "integer divide
  overflow" rather than the "integer overflow" the truncation traps
  already used. The two conditions now share one error.
assert_uninstantiable and assert_unlinkable only checked that some error
came back, and assert_exhaustion compared against a hardcoded string
rather than the reason the assertion states. Route all three through the
same check assert_trap uses.

assert_uninstantiable (34 assertions) and assert_exhaustion (15) already
reported the right reason. All 83 assert_unlinkable assertions were
passing on the wrong message: epsilon named the offending import first
and used its own vocabulary, so nothing distinguished an import that was
missing from one that was present with the wrong type. The two conditions
already had separate code paths, so this is wording only -- they now lead
with the "unknown import" and "incompatible import type" reasons the spec
states, keeping the import name and the specific mismatch as detail.

assert_invalid and assert_malformed remain unchecked.
The runner accepted any error from a module an assertion expects the
validator to reject, so a module rejected for an unrelated reason counted
as a pass. Check the stated reason, as assert_trap already does.

No module was wrongly accepted: all 2146 assertions were rejected
already, 934 of them with the message the spec states. The rest reported
the same failures in epsilon's own vocabulary, which the validator now
states the spec way, keeping its detail as a suffix. The out-of-range
index errors collapse into one unknownIndex helper, since the spec names
the offending index in several of the messages.

Three failures were being reported as the wrong condition rather than
just the wrong wording:

- memory.init and table.init checked their data or element segment before
  the memory or table the instruction addresses, so a module declaring
  neither blamed the segment.
- A constant expression naming a global that is not an immutable import
  reported that a constant expression was required, whether the global
  was mutable or did not exist at all.
- One "invalid limits" covered exceeding the spec's page ceiling,
  exceeding the host's configured ceiling, and a minimum above the
  maximum. The spec ceiling is now checked separately from the host's, so
  a host that configures a lower one is not reported as a spec violation.

One assertion cannot be satisfied from the binary: select.wast expects
"invalid result arity" for (select (result) ...), which wat2wasm encodes
as the untyped select opcode, making the module byte-identical to the one
the preceding assertion expects to fail with "type mismatch". The runner
records that pair as indistinguishable rather than weakening the check.

assert_malformed remains unchecked.
The last of the error assertions to check only that some error came back.
Of the 1810 assertions, 719 run; the rest are text-format modules the
runner cannot compile. Nothing was wrongly accepted, but only 88 stated
the reason the spec gives.

Most of the gap was vocabulary, one rename covering 528 assertions on its
own, and four parse errors that buried the reason behind the context they
were wrapped in. The rest were reported as the wrong condition:

- The parser surfaced a bare EOF for every way a read can run out. It now
  states which: input ending outside a section, input ending part way
  through a declared payload, a read reaching the end of the section that
  bounds it, and a LEB128 needing more bytes than its section holds. This
  reports what the parser already knew at the point of failure and reads
  no further than before.
- A sequence the input ran out of was reported as missing its end opcode,
  which is a different defect from being cut short.
- Limits flags and the function type prefix were read as plain bytes, so
  an over-long LEB128 encoding of either passed as valid.
- Bit 6 of a memarg selects an explicit memory index, which only
  multi-memory allows. It was accepted unconditionally.
- An undefined opcode in a constant expression was reported as an
  instruction that may not appear there, rather than as no instruction at
  all.

Three assertions expect what the reference interpreter reports after
reading past a section's declared size, which binary.wast:93 says as much
in a comment. Epsilon stops at the declared size and reports the boundary
it hit, so those join the runner's list of reasons the binary cannot
distinguish rather than that bound being relaxed to match.

Four parser tests asserted the errors that gained a more precise reason.
A fifth parsed a module with multi-memory off and validated it with the
option on; the memarg check now rejects that at parse time, so it reads
the module under the config it validates it with.
Fold the multi-memory rejection into the branch that already tests bit 6,
so an instruction without an explicit memory index pays one test for it
instead of two. Decide truncation in readCode where the error surfaces,
since lastOp and the control stack are already final there, keeping the
extra state out of the decode loop. Skip discardRemaining's copy when the
bounded region holds nothing, which is every function body the decoder
consumed to its end.
Order the reader's error checks cheapest first: comparing against io.EOF
loads the itab and data words of a package variable, while a nil check
reads neither and a length check reads neither, so the interface
comparison now runs only once the cheaper test has already selected for
it.

Let the byte counter run negative outside a bounded region instead of
pinning it at -1. Nothing reads the sentinel's exact value, so the guard
that kept it there can go and the counter can be decremented
unconditionally, which takes a branch off the path every byte travels.
@ziggy42
ziggy42 merged commit 24b949d into main Aug 8, 2026
2 checks passed
@ziggy42
ziggy42 deleted the fix/spec-runner-error-assertions branch August 8, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant