summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
...
* [reference-types] Support passive elem segments (#3572)Abbas Mashayekh2021-03-0514-121/+187
| | | | | | | | | | | Passive element segments do not belong to any table, so the link between Table and elem needs to be weaker; i.e. an elem may have a table in case of active segments, or simply be a collection of function references in case of passive/declarative segments. This PR takes Table::Segment out and turns it into a first class module element just like tables and functions. It also implements early support for parsing, printing, encoding and decoding passive/declarative elem segments.
* [effects] Record reads and writes of the GC heap (#3657)Thomas Lively2021-03-051-0/+50
| | | | | | | | | | | Just as reads and writes to memory can interfere with each other, reads and writes of GC objects can interfere with each other. This PR adds new `readsHeap` and `writesHeap` fields to EffectAnalyzer to account for this interference. Note that memory accesses can never alias with GC heap accesses, so they are considered separately. Similarly, it would be possible to prove that different GC heap accesses never interfere with each other based on the accessed types, but that's left to future work. Fixes #3655.
* [Wasm GC] Fix cost.h on array.new_default (#3658)Alon Zakai2021-03-052-0/+37
|
* Fix binary writing of local name indexes (#3649)Alon Zakai2021-03-0410-198/+275
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When writing a binary, we take the local indexes in the IR and turn them into the format in the binary, which clumps them by type. When writing the names section we should be aware of that ordering, but we never were, as noticed in #3499 This fixes that by saving the mapping of locals when we are emitting the name section, then using it when emitting the local names. This also fixes the order of the types themselves as part of the refactoring. We used to depend on the ordering of types to decide which to emit first, but that isn't good for at least two reasons. First, it hits #3648 - that order is not fully defined for recursive types. Also, it's not good for code size - we've ordered the locals in a way we think is best already (ReorderLocals pass). This PR makes us pick an order of types based on that, as much as possible, that is, when we see a type for the first time we append it to a list whose order we use. Test changes: Some are just because we use a different order than before, as in atomics64. But some are actual fixes, e.g. in heap-types where we now have (local $tv (ref null $vector)) which is indeed right - v there is for vector, and likewise m for matrix etc. - we just had wrong names before. Another example, we now have (local $local_externref externref) whereas before the name was funcref, and which was wrong... seems like the incorrectness was more common on reference types and GC types, which is why this was not noticed before. Fixes #3499 Makes part of #3648 moot.
* Emit "elem declare" for functions that need it (#3653)Alon Zakai2021-03-0417-3/+53
| | | | | | | This adds support for reading (elem declare func $foo .. in the text and binary formats. We can simply ignore it: we don't need to represent it in IR, rather we find what needs to be declared when writing. That part takes a little more work, for which this adds a shared helper function.
* Fix TypeComparator to satisfy C++'s Compare requirement (#3650)Thomas Lively2021-03-041-0/+29
| | | | | | | | | | | | | | The comparison implemented by TypeComparator was not previously antisymmetric because it held that both A < B and B < A when A and B were structurally identical but nominally distinct recursive types. This meant that it did not satisfy the conditions of C++'s "Compare" requirement, which meant that std::set did not operate correctly, as discovered in #3648. The PR fixes the problem by having making A < B be false (and vice versa), making type comparisons properly antisymmetric. As a drive by, also switches to using std::stable_sort in collectHeapTypes to make the order of the type section completely deterministic accross platforms. Fixes #3648.
* [Wasm GC] Parse text field names even of types that end up canonicalized ↵Alon Zakai2021-03-034-0/+25
| | | | | | | together (#3647) Names of structurally identical types end up "collapsed" together after the types are canonicalized, but with this PR we can properly read content that has structurally identical types with different names.
* [Wasm Exceptions] Fix a handwritten exceptions test (#3639)Alon Zakai2021-03-032-6/+2
| | | catch_all should not have a pop.
* Remove PostAssemblyScript passes (#3643)Daniel Wirtz2021-03-034-699/+0
|
* [Wasm GC] ref.cast and ref.test should have zero immediates (#3641)Alon Zakai2021-03-026-24/+24
| | | This updates them to be correct in the current spec and prototype v3.
* [Wasm GC] Allow subtyping in arguments to struct.get etc. Fixes #3636 (#3644)Alon Zakai2021-03-025-10/+43
| | | | | | | | | Note that Binaryen "canonicalizes" the type, so in the test output here we end up with $grandchild twice. This is a consequence of us not storing the heap type as an extra field. I can't think of a downside to this canonicalization, aside from losing perfect roundtripping, but I think that's a worthwhile tradeoff for efficiency as we've been thinking so far. Fixes #3636
* [Wasm GC] Add Names section support for field names (#3589)Alon Zakai2021-03-011-5/+5
| | | | | | | | | | Adds support for GC struct fields in the binary format, implementing WebAssembly/gc#193 No extra tests needed, see the .fromBinary output which shows this working. This also has a minor fix in the s-parser, we should not always add a name to the map of index=>name - only if it exists. Without that fix, the binary emitter would write out null strings.
* [Wasm GC] Add test/spec/br_on_null.wast and validation fixes for it (#3623)Alon Zakai2021-03-011-0/+42
| | | | | | This adds ValidationBuilder which can allow sharing of builder code that also validates, between the text and binary parsers. In general we share that code in the validator, but the validator can only run once IR exists, and in some cases we can't even emit valid IR structure at all.
* Fix DeNaN pass to handle existing colliding names (#3631)Alon Zakai2021-03-012-0/+67
|
* Add C and JS API bindings for ref.as_* (#3628)Daniel Wirtz2021-03-014-0/+95
|
* [Wasm Exceptions] Fix/work around delegate issues in Inlining pass (#3633)Alon Zakai2021-03-012-0/+57
| | | | | | | | | | 1. Ignore the fake delegate target in the unique name mapper. The mapper is run after inlining, so this fixes inlining into a function that has a delegate to the caller. 2. Do not inline a function with a delegate. We should support this eventually, but for now I think this is good enough. After this Inlining should be safe to run on exceptions code.
* [Wasm Exceptions] Properly ensure unique Try labels after an inlining (#3632)Alon Zakai2021-03-012-0/+47
| | | | | | | | | The old code here just referred to Block and Loop. Refactor it to use the generic helper code that also handles Try. Also add validation of Try names in the validator. The testcase here would have $label appear twice before this fix. After the fix there is $label0 for one of them.
* Allow empty body within catch block (#3630)Heejin Ahn2021-03-014-17/+51
| | | | | | | | Previously we assumed catch body's size should be at least 3: `catch` keyword, event name, and body. But catch's body can be empty when the event's type is none. This PR fixes the bug and allows empty catch bodies to be parsed correctly. Fixes #3629.
* Consider self-referential HeapTypes to be canonical (#3626)Thomas Lively2021-02-281-8/+0
| | | | | | | | | | | | | | This PR makes the TypeBuilder move self-referential HeapTypes to global HeapType store so that they are considered canonical. This means that when a HeapType is constructed with an identical definition, it will be equivalent to the original HeapType constructed by the TypeBuilder, but it does _not_ mean that self-referential HeapTypes are deduplicated. This fixes a bug in which two versions of each self-referential function signature were emitted. Before this PR, the global HeapType store was not aware of the original self-referential HeapTypes. When the function signatures were used to construct HeapTypes during type collection, new HeapTypes were allocated and emitted in addition to the original HeapTypes. Now the global HeapType store returns the original HeapTypes, so the extra HeapType is never allocated.
* Use enum instead of bool for StackSignature kind (#3625)Thomas Lively2021-02-261-148/+187
| | | | | As a readability improvement, use an enum with `Polymorphic` and `Fixed` variants to represent the polymorphic behavior of StackSignatures rather than a `bool uneachable`.
* Support printing recursive types (#3624)Thomas Lively2021-02-262-0/+32
| | | | | Also fixes a few locations in Print.cpp where types were being printed directly rather than going through the s-expression type printer and removes vestigial wrapper types that were no longer used.
* [Wasm GC] Add array.wast and validator fixes for it (#3622)Alon Zakai2021-02-262-1/+148
|
* Slightly improve table C API (#3604)Daniel Wirtz2021-02-262-2/+8
| | | Uses BinaryenIndex instead of int to mirror parameter types in table construction, and adds setters for name, initial and max.
* Add TypedFunctionReferences feature to C and JS API (#3603)Daniel Wirtz2021-02-264-0/+4
|
* Add RefIsGetOp/SetOp in C and JS API (#3605)Daniel Wirtz2021-02-261-0/+5
|
* Simplify printing code (#3618)Alon Zakai2021-02-251-2/+1
| | | | | | We can just iterate on children using the standard order as in delegates.h, as used by the binary format as well. The only exceptions are control flow instructions which need some special handling.
* Support comparing, subtyping, and naming recursive types (#3610)Thomas Lively2021-02-256-2/+77
| | | | | | | | | | | | | | | | | | | | | When the type section is emitted, types with an equal amount of references are ordered by an arbitrary measure of simplicity, which previously would infinitely recurse on structurally equivalent recursive types. Similarly, calculating whether an recursive type was a subtype of another recursive type could have infinitely recursed. This PR avoids infinite recursions in both cases by switching the algorithms from using normal inductive recursion to using coinductive recursion. The difference is that while the inductive algorithms assume the relations do not hold for a pair of HeapTypes until they have been exhaustively shown to hold, the coinductive algorithms assume the relations hold unless a counterexample can be found. In addition to those two algorithms, this PR also implement name generation for recursive types, using de Bruijn indices to stand in for inner uses of the recursive types. There are additional algorithms that will need to be switched from inductive to coinductive recursion, such as least upper bound generation, but these presented a good starting point and are sufficient to get some interesting programs working end-to-end.
* [Wasm GC] Fix the order of operands in array.new and struct.new (#3617)Alon Zakai2021-02-258-28/+70
| | | Also add a missing source file for a GC test, let.wasm.
* Support 64-bit data segment init-exps in Memory64 (#3593)Wouter van Oortmerssen2021-02-256-11/+11
| | | This as a consequence of https://reviews.llvm.org/D95651
* Support Type names in the Names section (#3615)Alon Zakai2021-02-2520-140/+140
|
* [Wasm GC] Print Struct field names (#3608)Alon Zakai2021-02-251-5/+5
|
* Support building recursive types (#3602)Thomas Lively2021-02-241-22/+71
| | | | | | | | | | | | | | | | | | | Updates TypeBuilder to support recursive types. Recursive types are particularly problematic because under the current scheme it is necessary to canonicalize the uses of a type's immediate children before canonicalizing the type itself to avoid leaking non-canonical, temporary types out of the TypeBuilder and into the global type stores. In the case of recursive types, it is not possible to do this because of their cyclic nature. In principle this could be overcome by hashing recursive types based on their structure rather than their contents, but that would be complicated. Instead, this PR takes the shortcut of not canonicalizing self-referential HeapTypes at all, but rather moving them out of the TypeBuilder and into the global type store without changing their addresses or needing to update any of their use sites. This breaks all cycles and makes it possible to canonicalize the other types correctly. Note that this PR only adds support for building recursive types. Doing almost anything with the types, such as printing, comparing, or emitting them will certainly lead to infinite recursions. A follow up PR will update all these operations to work correctly with recursive types.
* Fix hashing of a use of a name without the context/target for it (#3601)Alon Zakai2021-02-241-0/+10
| | | | | | | | | | Before this we would assert on hashing e.g. (br $x) by itself, without the context so we recognized the name $x. Somehow that was not an issue until delegate, we just happened to not hash such things. I believe I remember that @aheejin noticed this issue before, but given we didn't have a testcase, we deferred fixing it - now is the time, I guess, as with delegate it is easy to get e.g. CodeFolding to hash a Try with a delegate. Issue found by emscripten-core/emscripten#13485
* [Wasm Exceptions] Fix StackIR writing of nested delegates (#3599)Alon Zakai2021-02-232-0/+63
| | | | | | We were missing a pop of catchIndexStack at a Delegate. It ends the scope, so it should do that, like TryEnd does. Found by emscripten-core/emscripten#13485 on -O2.
* Properly use text format type names in printing (#3591)Alon Zakai2021-02-2394-648/+648
| | | | | | | | | | | | | | | | | | | This adds a TypeNames entry to modules, which can store names for types. So far this PR uses that to store type names from text format. Future PRs will add support for field names and for the binary format. (Field names are added to wasm.h here to see if we agree on this direction.) Most of the work here is threading a module through the various functions in Print.cpp. This keeps the module optional, so that we can still print an expression independently of a module, which has always been the case, and which I think we should keep (but, if a module was mandatory perhaps this would be a little simpler, and could be refactored into a form that depends on that). 99% of this diff are test updates, since almost all our tests use the text format, and many of them specify a type name but we used to ignore it. This is a step towards a proper solution for #3589
* [GC] Add subtyping support for HeapTypes (#3597)Alon Zakai2021-02-234-0/+142
|
* [Wasm Exceptions] Fix cfg-traversal on linking the basic block after a call ↵Alon Zakai2021-02-222-0/+40
| | | | | | | | | | | | | | | (#3594) This was an unfortunate case of the order of execution of call arguments. link(self->currBasicBlock, self->startBasicBlock()) would run the call first, which sets currBasicBlock, so we'd end up with the same value for both parameters. Without this fix, the testcase would drop the result of the call, as it thought it had no uses. Also improve debug logging here a tiny bit. Found by emscripten-core/emscripten#13485
* Support type use before definition in binaries (#3588)Thomas Lively2021-02-198-25/+25
| | | | | | Update parsing of binary type sections to use TypeBuilder to support uses before definitions. Now that both the binary and text parsers support out-of-order type uses, this PR also relaxes the logic for emitting types to allow uses to be emitted before definitions.
* [Wasm Exceptions] Fix binary parsing of a normal break to a try in a ↵Alon Zakai2021-02-196-23/+55
| | | | | | | | | | | | | | | | | | singleton (#3581) The fix here is to remove the code with // maybe we don't need a block here? That would remove a try's block if we thought it wasn't needed. However, it just checked for exception branches, but not normal branches, which are also possible. At that location, we don't have a good way to find out if the block has other branches to it aside from scanning its contents. So this PR just gives up on doing so, which means we add an unnecessary block if the optimizer is not run. If this matters we could make the binary parser more complicated by remembering whether a block had branches in the past, but I'm not sure if it's worth it.
* Support type uses before definitions in text parser (#3584)Thomas Lively2021-02-186-31/+38
| | | | | | | | | | | | | | | | | | | | | | Traverses the module to find type definitions and uses a TypeBuilder to construct the corresponding HeapTypes rather than constructing them directly. This allows types to be used in the definitions of other types before they themselves are defined, which is an important step toward supporting recursive types. After this PR, no further text parsing changes will be necessary to support recursive types. Beyond allowing types to be used before their definitions, this PR also makes a couple incidental changes to the parser's behavior. First, compound heaptypes can now only be declared in `(type ...)` elements and cannot be declared inline at their site of use. This reduces the flexibility of the parser, but is in line with what the text format spec will probably look like eventually (see https://github.com/WebAssembly/function-references/issues/42). The second change is that `(type ...)` elements are now all parsed before `(func ...)` elements rather than in text order with them, so the type indices will be different and wasts using numeric type indices will be broken. Note however, that we were already not completely spec compliant in this regard because we parsed types defined by `(type...)` and `(func...)` elements before types defined by the type uses of `call_indirect` instructions.
* Fix TypeBuilder canonicalization (#3578)Thomas Lively2021-02-181-4/+7
| | | | | | | | | | | | | | | | | | | | | | When types or heap types were used multiple times in a TypeBuilder instance, it was possible for the canonicalization algorithm to canonicalize a parent type before canonicalizing all of its component child types, leaking the temporary types into globally interned types. This bug led to incorrect canonicalization results and use-after free bugs. The cause of the bug was that types were canonicalized in the reverse of the order that they were visited in, but children were visited after the first occurrence of their parents, not necessarily after the last occurrence of their parents. One fix could have been to remove the logic that prevented types from being visited multiple times so that children would always be visited after their parents. That simple fix, however, would not scale gracefully to handle recursive types because it would require some way to detect recursions without accidentally reintroducing these bugs. This PR implements a more robust solution: topologically sorting the traversed types to ensure that children are canonicalized before their parents. This solution will be trivial to adapt for recursive types because recursive types are trivial to detect from the reachability graph used to perform the topological sort.
* [Wasm Exceptions] Handle delegation to the caller in RemoveUnusedNames (#3585)Alon Zakai2021-02-182-0/+16
|
* [Wasm Exceptions] Fix RemoveUnusedNames on Try (#3583)Alon Zakai2021-02-182-0/+55
| | | | | | | | | | | | | | The delegate field of Try was not being scanned, so we could remove a name that was used only by a delegate. The bug was because visitTry overrides the generic visitor visitExpression. So we need to call it manually. Sadly the code here was pretty old (I probably wrote it back in 2015 or so) and it was misleading, as it had unnecessary calls from the generic visitor to visitBlock, visitLoop, which are not needed. This PR removes them which is shorter and cleaner. Also, we must handle the case of the delegate field being unset, so check name.is().
* [Wasm Exceptions] Scan catch events in RemoveUnusedModuleElements (#3582)Alon Zakai2021-02-181-1/+2
| | | | Also refactor away some annoying repeated code in that pass. visitTry is the only actual change.
* [EH] Remove dependency of reference types from EH (#3575)Heejin Ahn2021-02-192-6/+3
| | | | | | | | The new spec does not have `exnref` so EH does not have dependency of the reference types proposal anymore. exception_handling_target_feature.wasm's contents are the same except previously its target features section contained both reference-types and exception-handling but now it only has exception-handling.
* [EH] Change catch_all's opcode (#3574)Heejin Ahn2021-02-193-126/+138
| | | | | | | | | | We decided to change `catch_all`'s opcode from 0x05, which is the same as `else`, to 0x19, to avoid some complicated handling in the tools. See: https://github.com/WebAssembly/exception-handling/issues/147 lso this contains the original cpp file used to generate dwarf_with_exceptions.wasm; instructions to generate the wasm from that cpp file are in the comments.
* Allow em_js strings to be exported as globals (#3577)Sam Clegg2021-02-181-13/+7
|
* [EH] Make rethrow's target a try label (#3568)Heejin Ahn2021-02-1818-136/+550
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I was previously mistaken about `rethrow`'s argument rule and thought it only counted `catch`'s depth. But it turns out it follows the same rule `delegate`'s label: the immediate argument follows the same rule as when computing branch labels, but it only can target `try` labels (semantically it targets that `try`'s corresponding `catch`); otherwise it will be a validation failure. Unlike `delegate`, `rethrow`'s label denotes not where to rethrow, but which exception to rethrow. For example, ```wasm try $l0 catch ($l0) try $l1 catch ($l1) rethrow $l0 ;; rethrow the exception caught by 'catch ($l0)' end end ``` Refer to this comment for the more detailed informal semantics: https://github.com/WebAssembly/exception-handling/issues/146#issuecomment-777714491 --- This also reverts some of `delegateTarget` -> `exceptionTarget` changes done in #3562 in the validator. Label validation rules apply differently for `delegate` and `rethrow` for try-catch. For example, this is valid: ```wasm try $l0 try delegate $l0 catch ($l0) end ``` But this is NOT valid: ```wasm try $l0 catch ($l0) try delegate $l0 end ``` So `try`'s label should be used within try-catch range (not catch-end range) for `delegate`s. But for the `rethrow` the rule is different. For example, this is valid: ```wasm try $l0 catch ($l0) rethrow $l0 end ``` But this is NOT valid: ```wasm try $l0 rethrow $l0 catch ($l0) end ``` So the `try`'s label should be used within catch-end range instead.
* [GC] Fuzzer: Avoid creating tuples with non-defaultable types (#3567)Alon Zakai2021-02-161-28/+29
|
* Fix removal of em_js strings (#3570)Sam Clegg2021-02-161-7/+5
|