summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* [NFC] Avoid scanning SmallSets twice during insert (#5221)Alon Zakai2022-11-301-15/+39
| | | As suggested in #5218
* [NFC] Add a TODO in ReorderFunctions (#5205)Alon Zakai2022-11-301-0/+2
|
* Update comment in OptimizeAddedConstants.cpp (#5283)Alon Zakai2022-11-291-2/+2
|
* [Parser] Do not assume `NAN` is positive (#5302)Thomas Lively2022-11-291-3/+4
| | | | | | | It turns out that this assumption does not necessarily hold on Windows with Visual Studio 2019. Instead of using `NAN` and `-NAN`, explicitly construct positive and negative NaN values with `std::copysign`, which should be portable. Fixes #5291.
* [NFC] Remove unneeded check (#5300)Alon Zakai2022-11-291-5/+3
| | | | The caller fills the map with what is relevant anyhow, so we don't need to check before looking for an item in the map.
* Fix validation and inlining bugs (#5301)Thomas Lively2022-11-292-3/+8
| | | | | | | | | | | | | | 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.
* [NFC] Refactor GlobalTypeRewriter to split out the type mapping logic (#5295)Alon Zakai2022-11-292-13/+30
| | | | | | | | | | | The logic that is split out into mapTypes gets a map of old type => new type and then updates the module to replace the old with the new. This will be useful in a future pass to merge types. We will tell it to map the types to be merged with the types we want to merge them into. This removes an assert on all types being in the map to allow some of them not to be. (the new pass that will use this will only want to map some types).
* Validator: Print the field number on subtyping errors (#5297)Alon Zakai2022-11-291-4/+6
|
* [NFC] Print type names in BINARYEN_PRINT_FULL mode (#5296)Alon Zakai2022-11-291-3/+28
|
* Add a placeholder closed-world flag (#5298)Alon Zakai2022-11-291-0/+12
| | | The flag does nothing so far.
* Remove equirecursive typing (#5240)Thomas Lively2022-11-2320-1167/+31
| | | | 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-232-10/+7
| | | | | | | | | | 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.
* Dump only the binary in pass-debug mode (#5290)Alon Zakai2022-11-221-4/+3
| | | | | Dumping the text is nice sometimes, but on huge testcases the wat can be 1 GB in size (!), and so dumping one per pass can lead to using 20 GB or so for the full optimization pipeline. Emit just the binary to avoid that.
* [Wasm GC] Fix CoalesceLocals on tees that receive a refined type (#5289)Alon Zakai2022-11-221-3/+22
| | | Same testcase as in #5287 but in another pass.
* Rename UserSection -> CustomSection. NFC (#5288)Sam Clegg2022-11-229-119/+119
| | | This reflects that naming used in the spec.
* [Wasm GC] Refinalize in UnneededSetRemover when necessary (#5287)Alon Zakai2022-11-221-0/+10
|
* [NFC] Expand comment about validating function type features (#5286)Thomas Lively2022-11-221-1/+3
| | | This addresses feedback missed in #5279.
* Validate that GC is enabled for rec groups and supertypes (#5279)Thomas Lively2022-11-222-8/+13
| | | | | | | | | 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-0/+20
| | | | | 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.
* Remove `-sEXPORT_ES6` + Node.js workaround for binaryen.js (#5235)Kleis Auke Wolthuizen2022-11-212-12/+0
| | | This workaround is no longer needed after commit emscripten-core/emscripten@ce4c405.
* Avoid calling back() on an empty string in setBinaryenBinDir (#5280)Piotr Sarna2022-11-181-1/+1
| | | | | | | | | std::string::back() is only well defined for non-empty strings. Without the change, wasm-reduce fails if it is called from $PATH, because then, the parent directory is an empty string. A workaround is to explicitly set the binaryen path with -b, and it is still necessary after this fix, but at least the program ends with a comprehensible error message instead of a generic assertion failure from the standard library.
* Add post-emscripten-side-module pass argument (#5274)Sam Clegg2022-11-181-3/+10
| | | | | | | In this mode we don't remove the start/stop_em_asm symbols or data. This is because with side modules we read this information directly from the wasm binaryen at runtime. See https://github.com/emscripten-core/emscripten/pull/18228
* Add `hasArgument` helper to pass options. NFC (#5278)Sam Clegg2022-11-174-18/+13
|
* Fix inverted logic bug with asyncify-ignore-indirect (#5275)Sam Clegg2022-11-171-4/+4
|
* Do not compare reference values across executions (#5276)Thomas Lively2022-11-171-18/+10
| | | | | | | 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-175-0/+237
| | | | | | | | | | | | | | | | | | | | | | | | (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-5/+4
| | | | | | | | | | | | | | 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.
* Fix warnings from -Wheader-hygiene and -Wimplicit-const-int-float-conversion ↵Martin Kustermann2022-11-173-6/+7
| | | | | | | | | (#5273) When `-Wheader-hygiene` is enabled, C compiler will warn when using namespace directive in global context in header file. When `-Wimplicit-const-int-float-conversion` is enabled C compiler will warn on implicit integer to double conversions that change values.
* [wasm-split] Improve the error message for bad checksums (#5268)Thomas Lively2022-11-161-2/+2
| | | | The previous error message was ambiguous and could easily be interpreted to mean the opposite of what it meant.
* Revert "Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265)" ↵Thomas Lively2022-11-164-83/+18
| | | | | (#5266) This reverts commit 570007dbecf86db5ddba8d303896d841fc2b2d27.
* Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265)Thomas Lively2022-11-164-18/+83
| | | | | 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-0/+6
| | | | 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).
* Fix an unused var warning in some compilers (#5260)Alon Zakai2022-11-151-2/+1
|
* GlobalStructInference: Handle the case of just 1 value (#5259)Alon Zakai2022-11-151-9/+11
| | | | | | | | | | | | #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.
* Switch from `typedef` to `using` in C++ code. NFC (#5258)Sam Clegg2022-11-1535-58/+58
| | | | This is more modern and (IMHO) easier to read than that old C typedef syntax.
* [Parser] Parse struct allocation and accessor instructions (#5255)Thomas Lively2022-11-151-7/+128
| | | | | 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-151-6/+25
| | | | | | | | | | | | | | | | | | | | | 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-154-83/+18
| | | | 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-154-0/+80
| | | | Fixes #5250
* Fix a trivial CodePushing bug with looking at the wrong index (#5252)Alon Zakai2022-11-141-1/+1
| | | | | | | | | | 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-4/+36
|
* Fix arithmetic in interpretation of ArrayNewSeg (#5251)Thomas Lively2022-11-142-6/+5
| | | | | | | | | | | 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.
* [GUFA] [NFC] Remove RefCast special-casing (#5244)Alon Zakai2022-11-141-33/+4
| | | | All that code did was filter contents by the type of the RefCast. We do that for all expressions now, so it was redundant.
* [Wasm GC] Fix nondeterminism in GUFA due to ordering (#5243)Alon Zakai2022-11-111-10/+13
| | | | | | | | | | 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-112-1/+4
| | | | | | | | | | | | 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-115-6/+260
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-4/+9
| | | 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-1/+7
| | | | | | | | | | | 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/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-26/+46
| | | | | | | | | | | | | | | | | | | * 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