summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* [NFC] Add some const annotations (#6203)Alon Zakai2024-01-052-4/+4
|
* [Parser] Parse br_if correctly (#6202)Thomas Lively2024-01-049-146/+234
| | | | 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-04272-28019/+41374
| | | | | | | | | | | | 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-0364-351/+152
| | | | | 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-032-6/+6
| | | | 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-035-12/+26
| | | | 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-037-18/+10
| | | | | | 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-033-155/+310
| | | | | | | | | | | | 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-024-18/+28
| | | | | - Deletes a stray whitespace after `throw_ref` - Adds missing `makeThrowRef` to `wasm-builder.h` - Adds a case for `TryTable` in `ControlFlowWalker`
* wasm-reduce: Improve tryToReduceCurrentToConst() (#6193)Alon Zakai2024-01-021-9/+26
| | | | | | | | | Avoid replacing with the exact same thing in the case of RefNull and a default tuple. Also be more careful with handling of numbers. Before we exited immediately if we saw a number, but we can try to replace a number with a 0 or a 1, even if it was a number before. That is, we consider 1 simpler than e.g. 12345678, and 0 simpler than 1.
* [Parser] Support standalone import definitions (#6191)Thomas Lively2024-01-024-62/+164
| | | | 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-0239-278/+392
| | | | | | | | | | 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-204-195/+125
| | | | | | | | | | | | | | | | 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-20122-1288/+1228
| | | | | | | | | | | | | | | | | | 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.)
* [NFC] Fix typo in Inlining (#6187)Alon Zakai2023-12-201-2/+2
|
* [EH] Add validation for new instructions (#6185)Heejin Ahn2023-12-202-5/+142
| | | | | | | | | | 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.
* Add tuple.drop validation (#6186)Alon Zakai2023-12-191-0/+5
| | | | | Without this fuzzer testcases fail if the initial content has a tuple.drop but multivalue is disabled (then the initial content validates erroneously, and that content is remixed into more content using multivalue which fails to validate).
* [EH] Add instructions for new proposal (#6181)Heejin Ahn2023-12-1935-72/+1185
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Remove empty _ARRAY/_VECTOR defines (NFC) (#6182)Heejin Ahn2023-12-1411-37/+3
| | | | | | | `_VECTOR` or `_ARRAY` defines in `wasm-delegations-fields.def` are supposed to be defined in terms of their non-vector/array counterparts when undefined. This removes empty `_VECTOR`/`_ARRAY` defines when including `wasm-delegations-fields.def`, while adding definitions for `DELEGATE_GET_FIELD` in case it is missing.
* [Parser] Parse explicit exports (#6179)Thomas Lively2023-12-144-3/+93
|
* [Parser] Parse tuple operations (#6174)Thomas Lively2023-12-137-137/+194
| | | | | Parse `tuple.make`, `tuple.extract`, and `tuple.drop`. Also slightly improve the way we break up tuples into individual elements in IRBuilder by using a `local.tee` instead of a block containing a `local.set` and `local.get`.
* Preserve multivalue drops in IRBuilder (#6150)Thomas Lively2023-12-133-36/+72
| | | | | | | | | In Binaryen IR, we allow single `Drop` expressions to drop multiple values packaged up as a tuple. When using IRBuilder to rebuild IR containing such a drop, it previously treated the drop as a normal WebAssembly drop that dropped only a single value, producing invalid IR that had extra, undropped values. Fix the problem by preserving the arity of `Drop` inputs in IRBuilder. To avoid bloating the IR, thread the size of the desired value through IRBuilder's pop implementation so that tuple values do not need to be split up and recombined.
* [EH][test] Split EH tests into old and new spec (#6178)Heejin Ahn2023-12-134-1816/+1826
| | | | | | | | | This moves tests for the old EH spec to `exception-handling-old.wast` and moves the new `exnref` test into `exception-handling.wast`, onto which I plan to add more tests for the new EH spec. The primary reason for splitting the files is I plan to exclude the new EH test from the fuzzing while the new spec's implementation is in progress, and I don't want to exclude the old EH tests altogether.
* J2CL: Use a more future proof naming convention for once functions (#6173)Goktug Gokdogan2023-12-133-23/+25
| | | | Existing convention uses _@once@_ but we also use @ for class separation. It is cleaner&more future proof to use something other convention like _<once>_.
* [EH][test] Slice test code into different functions (#6177)Heejin Ahn2023-12-131-626/+767
| | | | | | | We ported basic tests to `test/lit/basic/` in #6160, but comparing `CHECK` lines with the test code for long functions is not easy, even though it wouldn't necessarily be worse than the the separate files we used to have in `test/`. This slices `exception-handling.wast` into functions so that the `CHECK` lines are easy to check.
* [test] Port tests in test/ to test/lit/basic/ (#6160)Heejin Ahn2023-12-13219-24231/+23387
| | | | | | | | | | | | | | | | | | | | | This ports all tests from `test/` to `test/lit/basic/`. The set of commands and `CHECK` lines used are the same as the ones in #6159. Now we use `lit` to test these, this also deletes all `.wast`, `.wast.from-wast`, `.wast.fromBinary`, and `.wast.fromBinary.noDebugInfo` files from `test/` and all related test routines from the python scripts. All `CHECK` lines are generated by `update_lit_checks.py --all-items`. This also deletes these three multi-memory tests in `test/lit/`, because they seem to contain the same code with the ones in `test/`, which have been ported to `test/lit/basic/` along with other tests. - `test/lit/multi-memories-atomics64.wast` - `test/lit/multi-memories-basics.wast` - `test/lit/multi-memories-simd.wast` This also adds newlines between `(func`s in case there are none to make `CHECK` lines easy to view, and removes some extra existing newlines here and there.
* [Parser] Parse the remaining array operations (#6158)Thomas Lively2023-12-128-145/+941
| | | | | | | Parse `array.new_elem`, `array.init_data`, and `array.init_elem`. Accidentally also includes: * [Parser] Parse string types and operations (#6161)
* [Parser] Parse rethrow (#6155)Thomas Lively2023-12-125-17/+207
| | | | Like `delegate`, rethrow takes a `Try` label. Refactor the delegate handling so that `Try` can share its logic.
* Add an arity immediate to tuple.extract (#6172)Thomas Lively2023-12-1236-187/+193
| | | | | | | | Once support for tuple.extract lands in the new WAT parser, this arity immediate will let the parser determine how many values it should pop off the stack to serve as the tuple operand to `tuple.extract`. This will usually coincide with the arity of a tuple-producing instruction on top of the stack, but in the spirit of treating the input as a proper stack machine, it will not have to and the parser will still work correctly.
* [Parser] Parse table operations (#6154)Thomas Lively2023-12-126-17/+279
| | | | Including table.get, table.set, table.size, table.grow, table.fill, and table.copy.
* J2CL: Add extra guardrails (#6171)Goktug Gokdogan2023-12-123-69/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch puts a new guardrail that will only hoist the field if it is initialized with the owner class. The constant hoisting optimization in J2CL pass relies on the assumption that clinit that will initialize the field will be executed before the read of the field. That means the field that is optimized is within the same class: class Foo { public static final Object field = new Object(); } Although it is possible to observe the initial value, that is not intention of the developer (which the point of the optimization). However can also see a similar pattern in following: class Foo { public static Object field; } class Zoo { static { Foo.field = new Object(); } } Currently the pass also optimizes it as well since the field is only initialized once and by a clinit. However Zoo clinit is not guaranteed to be run before Foo.field access so it is less safe to speculate on the intention of the developer here hence it is not worth the risk. FWIW, we haven't seen this issue. But this is something we are also guarding in Closure Compiler so I decided it is worthwhile to do here as well.
* Add a `tuple.drop` text pseudoinstruction (#6170)Thomas Lively2023-12-1222-30/+68
| | | | | | | | | | | | | | | | | We previously overloaded `drop` to mean both normal drops of single values and also drops of tuple values. That works fine in the legacy text parser since it can infer parent-child relationships directly from the s-expression structure of the input, so it knows that a drop should drop an entire tuple if the tuple-producing instruction is a child of the drop. The new text parser, however, is much more like the binary parser in that it uses instruction types to create parent-child instructions. The new parser always assumes that `drop` is meant to drop just a single value because that's what it does in WebAssembly. Since we want to continue to let `Drop` IR expressions consume tuples, and since we will need a way to write tests for that IR pattern that work with the new parser, introduce a new pseudoinstruction, `tuple.drop`, to represent drops of tuples. This pseudoinstruction only exists in the text format and it parses to normal `Drop` expressions. `tuple.drop` takes the arity of its operand as an immediate, which will let the new parser parse it correctly in the future.
* Update `tuple.make` text format to include arity (#6169)Thomas Lively2023-12-1247-208/+217
| | | | | | | | | | Previously, the number of tuple elements was inferred from the number of s-expression children of the `tuple.make` expression, but that scheme would not work in the new wat parser, where s-expressions are optional and cannot be semantically meaningful. Update the text format to take the number of tuple elements (i.e. the tuple arity) as an immediate. This new format will be able to be implemented in the new parser as follow-on work.
* Add J2CL optimization pass to binaryen. (#6151)Goktug Gokdogan2023-12-128-0/+410
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR creates a new pass to optimize J2CL specific patterns that would otherwise difficult to recognize/prove generically by other binaryen passes. The pass currently handles fields what we call as "constant-like". These fields are fields initialized once and unconditionally through "clinit" function and technically they do have 2 observable states; - initial null/0 state - initialized state. However you can only observe initial null/0 state in contrived examples, not in real world/correct applications. This pass moves such "clinit" initialized fields to global initialization. Above pattern also matches other lazy init construct like String and Class literals (which binaryen already reduces to constant expressions). So the pass is generalized to include them as well. (by matching any functions with the name pattern "_@once_") In order for this pass to be effective: 1. It needs to run between O3 passes 2. We need to stop inlining of "once" functions. Stopping inlining of the once functions are important to preserve their structure. This both helps existing OnceReducer pass and new J2CL pass to be a lot more effective. Also it is not useful to inline these functions as by defintion they only executed once. This could be achieved by passing no-inline filter. Although the inlining is generally disabled for these functions, it is still needed for some cases since inliner is effectively responsible for removal of the once functions that are simplified into empty or simple delegating functions. For this reason, the pass will rename such trivial function so no-inline filter will no longer match them. Also note that after all optimizations completed, it does make sense to have a final stage where the "partial inline" of all once functions are allowed. This will speed them up by moving the initialization check to call-site.
* Inlining: Copy no-inline flags when copying a function (#6165)Alon Zakai2023-12-123-76/+169
| | | | Those fields should be copied together with all the rest of the metadata that already is. This was just missed in the prior PR.
* [EH] Use random value for exnref encoding when legacy GC is used (#6166)Heejin Ahn2023-12-111-6/+20
| | | | | Currently the legacy GC encoding's nullexternref encoding overlaps with exnref's. We assume the legacy GC encoding won't be used with the exnref for the moment and assign a random value to it to prevent the clash.
* [test] Fix wasm2js stale check failure (#6168)Heejin Ahn2023-12-111-2/+2
| | | | | | | I tried to exclude wasm2js asserts tests from `check_for_stale_files` in #6164, but ended up doing it incorrectly. The file I checked for was `wasm2js.wast.asserts`, while the output I should have excluded was `wasm2js.asserts.js`. This fixes the code so we now check the prefix and not the filename.
* [test] Tweak RUN commands of test/lit/basic/ (#6159)Heejin Ahn2023-12-114-793/+785
| | | | | | | | | | | | | | | | | | | | | | | This tweaks generated file names and `filecheck` prefixes to be more (IMHO) consistent. Also shortened binary/BINARY to bin/BIN for conciseness. This also changes the order of `RUN` commands a little. And this changes ```console wasm-opt %t.wast -all -o %t.text.wast -g -S ``` to ```console wasm-opt %s -all -o %t.text.wast -g -S ``` The current command doesn't take the source file but the generated file from the command above `wasm-dis`, which is not the behavior of `check.py`. This changes it back to the original source (`%s`). As a result of `wasm-opt` change, some tests are now failing because of the order of `(type)`s. So I just deleted all `CHECK` lines and regenerated them using `update_lit_checks.py --all-items`. The large amount of `CHECK` line changes are mainly because I moved `CHECK-TEXT` before `CHECK-BINARY` and not meaningful.
* [test] Remove asm2wasm tests from scripts (#6162)Heejin Ahn2023-12-113-25/+0
| | | | We don't have `*.fromasm` files anymore. Also `BIN_DIR` and `WATERFALL_BUILD_DIR` variables don't seem to be used as well.
* [test] Remove / move *.js tests from test/ (#6163)Heejin Ahn2023-12-1110-512/+4
| | | | | | | | | | | | | `wasm2js.asserts.js` and `wasm2js.traps.js` seem to be used in wasm2js asserts test: https://github.com/WebAssembly/binaryen/blob/1d615b38dd4152494d2f4d3520c8b1d917624a30/scripts/test/wasm2js.py#L28 https://github.com/WebAssembly/binaryen/blob/1d615b38dd4152494d2f4d3520c8b1d917624a30/scripts/test/wasm2js.py#L126-L127 But other `*.js` tests in `test/` don't seem to be used anywhere. Please let me know if they are actually being used. This moves `wasm2js.asserts.js` and `wasm2js.traps.js`, which are only used in wasmjs tests, to `test/wasm2js/`, and deletes all other `*.js` tests in `test/`.
* [test] Make get_tests return only files (#6164)Heejin Ahn2023-12-112-0/+3
| | | | | | | | | | | | | | | | | | | | Currently `get_tests` returns files and directories, especially when the extension is not given. This makes `get_tests` return a directory like `test/wasm2js/` as a test. `wasm2js.py`'s `check_for_stale_files` errors out when there are files within `test/wasm2js/` whose basenames don't match any files within any of `test/`, `test/spec/`, `test/wasm2js/`. https://github.com/WebAssembly/binaryen/blob/1d615b38dd4152494d2f4d3520c8b1d917624a30/scripts/test/wasm2js.py#L33-L46 `wasm2js.wast.asserts` is apparently a special case for asserts test: https://github.com/WebAssembly/binaryen/blob/1d615b38dd4152494d2f4d3520c8b1d917624a30/scripts/test/wasm2js.py#L28 and this doesn't seem to have the matching `wast` tests in the three test directories. But it just happened to not error out because `get_tests` returns directory names too and one of them was `wasm2js` (`test/wasm2js/` directory). This makes `get_tests` return only files, and make files in `assert_tests` not error out additionally.
* [CI] Use --break-system-packages on Alpine (#6167)Alon Zakai2023-12-111-1/+1
| | | Something changed in how CI sets up Python and now this is needed to avoid an error.
* [EH] Add exnref type back (#6149)Heejin Ahn2023-12-0814-18/+198
| | | | | | | | | | | | | At the Oct hybrid CG meeting, we decided to add back `exnref`, which was removed in 2020: https://github.com/WebAssembly/meetings/blob/main/main/2023/CG-10.md The new version of the proposal reflected in the explainer: https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md While adding support for `exnref` in the current codebase which has all GC subtype hierarchies, I noticed we might need `noexn` heap type for the bottom type of `exn`. We don't have it now so I just set it to 0xff for the moment.
* [test] Move basic tests in lit/ to lit/basic/ (#6156)Heejin Ahn2023-12-084-0/+0
| | | | | | | | | | | | | | | | | | | Here 'basic' tests means that what we have in `binaryen/test/`. We checked three things with those tests: - Run `wasm-opt -all -g` on it and compare the output with `*.from-wast` - Run `wasm-as -all -g` and `wasm-dis` on it and compare the output with `*.fromBinary`. - Run `wasm-as -all` and `wasm-dis` on it and compare the output with `*.fromBinary.noDebugInfo`. I planned to move those to `test/lit/`. But `test/lit/` has other kind of tests as well, so I think it'd be nice to have a dedicated directory for these tests. Before doing that, I noticed there are already four tests that have been already ported to do this, and this PR moves them to `test/lit/basic/`. I couldn't come up with a better name than `basic`. If you have other suggestions please let me know.
* binaryen.js: Remove closure flags that set the ES version (#6157)Alon Zakai2023-12-081-4/+1
| | | Emscripten sets that itself these days.
* [NFC] Use a reference instead of a pointer in Inlining (#6153)Alon Zakai2023-12-071-11/+11
|
* [Outlining] Add variations of call_indirect testsAshley Nelson2023-12-071-15/+120
| | | | | | | | | | | | | Mixes up the number of results, params, and operands used in call_indirect instructions that are outlined. Also adds a function identifier to the original call_indirect test to improve test output readability. Reviewers: tlively Reviewed By: tlively Pull Request: https://github.com/WebAssembly/binaryen/pull/6152
* [Outlining] Add loop instruction supportAshley Nelson2023-12-072-0/+40
| | | | | | | | | | Adds support for the loop instruction to be outlined and a test showing a repeat loop being outlined. Reviewers: tlively Reviewed By: tlively Pull Request: https://github.com/WebAssembly/binaryen/pull/6141
* [Outlining] Improve debug loggingAshley Nelson2023-12-073-22/+36
| | | | | | | | | | | | - Change outlining debug logs to use std::cerr - Add controlFlowQueue push log - Fix build error with wasm-ir-builder log's use of ShallowExpression Reviewers: tlively Reviewed By: tlively Pull Request: https://github.com/WebAssembly/binaryen/pull/6140