summaryrefslogtreecommitdiff
path: root/test/example
Commit message (Collapse)AuthorAgeFilesLines
* Preserve Function HeapTypes (#3952)Thomas Lively2021-06-305-10/+16
| | | | | | | | | When using nominal types, func.ref of two functions with identical signatures but different HeapTypes will yield different types. To preserve these semantics, Functions need to track their HeapTypes, not just their Signatures. This PR replaces the Signature field in Function with a HeapType field and adds new utility methods to make it almost as simple to update and query the function HeapType as it was to update and query the Function Signature.
* [EH] Make tag's attribute encoding detail (#3947)Heejin Ahn2021-06-211-1/+1
| | | | | | | | | This removes `attribute` field from `Tag` class, making the reserved and unused field known only to binary encoder and decoder. This also removes the `attribute` parameter from `makeTag` and `addTag` methods in wasm-builder.h, C API, and Binaryen JS API. Suggested in https://github.com/WebAssembly/binaryen/pull/3946#pullrequestreview-687756523.
* Remove (attr 0) from tag text format (#3946)Heejin Ahn2021-06-193-13/+13
| | | | | | | | This attribute is always 0 and reserved for future use. In Binayren's unofficial text format we were writing this field as `(attr 0)`, but we have recently come to the conclusion that this is not necessary. Relevant discussion: https://github.com/WebAssembly/exception-handling/pull/160#discussion_r653254680
* [EH] Replace event with tag (#3937)Heejin Ahn2021-06-184-33/+32
| | | | | | | | | | | We recently decided to change 'event' to 'tag', and to 'event section' to 'tag section', out of the rationale that the section contains a generalized tag that references a type, which may be used for something other than exceptions, and the name 'event' can be confusing in the web context. See - https://github.com/WebAssembly/exception-handling/issues/159#issuecomment-857910130 - https://github.com/WebAssembly/exception-handling/pull/161
* [Wasm GC] Add experimental support for non-nullable locals (#3932)Alon Zakai2021-06-151-1/+1
| | | | | | | | | | | | | | This adds a new feature flag, GCNNLocals that enables support for non-nullable locals. No validation is applied to check that they are actually assigned before their use yet - this just allows experimentation to begin. This feature is not enabled by default even with -all. If we enabled it, then it would take effect in most of our tests and likely confuse current users as well. Instead, the flag must be opted in explicitly using --enable-gc-nn-locals. That is, this is an experimental feature flag, and as such must be explicitly enabled. (Once the spec stabilizes, we will remove the feature anyhow when we implement the final status of non-nullability. )
* [wasm-split] Add an option to emit a placeholder map (#3931)Thomas Lively2021-06-121-2/+2
| | | | | | The new instruction emits a file containing a map between placeholder index and the name of the split out function that placeholder is replacing in the table. This map is intended to be useful for debugging, as discussed in https://github.com/emscripten-core/emscripten/issues/14330.
* Nominal subtyping (#3927)Thomas Lively2021-06-112-0/+145
| | | | | | | | | | | | | Add methods to the TypeBuilder interface to declare subtyping relationships between the built types. These relationships are validated and recorded globally as part of type building. If the relationships are not valid, a fatal error is produced. In the future, it would be better to report the error to the TypeBuilder client code, but this behavior is sufficient for now. Also updates SubTyper and TypeBounder to be aware of nominal mode so that subtyping and LUBs are correctly calculated. Tests of the failing behavior will be added in a future PR that exposes this functionality to the command line, since the current `example` testing infrastructure cannot handle testing fatal errors.
* Initial nominal typing support (#3919)Thomas Lively2021-06-082-0/+358
| | | | | | | | | | | | | | | | | | | | In nominal mode, HeapType constructors besides the Signature constructor always produce fresh types distinct from any previously created types. The HeapType constructor that takes a Signature maintains its previous behavior of constructing a canonical representative of the given signature because it is used frequently throughout the code base and never in a situation that would benefit from creating a fresh type. It is left as future work to clean up this discrepancy between the Signature HeapType constructor and other HeapType constructors. TypeBuilder skips shape and global canonicalization in nominal mode and always creates a fresh type for each of its entries. For this to work without any canonicalization, the TypeBuilder allocates temporary types on the global Type store and does not support building basic HeapTypes in nominal mode. The new mode is not available in any of the Binaryen tools yet because it is still missing critical functionality like the ability to declare subtyping relations and correctly calculate LUBs. This functionality will be implemented in future PRs.
* [OptimizeInstructions] Handle post-MVP sign extended operations (#3910)Max Graey2021-06-031-0/+50
| | | fixes part of #3906
* [wasm-split] Minimize names of newly created exports (#3905)Thomas Lively2021-06-012-0/+116
| | | | | | | | | wasm-split would previously use internal function names to create the external names of the functions that are newly exported from the primary module to be imported into the secondary module. When the input module contains full function names (as is commonly the case when emitting symbol maps), this caused the function names to be preserved as the export names, even when names are otherwise being stripped. To save on code size and properly anonymize functions, generate minimal export names when debuginfo is disabled instead.
* Remove Type ordering (#3793)Thomas Lively2021-05-1811-14/+14
| | | | | | | | | As found in #3682, the current implementation of type ordering is not correct, and although the immediate issue would be easy to fix, I don't think the current intended comparison algorithm is correct in the first place. Rather than try to switch to using a correct algorithm (which I am not sure I know how to implement, although I have an idea) this PR removes Type ordering entirely. In places that used Type ordering with std::set or std::map because they require deterministic iteration order, this PR uses InsertOrdered{Set,Map} instead.
* Fix typo in function name: BinayenElementSegmentIsPassive (#3862)Paulo Matos2021-05-061-1/+1
| | | Becomes BinaryenElementSegmentIsPassive
* Add LocalGraph::equivalent (#3848)Alon Zakai2021-04-292-0/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This compares two local.gets and checks whether we are sure they are equivalent, that is, they contain the same value. This does not solve the general problem, but uses the existing info to get a positive answer for the common case where two gets only receive values by a single set, like (local.set $x ..) (a use.. (local.get $x)) (another use.. (local.get $x)) If they only receive values from the same single set, then we know it must dominate them. The only risk is that the set is "in between" the gets, that is, that the set occurs after one get and before the other. That can happen in a loop in theory, (loop $loop (use (local.get $x)) (local.set $x ..some new value each iteration..) (use (local.get $x)) (br_if $loop ..) ) Both of those gets receive a value from the set, and they may be different values, from different loop iterations. But as mentioned in the source code, this is not a problem since wasm always has a zero-initialization value, and so the first local.get in that loop would have another set from which it can receive a value, the function entry. (The only way to avoid that is for this entire code to be unreachable, in which case nothing matters.) This will be useful in dead store elimination, which has to use this to reason about references and pointers in order to be able to do anything useful with GC and memory.
* UniqueDeferredQueue improvements (#3847)Alon Zakai2021-04-291-0/+38
| | | | | | | | Add clear(). Add UniqueNonrepeatingDeferredQueue which also has the property that it never repeats values in the output. Also add unit tests.
* Update test expectations after colliding landings (#3827)Alon Zakai2021-04-201-1/+1
|
* Fix element segment ordering in Print (#3818)Abbas Mashayekh2021-04-202-12/+12
| | | | | | | | | | | We used to print active element segments right after corresponding tables, and passive segments came after those. We didn't print internal segment names, and empty segments weren't being printed at all. This meant that there was no way for instructions to refer to those table segments after round tripping. This will fix those issues by printing segments in the order they were defined, including segment names when necessary and not omitting empty segments anymore.
* Minor wasm-split improvements (#3825)Thomas Lively2021-04-202-0/+171
| | | | | | | | | | | - Support functions appearing more than once in the table. It turns out we were assuming and asserting that functions would appear at most once, but we weren't making use of that assumption in any way. - Make TableSlotManager::getSlot take a function Name rather than a RefFunc expression to avoid allocating and leaking unnecessary expressions. - Add and use a Builder interface for building TableElementSegments to make them more similar to other module-level items.
* Rename SIMD extending load instructions (#3798)Daniel Wirtz2021-04-121-32/+14
| | | | | | | | | Renames the SIMD instructions * LoadExtSVec8x8ToVecI16x8 -> Load8x8SVec128 * LoadExtUVec8x8ToVecI16x8 -> Load8x8UVec128 * LoadExtSVec16x4ToVecI32x4 -> Load16x4SVec128 * LoadExtUVec16x4ToVecI32x4 -> Load16x4UVec128 * LoadExtSVec32x2ToVecI64x2 -> Load32x2SVec128 * LoadExtUVec32x2ToVecI64x2 -> Load32x2UVec128
* Rename various SIMD load instructions (#3795)Daniel Wirtz2021-04-111-6/+6
| | | | | | | | | Renames the SIMD instructions * LoadSplatVec8x16 -> Load8SplatVec128 * LoadSplatVec16x8 -> Load16SplatVec128 * LoadSplatVec32x4 -> Load32SplatVec128 * LoadSplatVec64x2 -> Load64SplatVec128 * Load32Zero -> Load32ZeroVec128 * Load64Zero -> Load64ZeroVec128
* Add v128.load/storeN_lane SIMD instructions to C/JS API (#3784)Daniel Wirtz2021-04-082-0/+98
| | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * Load8LaneVec128 (was LoadLaneVec8x16) * Load16LaneVec128 (was LoadLaneVec16x8) * Load32LaneVec128 (was LoadLaneVec32x4) * Load64LaneVec128 (was LoadLaneVec64x2) * Store8LaneVec128 (was StoreLaneVec8x16) * Store16LaneVec128 (was StoreLaneVec16x8) * Store32LaneVec128 (was StoreLaneVec32x4) * Store64LaneVec128 (was StoreLaneVec64x2)
* Add v128.load32/64_zero SIMD instructions to C/JS API (#3783)Daniel Wirtz2021-04-082-0/+20
| | | | | Adds C/JS APIs for the SIMD instructions * Load32Zero * Load64Zero
* Add new SIMD multiplication instructions to C/JS API (#3782)Daniel Wirtz2021-04-082-0/+91
| | | | | | | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * Q15MulrSatSVecI16x8 * ExtMulLowSVecI16x8 * ExtMulHighSVecI16x8 * ExtMulLowUVecI16x8 * ExtMulHighUVecI16x8 * ExtMulLowSVecI32x4 * ExtMulHighSVecI32x4 * ExtMulLowUVecI32x4 * ExtMulHighUVecI32x4 * ExtMulLowSVecI64x2 * ExtMulHighSVecI64x2 * ExtMulLowUVecI64x2 * ExtMulHighUVecI64x2
* Add new SIMD conversion instructions to C/JS API (#3781)Daniel Wirtz2021-04-082-0/+36
| | | | | | | | | Adds C/JS APIs for the SIMD instructions * ConvertLowSVecI32x4ToVecF64x2 * ConvertLowUVecI32x4ToVecF64x2 * TruncSatZeroSVecF64x2ToVecI32x4 * TruncSatZeroUVecF64x2ToVecI32x4 * DemoteZeroVecF64x2ToVecF32x4 * PromoteLowVecF32x4ToVecF64x2
* Add iNxM.extadd_pairwise_* SIMD instructions to C/JS API (#3780)Daniel Wirtz2021-04-082-0/+24
| | | | | | | Adds C/JS APIs for the SIMD instructions * ExtAddPairwiseSVecI8x16ToI16x8 * ExtAddPairwiseUVecI8x16ToI16x8 * ExtAddPairwiseSVecI16x8ToI32x4 * ExtAddPairwiseUVecI16x8ToI32x4
* Add i64x2.extend_low/high_* SIMD instructions to C/JS API (#3778)Daniel Wirtz2021-04-072-0/+24
| | | | | | | Adds C/JS APIs for the SIMD instructions * ExtendLowSVecI32x4ToVecI64x2 * ExtendHighSVecI32x4ToVecI64x2 * ExtendLowUVecI32x4ToVecI64x2 * ExtendHighUVecI32x4ToVecI64x2
* Add various SIMD instructions to C/JS API (#3777)Daniel Wirtz2021-04-072-0/+66
| | | | | | | | | | | | | Adds C/JS APIs for the SIMD instructions * PopcntVecI8x16 * AbsVecI64x2 * AllTrueVecI64x2 * BitmaskVecI64x2 * EqVecI64x2 * NeVecI64x2 * LtSVecI64x2 * GtSVecI64x2 * LeSVecI64x2 * GeSVecI64x2
* Update SIMD names and opcodes (#3771)Thomas Lively2021-04-052-115/+40
| | | | Also removes experimental SIMD instructions that were not included in the final spec proposal.
* Reorder global definitions in Print pass (#3770)Abbas Mashayekh2021-04-022-7/+7
| | | | This is needed to make sure globals are printed before element segments, where `global.get` can appear both as offset and an expression.
* Fix type canonicalization bugs (#3761)Thomas Lively2021-04-012-4/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When canonical heap types were already present in the global store, for example during the --roundtrip pass, type canonicalization was not working correctly. The issue was that the GlobalCanonicalizer was replacing temporary HeapTypes with their canonical equivalents one type at a time, but the act of replacing a temporary HeapType use with a canonical HeapType use could change the shape of later HeapTypes, preventing them from being correctly matched with their canonical counterparts. This PR fixes that problem by computing all the temporary-to-canonical heap type replacements before executing them. To avoid a similar problem when canonicalizing Types, one solution would have been to pre-calculate the replacements before executing them just like with the HeapTypes, but that would have required either complex bookkeeping or moving temporary Types into the global store when they are first canonicalized. That would have been complicated because unlike for temporary HeapTypeInfos, the unique_pointer to temporary TypeInfos is not readily available. This PR instead switches back to using pointer-identity based equality and hashing for TypeInfos, which works because we only ever canonicalize Types with canonical children. This change should be a nice performance improvement as well. Another bug this PR fixes is that shape hashing and equality considered BasicKind HeapTypes to be different from their corresponding BasicHeapTypes, which meant that canonicalization could produce different types for the same type definition depending on whether the definition used a TypeBuilder or not. The fix is to pre-canonicalize BasicHeapTypes (and Types that have them as children) during shape hashing and equality. The same mechanism is also used to simplify Store's canonicalization. Fixes #3736.
* Remove passive keyword from data segment parser (#3757)Abbas Mashayekh2021-03-301-1/+1
| | | | | | | | The passive keyword has been removed from spec's text format, and now any data segment that doesn't have an offset is considered as passive. This PR remove that from both parser and the Print pass, plus all tests that used that syntax. Fixes #2339
* LUBs (#3731)Thomas Lively2021-03-295-19/+353
| | | | | | | This is a partial revert of #3669, which removed the old implementation of Type::getLeastUpperBound that did not correctly handle recursive types. The new implementation in this PR uses a TypeBuilder to construct LUBs and for recursive types, it returns a temporary HeapType that has not yet been fully constructed to break what would otherwise be infinite recursions.
* Scan module-level code in necessary places (#3744)Alon Zakai2021-03-291-3/+3
| | | | | | | | | | | | | | | | | | Several old passes like DeadArgumentElimination and DuplicateFunctionElimination need to look at all ref.funcs, and they scanned functions for that, but that is not enough as such an instruction might appear in a global initializer. To fix this, add a walkModuleCode method. walkModuleCode is useful when doing the pattern of creating a function-parallel pass to scan functions quickly, but we also want to do the same scanning of code at the module level. This allows doing so in a single line. (It is also possible to just do walk() on the entire module, which will find all code, but that is not function-parallel. Perhaps we should have a walkParallel() option to simplify this further in a followup, and that would call walkModuleCode afterwards etc.) Also add some missing validation and comments in the validator about issues that I noticed in relation to the new testcases here.
* Refactor TypeBuilder (#3728)Thomas Lively2021-03-242-47/+75
| | | | | | | | | | 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.
* Equirecursive type canonicalization (#3717)Thomas Lively2021-03-232-19/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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] Fix MergeBlocks on BrOn (#3702)Alon Zakai2021-03-183-6/+6
| | | | | | | | | | | 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).
* Use stdbool boolean instead of int to represent boolean values in C API (#3670)Paulo Matos2021-03-173-6/+6
| | | Fixes #3664
* [Wasm GC] Optimize struct stores like stores to memory, ignore unneeded bits ↵Alon Zakai2021-03-121-0/+13
| | | | | | | (#3680) When storing to an i8, we can ignore any higher bits, etc. Adds a getByteSize utility to Field to make this convenient.
* Remove LUB calculation (#3669)Thomas Lively2021-03-112-114/+0
| | | | | | | | 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.
* [reference-types] Support passive elem segments (#3572)Abbas Mashayekh2021-03-054-30/+58
| | | | | | | | | | | 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.
* [Wasm GC] Allow subtyping in arguments to struct.get etc. Fixes #3636 (#3644)Alon Zakai2021-03-021-7/+21
| | | | | | | | | 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
* Add C and JS API bindings for ref.as_* (#3628)Daniel Wirtz2021-03-012-0/+42
|
* Use enum instead of bool for StackSignature kind (#3625)Thomas Lively2021-02-261-148/+187
| | | | | 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-262-0/+32
| | | | | 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.
* [Wasm GC] Add array.wast and validator fixes for it (#3622)Alon Zakai2021-02-261-1/+2
|
* Slightly improve table C API (#3604)Daniel Wirtz2021-02-262-2/+8
| | | Uses BinaryenIndex instead of int to mirror parameter types in table construction, and adds setters for name, initial and max.
* Add TypedFunctionReferences feature to C and JS API (#3603)Daniel Wirtz2021-02-262-0/+2
|
* Support building recursive types (#3602)Thomas Lively2021-02-241-22/+71
| | | | | | | | | | | | | | | | | | | Updates TypeBuilder to support recursive types. Recursive types are particularly problematic because under the current scheme it is necessary to canonicalize the uses of a type's immediate children before canonicalizing the type itself to avoid leaking non-canonical, temporary types out of the TypeBuilder and into the global type stores. In the case of recursive types, it is not possible to do this because of their cyclic nature. In principle this could be overcome by hashing recursive types based on their structure rather than their contents, but that would be complicated. Instead, this PR takes the shortcut of not canonicalizing self-referential HeapTypes at all, but rather moving them out of the TypeBuilder and into the global type store without changing their addresses or needing to update any of their use sites. This breaks all cycles and makes it possible to canonicalize the other types correctly. Note that this PR only adds support for building recursive types. Doing almost anything with the types, such as printing, comparing, or emitting them will certainly lead to infinite recursions. A follow up PR will update all these operations to work correctly with recursive types.
* Fix hashing of a use of a name without the context/target for it (#3601)Alon Zakai2021-02-241-0/+10
| | | | | | | | | | Before this we would assert on hashing e.g. (br $x) by itself, without the context so we recognized the name $x. Somehow that was not an issue until delegate, we just happened to not hash such things. I believe I remember that @aheejin noticed this issue before, but given we didn't have a testcase, we deferred fixing it - now is the time, I guess, as with delegate it is easy to get e.g. CodeFolding to hash a Try with a delegate. Issue found by emscripten-core/emscripten#13485
* Fix TypeBuilder canonicalization (#3578)Thomas Lively2021-02-181-4/+7
| | | | | | | | | | | | | | | | | | | | | | When types or heap types were used multiple times in a TypeBuilder instance, it was possible for the canonicalization algorithm to canonicalize a parent type before canonicalizing all of its component child types, leaking the temporary types into globally interned types. This bug led to incorrect canonicalization results and use-after free bugs. The cause of the bug was that types were canonicalized in the reverse of the order that they were visited in, but children were visited after the first occurrence of their parents, not necessarily after the last occurrence of their parents. One fix could have been to remove the logic that prevented types from being visited multiple times so that children would always be visited after their parents. That simple fix, however, would not scale gracefully to handle recursive types because it would require some way to detect recursions without accidentally reintroducing these bugs. This PR implements a more robust solution: topologically sorting the traversed types to ensure that children are canonicalized before their parents. This solution will be trivial to adapt for recursive types because recursive types are trivial to detect from the reachability graph used to perform the topological sort.
* [EH] Update C and binaryen.js API for delegate (#3565)Heejin Ahn2021-02-132-2/+46
| | | | | | | | | | This updates C and binaryen.js API to match the new `Try` structure to support `delegate`, added in #3561. Now `try` can take a name (which can be null) like a block, and also has an additional `delegateTarget` field argument which should only be used for try-delegate and otherwise null. This also adds several more variant of `makeTry` methods in wasm-builder. Some are for making try-delegate and some are for try-catch(_all).