summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix reduction of nondefaultable tuples (#3746)Alon Zakai2021-03-291-1/+1
| | | | There is a makeZeros right below that, which will assert on a nondefaultable type.
* handleNonNullableLocals(): Do not modify params (#3740)Alon Zakai2021-03-291-0/+4
| | | | Parameters can be non-nullable, and must stay so if they began as such. By mistake we modified them with the vars.
* Inlining: Always inline single-use functions (#3730)Alon Zakai2021-03-292-8/+8
| | | | | | | | | | | | | | | | This implements emscripten-core/emscripten#13744 Inlining functions with a single use allows us to remove the function afterward. That looks highly beneficial, shrinking every single benchmark in emscripten's benchmark suite, by an average of 2% on the macrobenchmarks and 3.5% on all of them. Speed also improves, although mostly on the microbenchmarks so that might be less realistic. There may be a slight downside to startup time due to emitting larger functions, but given the baseline compilers in VMs these days it seems worth it, as the delay would be just to get to the upper tier. On the benchmark suite the risk seems low. See more details in the PR above.
* Fix fuzzer on creating a function with a heaptype of just 'func' (#3738)Alon Zakai2021-03-251-6/+23
| | | Also handle more cases of non-function data types there.
* Print parse errors in reducer and roundtrip (#3737)Alon Zakai2021-03-252-2/+14
| | | | Without this, crashes from things like #3736 simply get reported as "a parse exception was thrown" with no detail.
* [Wasm GC] Add a Name-Types pass (#3735)Alon Zakai2021-03-254-0/+52
| | | | | The pass gives a simple short name to each type, $type$N. This can be useful in debugging, to avoid the autogenerated names which can be very long.
* Fix binary reading of tuples containing non-nullable types (#3734)Alon Zakai2021-03-251-5/+21
| | | | | | | | We must write them to a tuple with nullable types, then fix that up when reading. This is similar to what we do in handleNonNullableLocals, except that it operates on the entire tuple type, so it can't share that code. This fixes a regression from #3710 that was harder to notice by the fuzzer until now.
* Fix nondefaultability of Tuple types (#3733)Alon Zakai2021-03-252-2/+11
| | | | | | | This looks like a pre-existing issue to #3731, but the testcase only fails on that PR for a reason I did not investigate in depth, so it should land first. Also fix the check for nondefaultability in the fuzzer.
* Flat IR: Allow ref.as_non_null in nested positions (#3732)Alon Zakai2021-03-251-3/+10
| | | | | | We can't disallow it, as its result is non-null which we can't spill to a local. This may cause issues eventually in the combination of GC + flatten, but I don't expect it to. If it does we may need to revisit.
* [Wasm GC] Properly validate struct.new number of operands (#3726)Alon Zakai2021-03-251-9/+10
|
* Refactor TypeBuilder (#3728)Thomas Lively2021-03-244-32/+115
| | | | | | | | | | Makes TypeBuilders growable, adds a `getTempHeapType` method, allows the `getTemp*Type` methods to take arbitrary temporary or canonical HeapTypes rather than just an index, and allows BasicHeapTypes to be assigned to TypeBuilder slots. All of these changes are necessary for the upcoming re-implementation of equirecursive LUB calculation. Also adds a new utility to TypeBuilder for using `operator[]` as an intuitive and readable wrapper around the `getTempHeapType` and `setHeapType` methods.
* Resolve unused variable `globalStore` (#3729)Thomas Lively2021-03-241-0/+8
| | | | | This variable is only used when asserts are enabled, so it was causing compilation errors on optimized builds with -Wunused-variable -Werror. This PR fixes the build errors by hiding the variable and its uses behind ifdefs.
* Validator: Pass the module along when printing errors, so type names are ↵Alon Zakai2021-03-243-9/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | used (#3727) For example, on this invalid wat: (module (type $vec (struct (field i64))) (func $test (drop (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec)) ) ) ) We used to print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt ${i64} (i32.const 1) (rtt.canon ${i64}) ) We will now print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec) ) Note that $vec is used. In real-world examples the autogenerated structural name can be huge, which this avoids.
* [Wasm GC] Optimize BrOn* of the wrong kind (#3724)Alon Zakai2021-03-243-41/+121
| | | | | | | | | | | | #3719 optimized the case where the kind is what we want, like br_on_func of a function. This handles the opposite case, where we know the kind is wrong, and so the break is not taken. This seems equally useful for "polymorphic" code that does a bunch of checks and routes to different code for each case, as after inlining or other optimizations we may see which paths are taken and which are not. Also refactor the checking code to a shared location as RefIs/As will also want to use it.
* [Wasm GC] Handle non-nullable locals in Flatten pass (#3720)Alon Zakai2021-03-241-0/+3
| | | That pass adds lots of new locals, and we need to handle non-nullable ones.
* [Wasm GC] Validate the number of arguments in struct.new (#3723)Alon Zakai2021-03-241-0/+4
|
* [RT] Support expressions in element segments (#3666)Abbas Mashayekh2021-03-2432-271/+492
| | | | | | This PR adds support for `ref.null t` as a valid element segment item. The abbreviated format of `(elem ... func $f $g...)` is kept in both printing and binary emitting if all items are `ref.func`s. Public APIs aren't updated in this PR.
* [Wasm GC] Optimize br_on_* (#3719)Alon Zakai2021-03-241-2/+55
| | | | The type may prove the value is not null, and may also show it to be of the type we are casting to. In that case, we can simplify things.
* [Wasm GC] Fix canMakeZero on tuples (#3721)Alon Zakai2021-03-241-3/+11
|
* Equirecursive type canonicalization (#3717)Thomas Lively2021-03-231-352/+703
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Equirecursive type canonicalization Use Hopcroft's DFA minimization algorithm to properly canonicalize and deduplicate recursive types. Type canonicalization has two stages: 1. Shape canonicalization - The top-level structure of HeapTypes is used to split the declared HeapTypes into their initial partitions. - Hopcroft's algorithm refines the partitions such that all pairs of distinguishable types end up in different partitions. - A fresh HeapTypeInfo is created for each final partition. Each new HeapTypeInfo is linked to other new HeapTypeInfos to create a minimal type definition graph that defines the same types as the original graph. 2. Global canonicalization - Each new minimal HeapTypeInfo that does not have the same finite shape as an existing globally canonical HeapTypeInfo is moved to the global heap type store to become the new canonical HeapTypeInfo. - Each temporary Type referenced by the newly canonical HeapTypeInfos is replaced in-place with the equivalent canonical Type to avoid leaking temporary Types into the global stores.
* [Wasm GC] Add support for non-nullable types, all except for locals (#3710)Alon Zakai2021-03-2315-74/+136
| | | | | | | | | | | | | | | | | | | | | | After this PR we still do not support non-nullable locals. But we no longer turn all types into nullable upon load. In particular, we support non-nullable types on function parameters and struct fields, etc. This should be enough to experiment with optimizations in both binaryen and in VMs regarding non- nullability (since we expect that optimizing VMs can do well inside functions anyhow; it's non-nullability across calls and from data that the VM can't be expected to think about). Let is handled as before, by lowering it into gets and sets. In addition, we turn non-nullable locals into nullable ones, and add a ref.as_non_null on all their gets (to keep the type identical there). This is used not just for loading code with a let but also is needed after inlining. Most of the code changes here are removing FIXMEs for allowing non-nullable types. But there is also code to handle the issues mentioned above. Most of the test updates are removing extra nulls that we added before when we turned all types nullable. A few tests had actual issues, though, and also some new tests are added to cover the code changes here.
* Use the type in selectification in RemoveUnusedBrs (#3716)Alon Zakai2021-03-221-1/+1
| | | | | We have the if's type, and when replacing it with a select, can use that type. This could be more efficient. It also avoids a current crash after the removal of LUBs, but it's worth doing regardless of that.
* wasm-emscripten-finalize: Do not skip the start function body (#3714)Alon Zakai2021-03-222-4/+14
| | | | | | When we can skip function bodies, we still need to parse the start function for the pthreads case, see details in the comments. This still gives us 99% of the speedup as the start function is just 1 function and it's not that big, so with this we return to full speed after the reversion in #3705
* Fix a fuzz regression from #3669 (#3715)Alon Zakai2021-03-222-31/+33
| | | | | | | | | | | | | | | | | I'm not entirely sure how LUB removal made this noticeable, as it seems to be a pre-existing bug. However, somehow before #3669 it was not noticable - perhaps the finalize code worked around it. The bug is that RemoveUnusedBrs was moving code around and finalizing the parent before the child. The correct pattern is always to work from the children outwards, as otherwise the parent is trying to finalize itself based on non-finalized children. The fix is to just not finalize in the stealSlice method. The caller can do it after finishing any other work it has. As part of this refactoring, move stealSlice into the single pass that uses it; aside from that being more orderly, this method is really not a general-purpose tool, it is quite specific to what RemoveUnusedBrs does, and it might easily be used incorrectly elsewhere.
* Fixed reading 64-bit memories and output of globals (#3709)Wouter van Oortmerssen2021-03-192-4/+4
|
* Avoid warnings/errors on isTemp(*Type) being unused (#3707)Alon Zakai2021-03-191-1/+13
| | | | | It is a little "fun" to fake their uses because of the overloaded type. cppreference says that this is the way to do it, and I've found no other way than a C cast like this (std::function fails).
* Revert the effect of #3689 (#3705)Alon Zakai2021-03-181-2/+3
| | | | | | | | | | | | | That PR assumed that wasm-emscripten-finalize does not need to scan function bodies for metadata. But there is a case where it does, which is that EM_ASMs with pthreads do still require scanning of the code. So that approach is not valid. We could maybe disable the optimization just on pthreads, but I think major use cases need that. Also there is no simple way to disable it atm, we'd need changes on both emscripten and binaryen. Also that PR can no longer be reverted cleanly due to other changes. For all those reasons, this just disables the optimization so that users of tot are no longer broken, while we figure out how a valid way to optimize this use case.
* wasm-emscripten-finalize: Do not read the Names section when not writing ↵Alon Zakai2021-03-185-6/+33
| | | | | | | | | | | | | | | | | output (#3698) When not writing output we don't need debug info, as it is not relevant for our metadata. This saves loading and interning all the names, which takes several seconds on massive inputs. This is possible in principle in other tools, but this does not change anything in them for now. (We do use names internally in some nontrivial ways without opting in to it, so that would require further refactoring. Also the other tools almost always do write an output.) This is not 100% unobservable. If validation fails then the validation error would just contain the function index instead of the name from the Names section if there is one. However finalize does not validate atm so that would only matter if we change that later.
* [Wasm GC] Fix MergeBlocks on BrOn (#3702)Alon Zakai2021-03-181-25/+25
| | | | | | | | | | | The pass was only aware of Break and Switch. Refactor it to use the generic code, so that we can first handle Break, and then if anything remains, note a problem was found. The same path can handle a Switch which we handled before and also a BrOn etc. git diff is not that useful after the refactoring sadly, but basically this just moves the Break code and the Drop code, then adds the BranchUtils::operateOn stuff after them (and we switch to a unified visitor so that we get called for all expressions).
* Ignore missing CUs in DWARF rewriting (#3700)Alon Zakai2021-03-181-2/+8
| | | | | | | | | | | | | | | A recent change in LLVM causes it to sometimes end up with a thing with no parent. That is, a debug_line or a debug_loc that has no CU that refers to it. This is perhaps LLVM DCEing CUs, or something else that changed - not sure. But it seems like valid DWARF we should handle. This PR handles that in our code. Two things broke here. First, locs must be simply ignored when there is no CU. Second, lines are trickier as we used to compute their position by scanning them, and that list contained only ones with a CU. So we missed some and ended up with wrong offsets. To make things simpler and more robust, just track the position of each line table on itself. Fixes #3697
* Use stdbool boolean instead of int to represent boolean values in C API (#3670)Paulo Matos2021-03-172-93/+95
| | | Fixes #3664
* Skip function bodies in wasm-emscripten-finalize when we don't need them (#3689)Alon Zakai2021-03-175-4/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After sbc100 's work on EM_ASM and EM_JS they are now parsed from the wasm using exports etc. and so we no longer need to parse function bodies. As a result if we are not emitting a wasm from wasm-emscripten-finalize then all we are doing is scanning global structures like imports and exports and emitting metadata about them. And indeed we do not need to emit a wasm in some cases, specifically when not optimizing and when using WASM_BIGINT (to avoid needing to legalize). We had considering skipping wasm-emscripten-finalize entirely in that situation, and instead to parse the metadata from the wasm in python on the emscripten side. However sbc100 had the brilliant idea today to just skip function bodies. That is very simple to do - no need to write another parser for wasm, and also look at how simple this PR is - and also it will be faster to run wasm-emscripten-finalize in this mode than to run python. (With the only downside that the bytes of the wasm are loaded even if they aren't parsed; but almost certainly they are in the disk cache anyhow.) This PR implements that idea: when wasm-emscripten-finalize knows it will not write a wasm output, it notes "skip function bodies". The binary reader then skips the bodies and places unreachables there instead (so that the wasm still validates). There are no new tests here because this can't be tested - by design it is an unobservable optimization. (If we could notice the bodies have been skipped, we would not have skipped them.) This is also why no changes are needed on the emscripten side to benefit from this speedup. Basically when binaryen sees it will not need X, it skips parsing of X automatically. Benchmarking speed, it is as fast as you'd expect: the wasm-emscripten-finalize step is 15x faster on SQLite (1MB of wasm) and almost 50x faster on the biggest wasm I have on my drive (40MB of LLVM). (These numbers are on release builds, without debug info - debug into makes things slower, so the speedup is lower there, and will need further work.) Tested manually and also on wasm0 wasm2 other on emscripten.
* [NFC] Record isTemp and isSelfReferential on TypeInfos (#3695)Thomas Lively2021-03-161-76/+147
| | | | | | `isTemp` is used in new assertions that guard against leaking temporary types and heap types into the global stores and `isSelfReferential` replaces and external set of self-referential types. Both fields will additionally be used in upcoming PRs improving type canonicalization.
* Add missing fields in ModuleUtils::copyModule (#3692)Alon Zakai2021-03-161-0/+2
| | | We were missing type names and the features section.
* [Wasm GC] Validate static subtyping in rtt.sub (#3696)Alon Zakai2021-03-161-0/+3
| | | | Also add more spec tests, including one that verifies we validate rtt.sub and on a global location as fixed by #3694
* Validate code in global data structures (#3694)Alon Zakai2021-03-161-3/+14
| | | | | | This validation is almost never needed, but it starts to get interesting with GC, where a global initializer can be an rtt.sub which must be valid. No tests here as testing requires a further GC fix in a later PR.
* [Wasm GC] Optimize array.set stored values (#3690)Alon Zakai2021-03-161-0/+7
| | | Same as we already do for struct.set.
* Remove unused 'Module' param from Names::getValidName. NFC (#3691)Alon Zakai2021-03-161-14/+12
|
* Simplify fuzzer fixup code for names (#3688)Alon Zakai2021-03-151-33/+15
| | | Rather than use delegates.h, we have helpers for scope names.
* Remove old AsmConstWalker code (#3685)Sam Clegg2021-03-121-127/+9
|
* Fix fuzz issue with ElementSegment name collisions (#3674)Alon Zakai2021-03-122-12/+15
| | | | | Now that they have names they can collide. All the fuzzer wants is to ensure there is a segment to add to, so if there is one, do not add another.
* [Wasm GC] Avoid std::map<Type,..> in mapLocals (#3683)Alon Zakai2021-03-121-1/+1
| | | | | Works around #3682 With this, I can roundtrip a large real-world testcase.
* [Wasm GC] Optimize struct stores like stores to memory, ignore unneeded bits ↵Alon Zakai2021-03-123-23/+53
| | | | | | | (#3680) When storing to an i8, we can ignore any higher bits, etc. Adds a getByteSize utility to Field to make this convenient.
* Refactor OptimizeInstructions to use visit* methods. NFC (#3678)Alon Zakai2021-03-111-507/+550
| | | | | | | | | | | | | | | | Instead of a single big optimize() method we now use separate functions per instruction. This gives us smaller functions and less nesting in some cases, and avoids manually casting and checking etc. The reason this was not done originally is that this pass does repeated applications. That is, if optimize() changed something, it would run again on the result, perhaps further optimizing it. It did not need to run on the children, but just on the result itself, so it didn't just do another full walk, and so the simplest way was to just do a loop on optimize(). To replace that, this PR modifies replaceCurrent() which the methods now call to report that the current node can be replaced. There is some code in there now that keeps doing more processing while changes happen. It's not trivial code as it avoids recursion, but that slight complexity seems worthwhile in order to simplify the bulk of the (very large) pass.
* [Wasm GC] Avoid extremely large outputs in TypeNamePrinter (#3667)Alon Zakai2021-03-111-0/+22
|
* Remove LUB calculation (#3669)Thomas Lively2021-03-1110-279/+106
| | | | | | | | Since correct LUB calculation for recursive types is complicated, stop depending on LUBs throughout the code base. This also fixes a validation bug in which the validator required blocks to be typed with the LUB of all the branch types, when in fact any upper bound should have been valid. In addition to fixing that bug, this PR simplifies the code for break handling by not storing redundant information about the arity of types.
* Make unreachable a subtype of everything (#3673)Thomas Lively2021-03-113-110/+78
| | | | | | | Since in principle an unreachable expression can be used in any position. An exception to this rule is in OptimizeInstructions, which avoids replacing concrete expressions with unreachable expressions so that it doesn't need to refinalize any expressions. Notably, Type::getLeastUpperBound was already treating unreachable as the bottom type.
* [Wasm GC] Fix RTT type parsing (#3672)Alon Zakai2021-03-101-2/+2
| | | | | | This was missing from #3663 Fixes #3656
* Use uint32_t for Event Attribute in API (#3671)Paulo Matos2021-03-102-2/+2
|
* [Wasm GC] Properly handle "typeindex" in the binary format (#3663)Alon Zakai2021-03-093-25/+42
| | | | | | | | | We handled them as S63 instead of U32. That should be fine, as all U32 values fit in S63. But it is not strictly correct. The signed encoding may use an additional byte which is unnecessary, and there is an actual correctness issue where a U32 may be interpreted as a large negative S63 (because it sign extends a final bit that happens to be 1). May help #3656 but that testcase still does not pass even with this.