summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Debug info handling for new EH try-catch (#3496)Alon Zakai2021-01-257-45/+85
| | | | | | | | We now have multiple catches in each try, and a possible catch-all. This changes our "extra delimiter" storage to store either an "else" (unchanged from before) or an arbitrary list of things - we use that for catches.
* Reorder i31ref and dataref (#3509)Heejin Ahn2021-01-2315-69/+78
| | | | | | | | | | The binary spec (https://docs.google.com/document/d/1yAWU3dbs8kUa_wcnnirDxUu9nEBsNfq0Xo90OWx6yuo/edit#) lists `dataref` after `i31ref`, and `dataref` also comes after `i31ref` in its binary code in the value-increasing order. This reorders these two in wasm-type.h and other places, although in most of those places the order is irrelevant. This also adds C and JS API for `dataref`.
* [GC] Update GC binary format for prototype v3 (#3507)Alon Zakai2021-01-222-16/+0
| | | | | Some fields were removed, see https://docs.google.com/document/d/1yAWU3dbs8kUa_wcnnirDxUu9nEBsNfq0Xo90OWx6yuo/edit#
* Remove exnref and br_on_exn (#3505)Heejin Ahn2021-01-2246-557/+14
| | | This removes `exnref` type and `br_on_exn` instruction.
* [GC] Add dataref type (#3500)Alon Zakai2021-01-2122-6/+122
| | | | | This is not 100% of everything, but is enough to get tests passing, which includes full binary and text format support, getting all switches to compile without error, and some additions to InstrumentLocals.
* Update interpreter for new EH spec (#3498)Heejin Ahn2021-01-216-41/+63
| | | | | | | | | | | | | This updates the interpreter for the EH instructions (modulo `delegate`) to match the new spec. Before we had an `exnref` type so threw a `Literal` of `exnref` type which contained `ExceptionPackage`. But now that we don't have `exnref` anymore, so we add the contents of `ExceptionPackage` to `WasmException`, which is used only for the `ExpressionRunner` class hierarchy. `exnref` and `ExceptionPackage` will be removed in a followup CL. This allows nonzero depths for `rethrow` for now for testing; we disallowed that for safety measure, but given that there are no passes that modifies that field, I think the risk is low.
* CFG traversal for the new EH spec (#3494)Heejin Ahn2021-01-212-43/+120
| | | | | | | | | | | | | | | | | | | | | | This updates CFG traversal to match the new spec. Previously there was only a single `catch` block that caught all exceptions, so all throwing instructions needed to have a link to its innermost catch BB. But now we can have multiple catches per try, requiring all throwing instrutions to have an edge to all of those innermost catch BBs. Furthermore, if there are only `catch`es and not a `catch_all` in a try, throwing instructions can further unwind to outer catches until they find a `catch_all`. `unwindCatchStack` and `unwindExprStack` are necessary to track and make correct links between throwing instructions and their unwind destination BBs. `processCatchStack` is used to remember the catch BBs currently being processed, so that after processing all of them, we can make a link from each of those catch's last block to the continuation block after the try-catch. RSE test cases are updated because they use the CFG traversal. The tests there mainly test that if all possible CFG edge to a `local.set` sets the same value to a local, the `local.set` is redundant and thus can be removed.
* Simplify set/gets of vectors in binaryen.js (#3495)Heejin Ahn2021-01-201-174/+39
| | | | | This uses existing `getAllNested` function in `ExpressionWrapper` functions. Also adds `setAllNested` which works in the other direction and uses it within `ExpressionWrapper` functions.
* Prototype additional f64x2 conversions (#3501)Thomas Lively2021-01-1910-23/+175
| | | | As proposed in https://github.com/WebAssembly/simd/pull/383, with opcodes coordinated with the WIP V8 prototype.
* wasm-reduce: Fix setting of feature flags after loading (#3493)Alon Zakai2021-01-151-2/+6
| | | | | We mistakenly did not set the flags to all, which meant that if the features section was not present, we'd not have the proper features set, leading to errors on writing.
* wasm-reduce: default to -all, and make it customizable (#3492)Alon Zakai2021-01-151-11/+20
| | | | | | | | | This goes back to the downsides of #2813, but that seems unavoidable as without this, testcases without the features section but that use features did not work. This PR at least makes it easy to customize the flags send to the commands. See also #3393 (comment)
* [GC] Read and lower Let instructions (#3485)Alon Zakai2021-01-152-12/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For now we don't support non-nullability, and can therefore lower a let into simpler things. That is, (let $x = ... ;; ) => (block $x = ... ;; ) This lets us handle wasm binaries with let, so that we can optimize them (with the current downside of losing non-nullability). This is still not trivial to do, sadly, because the indexing of lets is somewhat odd in the binary. A let modifies the indexes of other things declared before it, which means that index "0" means different things at different times. And this is trickier for us because we add more locals as needed for tuples and stacky code. So this PR makes us track the absolute local indexes from which each let started to allocate its locals. The binary testcase was created from this wat using wasp: (module (type $vector (array (field (mut f64)))) (func $main (local $x i32) (local $y i32) (drop (local.get $x)) ;; 0 is the index appearing in the binary ;; first let (array.new_with_rtt $vector (f64.const 3.14159) (i32.const 1) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ;; another one, nested (array.new_with_rtt $vector (f64.const 1234) (i32.const 2) (rtt.canon $vector) ) (let (local $w (ref $vector)) (drop (local.get $v)) ;; 1 (drop (local.get $w)) ;; 0 (drop (local.get $x)) ;; 2 ) ) ;; another one, later (array.new_with_rtt $vector (f64.const 2.1828) (i32.const 3) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ) (drop (local.get $x)) ;; 0 ) )
* Reducer: Improve warning on scripts that ignore the input (#3490)Alon Zakai2021-01-151-9/+20
| | | | | | | | | | | | | The risk the warning checks for is giving the reducer a script that ignores the input. To do so it runs the command in the input, and runs it on a garbage file, and checks if the result is different. However, if the script does immediately fail on the input - because the input is a crash testcase or such - then this does not work, as the result on a garbage input may be the same error. To avoid that, also check what happens on a trivial valid wasm as input. Only show the warning if the result on the original input, on a garbage wasm, and on a trivial wasm, are all the same - in that case, likely the script really is ignoring the input.
* Basic EH instrucion support for the new spec (#3487)Heejin Ahn2021-01-1529-156/+565
| | | | | | | | | | | | | | | | | | | | This updates `try`-`catch`-`catch_all` and `rethrow` instructions to match the new spec. `delegate` is not included. Now `Try` contains not a single `catchBody` expression but a vector of catch bodies and events. This updates most existing routines, optimizations, and tests modulo the interpreter and the CFG traversal. Because the interpreter has not been updated yet, the EH spec test is temporarily disabled in check.py. Also, because the CFG traversal for EH is not yet updated, several EH tests in `rse_all-features.wast`, which uses CFG traversal, are temporarily commented out. Also added a few more tests in existing EH test functions in test/passes. In the previous spec, `catch` was catching all exceptions so it was assumed that anything `try` body throws is caught by its `catch`, but now we can assume the same only if there is a `catch_all`. Newly added tests test cases when there is a `catch_all` and cases there are only `catch`es separately.
* Avoid usedElements around code that modifys that value (#3488)Alon Zakai2021-01-141-6/+6
| | | | | | | | Followup to #3486, I wonder if it isn't a little more clear this way, which avoids the confusion of usedElements being changed while we are using it. In general I think it's best to only use usedElements in the most internal methods, and to call size() otherwise.
* [GC] RTT types are not defaultable (#3489)Alon Zakai2021-01-131-1/+1
| | | See WebAssembly/gc#175
* Fix an index error in ArenaVectorBase (#3486)Heejin Ahn2021-01-141-1/+1
| | | | | | | | Because `resize()` sets `usedElements` to its argument, we were accessing `data[usedElements]`, which can be outside of allocated memory depending the internal state, i.e., `allocatedElements`'s value. It is hard to come up with a test case for this because apparently the failure condition depends on the vector's internal state.
* [GC] Fix casts of non-GC data (#3483)Alon Zakai2021-01-121-2/+10
| | | | | The code previously assumed it could always call getGCData, but that assumes the input is an array or a struct. It could also be an anyref etc. that contains something other than GC data.
* [GC] Add Type::IsDefaultable and use that to do more validation (#3456)Alon Zakai2021-01-113-6/+11
|
* [GC] More HeapType instead of Type (#3475)Alon Zakai2021-01-112-55/+92
| | | | | | | | To handle both nullable and non-nullable i31s and other heap types, we cannot just look at the isBasic case (which is just one of the two). This may fix this issue on the release builder: https://github.com/WebAssembly/binaryen/runs/1669944081?check_suite_focus=true but the issue does not reproduce locally, so I worry it is something else...
* [GC] Fix minor binary format issues of ordering and immediates (#3472)Alon Zakai2021-01-113-29/+26
| | | | | | | | | Noticed by comparing to V8 and Wasp. After this things are almost identical, but there is also at least https://bugs.chromium.org/p/v8/issues/detail?id=11300 Test updates are due to having an instruction with two operands of which one is unreachable. The new order puts the non-unreachable first, so it is not removed by round-tripping through the binary format like before (which removes all unreachable code).
* finalize: remove initializers from metadata output (#3479)Sam Clegg2021-01-113-22/+3
| | | See https://github.com/emscripten-core/emscripten/pull/13208
* Add more verbose logging of an assert that only happens on the release ↵Alon Zakai2021-01-081-1/+6
| | | | | builder for some inexplicable reason (#3477) See #3459
* [GC] Validate that struct.set is to a mutable field. (#3473)Alon Zakai2021-01-081-1/+4
| | | | This required a few test fixes, to ensure we don't have invalid wasts with writes to immutable fields.
* [GC] Fix the opcode of i31 (#3471)Alon Zakai2021-01-081-1/+1
|
* [GC] Fix parsing/printing of ref types using i31 (#3469)Alon Zakai2021-01-077-63/+74
| | | | | | | | | | | | This lets us parse (ref null i31) and (ref i31) and not just i31ref. It also fixes the parsing of i31ref, making it nullable for now, which we need to do until we support non-nullability. Fix some internal handling of i31 where we had just i31ref (which meant we just handled the non-nullable type). After fixing a bug in printing (where we didn't print out (ref null i31) properly), I found some a simplification, to remove TypeName.
* Prototype prefetch instructions (#3467)Thomas Lively2021-01-0617-3/+152
| | | | As proposed in https://github.com/WebAssembly/simd/pull/352, using the opcodes used in the LLVM and V8 implementations.
* Prototype SIMD extending pairwise add instructions (#3466)Thomas Lively2021-01-0517-77/+102
| | | | | | As proposed in https://github.com/WebAssembly/simd/pull/380, using the opcodes used in LLVM and V8. Since these opcodes overlap with the opcodes of i64x2.all_true and i64x2.any_true, which have long since been removed from the SIMD proposal, this PR also removes those instructions.
* Improve C and JS API module inspection features (#3464)Daniel Wirtz2021-01-053-37/+82
| | | | | | * BinaryenGetFunction, BinaryenGetGlobal, BinaryenGetEvent now return NULL if an element does not exist * Adds BinaryenGetExport, BinaryenGetNumGlobals, BinaryenGetGlobalByIndex * Corrects BinaryenGetNumFunctions return type * Adds related descriptions of C API functions
* MemoryPacking: Preserve segment names (#3458)Sam Clegg2020-12-185-18/+44
| | | | | Also, avoid packing builtin llvm segments names so that segments such as `__llvm_covfun` (use by llvm-cov) are preserved in the final output.
* Followup to #3451 after feedback (#3457)Alon Zakai2020-12-181-1/+1
| | | | The validation code can be further simplified after adding castType, and we were missing a test for the type that flows out of br_on_cast.
* finalize: there can only ever be a single initializer function. NFC. (#3452)Sam Clegg2020-12-183-13/+8
|
* [module-splitting] Fix a crash when a function is exported twice (#3455)Thomas Lively2020-12-171-0/+4
| | | | | | | | | `ModuleSplitter::thunkExportedSecondaryFunctions` creates a thunk for each secondary function that needs to be exported from the main module. Previously, if a secondary function was exported twice, this code would try to create two thunks for it rather than just making one thunk and exporting it twice. This caused a fatal error because the second thunk had the same name as the first thunk and therefore could not be added to the module. This PR fixes the issue by creating no more than one thunk per function.
* [GC] Add br_on_cast (#3451)Alon Zakai2020-12-1715-42/+154
| | | | | | | | | | | | | | | | The tricky part here, as pointed out by aheejin in my previous attempt, is that we need to know the type of the value we send if the branch is taken. We can normally calculate that from the rtt parameter's type - we are casting to that RTT, so we know what type that is - but if the rtt is unreachable, that's a problem. To fix that, store the cast type on BrOnCast instructions. This includes a test with a br_on_cast that succeeds and sends the cast value, one that fails and passes through the uncast value, and also of one with an unreachable RTT. This includes a fix for Precompute, as noticed by that new test. If a break is taken, with a ref as a value, we can't precompute it - for the same reasons we can't precompute a ref in general, that it is a pointer to possibly shared data.
* [wasm-split] Add an --initial-table option (#3454)Thomas Lively2020-12-171-0/+38
| | | | | | | | Adds an option to wasm-split to allow the user to specify the initial table size for both instrumenting and splitting use cases. In the short term this will be used in Emscripten SPLIT_MODULE + dynamic linking workflow to ensure that the expected table size baked into the JS works for both the instrumented and the primary split modules. In the longer term this may be replaced with a more elegant mechanism for making the JS works in both cases.
* Refactor printing code so that printing Expressions always works (#3450)Alon Zakai2020-12-1724-159/+96
| | | | | | | | This avoids needing to add include wasm-printing if a file doesn't already have it. To achieve that, add the std::ostream hooks in wasm.h, and also use them when possible, removing the need for the special WasmPrinter object. Also stop printing in "full" (print types on each line) in error messages by default. The user can still get that, as always, using BINARYEN_PRINT_FULL=1 in the env.
* Add comment a followup to #3424. NFC. (#3449)Sam Clegg2020-12-161-0/+4
|
* More refactoring of branch utility code to remove boilerplate. (#3448)Alon Zakai2020-12-165-158/+83
| | | | | | | | | | | | | | | | | | | This is almost NFC, but it may emit slightly different IR in cases that don't matter much. Specifically, (block (result i32) ;; can also be unreachable (unreachable) (i32.const 1) ) That can be finalized to have type unreachable or i32, as both are valid. After this PR we should consistently do the same thing in all places. (Either option would be ok - we prefer to keep the type if there is one.) In practice, DCE will remove all the dead code anyhow, leaving no difference to matter. However, the IR is different without DCE, and that may be noticeable in an unoptimized build - but it should have no effect on behavior, just on the binary.
* Fix wasm-split name collision bug (#3447)Thomas Lively2020-12-161-3/+16
| | | | | | | | | During module splitting, a map is constructed from internal names to their corresponding export names. This code previously did not take into account the fact that the same internal name may be used by different kinds of entities (e.g. a table and a memory may have the same internal name), which resulted in the secondary module incorrectly using the same import name for all of the entities that shared an internal name. This PR fixes the problem by including the ExternalKind of the entity in the keys of the export map.
* [GC] Fully implement RTT semantics (#3441)Alon Zakai2020-12-157-36/+227
| | | | | | | | | | | | | | This adds info to RTT literals so that they can represent the chain of rtt.canon/sub commands that generated them, and it adds an internal RTT for each GC allocation (array or struct). The approach taken is to simply store the full chain of rtt.sub types that led to each literal. This is not efficient, but it is simple and seems sufficient for the semantics described in the GC MVP doc - specifically, only the types matter, in that repeated executions of rtt.canon/sub on the same inputs yield equal outputs. This PR fixes a bunch of minor issues regarding that, enough to allow testing of the optimization and execution of ref.test/cast.
* Use enums for mutability and nullability (#3443)Thomas Lively2020-12-147-29/+42
| | | | | Previously we were using bools for both of these concepts, but using enums makes the code clearer. In particular, the PR removes many instances of `/*nullability=*/ true`.
* Fixed wasm-emscripten-finalize AsmConstWalker not handling 64-bit pointers ↵Wouter van Oortmerssen2020-12-141-6/+15
| | | | | (#3431) Also improved the LLD test scripts to accomodate 64-bit tests.
* [StackCheck] Handle colliding names (#3390)Alon Zakai2020-12-141-31/+30
| | | | | Add Names::getValidGlobalName calls to ensure we don't collide with an existing name. Fixes emscripten-core/emscripten#12834
* Refactor BranchUtils to avoid boilerplate. NFC (#3442)Alon Zakai2020-12-143-143/+114
| | | This should make it easier to add br_on_cast for example.
* [wasm-reduce] Improve support for reducing on text files (#3437)Alon Zakai2020-12-141-4/+8
| | | | Passing --detect-features there doesn't work (as there is no feature section).
* Prototype SIMD instructions implemented in LLVM (#3440)Thomas Lively2020-12-1112-35/+267
| | | | | | - i64x2.eq (https://github.com/WebAssembly/simd/pull/381) - i64x2 widens (https://github.com/WebAssembly/simd/pull/290) - i64x2.bitmask (https://github.com/WebAssembly/simd/pull/368) - signselect ops (https://github.com/WebAssembly/simd/pull/124)
* [GC] Fix Array optimization issues (#3438)Alon Zakai2020-12-112-13/+38
| | | | | | | | | | | Precompute still tried to precompute a reference because the check was not in the topmost place. Also we truncated i8/i16 values, but did not extend them properly. That was also an issue with structs. The new test replaces the old one by moving from -O1 to -Oz (which runs more opts, and would have noticed this earlier), and adds array operations too, including sign extends.
* [GC] Add ref.test and ref.cast (#3439)Alon Zakai2020-12-1112-45/+103
| | | | This adds enough to read and write them and test that, but leaves interpreter support for later.
* TypeBuilder (#3418)Thomas Lively2020-12-102-8/+352
| | | | | | | | | | | | | | | | | Introduce TypeBuilder, a utility for constructing heap types in terms of other heap types that may have not yet been defined. Internally, it works by creating HeapTypes backed by mutable HeapTypeInfos owned by the TypeBuilder. That lets the TypeBuilder create temporary Types that can refer to the TypeBuilder-managed HeapTypes. Those temporary Types can in turn be used to initialize the very HeapTypes they refer to. Since the TypeBuilder-managed HeapTypes are only valid for the lifetime of their TypeBuilder, there is a canonicalization step that converts them into globally interned canonical HeapTypes. This PR allows HeapTypes to be built in terms of as of yet undefined HeapTypes, but it currently errors out in the presence of recursive types. Supporting recursive types will require further work to canonicalize them into finite, acyclic representations. Currently any attempt to compare, print, or otherwise manipulate recursive types would infinitely recurse.
* [GC] Add Array operations (#3436)Alon Zakai2020-12-1017-174/+469
| | | | | | | | | | | | | | array.new/get/set/len - pretty straightforward after structs and all the infrastructure for them. Also fixes validation of the unnecessary heapType param in the text and binary formats in structs as well as arrays. Fixes printing of packed types in type names, which emitted i32 for them. That broke when we emitted the same name for an array of i8 and i32 as in the new testing here. Also fix a bug in Field::operator< which was wrong for packed types; again, this was easy to notice with the new testing.