summaryrefslogtreecommitdiff
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* [Wasm GC] Fix GlobalStructInference on unrefined globals (#5338)Alon Zakai2022-12-121-0/+93
| | | | | | | If a global's type is not fully refined, then when --gsi replaces a reference with a global.get, we end up with a type that might not be good enough. For example, if the type is any then it is not a subtype of eq and we can't do ref.eq on it, which this pass requires. We also can't just do struct.get on it if it is a too-distant parent or such.
* Add Atomics support to Multi-Memory Lowering Pass (#5339)Ashley Nelson2022-12-121-2/+185
| | | | | This PR adds support for Atomic instructions in the multi-memory lowering pass. Also includes optional bounds checks per the wasm spec guidelines, (visitAtomicRMW, visitAtomicCmpxchg, visitAtomicWait, visitAtomicNotify). Note: The latter two instructions, memory.atomic.wait and memory.atomic.notify, have browser engine implementations that predate the still-in-progress threads spec. And whether or not atomic.notify should trap for out-of-bounds addresses remains an open issue. For now, this PR is using the same semantics as v8, which is to bounds check all Atomic instructions the same way and trap for out-of-bounds.
* Add SIMD support to Multi-Memory Lowering Pass (#5336)Ashley Nelson2022-12-121-2/+170
| | | This PR adds support for SIMD instructions in the multi-memory lowering pass. Also includes optional bounds checks per the wasm spec guidelines, (SIMDLoad, SIMDLoadSplat, SIMDLoadExtend, SIMDLoadZero, SIMDLoadStoreLane load | store).
* Adds bounds checks to Load/Store in Multi-Memories Lowering Pass (#5256)Ashley Nelson2022-12-093-0/+349
| | | Per the wasm spec guidelines for Load (rule 10) & Store (rule 12), this PR adds an option for bounds checking, producing a runtime error if the instruction exceeds the bounds of the particular memory within the combined memory.
* Use non-nullable ref.cast for non-nullable input (#5335)Thomas Lively2022-12-0918-131/+130
| | | | | | | | | | | | We switched from emitting the legacy `ref.cast_static` instruction to emitting `ref.cast null` in #5331, but that wasn't quite correct. The legacy instruction had polymorphic typing so that its output type was nullable if and only if its input type was nullable. In contrast, `ref.cast null` always has a a nullable output type. Fix our output by instead emitting non-nullable `ref.cast` if the output should be non-nullable. Parse `ref.cast` in binary and text forms as well. Since the IR can only represent the legacy polymorphic semantics, disallow unsupported casts from nullable to non-nullable references or vice versa for now.
* Allow casting to basic heap types (#5332)Thomas Lively2022-12-088-106/+173
| | | | | | | The standard casting instructions now allow casting to basic heap types, not just user-defined types, but they also require that the intended type and argument type have a common supertype. Update the validator to use the standard rules, update the binary parser and printer to allow basic types, and update the tests to remove or modify newly invalid test cases.
* Add standard versions of WasmGC casts (#5331)Thomas Lively2022-12-0735-467/+582
| | | | | | | We previously supported only the non-standard cast instructions introduced when we were experimenting with nominal types. Parse the names and opcodes of their standard counterparts and switch to emitting the standard names and opcodes. Port all of the tests to use the standard instructions, but add additional tests showing that the non-standard versions are still parsed correctly.
* [Wasm GC] Add array support to TypeMerging (#5329)Alon Zakai2022-12-071-0/+41
|
* [Wasm GC] Add TypeMerging pass (#5321)Alon Zakai2022-12-074-0/+390
| | | | | | | | This finds types that can be merged into their super: types that add no fields, and are not used in casts, etc. - so we might as well use the super. This complements TypeSSA, in that it can merge back the new types that TypeSSA created, if we never found a use for them. Without this, TypeSSA can bloat binary size quite a lot (I see 10-20%).
* Update tests ahead of transition from `data` to `struct` (#5320)Thomas Lively2022-12-0731-787/+302
| | | | | | | | | | The upstream WasmGC spec has removed `data` and introduced `struct`. To make the migration easier, we have been supporting `struct` as an `alias` for `data` and `structref` as an alias for `dataref`. Update the tests to prefer the `struct` aliases over `data` for test input to make the future migration easier. Also update some tests that had stale comments about ref.null types being updated and remove some tests for instructions like br_on_data and ref.as_data that do not make sense without a `data` type.
* [Wasm GC] Add array support to TypeSSA (#5327)Alon Zakai2022-12-071-0/+230
| | | Previously it only handled structs.
* Fix Asyncify assertions after #5293 (#5328)Alon Zakai2022-12-071-7/+74
| | | | | | | | | | | Followup to #5293, this fixes a small regression there regarding assertions. We do have a need to visit non-instrumented functions if we want assertions, as we assert on some things there, namely that such functions do not change the state (if they changed it, we'd need to instrument them to handle that properly). This moves that logic into a new pass. We run that pass when assertions are enabled. Test diff basically undoes part the test diff from that earlier PR for that one file.
* Fix an Inlining bug with a name collision in a br nested in a call param (#5323)Alon Zakai2022-12-061-0/+44
|
* Optimize Asyncify to not flatten/optimize unnecessarily (#5293)Alexander Guryanov2022-12-068-215/+45
| | | | | | | | | Add a way to proxy passes and the addition of passes in pass runners. With that we can make Asyncify only modify functions it actually needs to. On a project that Asyncify only needs to modify a few functions on, this can save a huge amount of time as it avoids flattening+optimizing the majority of the module. Fixes #4822
* [Wasm GC] Add TypeSSA pass (#5299)Alon Zakai2022-12-023-0/+227
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This creates new nominal types for each (interesting) struct.new. That then allows type-based optimizations to be more precise, as those optimizations will track separate info for each struct.new, in effect. That is kind of like SSA, however, we do not handle merges. For example: x = struct.new $A (5); print(x.value); y = struct.new $A (11); print(y.value); // => // x = struct.new $A.x (5); print(x.value); y = struct.new $A.y (11); print(y.value); After the pass runs each of those struct.new creates a unique type, and type-based analysis can see that 5 or 11 are the only values written in that type (if nothing else writes there). This bloats the type section with the new subtypes, so it is best used with a pass to merge unneeded duplicate types, which a later PR will add. That later PR will exactly merge back in the types created here, which are nominally different but indistinguishable otherwise. This pass is not enabled by default. It's not clear yet where is the best place to do it, as it must be balanced by type merging, but it might be better to do multiple rounds of optimization between the two. Needs more investigation.
* Remove more uses of NAN (#5310)Thomas Lively2022-12-021-8/+10
| | | | | In favor of the more portable code snippet using `std::copysign`. Also reintroduce assertions that the NaNs have the expected signs. This continues work started in #5302.
* Support `array` and `struct` types in the type fuzzer (#5308)Thomas Lively2022-12-022-41/+47
| | | | | | | Since `data` has been removed from the upstream proposal and `struct` has been added in its place, update the type fuzzer to be structured around `struct` and `array` (which it had not previously been updated to support) rather than `data`. A follow-on PR will make the broader change of removing `data` and adding `struct`.
* Do not special case ref.null in `LUBFinder` (#5307)Thomas Lively2022-12-016-58/+101
| | | | | | | | | | | | Before we implemented bottom heap types, `ref.null` had to be annotated with specific types. The `LUBFinder` utility ignored these types so that it could find the best LUB from all considered non-null expressions, then go back and update the type annotations on the nulls to match that LUB. Now that we have bottom types, however, none of that is necessary, and in fact ignoring nulls can miss possible refinements to bottom types. Update and simplify `LUBFinder` so that it is a simple wrapper around the underlying `Type::getLeastUpperBound` utility with no additional logic. Update tests to account for the more powerful optimizations.
* [Wasm GC] Implement closed-world flag (#5303)Alon Zakai2022-11-304-23/+256
| | | | | | | | | | | | | With this change we default to an open world, that is, we do the safe thing by default: we no longer assume a closed world. Users that want a closed world must pass --closed-world. Atm we just do not run passes that assume a closed world. (We might later refine them to find which types don't escape and only optimize those.) The RemoveUnusedModuleElements is an exception in that the closed-world flag influences one part of its operation, but not the rest. Fixes #5292
* [NFC] Avoid unneeded work in GTO (#5304)Alon Zakai2022-11-305-21/+9
| | | | | As noticed in #5303, the test changes here are because we did unnecessary work which created a new rec group, which then led to a rec group being printed out.
* Fix validation and inlining bugs (#5301)Thomas Lively2022-11-291-4/+40
| | | | | | | | | | | | | | Inlining had a bug where it gave return_calls in inlined callees concrete types even when they should have remained unreachable. This bug flew under the radar because validation had a bug where it allowed expressions to have concrete types when they should have been unreachable. The fuzzer found this bug by adding another pass after inlining where the unexpected types caused an assertion failure. Fix the bugs and add a test that would have triggered the inlining bug. Unfortunately the test would have also passed before this change due to the validation bug, but it's better than nothing. Fixes #5294.
* Add a placeholder closed-world flag (#5298)Alon Zakai2022-11-292-0/+18
| | | The flag does nothing so far.
* Remove equirecursive typing (#5240)Thomas Lively2022-11-2323-333/+161
| | | | Equirecursive is no longer standards track and its implementation is extremely complex. Remove it.
* Change the default type system to isorecursive (#5239)Thomas Lively2022-11-23319-4610/+4590
| | | | | | | | | | This makes Binaryen's default type system match the WasmGC spec. Update the way type definitions without supertypes are printed to reduce the output diff for MVP tests that do not involve WasmGC. Also port some type-builder.cpp tests from test/example to test/gtest since they needed to be rewritten to work with isorecursive type anyway. A follow-on PR will remove equirecursive types completely.
* [Wasm GC] Fix CoalesceLocals on tees that receive a refined type (#5289)Alon Zakai2022-11-221-0/+51
| | | Same testcase as in #5287 but in another pass.
* [Wasm GC] Refinalize in UnneededSetRemover when necessary (#5287)Alon Zakai2022-11-221-6/+31
|
* Validate that GC is enabled for rec groups and supertypes (#5279)Thomas Lively2022-11-222-0/+30
| | | | | | | | | Update `HeapType::getFeatures` to report that GC is used for heap types that have nontrivial recursion groups or supertypes. Update validation to check the features on function heap types, not just their individual params and results. This fixes a fuzz bug in #5239 where initial contents included a rec group but the fuzzer disabled GC. Since the resulting module passed validation, the rec groups made it into the binary output, making the type section malformed.
* Code Pushing: Ignore unreachable sets (#5284)Alon Zakai2022-11-211-1/+29
| | | | | Normally we ignore them anyhow (unreachability is an effect, either a trap or a control flow switch), but in traps-never-happen mode we can ignore a trap, so we need to check this manually.
* Do not compare reference values across executions (#5276)Thomas Lively2022-11-171-0/+22
| | | | | | | Since we optimize assuming a closed world, optimizations can change the types and structure of GC data even in externally-visible ways. Because differences are expected, the fuzzer already did not compare reference-typed values from before and after optimizations when running with nominal typing. Update it to not compare these values under any type system.
* [Wasm GC] Start an OptimizeCasts pass and reuse cast values there (#5263)Alon Zakai2022-11-173-0/+402
| | | | | | | | | | | | | | | | | | | | | | | | (some.operation (ref.cast .. (local.get $ref)) (local.get $ref) ) => (some.operation (local.tee $temp (ref.cast .. (local.get $ref)) ) (local.get $temp) ) This can help cases where we cast for some reason but happen to not use the cast value in all places. This occurs in j2wasm in itable calls sometimes: The this pointer is is refined, but the itable may be done with an unrefined pointer, which is less optimizable. So far this is just inside basic blocks, but that is enough for the cast of itable calls and other common patterns I see.
* Fix isorecursive canonicalization (#5269)Thomas Lively2022-11-171-1/+1
| | | | | | | | | | | | | | Fixes a longstanding problem with isorecursive canonicalization that only showed up in MacOS and occasionally Windows builds. The problem was that `RecGroupEquator` was not quite correct in the presence of self-references in rec groups. Specifically, `RecGroupEquator` did not differentiate between instances of the same type appearing across two rec groups where the type was a self-reference in one group but not in the other. The reason this only showed up occasionally on some platforms was that this bug could only cause incorrect behavior if two groups that would incorrectly be compared as equal were hashed into the same bucket of a hash map. Apparently the hash map used on Linux never hashes the two problematic groups into the same bucket.
* Revert "Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265)" ↵Thomas Lively2022-11-1617-76/+81
| | | | | (#5266) This reverts commit 570007dbecf86db5ddba8d303896d841fc2b2d27.
* Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265)Thomas Lively2022-11-1617-81/+76
| | | | | This reverts commit b2054b72b7daa89b7ad161c0693befad06a20c90. It looks like the necessary V8 change has not rolled out everywhere yet.
* [Wasm GC] Fix a GUFA bug on null call_ref targets (#5262)Alon Zakai2022-11-161-2/+22
| | | | If the target is a bottom type then it is a heap type but it is not a signature type, and we should treat it as unreachable (and not crash).
* GlobalStructInference: Handle the case of just 1 value (#5259)Alon Zakai2022-11-152-6/+61
| | | | | | | | | | | | #5253 handled the case of just one possible global. It is also possible we have multiple globals but just one value. This handles that case. (It slightly overlaps with other passes, but as this pass actually identifies the creations of the objects in globals, it has a guarantee of success that the others don't, and it is very easy to just do given all the work done to handle the case of 2 values). Also fix a minor bug in #5253 - we need to trap if the old reference were null. That is, we know the reference must point to the only object ever created of that type, but that is only if it is not null; if it's null we need to trap.
* [Parser] Parse struct allocation and accessor instructions (#5255)Thomas Lively2022-11-151-1/+80
| | | | | Including support for parsing field indices. Although only numeric field indices are supported at the moment, set up the code to make it straightforward to implement type-dependent symbolic field names in the future.
* GlobalStructInference: Handle cases with just 1 global too (#5253)Alon Zakai2022-11-152-19/+171
| | | | | | | | | | | | | | | | | | | | | Expand GlobalStructInference to operate on cases with a single possible global, and not just 2 or more. Even the case of a single global is useful, it turns out, as we can alter the reference in places like this: (struct.get $type 0 (..ref..) ) No matter what ref is, if there is a single global it must refer to, we can switch to this: (struct.get $type 0 (global.get $global) ) That can unlock further opts later. Note that we can do this even if we don't know what the value actually is - we may not know what the struct.get returns, but we do know what it reads from.
* Make `call_ref` type annotations mandatory (#5246)Thomas Lively2022-11-1517-76/+81
| | | | They were optional for a while to allow users to gracefully transition to using them, but now make them mandatory to match the upstream WasmGC spec.
* Add a pass to lower sign-ext operations to MVP (#5254)Alon Zakai2022-11-153-0/+72
| | | | Fixes #5250
* Fix a trivial CodePushing bug with looking at the wrong index (#5252)Alon Zakai2022-11-142-11/+266
| | | | | | | | | | Pretty simple logic bug, but it ended up causing us to not optimize sometimes. Sadly the original tests happened to not have anything that depended on the index in isolation. Fix + add comprehensive tests for using that index properly. Also test the call.without.effects intrinsic, which is orthoginal to this, but also worth testing as it is a big use case here.
* [Parser] Parse `ref.is*`, `ref.eq`, `i31.new`, and `i31.get*` (#5247)Thomas Lively2022-11-141-0/+88
|
* Fix arithmetic in interpretation of ArrayNewSeg (#5251)Thomas Lively2022-11-142-2/+14
| | | | | | | | | | | The offset and size were previously being sign extended from 32 to 64 bits, which meant that negative sizes could make the bounds check pass and cause an exception to be thrown by an overly large allocation. Switch to using uint64_t from the start rather than mixing sizes and signs, and update the tests to reproduce the error more robustly in the absence of the fix. Also fix a bug in RemoveUnusedModuleElements triggered by the new test. Fixes #5249.
* [Wasm GC] Fix nondeterminism in GUFA due to ordering (#5243)Alon Zakai2022-11-111-0/+46
| | | | | | | | | | We don't actually have the distributive property since our PossibleContents representation is an approximation, and the fuzzer found a case where that is noticeable. See more details in the new comment + testcase. I measured speed and memory usage and this actually causes almost no noticeable change.
* Fix two fuzz bugs with ArrayNewSeg (#5242)Thomas Lively2022-11-114-22/+59
| | | | | | | | | | | | First, we forgot to note the type annotation on `ArrayNewSeg` instructions, so in small modules where these are the only annotated instructions, the type section would be incomplete. Second, in the interpreter we were reserving space for the array before checking that the segment access was valid. This could cause huge allocations that threw bad_alloc exceptions before the interpreter could get around to trapping. Fix the problem by reserving the array after validating the arguements. Fixes #5236.
* [Wasm GC] Add Monomorphize pass (#5238)Alon Zakai2022-11-113-0/+602
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Monomorphization finds cases where we send more refined types to a function than it declares. In such cases we can copy the function and refine the parameters: // B is a subtype of A foo(new B()); function foo(x : A) { ..} => foo_B(new B()); // call redirected to refined copy function foo(x : A) { ..} // unchanged function foo_B(x : B) { ..} // refined copy This increases code size so it may not be worth it in all cases. This initial PR is hopefully enough to start experimenting with this on performance, and so it does not enable the pass by default. This adds two variations of monomorphization, one that always does it, and the default which is "careful": it sees whether monomorphizing lets the refined function actually be better than the original (say, by removing a cast). If there is no improvement then we do not make any changes. This saves a significant amount of code size - on j2wasm the careful version increases by 13% instead of 20% - but it does run more slowly obviously.
* Handles memory.grow failure in MultiMemoryLowering Pass (#5241)Ashley Nelson2022-11-111-9/+27
| | | Per the wasm spec, memory.grow instructions should return -1 when there is a failure to allocate enough memory. This PR adds support for returning this error code.
* Fix a fuzz bug with incremental unreachability in OptimizeInstructions (#5237)Alon Zakai2022-11-091-0/+43
| | | | | | | | | | | OptimizeInstructions in rare cases can add unreachability. We propagate it out at the end all at once. The fuzzer was smart enough to find a very special combination of code + passes that can hit an issue, see the testcase. As mentioned in the TODO, we should perhaps avoid adding unreachability in OptimizeInstructions at all. If this happens again that might be worth the effort. But also checking the type of the child as in this PR doesn't add much complexity in the code.
* Fix possible-contents.h for `array.new_{data,elem}` (#5232)Thomas Lively2022-11-081-0/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update MemoryPacking for array.new_data The MemoryPacking pass looks at all instructions that reference memory segments to determine how they can be optimized. #5214 introduced a new instruction that references memory segments, array.new_data, but did not update MemoryPacking accordingly. This omission meant that MemoryPacking could produce invalid or misoptimized modules in the presence of array.new_data. Fix the problem by making MemoryPacking aware of array.new_data. Consider array.new_data when determining whether a segment is used and update array.new_data to reflect the new, optimized segment numberings afterward. To keep things simple, do not try to split any segment that is referred to by a array.new_data instruction. * fix * Add test explanations * Fix possible-contents.h for `array.new_{data,elem}` This code was not properly updated in #5214, so GUFA would incorrectly optimize out `array.new_data` and `array.new_elem` instructions. Fix the problem by making these instructions data flow roots. * fix * move tests
* Update MemoryPacking for array.new_data (#5229)Thomas Lively2022-11-081-0/+173
| | | | | | | | | | | | | | | | | | | * Update MemoryPacking for array.new_data The MemoryPacking pass looks at all instructions that reference memory segments to determine how they can be optimized. #5214 introduced a new instruction that references memory segments, array.new_data, but did not update MemoryPacking accordingly. This omission meant that MemoryPacking could produce invalid or misoptimized modules in the presence of array.new_data. Fix the problem by making MemoryPacking aware of array.new_data. Consider array.new_data when determining whether a segment is used and update array.new_data to reflect the new, optimized segment numberings afterward. To keep things simple, do not try to split any segment that is referred to by a array.new_data instruction. * fix * Add test explanations
* Add arguments to control which imports/exports are JSPI'd. (#5217)Brendan Dahl2022-11-081-0/+69
| | | | | | | | | | Instead of automatically determining which exports will be async they will be explicitly set by the user. We'll rely on the runtime trapping if they are incorrectly set. Two new arguments that behave similar to asyncify-imports: - jspi-imports - jspi-exports