Repository navigation
Verify which error the spec runner's error assertions actually got - #87
Merged
Merged
Conversation
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.
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.
The spec runner checked error assertions with
err == nil, so a modulefailing 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.
assert_trapassert_uninstantiableassert_exhaustionassert_unlinkableassert_invalidassert_malformedMost of that is vocabulary — one rename accounts for 528 assertions. The
substantive findings:
call_indirectwith an out-of-range index reportedout of bounds table access. The spec separates this from the table accessor instructions, whichkeep that wording;
call_indirecttraps withundefined element.INT_MIN / -1reportedinteger divide overflowinstead of theinteger overflowthe truncation traps already used.present with the wrong type. Both conditions already had separate code paths.
memory.initandtable.initchecked their data or element segmentbefore the memory or table the instruction addresses, so a module declaring
neither blamed the segment.
that is mutable as the same failure.
invalid limitscovered the spec's page ceiling, the host'sconfigured 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.
EOFfor every way a read can run out. It nowstates which, and distinguishes a truncated instruction sequence from one
merely missing its end opcode.
over-long LEB128 encoding of either passed as valid.
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.wastexpects the samecall_indirecttrap as both
uninitialized element 2anduninitialized element, so no singlemessage 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.wastexpectsinvalid result arityfrom(select (result) …), whichwat2wasm compiles to a module byte-identical to the one the assertion before
it expects to fail with
type mismatch.section's declared size —
binary.wast:93says as much in a comment. Epsilonstops 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_malformedcases given as text-formatmodules, which it cannot compile. That predates this change.
make fmt,make vet,make test-allandGOARCH=amd64 go test ./...pass.🤖 Generated with Claude Code