summaryrefslogtreecommitdiff
path: root/scripts
Commit message (Collapse)AuthorAgeFilesLines
...
* [threads] ref.i31_shared (#6735)Thomas Lively2024-07-123-3/+5
| | | | | | | Implement `ref.i31_shared` the new instruction for creating references to shared i31s. Implement binary and text parsing and emitting as well as interpretation. Copy the upstream spec test for i31 and modify it so that all the heap types are shared. Comment out some parts that we do not yet support.
* [StackIR] Allow StackIR to be disabled from the commandline (#6725)Alon Zakai2024-07-101-0/+1
| | | | | | | | | Normally we use it when optimizing (above a certain level). This lets the user prevent it from being used even then. Also add optimization options to wasm-metadce so that this is possible there as well and not just in wasm-opt (this also opens the door to running more passes in metadce, which may be useful later).
* Rename external conversion instructions (#6716)Jérôme Vouillon2024-07-082-3/+5
| | | | | | | | | Rename instructions `extern.internalize` into `any.convert_extern` and `extern.externalize` into `extern.convert_any` to follow more closely the spec. This was changed in https://github.com/WebAssembly/gc/issues/432. The legacy name is still accepted in text inputs and in the C and JS APIs.
* [threads] Ignore shared-array.wast in fuzzer initial contents (#6706)Thomas Lively2024-06-261-0/+1
|
* [threads] Validate shared-polymorphic instructions (#6702)Thomas Lively2024-06-251-0/+1
| | | | Such as `ref.eq`, `i31.get_{s,u}`, and `array.len`. Also validate that struct and array operations work on shared structs and arrays.
* Re-enable spec tests requiring multivalue (#6684)Thomas Lively2024-06-201-2/+0
| | | And delete tests that no longer pass now that multivalue is standard.
* Validate memarg offsets (#6683)Thomas Lively2024-06-201-2/+1
| | | | | For 32-bit memories, the offset value must be in the u32 range. Update the address.wast spec test to assert that a module with an overlarge offset value is invalid rather than malformed.
* Validate that names are valid UTF-8 (#6682)Thomas Lively2024-06-191-4/+0
| | | | | | Add an `isUTF8` utility and use it in both the text and binary parsers. Add missing checks for overlong encodings and overlarge code points in our WTF8 reader, which the new utility uses. Re-enable the spec tests that test UTF-8 validation.
* Fix validation of unused LEB128 bits (#6680)Thomas Lively2024-06-191-1/+0
| | | | | The unused bits must be a sign extension of the significant value, but we were previously only validating that unsigned LEBs had their unused bytes set to zero. Re-enable the spec test that checks for proper validation.
* Check malformed mutability on imported globals (#6679)Thomas Lively2024-06-181-1/+0
| | | And re-enable the globals.wast spec test, which checks this.
* Re-enable binary.wast spec test (#6677)Thomas Lively2024-06-181-3/+0
| | | | | | Fix the wast parser to accept IDs on quoted modules, remove tests that are invalidated by the multimemory proposal, and add validation that the total number of variables in a function is less than 2^32 and that the code section is present if there is a non-empty function section.
* [Parser] Fix bug in unreachable fallback logic (#6676)Thomas Lively2024-06-181-3/+0
| | | | | | | | | When popping past an unreachable instruction would lead to popping from an empty stack or popping an incorrect type, we need to avoid popping and produce new Unreachable instructions instead to ensure we parse valid IR. The logic for this was flawed and made the synthetic Unreachable come before the popped unreachable child, which was not correct in the case that that popped unreachable was a branch or other non-trapping instruction. Fix and simplify the logic and re-enable the spec test that uncovered the bug.
* fix(#6671): fix possible stack buffer overflow in gen-s-parser.inc (#6678)mtb2024-06-181-0/+6
| | | | | | The stack buffer overflow is occurring because memcpy(buf, op.data(), op.size()); can write up to op.size() bytes into buf, but buf is only 33 bytes long. If op.size() is greater than 33, this will result in a buffer overflow.
* Reject invalid section IDs (#6675)Thomas Lively2024-06-181-1/+0
| | | | | | Rather than treating them as custom sections. Also fix UB where invalid `Section` enum values could be used as keys in a map. Use the raw `uint8_t` section IDs as keys instead. Re-enable a disabled spec test that was failing because of this bug and UB.
* Enable more spec tests (#6669)Thomas Lively2024-06-172-43/+30
| | | | | Re-triage all the disabled spec tests and re-enable many of them. Improve the module splitting logic to correctly handle (by skipping) quoted modules and their associated assertions.
* [threads] Binary reading and writing of shared composite types (#6664)Thomas Lively2024-06-141-0/+4
| | | | Also update the parser so that implicit type uses are not matched with shared function types.
* Remove obsolete parser code (#6607)Thomas Lively2024-05-291-617/+598
| | | | | Remove `SExpressionParser`, `SExpressionWasmBuilder`, and `cashew::Parser`. Simplify gen-s-parser.py. Remove the --new-wat-parser and --deprecated-wat-parser flags.
* Fuzzer: Stop testing with TurboFan as Turboshaft is rolling out and is ↵Alon Zakai2024-05-281-7/+0
| | | | faster (#6623)
* Fix binary emitting of br_if with a refined value by emitting a cast (#6510)Alon Zakai2024-05-161-1/+18
| | | | | | | | | | | | | | | | This makes us compliant with the wasm spec by adding a cast: we use the refined type for br_if fallthrough values, and the wasm spec uses the branch target. If the two differ, we add a cast after the br_if to make things match. Alternatively we could match the wasm spec's typing in our IR, but we hope the wasm spec will improve here, and so this is will only be temporary in that case. Even if not, this is useful because by using the most refined type in the IR we optimize in the best way possible, and only suffer when we emit fixups in the binary, but in practice those cases are very rare: br_if is almost always dropped rather than used, in real-world code (except for fuzz cases and exploits). We check carefully when a br_if value is actually used (and not dropped) and its type actually differs, and it does not already have a cast. The last condition ensures that we do not keep adding casts over repeated roundtripping.
* [Strings] Remove operations not included in imported strings (#6589)Thomas Lively2024-05-151-20/+3
| | | | | | The stringref proposal has been superseded by the imported JS strings proposal, but the former has many more operations than the latter. To reduce complexity, remove all operations that are part of stringref but not part of imported strings.
* [Strings] Remove stringview types and instructions (#6579)Thomas Lively2024-05-151-11/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The stringview types from the stringref proposal have three irregularities that break common invariants and require pervasive special casing to handle properly: they are supertypes of `none` but not subtypes of `any`, they cannot be the targets of casts, and they cannot be used to construct nullable references. At the same time, the stringref proposal has been superseded by the imported strings proposal, which does not have these irregularities. The cost of maintaing and improving our support for stringview types is no longer worth the benefit of supporting them. Simplify the code base by entirely removing the stringview types and related instructions that do not have analogues in the imported strings proposal and do not make sense in the absense of stringviews. Three remaining instructions, `stringview_wtf16.get_codeunit`, `stringview_wtf16.slice`, and `stringview_wtf16.length` take stringview operands in the stringref proposal but cannot be removed because they lower to operations from the imported strings proposal. These instructions are changed to take stringref operands in Binaryen IR, and to allow a graceful upgrade path for users of these instructions, the text and binary parsers still accept but ignore `string.as_wtf16`, which is the instruction used to convert stringrefs to stringviews. The binary writer emits code sequences that use scratch locals and `string.as_wtf16` to keep the output valid. Future PRs will further align binaryen with the imported strings proposal instead of the stringref proposal, for example by making `string` a subtype of `extern` instead of a subtype of `any` and by removing additional instructions that do not have analogues in the imported strings proposal.
* Fix running just a single spec test via `check.py spec --spec-test foo`. ↵Sam Clegg2024-05-101-5/+6
| | | | NFC (#6580)
* Fuzzer: Add another stringview subtyping error message to ignore (#6575)Alon Zakai2024-05-091-0/+1
|
* Fuzzer: Stop emitting nullable stringviews (#6574)Alon Zakai2024-05-081-0/+3
| | | | | | | | | | | | | As of https://chromium-review.googlesource.com/c/v8/v8/+/5471674 V8 requires stringviews to be non-nullable. It might be possible to make that change in our IR, or to remove views entirely, but for now this PR makes the fuzzer stop emitting nullable stringviews as a workaround to allow us to fuzz current V8. There are still rare corner cases where this pattern is emitted, that we have not tracked down, and so this also makes the fuzzer ignore the error for now.
* Re-enable fuzzing of text round trips (#6560)Thomas Lively2024-04-291-2/+1
| | | The bug that had been preventing this fuzzing no longer reproduces.
* [Strings] Add the string heaptype to core fuzzer places (#6527)Alon Zakai2024-04-231-1/+2
| | | | | | | With this we emit strings spontaneously (as opposed to just getting them from initial contents). The relevant -ttf test has been tweaked slightly to show the impact of this change: now there are some string.new/const in the output.
* Fuzzer: Do not run other VMs if the Binaryen interpreter hits a VM ↵Alon Zakai2024-04-101-10/+19
| | | | | | | | | limitation (#6483) The VM limitation might be an OOM (which can change due to opts) or an atomic wait (which can hang on proper VMs with support). We already avoided running VMs on the optimized wasm in this case, but we still ran them on the original wasm, which this changes, mainly to avoid that atomic wait situation.
* [NFC] Fix fuzzer counting of ignored runs due to many errors (#6444)Alon Zakai2024-03-271-4/+12
| | | | | | When the interpreter sees that most exports simply trap we mark the iteration as ignored. But we run the interpreter on the before wasm and also the after wasm, so we were incrementing that counter by 2 each time, which could be misleading.
* [Strings] Escape strings printed by fuzz-exec (#6441)Thomas Lively2024-03-261-3/+52
| | | | | | | | | | | Previously we printed strings as WTF-8 in the output of fuzz-exec, but this could produce invalid unicode output and did not make unprintable characters visible. Fix both these problems by escaping the output, using the JSON string escape procedure since the string to be escaped is WTF-16. Reimplement the same escaping procedure in fuzz_shell.js so that the way we print strings when running on a real JS engine matches the way we print them in our own fuzz-exec interpreter. Fixes #6435.
* [Strings] Represent string values as WTF-16 internally (#6418)Thomas Lively2024-03-221-3/+0
| | | | | | | | | | | | | | | | WTF-16, i.e. arbitrary sequences of 16-bit values, is the encoding of Java and JavaScript strings, and using the same encoding makes the interpretation of string operations trivial, even when accounting for non-ascii characters. Specifically, use little-endian WTF-16. Re-encode string constants from WTF-8 to WTF-16 in the parsers, then back to WTF-8 in the writers. Update the constructor for string `Literal`s to interpret the string as WTF-16 and store a sequence of WTF-16 code units, i.e. 16-bit integers. Update `Builder::makeConstantExpression` accordingly to convert from the new `Literal` string representation back to a WTF-16 string. Update the interpreter to remove the logic for detecting non-ascii characters and bailing out. The naive implementations of all the string operations are correct now that our string encoding matches the JS string encoding.
* Update file name in INITIAL_CONTENTS_IGNORE (#6425)Thomas Lively2024-03-221-1/+1
| | | | The test file was renamed, but the fuzzer still used the old name in INITIAL_CONTENTS_IGNORE.
* [Strings] Implement stringview_wtf16.slice (#6404)Alon Zakai2024-03-191-1/+2
|
* Typed continuations: suspend instructions (#6393)Frank Emrich2024-03-192-0/+2
| | | | | | | | | | | | | | | | | | | | | This PR is part of a series that adds basic support for the [typed continuations/wasmfx proposal](https://github.com/wasmfx/specfx). This particular PR adds support for the `suspend` instruction for suspending with a given tag, documented [here](https://github.com/wasmfx/specfx/blob/main/proposals/continuations/Overview.md#instructions). These instructions are of the form `(suspend $tag)`. Assuming that `$tag` is defined with _n_ `param` types `t_1` to `t_n`, the instruction consumes _n_ arguments of types `t_1` to `t_n`. Its result type is the same as the `result` type of the tag. Thus, the folded textual representation looks like `(suspend $tag arg1 ... argn)`. Support for the instruction is implemented in both the old and the new wat parser. Note that this PR does not implement validation of the new instruction. This PR also fixes finalization of `cont.new`, `cont.bind` and `resume` nodes in those cases where any of their children are unreachable.
* Fuzzer: Fix up null outputs in wasm2js optimized builds (#6374)Alon Zakai2024-03-081-0/+15
| | | | | | | | This is fallout from #6310 where we moved to use fuzz_shell.js for all fuzzing purposes. That script doesn't know wasm types, all it has on the JS side is the number of arguments to a function, and it passes in null for them all regardless of their type. That normally works fine - null is cast to the right type upon use - but in wasm2js optimized builds we can remove casts, which can make that noticeable.
* Do not write assertions to split.wast for spec tests (#6383)Thomas Lively2024-03-071-1/+1
| | | | | | | | | | As part of our running of spec tests, we split out each module in a test script into a separate text file for processing with wasm-opt. We previously included the test assertions corresponding to the module into that text file, where they were ignored by the legacy text parser. The new parser errors out due to the extra tokens after the module, though, so to avoid problems once we switch to the new parser, stop including the assertions in those text files. Also remove a nearby unused argument as a drive-by cleanup.
* Fuzzer: Standardize notation for exception prefixes (#6369)Alon Zakai2024-03-052-4/+10
| | | | | | | | | We had exception: in one and exception thrown: in another. Making those consistent allows fuzz_shell.js to print the exception after that prefix, which makes debugging easier sometimes. Also canonicalize tag names. Like funcref names, JS VMs print out the internal name, which can change after opts, so canonicalize it.
* Fuzzer: Ignore fuzz testcases that make VMs run out of stack (#6376)Alon Zakai2024-03-041-8/+19
| | | | | | | | | | | | | | | When the stack runs out is observable and optimizations can change it, so we must ignore such testcases. Also add some logic to help debug stuff like this, as suggested by tlively in the past, to add some metrics on the reasons we ignored a testcase. That emits something like this: (ignored 253 iters, for reasons {'too many errors vs calls': 230, '[host limit ': 20, 'uninitialized non-defaultable local': 3}) As a drive by make the metrics print wasm bytes/iter rather than by second (the former is easy to compute from the latter anyhow, and the latter is more interesting I think).
* Typed continuations: cont.bind instructions (#6365)Frank Emrich2024-03-042-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | This PR is part of a series that adds basic support for the [typed continuations/wasmfx proposal](https://github.com/wasmfx/specfx). This particular PR adds support for the `cont.bind` instruction for partially applying continuations, documented [here](https://github.com/wasmfx/specfx/blob/main/proposals/continuations/Overview.md#instructions). In short, these instructions are of the form `(cont.bind $ct_before $ct_after)` where `$ct_before` and `$ct_after` are related continuation types. They must only differ in the number of arguments, where `$ct_before` has _n_ additional parameters as compared to `$ct_after`, for some _n_ ≥ 0. The idea is that `(cont.bind $ct_before $ct_after)` then takes a reference to a continuation of type `$ct_before` as well as _n_ operands and returns a (reference to a) continuation of type `$ct_after`. Thus, the folded textual representation looks like `(cont.bind $ct_before $ct_after arg1 ... argn c)`. Support for the instruction is implemented in both the old and the new wat parser. Note that this PR does not implement validation of the new instruction.
* Fuzzing: Remove some obsolete experimental V8 flags (#6347)Alon Zakai2024-02-281-4/+0
| | | | Those flags were removed in V8 as the features are no longer experimental. This PR removes some warnings from being logged (but V8 does not error on them).
* Fuzz V8 Turboshaft (#6360)Alon Zakai2024-02-281-1/+8
|
* Fuzzer: Separate arguments used to make the fuzz wasm from the opts we run ↵Alon Zakai2024-02-271-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | on it (#6357) Before FUZZ_OPTS was used both when doing --translate-to-fuzz/-ttf to generate the wasm from the random bytes and also when later running optimizations to generate a second wasm file for comparison. That is, we ended up doing this, if the opts were -O3: wasm-opt random.input -ttf -o a.wasm -O3 wasm-opt a.wasm -O3 -o b.wasm Now we have a pair a.wasm,b.wasm which we can test. However, we have run -O3 on both which is a little silly - the second -O3 might not actually have anything left to do, which would mean we compare the same wasm to itself. Worse, this is incorrect, as there are things we need to do only during the generation phase, like --denan. We need that in order to generate a valid wasm to test on, but it is "destructive" in itself: when removing NaNs (to avoid nondeterminism) if replaces them with 0, which is different. As a result, running --denan when generating the second wasm from the first could lead to different execution in them. This was always a problem, but became more noticable recently now that DeNaN modifies SIMD operations, as one optimization we do is to replace a memory.copy with v128.load + v128.store, and --denan will make sure the loaded value has no NaNs... To fix this, separate the generation and optimization phase. Instead of wasm-opt random.input -ttf -o a.wasm --denan -O3 wasm-opt a.wasm --denan -O3 -o b.wasm (note how --denan -O3 appears twice), do this: wasm-opt random.input -ttf -o a.wasm --denan wasm-opt a.wasm -O3 -o b.wasm (note how --denan appears in generation, and -O3 in optimization).
* [Parser] Parse annotations, including source map comments (#6345)Thomas Lively2024-02-261-2/+2
| | | | | | | | | | Parse annotations using the standards-track `(@annotation ...)` format as well as the `;;@ source-map:0:1` format. Have the lexer implicitly collect annotations while it skips whitespace and add lexer APIs to access the annotations since the last token was parsed. Collect annotations before parsing each instruction and pass the annotations explicitly to the parser and parser context functions for instructions. Add an API to `IRBuilder` to set a debug location to be attached to the next visited or created instruction and use it from the parser.
* Fuzzer: Fix BigInt printing (#6348)Alon Zakai2024-02-261-0/+4
| | | | Before this we only printed the type of a BigInt and not the value.
* Fuzzer: Handle negative i31s (#6341)Alon Zakai2024-02-231-1/+1
|
* Fuzzer: Ignore V8 errors on uninitialized non-defaultable locals (#6337)Alon Zakai2024-02-221-0/+9
| | | | | | | | | | See #5665 #5599, this is an existing issue and we have a workaround for it using --dce, but it does not always work. I seem to be seeing this in higher frequency since landing recent fuzzer improvements, so ignore it. There is some risk of us missing real bugs here (that we validate and V8 does not), but this is a validation error which is not as serious as a difference in behavior. And this is a long-standing issue that hasn't bitten us yet.
* Typed continuations: cont.new instructions (#6308)Frank Emrich2024-02-222-0/+2
| | | | | | | | | | | | | | | | | This PR is part of a series that adds basic support for the [typed continuations/wasmfx proposal](https://github.com/wasmfx/specfx). This particular PR adds support for the `cont.new` instruction for creating continuations, documented [here(https://github.com/wasmfx/specfx/blob/main/proposals/continuations/Overview.md#instructions). In short, these instructions are of the form `(cont.new $ct)` where `$ct` must be a continuation type. The instruction takes a single (nullable) function reference as its argument, which means that the folded representation of the instruction is of the form `(cont.new $ct (foo ...))`. Support for the instruction is implemented in both the old and the new wat parser. Note that this PR does not implement validation of the new instruction.
* Fuzzer: Adjust feature fuzzing frequency (#6305)Alon Zakai2024-02-221-14/+21
| | | | | | | | | We used to fuzz MVP 1/3, all 1/3, and a mixture 1/3, but that gives far too much priority to the MVP which is increasingly less important. It is also a good idea to give "all" more priority as that enables more initial content to run (the fuzzer will discard initial content if it doesn't validate with the features chosen in the current iteration). Also (NFC) rename POSSIBLE_FEATURE_OPTS to make the code easier to follow.
* Fuzzer: Allow using initial content with V8 (#6327)Alon Zakai2024-02-223-5/+8
| | | | | | | | | | | | | | | One problem was that spec testcases had exports with names that are not valid to write as JS exports.name. For example an export with a - in the name would end up as exports.foo-bar etc. Since #6310 that is fixed as we do not emit such JS (we use the generic fuzz_shell.js script which iterates over the keys in exports with exports[name]). Also fix a few trivial fuzzer issues that initial content uncovered: - Ignore a wat file with invalid utf-8. - Print string literals in the same way from JS as from C++. - Enable the stringref flag in V8. - Remove tag imports (the same as we do for global and function and other imports).
* Fuzzer: Match the logging of i31ref between JS and C++ (#6335)Alon Zakai2024-02-221-0/+4
| | | | | | | | | | | | | JS engines print i31ref as just a number, so we need a small regex to standardize the representation (similar to what we do for funcrefs on the code above). On the C++ side, make it actually print the i31ref rather than treat it like a generic reference (for whom we only print "object"). To do that we must unwrap an externalized i31 as necessary, and add a case for i31 in the printing logic. Also move that printing logic to its own function, as it was starting to get quite long.
* Fuzzer: Add a pass to prune illegal imports and exports for JS (#6312)Alon Zakai2024-02-202-3/+8
| | | | | | | | | | | | | | | | | | We already have passes to legalize i64 imports and exports, which the fuzzer will run so that we can run wasm files in JS VMs. SIMD and multivalue also pose a problem as they trap on the boundary. In principle we could legalize them as well, but that is substantial effort, so instead just prune them: given a wasm module, remove any imports or exports that use SIMD or multivalue (or anything else that is not legal for JS). Running this in the fuzzer will allow us to not skip running v8 on any testcase we enable SIMD and multivalue for. (Multivalue is allowed in newer VMs, so that part of this PR could be removed eventually.) Also remove the limitation on running v8 with multimemory (v8 now supports that).