Commit 443fc54
authored
Store a full WasmFeatures inside of BinaryReader (#1548)
* Move `WasmFeatures` to a standalone module in `wasmparser`
This makes the type available even without the `validate` feature since
it doesn't have any intrinsic dependencies on validation.
* Extend `WasmFeatures` with methods for testing features
A bit nicer than `.contains(WasmFeatures::FEATURE)` and abstracts the
implementation for possible future iterations such as forcing features
to always be on.
* Store a full `WasmFeatures` inside of `BinaryReader`
Historically wasmparser has had a pretty clean split between validation
and parsing with the idea that the parser produces a bunch of stuff and
validation weeds it all out depending on activated features. Parsing has
historically not had access to the set of active features to have it
work the same no matter what. Over time, though, this has become quite
the burden.
The integration with the spec test repo in this repository tries to
make sure that any invalid wasm binary matches the same error message,
with a degree of flexibility. Not being able to take wasm features into
account when parsing makes this quite difficult. For example WebAssembly
binaries invalid before a feature is implemented might be valid after a
feature is implemented. They might also have an entirely different class
of error after a feature is implemented. Effectively WebAssembly does
not guarantee stability of the error message for invalid wasms as it
evolves, only that valid wasms all remain interpreted the same way.
Wasmparser has historically had a number of hacks around this. The
`roundtrip.rs` test suite has a very large function trying to match
error messages between wasmparser and the spec interpreter. Lots of
special cases happen here for wasmparser's feature-agnostic parser when
run against the spec test suite where each proposal has its own copy of
the spec interpreter, possibly with subtly different binary decoders.
Wasmparser additionally has hacks present in the public API such as
`BinaryReader::allow_memarg64` and the `table_byte` field of the
`CallIndirect` instruction. These have historically exclusively been
around to get the spec tests passing but otherwise serve no purpose.
Overall, there's been a lot of pain historically from not being able to
understand active wasm features when parsing wasm. It's quite easy to
write a code path along the lines of "if this feature is active parse
this way otherwise parse this way", but the features have never been
available to test this. Additionally `BinaryReader` instances were
created in quite a few locations throughout `wasmparser` which would
mean threading these around would be quite difficult. This commit
changes all of this.
This commit replaces the `allow_memarg64: bool` field of `BinaryReader`
with `features: WasmFeatures`. This means that all instances of
`BinaryReader` have access to all activated features and will be able to
parse differently when a feature is disabled or enabled. This should
make it much easier to pass the various stages of spec tests depending
on what happens to be merged into the spec interpreter.
To assist with threading this value around and to ensure it's accurate
the `new_with_offset` constructor of `BinaryReader` was removed and the
only remaining `new` constructor now requires that features must be
specified. Much of `wasmparser` has now additionally been refactored to
take a `BinaryReader` as a constructor rather than a slice-and-offset.
This centralizes the construction of `BinaryReader` and cuts down on
constant conversions in-and-out of a `BinaryReader`. For example much of
wasmparser now forwards along `BinaryReader` instances as-is. This is a
large-ish API change, too, for anyone constructing these manually
(shouldn't affect those exclusively using the validator).
The intention is that it's generally ok to pass `WasmFeatures::all()` to
the construction of a `BinaryReader`. For example the
`wasmparser::Parser` type defaults to having all features active. This
means that errors will be different (or not present) for newer wasm
features but they'll all still get filtered out by the validator. The
features in the `BinaryReader` are not intended to be a strict gating
procedure such that it's an exact wasm MVP parser, for example, instead
only being available as necessary for spec tests and other relevant edge
cases.
* Fix a rebase conflict
* Add missing calls to `shrink` for linking/reloc parsers
* Fix fuzzer compilation1 parent 143aacb commit 443fc54
51 files changed
Lines changed: 598 additions & 544 deletions
File tree
- crates
- wasm-encoder/src/core
- wasm-metadata/src
- wasm-mutate/src
- mutators
- wasmparser/src
- readers
- component
- core
- validator
- core
- wasmprinter/src
- wit-component
- src
- tests
- fuzz/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
603 | 604 | | |
604 | 605 | | |
605 | 606 | | |
606 | | - | |
| 607 | + | |
| 608 | + | |
607 | 609 | | |
608 | 610 | | |
609 | 611 | | |
| |||
688 | 690 | | |
689 | 691 | | |
690 | 692 | | |
691 | | - | |
| 693 | + | |
| 694 | + | |
692 | 695 | | |
693 | 696 | | |
694 | 697 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
| 224 | + | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | 251 | | |
256 | 252 | | |
257 | 253 | | |
258 | 254 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 255 | + | |
| 256 | + | |
265 | 257 | | |
266 | 258 | | |
267 | 259 | | |
| |||
281 | 273 | | |
282 | 274 | | |
283 | 275 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | 276 | | |
290 | 277 | | |
291 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
| 78 | + | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
| |||
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
104 | | - | |
| 103 | + | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| |||
143 | 142 | | |
144 | 143 | | |
145 | 144 | | |
146 | | - | |
147 | | - | |
| 145 | + | |
| 146 | + | |
148 | 147 | | |
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
155 | | - | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 31 | + | |
| 32 | + | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
182 | | - | |
183 | | - | |
| 183 | + | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
0 commit comments