summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* [Wasm GC] Casts of a non-nullable bottom type to non-null fail (#5645)Alon Zakai2023-04-124-37/+88
| | | | | | | | | | | Casting (ref nofunc) to (ref func) seems like it can succeed based on the rule of "if it's a subtype, it can cast ok." But the fuzzer found a corner case where that leads to a validation error (see testcase). Refactor the cast evaluation logic to handle uninhabitable refs directly, and return Unreachable for them (since the cast cannot even be reached). Also reorder the rule checks there to always check for a non-nullable cast of a bottom type (which always fails).
* [NFC] Refactor some old fuzzer code (#5658)Alon Zakai2023-04-121-13/+8
| | | | A return value was unused, and we have BranchUtils::operateOnScopeNameDefs now which can replace old manual code.
* [NFC] Refactor fuzzer array check logic (#5659)Alon Zakai2023-04-121-20/+30
|
* Fuzzer: When nested under makeTrivial(), avoid normal make() (#5657)Alon Zakai2023-04-122-0/+16
| | | | | | | | Without this, in certain complex operations we could end up calling a nested make() operation that included nontrivial things, which could cause problems. The specific problem I encountered was in fixAfterChanges() we tried to fix up a duplicate label, but calling makeTrivial() emitted something very large that happened to include a new block with a new label nested under a struct.get, and that block's label conflicted with a label we'd already processed.
* [Wasm GC] Fuzz struct.set and array.set (#5655)Alon Zakai2023-04-122-1/+73
|
* Add a name hint to getValidName() (#5653)Alon Zakai2023-04-111-19/+45
| | | | | | | Without the hint, we always look for a valid name using name$0, $1, $2, etc., starting from 0, and in some cases that can lead to quadratic behavior. Noticed on a testcase in the fuzzer that runs for over 24 seconds (I gave up at that point) but takes only 2 seconds with this.
* [Wasm GC] Fuzz struct.get and array.get (#5651)Alon Zakai2023-04-104-4/+76
|
* [GUFA] Fix packed field filtering (#5652)Alon Zakai2023-04-101-6/+41
| | | | | | | | | | | | | | | | | | | | | | Technically we need to filter both before and after combining, that is, if a location's contents will be filtered by F() then if the new contents are x and old contents y then we need to end up with F(F(x) U F(y)). That is, filtering before is necessary to ensure the union of content does not end up unnecessarily large, and the filtering after is necessary to ensure the final result is properly filtered to fit. (If our representation were perfect then this would not be needed, but it is not, as the union of two exact types can end up as a very large cone, for example.) For efficiency we have been filtering afterwards. But that is not enough for packed fields, it turns out, where we must filter before. If we don't, then if inputs 0 and 0x100 arrive to an i8 field then combining them we get "unknown integer" (which is then filtered by 0xff, but it's too late). By filtering before, the actual values are both 0 and we end up with that as the only possible value. It turns out that filtering before is enough for such fields, so do only that.
* Do not flatten memory when array.new_data is present (#5650)Alon Zakai2023-04-101-12/+25
| | | Like data.drop etc., it notices data segment identity.
* binaryen.js: Use malloc/free instead of stackAlloc in setMemory (#5646)Mathias Nater2023-04-101-2/+6
| | | | | Memory data segments can be of large size, and might not fit in the stack. fixes #5595
* [Wasm GC] Update struct.get types in TypeRefining (#5649)Alon Zakai2023-04-101-1/+27
| | | | | We depended on ReFinalize doing it for us, and that usually works, but there is a corner case that depends on knowing all the type changes being done. So use our complete information to update those types in the pass.
* Fix MemoryPacking handling of array.init_data (#5644)Thomas Lively2023-04-071-5/+7
| | | | | | | | Do not optimize out or split segments that are referred to array.init_data instructions. Fixes a bug where segments could get optimized out, producing invalid modules. Doing the work to actually split segments used by array.init_data is left for the future. Also fix a latent UBSan failure revealed by the new test case.
* [NFC] Use the new getField() in the heap type fuzzer (#5643)Alon Zakai2023-04-071-17/+10
|
* Fix and simplify refinalization in OptimizeInstructions (#5642)Alon Zakai2023-04-071-23/+7
| | | | | The fuzzer found another case we were missing. I realized that we can just check for this in replaceCurrent, at least for places that call that method, which is the common case. So this simplifies the code while fixing a bug.
* [Wasm GC] Handle packed fields in GUFA and CFP (#5640)Alon Zakai2023-04-072-0/+42
| | | | | The same bug was present in both: We ignored packing, so writing a larger value than fits in the field would lead to us propagating that original value.
* [GUFA] Refine global types during flow (#5639)Alon Zakai2023-04-072-12/+32
| | | | | | | | | | | | Previously (ref.as_non_null (global.get ..)) would return the global with no changes, and if the global was nullable then the type didn't match the output, which hit an assertion (where GUFA checks that the contents match the declared type in the wasm). To fix this, refine global types, that is, the type we track on GlobalInfo may be more refined than the global itself. In the above example, if the global is nullable then the GlobalInfo would point to that global but have a non-nullable type. In fact the code was already prepared for this, and few changes were needed.
* [Wasm GC] Fix an assertion in array.set processing in OptimizeInstructions ↵Alon Zakai2023-04-072-3/+26
| | | | (#5641)
* [Wasm GC] Fix GUFA on ArrayInit (#5638)Alon Zakai2023-04-071-3/+14
|
* Implement array.fill, array.init_data, and array.init_elem (#5637)Thomas Lively2023-04-0622-31/+629
| | | | | These complement array.copy, which we already supported, as an initial complete set of bulk array operations. Replace the WIP spec tests with the upstream spec tests, lightly edited for compatibility with Binaryen.
* [Wasm GC] OptimizeInstructions: ref.as_non_null of null will trap (#5635)Alon Zakai2023-04-061-0/+3
| | | | | | | Trivial peephole optimization. Some work was needed in the tests as some of them relied on that pattern for convenience, so I modified them to try to keep them testing the same thing as much as possible (for one, struct.set.null.fallthrough, I don't think we can actually keep testing the same, as the situation should not be possible any more).
* [Wasm GC] Handle another unreachability case in trapOnNull() (#5634)Alon Zakai2023-04-051-1/+2
| | | This is the flip case of #5630
* Fuzzer: Improve mutate() (#5631)Alon Zakai2023-04-051-9/+33
| | | Don't use a fixed 10% chance to mutate, but pick a mutation rate in each function.
* RemoveUnusedModuleElements: Add SIMD support for memory operations (#5632)Alon Zakai2023-04-051-0/+6
| | | | Fixes #5629
* Avoid imported memories in the fuzzer (#5626)Alon Zakai2023-04-051-12/+15
| | | | | | | We already did this for the first memory, and just needed to loop to handle initial content in the test suite that has multiple memories. Also clean up that code while I'm around, to avoid repeating wasm.memories[0] all the time.
* Wasm GC] Handle unreachability in a select child in trapOnNull() (#5630)Alon Zakai2023-04-051-1/+6
|
* Only update functions in optimizeAfterInlining() (#5624)Alon Zakai2023-04-053-6/+11
| | | | | This saves the work of freeing and allocating for all the other maps. This is a code path that is used by several passes so it showed up in profiling for #5561
* Fix a crash in MemoryPacking due to an unreachable pointer (#5623)Thomas Lively2023-04-051-1/+1
| | | | | | | | Previously, the pointer type for newly emitted instructions was determined by the type of the destination pointer on a memory.init instruction, but that did not take into account that the destination pointer may be unreachable. Properly look up the pointer type on the memory instead to fix the problem. Fixes #5620.
* [Wasm GC] Fuzz struct.new and array.new (#5622)Alon Zakai2023-04-042-29/+48
| | | | | | | | | Repurpose makeBasicRef, makeCompoundRef to generate not just "constant" refs but any reference, and use those to create StructNew/ArrayNew. The key changes are to add makeCompoundRef to make(), and to make the function call make() for children, where possible, instead of just makeTrivial(). We also replace the i31-specific path with a call to makeBasicRef which handles i31 among other things.
* Support multiple memories in RemoveUnusedModuleElements (#5604)Thomas Lively2023-04-042-107/+131
| | | | | | | | Add support for memory and data segment module elements and treat them uniformly with other module elements rather than as special cases. There is a cyclic dependency between memories (or tables) and their active segments because exported or accessed memories (or tables) keep their active segments alive, but active segments for imported memories (or tables) keep their memories (or tables) alive as well.
* [Wasm GC] Fix CoalesceLocals ineffective tee removal with type changes (#5621)Alon Zakai2023-04-041-1/+10
| | | When we remove a tee there, we must not change the type at all.
* Use Names instead of indices to identify segments (#5618)Thomas Lively2023-04-0423-182/+272
| | | | | | | | | | All top-level Module elements are identified and referred to by Name, but for historical reasons element and data segments were referred to by index instead. Fix this inconsistency by using Names to refer to segments from expressions that use them. Also parse and print segment names like we do for other elements. The C API is partially converted to use names instead of indices, but there are still many functions that refer to data segments by index. Finishing the conversion can be done in the future once it becomes necessary.
* [Wasm GC] Fix CoalesceLocals i31 local.get removal (#5619)Alon Zakai2023-04-041-1/+6
| | | | When removing a local.get we must replace it with something of the identical type, and not make it non-nullable.
* [Wasm GC] Fuzz RefCast (#5617)Alon Zakai2023-04-032-7/+86
|
* [Wasm GC] Avoid refining in TypeUpdating unreachability propagation (#5616)Alon Zakai2023-04-031-1/+17
| | | | | That code should only propagate unreachability, and not refine. If it refines when we call finalize() then other code around it might end up invalid (as it could be partially refined; see testcase).
* [Wasm GC] Parse (sub $super _) for array, func, and struct (#5515)Andy Wingo2023-04-031-23/+55
| | | | The pretty-printer will still serialize these using the old func_subtype, array_subtype, and struct_subtype syntax, though.
* Fix a call to make_unique without std (#5615)Alon Zakai2023-04-031-1/+1
| | | Followup to #5613
* [Wasm GC] Stop emitted deprecated cast etc. instructions (#5614)Alon Zakai2023-03-311-46/+0
| | | | | | | | | This is necessary to start fuzzing RefCast etc., as otherwise the fuzzer errors on V8 which has already removed support for the deprecated ones apparently. Do not remove read support for them yet, as perhaps some users still need that.
* [NFC] Remove our bespoke `make_unique` implementation (#5613)Thomas Lively2023-03-3120-65/+61
| | | | This code predates our adoption of C++14 and can now be removed in favor of `std::make_unique`, which should be more efficient.
* Add a TODO in SignaturePruning (#5611)Alon Zakai2023-03-311-0/+8
|
* Fix Emscripten build for latest tot changes (#5610)Alon Zakai2023-03-311-1/+1
|
* [Wasm GC] Fix nondeterminism in SignaturePruning (#5608)Alon Zakai2023-03-311-3/+8
| | | | | | | The order of iteration on sigFuncs there can matter, as each time we prune we end up changing things that can affect other prunings (specifically, ParamUtils::removeParameter can decide that it can't remove a parameter based on the effects on arguments, and current limitations in how we handle that; and pruning can affect effects).
* Do not treat `atomic.fence` as using a memory (#5603)Thomas Lively2023-03-292-3/+0
| | | | | | | | | * Do not treat `atomic.fence` as using a memory Update RemoveUnusedModuleElements so that it no longer keeps the memory alive due to an `atomic.fence` instruction and update validation to allow modules to use `atomic.fence` without a memory. * update wasm2js tests
* [NFC] Simplify initialization in RemoveUnusedModuleElements.cpp (#5601)Thomas Lively2023-03-291-25/+21
| | | Use copy-list-initialization to shorten the code and reduce visual redundancy.
* Support memory64 in MemoryPacking (#5605)Thomas Lively2023-03-291-2/+5
| | | | | | Fix the relevant pointer and size expressions produced by MemoryPacking to be i64s when working with 64-bit memories. Fixes #5578.
* Use a SmallVector in MergeBlocks [NFC] (#5594)Alon Zakai2023-03-211-4/+9
| | | | | | | | This makes the pass 2-3% faster in some measurements I did locally. Noticed when profiling for #5561 (comment) Helps #4165
* Properly error on multivalue returns in GenerateDynCalls (#5588)Alon Zakai2023-03-211-0/+10
| | | | Fixes #5586
* [Wasm GC] Fix detection of externalize/internalize as constant (#5592)Alon Zakai2023-03-202-3/+20
| | | | | | | | | | | | Both isValidInConstantExpression and isSingleConstantExpression must look recursively at the internals of a RefAs that externalizes and internalizes, or else we might do something like externalize a local.get, which is not constant. getLiteral must handle externalize/internalize as well, and return a properly- modified literal. Without these fixes the testcase hits different internal assertions, and we either fail to recognize something is constant or not, or think that it is but fail to produce a literal for it.
* Ensure a deterministic order in the type names section (#5590)Alon Zakai2023-03-202-1/+6
| | | | | | | | | Before this PR we iterated over an unordered set. Replace that with an iteration on a vector. (Also, the value in the set was not even used, so this should even be faster.) Add random names in the fuzzer to types, the lack of which is I believe the reason this was not detected before.
* [Exceptions] Fix error on bad delegate index (#5587)Alon Zakai2023-03-171-1/+6
| | | | Fixes #5584
* [Wasm GC] Allow extern.externalize in globals (#5585)Alon Zakai2023-03-172-1/+8
| | | | | | | | | | This fixes wasm-ctor-eval on evalling a GC data structure that contains a field initialized with an externalized value. Per the spec this is a constant instruction and I verified that V8 allows this. Also add missing validation in wasm-ctor-eval of the output (which makes debugging this kind of thing a little easier).