summaryrefslogtreecommitdiff
path: root/test/example
Commit message (Collapse)AuthorAgeFilesLines
* Make `TypeBuilder::build()` fallible (#4474)Thomas Lively2022-01-252-26/+26
| | | | | | | | | | | It is possible for type building to fail, for example if the declared nominal supertypes form a cycle or are structurally invalid. Previously we would report a fatal error and kill the program from inside `TypeBuilder::build()` in these situations, but this handles errors at the wrong layer of the code base and is inconvenient for testing the error cases. In preparation for testing the new error cases introduced by isorecursive typing, make type building fallible and add new tests for existing error cases. Also fix supertype cycle detection, which it turns out did not work correctly.
* Remove unused `isNominal` field on HeapTypeInfo (#4465)Thomas Lively2022-01-202-557/+0
| | | | | | | | This field was originally added with the goal of allowing types from multiple type systems to coexist by determining the type system on a per-type level rather than globally. This goal was never fully achieved and the `isNominal` field is not used outside of tests. Now that we are working on implementing the hybrid isorecursive system, it does not look like having types from multiple systems coexist will be useful in the near term, so clean up this tech debt.
* Introduce gtest (#4466)Thomas Lively2022-01-202-109/+0
| | | | | | | | | | | | | | | | | | | | | | | | Add gtest as a git submodule in third_party and integrate it into the build the same way WABT does. Adds a new executable, `binaryen-unittests`, to execute `gtest_main`. As a nontrivial example test, port one of the `TypeBuilder` tests from example/ to gtest/. Using gtest has a number of advantages over the current example tests: - Tests are compiled and linked at build time rather than runtime, surfacing errors earlier and speeding up test execution. - Tests are all built into a single binary, reducing overall link time and further reducing test overhead. - Tests are built from the same CMake project as the rest of Binaryen, so compiler settings (e.g. sanitizers) are applied uniformly rather than having to be separately set via the COMPILER_FLAGS environment variable. - Using the industry-standard gtest rather than our own script reduces our maintenance burden. Using gtest will lower the barrier to writing C++ tests and will hopefully lead to us having more proper unit tests.
* LiteralList => Literals (#4451)Alon Zakai2022-01-131-5/+16
| | | | | | | LiteralList overlaps with Literals, but is less efficient as it is not a SmallVector. Add reserve/capacity methods to SmallVector which are now necessary to compile.
* Do not track effects of immutable things (#4376)Alon Zakai2021-12-081-1/+0
| | | | We don't use those effects now in any way, and if we need them some day we can add them back. For now they just add overhead and complexity.
* Allow building basic HeapTypes in nominal mode (#4346)Thomas Lively2021-11-194-24/+83
| | | | | | | | | | | | | | | | As we work toward allowing nominal and structural types to coexist, any difference in how they can be built or used will be an inconvenient footgun that we will have to work around. In the spirit of reducing the differences between the type systems, allow TypeBuilder to construct basic HeapTypes in nominal mode just as it can in equirecursive mode. Although this change is a net increase in code complexity for not much benefit (wasm-opt never needs to build basic HeapTypes), it is also an incremental step toward getting rid of separate type system modes, so I expect it to simplify other PRs in the near future. This change also uncovered a bug in how the type fuzzer generated subtypes of basic HeapTypes. The generated subtypes did not necessarily have the intended `Kind`, which caused failures in nominal subtype validation in the fuzzer.
* Add table.grow operation (#4245)Max Graey2021-10-182-0/+11
|
* [Wasm GC] Take advantage of immutable struct fields in effects.h (#4240)Alon Zakai2021-10-131-1/+2
| | | | | | This is the easy part of using immutability more: Just note immutable fields as such when we read from them, and then a write to a struct does not interfere with such reads. That is, only a read from a mutable field can notice the effect of a write.
* Fix function name `BinaryenTableSizeSetTable` (#4230)Paulo Matos2021-10-121-1/+5
| | | | | `BinaryenTableSizeSetTable` was being declared in the header correctly, but defined as `BinaryenTableSetSizeTable`. Add test for `BinaryenTableSizeGetTable` and `BinaryenTableSizeSetTable`.
* Add table.size operation (#4224)Max Graey2021-10-082-0/+3
|
* Add table.set operation (#4215)Max Graey2021-10-072-0/+21
|
* Implement standalone nominal types (#4201)Thomas Lively2021-10-052-0/+527
| | | | | | | | These new nominal types do not depend on the global type sytem being changed with the --nominal flag. Instead, they can coexist with the existing equirecursive structural types, as required in the new milestone 4 spec. This PR implements subtyping, upper bounding, canonicalizing, and other type operations but using the new types in the parsers and elsewhere in Binaryen is left to a follow-on PR.
* Add a SmallSet and use it in LocalGraph. NFC (#4188)Alon Zakai2021-09-292-0/+222
| | | | | | | | | | | | | | | | | A SmallSet starts with fixed storage that it uses in the simplest possible way (linear scan, no sorting). If it exceeds a size then it starts using a normal std::set. So for small amounts of data it avoids allocation and any other overhead. This adds a unit test and also uses it in LocalGraph which provides a large amount of additional coverage. I also changed an unrelated data structure from std::map to std::unordered_map which I noticed while doing profiling in LocalGraph. (And a tiny bit of additional refactoring there.) This makes LocalGraph-using passes like ssa-nomerge and precompute-propagate 10-15% faster on a bunch of real-world codebases I tested.
* Clang-format c/cpp files in test directory (#4192)Heejin Ahn2021-09-2915-1309/+1996
| | | | | | | | | This clang-formats c/cpp files in test/ directory, and updates clang-format-diff.sh so that it does not ignore test/ directory anymore. bigswitch.cpp is excluded from formatting, because there are big commented-out code blocks, and apparently clang-format messes up formatting in them. Also to make matters worse, different clang-format versions do different things on those commented-out code blocks.
* Disable partial inlining by default and add a flag for it. (#4191)Alon Zakai2021-09-271-2/+1
| | | | | Locally I saw a 10% speedup on j2cl but reports of regressions have arrived, so let's disable it for now pending investigation. The option added here should make it easy to experiment.
* Add feature flag for relaxed-simd (#4183)Ng Zhi An2021-09-232-1/+4
|
* [Matcher] Add bval for matching boolean literals (#4162)Max Graey2021-09-202-2/+14
|
* Support specialized function types in element segments (#4109)Alon Zakai2021-09-021-0/+1
| | | | | | Before this, the element segments would be printed as having type funcref, and then if their table had a specialized type, the element type would not be a subtype of the table and validation would fail.
* Fix the effects of array.copy (#4118)Alon Zakai2021-09-011-0/+14
| | | | | | This appeared to be a regression from #4117, however this was always a bug, and that PR just exposed it. That is, somehow we forgot to indicate the effects of ArrayCopy, and after that PR we'd vacuum it out incorrectly.
* Use the new module version of EffectAnalyzer (#4116)Alon Zakai2021-08-311-3/+3
| | | | | | | | | | | This finishes the refactoring started in #4115 by doing the same change to pass a Module into EffectAnalyzer instead of features. To do so this refactors the fallthrough API and a few other small things. After those changes, this PR removes the old feature constructor of EffectAnalyzer entirely. This requires a small breaking change in the C API, changing BinaryenExpressionGetSideEffects's feature param to a module. That makes this change not NFC, but otherwise it is.
* [API] Add type argument for BinaryenAddTable method (#4107)Max Graey2021-08-272-5/+5
| | | In the JS API this is optional and it defaults to `funcref`.
* Dominator Tree (#4100)Alon Zakai2021-08-262-0/+164
| | | | | | | | Add a class to compute the dominator tree for a CFG consisting of a list of basic blocks assumed to be in reverse postorder. This will be useful once cfg-walker emits blocks in reverse-postorder (which it almost does, another PR will handle that). Then we can write optimization passes that use block dominance.
* Add a shallowHash() method (#4077)Alon Zakai2021-08-121-2/+31
| | | | | | This adds and tests the new method. It will be used in a new pass later, where computing shallow hashes allows it to be done in linear time. 99% of the diff is whitespace.
* Fix a bug in nominal LUB calculation (#4046)Thomas Lively2021-08-021-0/+14
| | | The wrong variable was null checked, leading to segfaults.
* 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