summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* 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).
* [Wasm GC] wasm-ctor-eval: Handle externalized data (#5582)Alon Zakai2023-03-162-4/+29
|
* [NFC] Templatize `makeBlock` so it can be used with any iterable (#5583)Thomas Lively2023-03-162-30/+25
| | | | | | | | Replace the different overloads we previously had for different kinds of containers with generic templates. We still need dedicated overloads for `std::initializer_list` because it is never inferred in a template context, though. Also, since `std::initializer_list` does not allow subscripting, update the arena vector implementation to use iterators instead now that initializer lists can be passed down to that layer without being reified as vectors.
* Handle ReturnCall in MergeSimilarFunctions (#5581)Alon Zakai2023-03-161-1/+4
| | | | Fixes #5580
* [Wasm GC] Fuzz ref.test (#5577)Alon Zakai2023-03-162-0/+38
|
* Add bulk-array.wast spec test outline (#5568)Thomas Lively2023-03-164-33/+13
| | | | | | | | | Add spec/bulk-array.wast, which contains an outline of the tests that will be necessary for the upcoming bulk array instructions: array.copy (already implemented), array.fill, array.init_data, and array.init_elem. Although the test file does not actually contain any tests yet, it contains some setup code defining types, globals, and element segments that the tests will use. Fix miscellaneous bugs in parsing, validation, and printing to allow this setup code to run without issues.
* Support interpretation of extern.externalize and extern.internalize (#5576)Thomas Lively2023-03-164-23/+66
| | | | | | | To allow the external and internal reference values to be differentiated yet round-trippable, set the `Literal` type to externref on external references, but keep the gcData the same for both. The only exception is for i31 references, for which the externalized version gets a `gcData` that contains a copy of the original i31 literal.
* Fuzzer: Generate both immutable and mutable globals (#5575)Alon Zakai2023-03-152-3/+8
|
* Fuzzer: Pick interesting subtypes in getSubType(HeapType) (#5573)Alon Zakai2023-03-152-7/+38
|
* [Wasm GC] Remove RefIsFunc and RefIsI31 from the binary format (#5574)Alon Zakai2023-03-153-39/+0
| | | | We still support ref.is_func/i31 in the text format for now. After we verify that no users depend on that we can remove it as well.
* Fix misoptimization in TypeMerging (#5572)Thomas Lively2023-03-141-55/+144
| | | | | | | | | | | | TypeMerging previously tried to merge types with their supertypes and siblings in a single step, but this could cause a misoptimization in which a type was merged with its parent's sibling without being merged with its parent, breaking subtyping. Fix the bug by merging with supertypes and siblings separately. Since we now have multiple merging steps, also take the opportunity to run the sibling merging step multiple times to exploit more merging opportunities. Fixes #5556.
* [Wasm GC] Properly handle packed field truncation in StructNew (#5570)Alon Zakai2023-03-131-2/+3
|
* Fix fuzzer emitting invalid constant expressions (#5571)Thomas Lively2023-03-131-19/+21
| | | | | | | | | | The fuzzer had code to avoid emitting `global.get` of locally defined (i.e. non-imported) globals in global initializers and data segment offsets, but that code only handled top-level `global.get` because it predated the extended-const proposal. Unfortunately this bug went undetected until #5557, which fixed the validator to make it reject invalid uses of `global.get` in constant expressions. Fix the bug so the validator no longer produces invalid modules.
* Fuzzer: Avoid emitting massive nested structs (#5564)Alon Zakai2023-03-131-7/+26
| | | | | | | | | | | The nesting limit of around 20 was enough to cause exponential blowup. A 20K input file lead to a 2GB wasm in one case I saw (!) which takes many seconds to fuzz. Instead, reduce the limit, and also check if random tells us that the random input is done; when that's done we should stop, which limits us to O(input size). Also do this for non-nullable types, and handle that in globals (we cannot emit a RefAsNulNull there, so switch the global type if necessary).
* Fuzzer: Limit array sizes (#5569)Alon Zakai2023-03-132-10/+4
| | | | | | Even with a 1% chance of a huge array, there is a second problem aside from hitting an allocation failure, which is DoS - building such a huge array of Literals takes noticeable time in the fuzzer. Instead, just limit array max sizes, which is consistent with what we do for struct sizes etc.
* Fix ambiguous operators under C++20 (#5567)Thomas Lively2023-03-101-2/+4
| | | | | | | | | | | | When resolving `operator!=`, C++20 also considers `operator==` implementations when the types on `operator!=` do not match exactly. This caused the modified code to have no most-specific overload to choose, resulting in an error. This is actually a bug in the language that is being fixed, but there exist compilers without the fix applied. Work around the problem by updating the types in the declaration of `operator==` and `operator!=` to be more exact. This is a copy of #5029 with formatting fixes.
* Make constant expression validation stricter (#5557)Thomas Lively2023-03-106-79/+100
| | | | | | | | | | Previously we treated global.get as a constant expression and only additionally verified that the target globals were immutable in some cases. But global.get of a mutable global is never a constant expression, and further, only imported globals are available in constant expressions unless GC is enabled. Fix constant expression validation to only allow global.get of immutable, imported globals, and fix all the invalid tests.
* Fuzzer: Emit fewer uninhabitable types in getSubType (#5563)Alon Zakai2023-03-101-0/+9
| | | | Only rarely return an uninhabitable subtype of an inhabitable one. This avoids a major source of uninhabitability and immediate traps.
* [NFC] Add missing parts of `ChildIterator` (#5566)Thomas Lively2023-03-101-6/+12
| | | | | The missing associated types will become necessary if we ever use these iterators in a nontrivial manner. Make the parent reference into a pointer so that the copy constructor and assignment operator are not implicitly deleted.