summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* 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-126-149/+16
|
* Regenerate lld tests (#3684)Sam Clegg2021-03-1226-183/+214
| | | | | | | | | | | This change as automatically generated by: $ ./scripts/test/generate_lld_tests.py $ ./auto_update_tests.py --binaryen-bin=../binaryen-out/bin lld The changes here are mostly due to: - llvm now emits names for globals and segments - emscripten now packs EM_ASM consts into a single contiguous segment
* 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-125-23/+108
| | | | | | | (#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
|
* [Wasm GC] Add more passing spec tests. (#3677)Alon Zakai2021-03-114-0/+291
|
* Remove LUB calculation (#3669)Thomas Lively2021-03-1112-393/+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-114-113/+79
| | | | | | | 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.
* [Wasm GC] Allow set values to be subtypes (#3665)Alon Zakai2021-03-095-15/+62
|
* Reducer: Improve reduction of function bodies and the factor for text ↵Alon Zakai2021-03-091-6/+21
| | | | | | | | | | | | | | | | | reduction (#3668) The old code tried to call visitExpression from outside of a walk on the wasm, which works except that replaceCurrent does nothing as there is no current node. Perhaps it should assert if called outside of a walk? Might be an expensive check, but once we have no-assert builds maybe that's worthwhile. Replace that with a working check during the walk. Also limit the frequency of it (do it 1000x more often than a normal reduction, but not all the time like we used to). Also optimize the starting factor for text reduction. Text files are much larger for the same amount of IR, so the initial factor was far too high and inefficient.
* Fixed .debug_loc parsing for wasm64 files (#3660)Wouter van Oortmerssen2021-03-082-5/+11
| | | | | The address size was hard-coded to 4, it now gets this information from .debug_info. This required changing the parsing order. Also made failure to parse .debug_loc fail the program, as before this error was easy to ignore.
* [reference-types] Support passive elem segments (#3572)Abbas Mashayekh2021-03-0554-816/+1219
| | | | | | | | | | | Passive element segments do not belong to any table, so the link between Table and elem needs to be weaker; i.e. an elem may have a table in case of active segments, or simply be a collection of function references in case of passive/declarative segments. This PR takes Table::Segment out and turns it into a first class module element just like tables and functions. It also implements early support for parsing, printing, encoding and decoding passive/declarative elem segments.
* [effects] Record reads and writes of the GC heap (#3657)Thomas Lively2021-03-052-0/+63
| | | | | | | | | | | Just as reads and writes to memory can interfere with each other, reads and writes of GC objects can interfere with each other. This PR adds new `readsHeap` and `writesHeap` fields to EffectAnalyzer to account for this interference. Note that memory accesses can never alias with GC heap accesses, so they are considered separately. Similarly, it would be possible to prove that different GC heap accesses never interfere with each other based on the accessed types, but that's left to future work. Fixes #3655.
* [Wasm GC] Fix cost.h on array.new_default (#3658)Alon Zakai2021-03-053-1/+38
|
* Fix binary writing of local name indexes (#3649)Alon Zakai2021-03-0414-223/+339
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When writing a binary, we take the local indexes in the IR and turn them into the format in the binary, which clumps them by type. When writing the names section we should be aware of that ordering, but we never were, as noticed in #3499 This fixes that by saving the mapping of locals when we are emitting the name section, then using it when emitting the local names. This also fixes the order of the types themselves as part of the refactoring. We used to depend on the ordering of types to decide which to emit first, but that isn't good for at least two reasons. First, it hits #3648 - that order is not fully defined for recursive types. Also, it's not good for code size - we've ordered the locals in a way we think is best already (ReorderLocals pass). This PR makes us pick an order of types based on that, as much as possible, that is, when we see a type for the first time we append it to a list whose order we use. Test changes: Some are just because we use a different order than before, as in atomics64. But some are actual fixes, e.g. in heap-types where we now have (local $tv (ref null $vector)) which is indeed right - v there is for vector, and likewise m for matrix etc. - we just had wrong names before. Another example, we now have (local $local_externref externref) whereas before the name was funcref, and which was wrong... seems like the incorrectness was more common on reference types and GC types, which is why this was not noticed before. Fixes #3499 Makes part of #3648 moot.
* Add a CMake option to install only the tools (#3654)Derek Schuff2021-03-041-6/+9
| | | | | | | This option will avoid installing the static library and headers, for distributions that want to be as small as possible, and don't need to support development with libbinaryen (such as emsdk). It still installs the dynamic library since that's needed by the tools.
* Emit "elem declare" for functions that need it (#3653)Alon Zakai2021-03-0424-4/+183
| | | | | | | This adds support for reading (elem declare func $foo .. in the text and binary formats. We can simply ignore it: we don't need to represent it in IR, rather we find what needs to be declared when writing. That part takes a little more work, for which this adds a shared helper function.
* Fix TypeComparator to satisfy C++'s Compare requirement (#3650)Thomas Lively2021-03-043-8/+37
| | | | | | | | | | | | | | The comparison implemented by TypeComparator was not previously antisymmetric because it held that both A < B and B < A when A and B were structurally identical but nominally distinct recursive types. This meant that it did not satisfy the conditions of C++'s "Compare" requirement, which meant that std::set did not operate correctly, as discovered in #3648. The PR fixes the problem by having making A < B be false (and vice versa), making type comparisons properly antisymmetric. As a drive by, also switches to using std::stable_sort in collectHeapTypes to make the order of the type section completely deterministic accross platforms. Fixes #3648.
* Stop emitting features section in fuzzer (#3652)Alon Zakai2021-03-041-1/+1
|
* Make the reduction script more robust, and document text reduction (#3640)Alon Zakai2021-03-031-5/+17
| | | | | The check for a valid wasm file must be different if the wasm has a feature section or not, so just try both ways, with --detect-features and --all-features. If the wasm is valid, at least one will work.
* [Wasm GC] Parse text field names even of types that end up canonicalized ↵Alon Zakai2021-03-036-16/+46
| | | | | | | together (#3647) Names of structurally identical types end up "collapsed" together after the types are canonicalized, but with this PR we can properly read content that has structurally identical types with different names.
* [Wasm Exceptions] Fix a handwritten exceptions test (#3639)Alon Zakai2021-03-032-6/+2
| | | catch_all should not have a pop.
* Remove PostAssemblyScript passes (#3643)Daniel Wirtz2021-03-039-1354/+7
|
* Release 100 (#3645)Sam Clegg2021-03-022-1/+4
| | | Fixes: #3459
* ci: build alpine linux to match what the release builder does (#3642)Sam Clegg2021-03-022-0/+39
| | | | | | Also fix the underlying issue which was that `lit` was not being correctly installed via pip3. See #3459
* [Wasm GC] ref.cast and ref.test should have zero immediates (#3641)Alon Zakai2021-03-028-40/+30
| | | This updates them to be correct in the current spec and prototype v3.
* [Wasm GC] Allow subtyping in arguments to struct.get etc. Fixes #3636 (#3644)Alon Zakai2021-03-027-12/+45
| | | | | | | | | Note that Binaryen "canonicalizes" the type, so in the test output here we end up with $grandchild twice. This is a consequence of us not storing the heap type as an extra field. I can't think of a downside to this canonicalization, aside from losing perfect roundtripping, but I think that's a worthwhile tradeoff for efficiency as we've been thinking so far. Fixes #3636
* Remove duplicate assertion (#3638)Alon Zakai2021-03-021-1/+0
|
* [Wasm GC] Add Names section support for field names (#3589)Alon Zakai2021-03-014-7/+62
| | | | | | | | | | Adds support for GC struct fields in the binary format, implementing WebAssembly/gc#193 No extra tests needed, see the .fromBinary output which shows this working. This also has a minor fix in the s-parser, we should not always add a name to the map of index=>name - only if it exists. Without that fix, the binary emitter would write out null strings.
* [Wasm GC] Add test/spec/br_on_null.wast and validation fixes for it (#3623)Alon Zakai2021-03-016-28/+118
| | | | | | This adds ValidationBuilder which can allow sharing of builder code that also validates, between the text and binary parsers. In general we share that code in the validator, but the validator can only run once IR exists, and in some cases we can't even emit valid IR structure at all.
* Fix DeNaN pass to handle existing colliding names (#3631)Alon Zakai2021-03-013-8/+86
|
* Add C and JS API bindings for ref.as_* (#3628)Daniel Wirtz2021-03-017-0/+188
|
* Refactor code out of parsing.h NFC. (#3635)Alon Zakai2021-03-014-314/+356
| | | | Most of it goes in a new parsing.cpp. One method was only used in the s-expression's parser, and has been moved there.
* [Wasm Exceptions] Fix/work around delegate issues in Inlining pass (#3633)Alon Zakai2021-03-014-0/+74
| | | | | | | | | | 1. Ignore the fake delegate target in the unique name mapper. The mapper is run after inlining, so this fixes inlining into a function that has a delegate to the caller. 2. Do not inline a function with a delegate. We should support this eventually, but for now I think this is good enough. After this Inlining should be safe to run on exceptions code.
* [Wasm Exceptions] Properly ensure unique Try labels after an inlining (#3632)Alon Zakai2021-03-014-27/+68
| | | | | | | | | The old code here just referred to Block and Loop. Refactor it to use the generic helper code that also handles Try. Also add validation of Try names in the validator. The testcase here would have $label appear twice before this fix. After the fix there is $label0 for one of them.
* Allow empty body within catch block (#3630)Heejin Ahn2021-03-015-18/+52
| | | | | | | | Previously we assumed catch body's size should be at least 3: `catch` keyword, event name, and body. But catch's body can be empty when the event's type is none. This PR fixes the bug and allows empty catch bodies to be parsed correctly. Fixes #3629.
* Consider self-referential HeapTypes to be canonical (#3626)Thomas Lively2021-02-282-21/+13
| | | | | | | | | | | | | | This PR makes the TypeBuilder move self-referential HeapTypes to global HeapType store so that they are considered canonical. This means that when a HeapType is constructed with an identical definition, it will be equivalent to the original HeapType constructed by the TypeBuilder, but it does _not_ mean that self-referential HeapTypes are deduplicated. This fixes a bug in which two versions of each self-referential function signature were emitted. Before this PR, the global HeapType store was not aware of the original self-referential HeapTypes. When the function signatures were used to construct HeapTypes during type collection, new HeapTypes were allocated and emitted in addition to the original HeapTypes. Now the global HeapType store returns the original HeapTypes, so the extra HeapType is never allocated.
* Use enum instead of bool for StackSignature kind (#3625)Thomas Lively2021-02-264-203/+251
| | | | | As a readability improvement, use an enum with `Polymorphic` and `Fixed` variants to represent the polymorphic behavior of StackSignatures rather than a `bool uneachable`.
* Support printing recursive types (#3624)Thomas Lively2021-02-265-240/+285
| | | | | Also fixes a few locations in Print.cpp where types were being printed directly rather than going through the s-expression type printer and removes vestigial wrapper types that were no longer used.
* Remove unneeded static_assert on number of Names in hashing (#3606)Alon Zakai2021-02-261-2/+0
| | | | | | The assertion is not really needed. Wasm64 will need changes to support more than 2^32 names, in theory, but (1) wasm64 is just memory64 atm, and (2) we'd need to add a general option for Index to be larger than 32 bits in general, so there is nothing specific to the hashing code here.
* [Wasm GC] Add array.wast and validator fixes for it (#3622)Alon Zakai2021-02-264-2/+154
|
* Update clang-tidy-diff.sh for GH Actions (#3619)Thomas Lively2021-02-261-10/+3
|
* Use Tarjan's SCC alg. to find self-referential types (#3621)Thomas Lively2021-02-261-30/+90
| | | | | | | | | | | | | | | | | Previously we computed the fixed point of the parent-child relation to identify self-referential HeapTypes in the TypeBuilder canonicalizer. That algorithm was O(|V|^3) in the worst case and took over five seconds to find the self-referential HeapTypes in an example program with just 1134 HeapTypes, probably due to high allocation traffic from the std::unordered_map and std::unordered_sets used to implement the parent-child graph's adjacency list. This PR replaces that algorithm with Tarjan's strongly connected component algorithm, which runs in O(|V|+|E|) and finds the self-referential HeapTypes in the mentioned example program in under 30 ms. All strongly connected components of more than one element in the HeapType parent-child graph correspond to sets of mutually recursive HeapTypes that are therefore self-referential. The only other self-referential HeapTypes are those that are not mutually recursive with any other HeapTypes, but these are trivial to find because they must be their own direct children.
* Slightly improve table C API (#3604)Daniel Wirtz2021-02-264-6/+36
| | | Uses BinaryenIndex instead of int to mirror parameter types in table construction, and adds setters for name, initial and max.