summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Fix OOB string_view read in generated parser code (#5349)Thomas Lively2022-12-142-714/+710
| | | | | | | | | The `op` string_view was intentionally created to point into the `buf` buffer so that reading past its end would still be safe, but some C++ standard library implementations assert when reading past the end of a string_view. Change the generated code to read out of `buf` instead to avoid those assertions. Fixes #5322. Fixes #5342.
* [Wasm GC] Fix GlobalStructInference on unrefined globals (#5338)Alon Zakai2022-12-122-2/+113
| | | | | | | 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-122-2/+226
| | | | | 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-122-8/+204
| | | 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-096-70/+465
| | | 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-0923-142/+174
| | | | | | | | | | | | 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-0811-140/+217
| | | | | | | 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.
* Validate ref.as_* argument is a reference (#5330)Alon Zakai2022-12-081-1/+5
| | | | | | | | | | | | | | Without this we hit an assert with no line number info (or in a no-asserts build, bad things can happen). With this: $ bin/wasm-opt -all ~/Downloads/crash.wat --nominal [parse exception: Invalid ref for ref.as (at 155065:119)] Fatal: error parsing wasm (That can only happen for ref.as_non_null, as all the others do not have that assert - their types do not depend on the child's type, so their finalize does not error. Still, it is nice to validate earlier for them as well, so this PR handles them all.)
* Add standard versions of WasmGC casts (#5331)Thomas Lively2022-12-0745-612/+752
| | | | | | | 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-072-15/+55
|
* [Wasm GC] Add TypeMerging pass (#5321)Alon Zakai2022-12-0712-0/+670
| | | | | | | | 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-072-37/+309
| | | Previously it only handled structs.
* Fix Asyncify assertions after #5293 (#5328)Alon Zakai2022-12-072-11/+123
| | | | | | | | | | | 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-063-5/+69
|
* [Parser][NFC] Add `Idx` to type aliases representing indices (#5326)Thomas Lively2022-12-061-38/+42
| | | | | | | Previously we had types like `LocalT` and `MemoryT` to represent references to locals and memories, but when we added field indices in #5255, we had to use `FieldIdxT` instead of `FieldT` because `FieldT` was already in use as the type representing a field itself. Update `LocalT`, `MemoryT` and `GlobalT` to have `Idx` in their names to be consistent with `FieldIdxT`.
* Optimize Asyncify to not flatten/optimize unnecessarily (#5293)Alexander Guryanov2022-12-0610-219/+100
| | | | | | | | | 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
* binaryen.js: Properly export malloc/free (#5324)Alon Zakai2022-12-051-0/+2
| | | | This should unbreak the build. This is an old problem but was just noticed due to a recent emscripten change (emscripten-core/emscripten#18292).
* Add CMake option to only build tools needed for Emscripten (#5319)Derek Schuff2022-12-022-3/+8
| | | This helps cut the size and build time of the emsdk package.
* [Wasm GC] Add TypeSSA pass (#5299)Alon Zakai2022-12-029-0/+514
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rename BYN_INSTALL_TOOLS_ONLY to INSTALL_LIBS (NFC) (#5318)Derek Schuff2022-12-021-2/+5
| | | This better reflects what it really means. Also declare it with option()
* [NFC] Do not read past the end of a string_view (#5317)Thomas Lively2022-12-021-5/+5
| | | | | | | | wasm-s-parser.cpp was detecting the end of type strings by looking for null characters, but those null characters would be past the end of the relevant string_view. Bring that code in line with similar code by checking the length of the string_view instead. Fixes an assertion failure in MSVC debug mode. Fixes #5312.
* [Parser] Avoid calling `strtod` on NaNs entirely (#5316)Thomas Lively2022-12-021-5/+6
| | | | | | | | MSVC's implementation of `strtod` doesn't return a negative Nan for "-nan", so we already had a workaround to explicitly handle that case without calling `strtod`. Unfortunately the workaround was not used for negative NaNs with payloads, so there were still bugs. Fix the problem and make the code even more portable by avoiding `strtod` completely for any kind of nan, positive or negative, with or without payload.
* [NFC] Allow TypeBuilder::Entry::subTypeOf to take any HeapType (#5314)Thomas Lively2022-12-021-2/+1
| | | | We generalized the underlying API, TypeBuilder::setSubType, to allow it to take any HeapType as the supertype in #5045. Make the same change now in the helper.
* Remove more uses of NAN (#5310)Thomas Lively2022-12-022-8/+12
| | | | | 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-023-81/+101
| | | | | | | 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`.
* Use C++17's [[maybe_unused]]. NFC (#5309)Sam Clegg2022-12-0222-85/+35
|
* Do not special case ref.null in `LUBFinder` (#5307)Thomas Lively2022-12-0113-178/+132
| | | | | | | | | | | | 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-3010-38/+307
| | | | | | | | | | | | | 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-306-22/+12
| | | | | 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.
* [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-293-7/+48
| | | | | | | | | | | | | | 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-293-0/+30
| | | The flag does nothing so far.
* Remove equirecursive typing (#5240)Thomas Lively2022-11-2344-1501/+194
| | | | 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-23322-4620/+4600
| | | | | | | | | | 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-222-3/+73
| | | 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-222-6/+41
|
* [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-224-8/+43
| | | | | | | | | 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-212-1/+49
| | | | | 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-214-19/+12
| | | This workaround is no longer needed after commit emscripten-core/emscripten@ce4c405.