summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Stop propagating/inlining string constants (#6234)" (#6258)Alon Zakai2024-01-311-5/+3
| | | | | | | | | | This reverts commit 9090ce56fcc67e15005aeedc59c6bc6773220f11. This has the effect of once more propagating string constants from globals to other places (and from non-globals too), which is useful for various optimizations even if it isn't useful in the final output. To fix the final output problem, #6257 added a pass that is run at the end to collect string.const to globals, which allows us to once more propagate strings in the optimizer, now without a downside.
* StringGathering pass (#6257)Alon Zakai2024-01-314-65/+100
| | | | | | | | | | | | | | | This pass finds all string.const and creates globals for them. After this transform, no string.const appears anywhere but in a global, and each string appears in one global which is then global.get-ed everywhere. This avoids overhead in VMs where executing a string.const is an allocation, and is also a good step towards imported strings. For that, this pass will be extended from gathering to a full lowering pass, which will first gather into globals as this pass does, and then turn each of those globals with a string.const into an imported externref. (For that reason this pass is in a file called StringLowering, as the two passes will share much of their code, and the larger pass should decide the name I think.) This pass runs in -O2 and above. Repeated executions have no downside (see details in code).
* [PostEmscripten] Fix calcSegmentOffsets for large offsets (#6260)Sam Clegg2024-01-311-10/+32
| | | | Specifically offsets larger than 2^32 which were being interpreted misinterpreted here as very large int64_t values.
* [EH] Change translator option name (#6259)Heejin Ahn2024-01-303-3/+3
| | | | | | The previous name feels too verbose and unwieldy. This also removes the "new-to-old EH" placeholder. I think it'd be better to add it back when it is actually added.
* [Parser] Parse start declarations (#6256)Thomas Lively2024-01-301-2/+6
|
* Directize: Handle overflows and out of bounds (#6255)Alon Zakai2024-01-301-0/+174
|
* [Parser] Parse pops (by doing nothing) (#6252)Thomas Lively2024-01-301-23/+44
| | | | | | | | | | | | | Parse pop expressions and check that they have the expected types, but do not actually create new Pop expressions or push anything onto the stack because we already create Pop expressions as necessary when visiting the beginning of catch blocks. Unlike the legacy text parser, the new text parser is not capable of parsing pops in invalid locations in the IR. This means that the new text parser will never be able to parse test/lit/catch-pop-fixup-eh-old.wast, which deliberately parses invalid IR to check that the pops can be fixed up and moved to the correct locations. It should be acceptable to delete that test when we turn on the new parser by default, though, so that won't be a problem.
* Update pop text syntax (#6251)Thomas Lively2024-01-298-22/+22
| | | | | | Rather than `(pop valtype*)`, use `(pop valtype)`, where `valtype` is now allowed to be a tuple. This will make it possible to parse un-folded multivalue pops in the new text parser. The alternative would have been to put an arity in the syntax like we have for other tuple instructions, but that's much uglier.
* [Parser] Parse local.set and global.set of tuple values correctly (#6250)Thomas Lively2024-01-291-7/+50
| | | | These instructions always pop a single value, except when tuples are involved, in which case they need special handling to know how many values to pop.
* [Parser] Parse tuple types (#6249)Thomas Lively2024-01-291-1/+7
| | | | | Use the new `(tuple ...)` syntax. Enforce that tuples have a valid number of elements and are not nested to avoid assertion failures when parsing invalid input.
* Update the text syntax for tuple types (#6246)Thomas Lively2024-01-2643-229/+229
| | | | Instead of e.g. `(i32 i32)`, use `(tuple i32 i32)`. Having a keyword to introduce the s-expression is more consistent with the rest of the language.
* [EH] Support CFGWalker for new EH spec (#6235)Heejin Ahn2024-01-251-0/+341
| | | | | | | | This adds support `CFGWalker` for the new EH instructions (`try_table` and `throw_ref`). `CFGWalker` is used by many different passes, but in the same vein as #3494, this adds tests for `RedundantSetElimination` pass. `rse-eh.wast` file is created from translated and simplified version of `rse-eh-old.wast`, but many tests were removed because we don't have special `catch` block or `delegate` anymore.
* MemoryPacking: Ignore empty segments (#6243)Alon Zakai2024-01-251-1/+6
| | | | | | They might trap. Leave that for RemoveUnusedModuleElements. Fixes #6230
* RemoveUnusedModuleElements: Do not remove unused-but-trapping segments (#6242)Alon Zakai2024-01-252-1/+250
| | | | | | | | | | | | | | An out of bounds active segment traps during startup, which is an effect we must preserve. To avoid a regression here, ignore this in TNH mode (where the user assures us nothing will trap), and also check if a segment will trivially be in bounds and not trap (if so, it can be removed). Fixes the remove-unused-module-elements part of #6230 The small change to an existing testcase made a segment there be in bounds, to avoid this affecting it. Tests for this are in a new file.
* C API: Add BinaryenArrayNewData (#6236)ericvergnaud2024-01-252-0/+11
|
* [Parser] Parse throw_ref (#6238)Thomas Lively2024-01-251-105/+117
|
* wasm-ctor-eval: Eval strings (#6244)Alon Zakai2024-01-251-0/+23
|
* [Parser] Parse try_table (#6237)Thomas Lively2024-01-251-136/+262
|
* Memory flattening: Check for overflow (#6233)Alon Zakai2024-01-241-0/+16
| | | | | Fixes a fuzz testcase for wasm-ctor-eval. Add the beginnings of a polyfill for stdckdint.h to help that.
* [EH] Add translator from old to new EH instructions (#6210)Heejin Ahn2024-01-233-0/+1485
| | | | | | | | | | | | | | | | | | | | This translates the old Phase 3 EH instructions, which include `try`, `catch`, `catch_all`, `delegate`, and `rethrow`, into the new EH instructions, which include `try_table` (with `catch` / `catch_ref` / `catch_all` / `catch_all_ref`) and `throw_ref`, passed at the Oct 2023 CG meeting. This translator can be used as a standalone tool by users of the previous EH toolchain to generate binaries for the new spec without recompiling, and also can be used at the end of the Binaryen pipeline to produce binaries for the new spec while the end-to-end toolchain implementation for the new spec is in progress. While the goal of this pass is not optimization, this tries to a little better than the most naive implementation, namely by omitting a few instructions where possible and trying to minimize the number of additional locals, because this can be used as a standalone translator or the last stage of the pipeline while we can't post-optimize the results because the whole pipeline (-On) is not ready for the new EH.
* Stop propagating/inlining string constants (#6234)Alon Zakai2024-01-232-3/+70
| | | | | This causes overhead atm since in VMs executing a string.const will actually allocate a string, and more copies means more allocations. For now, just do not add more. This required changes to two passes: SimplifyGlobals and Precompute.
* [EH] Support Stack IR for try_table (#6231)Heejin Ahn2024-01-221-0/+61
|
* [EH] Rename -eh lit test names to -eh-old (#6227)Heejin Ahn2024-01-2224-1/+1
| | | | | | | This renames all existing EH lit tests with filenames `*eh*` to `*eh-old*`. This is a prep work so that we can add tests for the new EH spec using `*eh*`. The reason I'm trying to split old and new EH test files is we don't support fuzzing for the new EH yet and I wouldn't want to exclude old EH tests from fuzzing too because of that.
* Remove incorrect validation of segment sizes (#6228)Alon Zakai2024-01-221-0/+18
| | | | This should be a runtime error, not a validator error. It caused a fuzzer failure on wasm-ctor-eval.
* SimplifyGlobals: Apply constant globals to segment offsets (#6226)Alon Zakai2024-01-181-0/+85
| | | | | | | We already applied such globals to other globals, but can do the same to offsets of data and element segments. Suggested in #6220
* C API: Add BinaryenFunctionAppendVar (#6213)KinderGartenKiller2024-01-172-0/+11
|
* Typed continuations: resume instructions (#6083)Frank Emrich2024-01-111-0/+163
| | | | | This PR is part of a series that adds basic support for the [typed continuations proposal](https://github.com/wasmfx/specfx). This particular PR adds support for the `resume` instruction. The most notable missing feature is validation, which is not implemented, yet.
* wasm-merge: Sort globals to ensure proper validation (#6221)Alon Zakai2024-01-113-5/+39
| | | | | | | | | | | | | If the first module has a global that reads from a global that appears in a later module, then we need to reorder the globals, because if we just append the globals from the later module we'd end up with a global reading from another that is not before it. Changes to the existing renamings test are just due to the global sorting pass that now runs (it not only fixes up validation errors but also tries to sort in a more optimal order for size). Fixes #6220
* Precompute into select arms (#6212)Alon Zakai2024-01-101-0/+788
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | E.g. (i32.add (select (i32.const 100) (i32.const 200) (..condition..) ) (i32.const 50) ) ;; => (select (i32.const 150) (i32.const 250) (..condition..) ) We cannot fully precompute the select, but we can "partially precompute" it, by precomputing its arms using the parent. This may require looking several steps up the parent chain, which is an awkward operation in our simple walkers, so to do it we capture stacks of parents and operate directly on them. This is a little slower than a normal walk, so only do it when we see a promising select, and only in -O2 and above (this makes the pass 7% or so slower; not a large cost, but best to avoid it in -O1).
* [Parser] Parse remaining heap and reference types (#6218)Thomas Lively2024-01-101-2/+21
| | | Parse types like `exnref` and `nofunc` that we did not previously support.
* Testing: Write out and read back in the big binary in c-api-kitchen-sink.c ↵Alon Zakai2024-01-091-1/+19
| | | | (#6217)
* Fix global effect computation with -O flags (#6211)Alon Zakai2024-01-091-0/+198
| | | | | | | | | | | | | | | | | | | | We tested --generate-global-effects --vacuum and such, but not --generate-global-effects -O3 or the other -O flags. Unfortunately, our targeted testing missed a bug because of that. Specifically, we have special logic for -O flags to make sure the passes they expand into run with the proper opt and shrink levels, but that logic happened to also interfere with global effect computation. It would also interfere with allowing GUFA info or other things to be stored on the side, which we've proposed. This PR fixes that + future issues. The fix is to just allow a pass runner to execute more than once. We thought to avoid that and assert against it to keep the model "hermetic" (you create a pass runner, you run the passes, and you throw it out), which feels nice in a way, but it led to the bug here, and I'm not sure it would prevent any other ones really. It is also more code. It is simpler to allow a runner to execute more than once, and add a method to clear it. With that, the logic for -O3 execution is both simpler and does not interfere with anything but the opt and shrink level flags: we create a single runner, give it the proper options, and then keep using that runner + those options as we go, normally.
* Fix incorrect wat in tests (#6207)Thomas Lively2024-01-0862-302/+274
| | | | | | | | | The new wat parser is much more strict than the legacy wat parser; the latter accepts all sorts of things that the spec does not allow. To ease an eventual transition to using the new wat parser by default, update the tests to use the standard text format in many places where they previously did not. We do not yet have a way to prevent new errors from being introduced into the test suite, but at least there will now be many fewer errors when it comes time to make the switch.
* Fix branches to loops in IRBuilder (#6205)Thomas Lively2024-01-051-30/+71
| | | | | | | Since branches to loops go to the beginnings of the loops, they should send values matching the input types for the loops (which are always none because we don't support loop input types). IRBuilder was previously using the output types of loops to determine what values the branches should carry, which was incorrect. Fix it.
* [Parser] Parse br_if correctly (#6202)Thomas Lively2024-01-041-128/+208
| | | | The new text parser and IRBuilder were previously not differentiating between `br` and `br_if`. Handle `br_if` correctly by popping and assigning a condition.
* Require `then` and `else` with `if` (#6201)Thomas Lively2024-01-04268-27859/+41183
| | | | | | | | | | | | We previously supported (and primarily used) a non-standard text format for conditionals in which the condition, if-true expression, and if-false expression were all simply s-expression children of the `if` expression. The standard text format, however, requires the use of `then` and `else` forms to introduce the if-true and if-false arms of the conditional. Update the legacy text parser to require the standard format and update all tests to match. Update the printer to print the standard format as well. The .wast and .wat test inputs were mechanically updated with this script: https://gist.github.com/tlively/85ae7f01f92f772241ec994c840ccbb1
* Use the standard shared memory text format (#6200)Thomas Lively2024-01-0362-287/+144
| | | | | Update the legacy text parser and all tests to use the standard text format for shared memories, e.g. `(memory $m 1 1 shared)` rather than `(memory $m (shared 1 1))`. Also remove support for non-standard in-line "data" or "segment" declarations. This change makes the tests more compatible with the new text parser, which only supports the standard format.
* [Parser] Go back to "sub final" intead of "sub open" (#6199)Thomas Lively2024-01-031-5/+5
| | | | The planned spec change to use "sub open" never came together, so the standard format remains "sub final".
* [Parser] Parse br_on_cast{_fail} input annotations (#6198)Thomas Lively2024-01-031-2/+2
| | | | And validate in IRBuilder both that the input annotation is valid and that the input matches it.
* Drop support for type annotations on array.len (#6197)Thomas Lively2024-01-036-10/+9
| | | | | | These type annotations were removed during the development of the GC proposal, but we maintained support for parsing them to ease the transition. Now that GC is shipped, remove support for the non-standard annotation and update our tests accordingly.
* [Parser] Parse folded instructions that contain parentheses (#6196)Thomas Lively2024-01-031-117/+259
| | | | | | | | | | | | To parse folded instructions in the right order, we need to defer parsing each instruction until we have parsed each of its children and found its closing parenthesis. Previously we naively looked for parentheses to determine where instructions began and ended before we parsed them, but that scheme did not correctly handle instructions that can contain parentheses in their immediates, such as call_indirect. Fix the problem by using the actual instruction parser functions with a placeholder context to find the end of the instructions, including any kind of immediates they might have.
* [EH] Misc. fixes for EH (#6195)Heejin Ahn2024-01-021-12/+12
| | | | | - Deletes a stray whitespace after `throw_ref` - Adds missing `makeThrowRef` to `wasm-builder.h` - Adds a case for `TryTable` in `ControlFlowWalker`
* [Parser] Support standalone import definitions (#6191)Thomas Lively2024-01-021-55/+69
| | | | We previously support the in-line import abbreviation, but now add support for explicit, non-abbreviated imports as well.
* Match names more precisely in update_lit_checks.py (#6190)Thomas Lively2024-01-0238-272/+378
| | | | | | | | | | Previously the lit test update script interpreted module names as the names of import items and export names as the names of export items, but it is more precise to use the actual identifiers of the imported or exported items as the names instead. Update update_lit_checks.py to use a more correct regex to match names and to correctly use the identifiers of import and export items as their names. In some cases this can improve the readability of test output.
* Unify method pairs with and without Type param (#6184)Heejin Ahn2023-12-201-1/+1
| | | | | | | | | | | | | | | | As suggested in https://github.com/WebAssembly/binaryen/pull/6181#discussion_r1427188670, using `std::optional<Type>`, this unifies two different versions of `make***`, for block-like structures (`block`, `if`, `loop`, `try`, and `try_table`) with and without a type parameter. This also allows unifying of `finalize` methods, with and without a type. This also sets `breakability` argument of `Block::finalize` to `Unknown` so we can only have one `Block::finalize` that handles all cases. This also adds an optional `std::optional<Type> type` parameter to `blockifyWithName`, and `makeSequence` functions in `wasm-builder.h`. blockify was not included because it has a variadic parameter.
* Drop support for non-standard quoted function names (#6188)Thomas Lively2023-12-20118-1244/+1167
| | | | | | | | | | | | | | | | | | We previously supported a non-standard `(func "name" ...` syntax for declaring functions exported with the quoted name. Since that is not part of the standard text format, drop support for it, replacing it with the standard `(func $name (export "name") ...` syntax instead. Also replace our other usage of the quoted form in our text output, which was where we quoted names containing characters that are not allowed to appear in standard names. To handle that case, adjust our output from `"$name"` to `$"name"`, which is the standards-track way of supporting such names. Also fix how we detect non-standard name characters to match the spec. Update the lit test output generation script to account for these changes, including by making the `$` prefix on names mandatory. This causes the script to stop interpreting declarative element segments with the `(elem declare ...` syntax as being named "declare", so prevent our generated output from regressing by counting "declare" as a name in the script.
* [EH][test] Add a few more tests (#6189)Heejin Ahn2023-12-201-33/+331
| | | | | This adds tests that test all four kinds of `catch` clauses for an empty tag and a multivalue tag. (Previously we had this test only for an `i32` tag.)
* [EH] Add validation for new instructions (#6185)Heejin Ahn2023-12-201-0/+64
| | | | | | | | | | This adds validation for the new EH instructions (`try_table` and `throw_ref`): https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md This also adds a spec test for checking invalid modules. We cannot check the executions yet because we don't have the interpreter implementation. The new test file also contains tests for the existing `throw`, because this is meant to replace the old spec test someday.
* [EH] Add instructions for new proposal (#6181)Heejin Ahn2023-12-193-42/+679
| | | | | | | | | | | | | | | | | | | | | | | | This adds basic support for the new instructions in the new EH proposal passed at the Oct CG hybrid CG meeting: https://github.com/WebAssembly/meetings/blob/main/main/2023/CG-10.md https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md This mainly adds two instructions: `try_table` and `throw_ref`. This is the bare minimum required to read and write text and binary format, and does not include analyses or optimizations. (It includes some analysis required for validation of existing instructions.) Validation for the new instructions is not yet included. `try_table` faces the same problem with the `resume` instruction in #6083 that without the module-level tag info, we are unable to know the 'sent types' of `try_table`. This solves it with a similar approach taken in #6083: this adds `Module*` parameter to `finalize` methods, which defaults to `nullptr` when not given. The `Module*` parameter is given when called from the binary and text parser, and we cache those tag types in `sentTypes` array within `TryTable` class. In later optimization passes, as long as they don't touch tags, it is fine to call `finalize` without the `Module*`. Refer to https://github.com/WebAssembly/binaryen/pull/6083#issuecomment-1854634679 and #6096 for related discussions when `resume` was added.
* [Parser] Parse explicit exports (#6179)Thomas Lively2023-12-141-3/+15
|