summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Strings] string.measure (#4775)Alon Zakai2022-07-071-3/+31
|
* [Strings] Add string.const (#4768)Alon Zakai2022-07-061-0/+102
| | | | | This is more work than a typical instruction because it also adds a new section: all the (string.const "foo") strings are put in a new "strings" section in the binary, and the instructions refer to them by index.
* [Strings] Add feature flag for Strings proposal (#4766)Alon Zakai2022-06-301-0/+4
|
* [Strings] Add string.new* instructions (#4761)Alon Zakai2022-06-291-0/+31
| | | | | | This is the first instruction from the Strings proposal. This includes everything but interpreter support.
* [Strings] Add string proposal types (#4755)Alon Zakai2022-06-291-0/+36
| | | | | | | | This starts to implement the Wasm Strings proposal https://github.com/WebAssembly/stringref/blob/main/proposals/stringref/Overview.md This just adds the types.
* First class Data Segments (#4733)Ashley Nelson2022-06-211-31/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Updating wasm.h/cpp for DataSegments * Updating wasm-binary.h/cpp for DataSegments * Removed link from Memory to DataSegments and updated module-utils, Metrics and wasm-traversal * checking isPassive when copying data segments to know whether to construct the data segment with an offset or not * Removing memory member var from DataSegment class as there is only one memory rn. Updated wasm-validator.cpp * Updated wasm-interpreter * First look at updating Passes * Updated wasm-s-parser * Updated files in src/ir * Updating tools files * Last pass on src files before building * added visitDataSegment * Fixing build errors * Data segments need a name * fixing var name * ran clang-format * Ensuring a name on DataSegment * Ensuring more datasegments have names * Adding explicit name support * Fix fuzzing name * Outputting data name in wasm binary only if explicit * Checking temp dataSegments vector to validateBinary because it's the one with the segments before we processNames * Pass on when data segment names are explicitly set * Ran auto_update_tests.py and check.py, success all around * Removed an errant semi-colon and corrected a counter. Everything still passes * Linting * Fixing processing memory names after parsed from binary * Updating the test from the last fix * Correcting error comment * Impl kripken@ comments * Impl tlively@ comments * Updated tests that remove data print when == 0 * Ran clang format * Impl tlively@ comments * Ran clang-format
* Do not emit recursion groups without GC enabled (#4738)Thomas Lively2022-06-181-2/+7
| | | | | | | | We emit nominal types as a single large recursion group, but this produces invalid modules when --nominal or --hybrid was used without GC enabled. Fix the bug by always emitting types as though they were structural (i.e. without recursion groups) when GC is not enabled. Fixes #4723.
* Fix table exporting (#4736)Alon Zakai2022-06-171-1/+2
| | | | | | | This code was apparently not updated when we added multi-table support, and still had the old hardcoded index 0. Fixes #4711
* Update relaxed SIMD instructionsThomas Lively2022-06-071-8/+0
| | | | | Update the opcodes for all relaxed SIMD instructions and remove the unsigned dot product instructions that are no longer in the proposal.
* Fix binary parsing of the prototype nominal format (#4679)Thomas Lively2022-05-191-3/+0
| | | | | | We were checking that nominal modules only had a single element in their type sections, but that's not correct for the prototype nominal binary format we still want to support. The test for this missed catching the bug because it wasn't actually parsing in nominal mode.
* Add ref.cast_nop_static (#4656)Thomas Lively2022-05-111-2/+5
| | | | | | This unsafe experimental instruction is semantically equivalent to ref.cast_static, but V8 will unsafely turn it into a nop. This is meant to help us measure cast overhead more precisely than we can by globally turning all casts into nops.
* Parse the prototype nominal binary format (#4644)Thomas Lively2022-05-041-9/+40
| | | | | | In f124a11ca3 we removed support for the prototype nominal binary format entirely, but that means that we can no longer parse older binary modules that used that format. Fix this regression by restoring the ability to parse the prototype binary format.
* Remove externref (#4633)Thomas Lively2022-05-041-12/+0
| | | | | | Remove `Type::externref` and `HeapType::ext` and replace them with uses of anyref and any, respectively, now that we have unified these types in the GC proposal. For backwards compatibility, continue to parse `extern` and `externref` and maintain their relevant C API functions.
* Update the type section binary format (#4625)Thomas Lively2022-05-021-64/+62
| | | | | | | | | | Print subtype declarations using the standards-track format with a vector of supertypes followed by a normal type declaration rather than our interim nominal format that used alternative versions of the func, struct, and array forms. Desugar the nominal format to additionally emit all the types into a single large recursion group. Currently V8 is performing this desugaring, but after this change and a future change that fixes the order of nominal types to ensure supertypes precede subtypes, it will no longer need to.
* Implement relaxed SIMD dot product instructions (#4586)Thomas Lively2022-04-111-0/+16
| | | As proposed in https://github.com/WebAssembly/relaxed-simd/issues/52.
* [SIMD] Make swizzle's opcode name consistent (NFC) (#4585)Heejin Ahn2022-04-091-2/+2
| | | | Other opcode ends with `Inxm` or `Fnxm` (where n and m are integers), while `i8x16.swizzle`'s opcode name doesn't have an `I` in there.
* Implement i16x8.relaxed_q15mulr_s (#4583)Thomas Lively2022-04-071-1/+5
| | | As proposed in https://github.com/WebAssembly/relaxed-simd/issues/40.
* [Wasm GC] Fix stacky non-nullable tuples (#4561)Alon Zakai2022-03-311-7/+8
| | | | | #4555 fixed validation for such tuples, but we also did not handle them in "stacky" code using pops etc., due to a logic bug in the binary reading code.
* Add support for extended-const proposal (#4529)Sam Clegg2022-03-191-0/+4
| | | See https://github.com/WebAssembly/extended-const
* Isorecursive binary format (#4494)Thomas Lively2022-02-031-16/+51
| | | | | | | | | | | Write and parse recursion groups in binary type sections. Unlike in the text format, where we ignore recursion groups when not using isorecursive types, do not allow parsing binary recursion group when using other type systems. Doing so would produce incorrect results because recursions groups only count as single entries in the type system vector so we dynamically grow the TypeBuilder when we encounter them. That would change the mapping of later indices to types, and would change the meaning of previous type definitions that use those later indices. This is not a problem in the isorecursive system because in that system type definitions are not allowed to use later indices.
* Make `TypeBuilder::build()` fallible (#4474)Thomas Lively2022-01-251-1/+5
| | | | | | | | | | | 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-201-3/+1
| | | | | | | | 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.
* Refactor ModuleUtils::collectHeapTypes (#4455)Thomas Lively2022-01-141-11/+11
| | | | | Update the API to make both the type indices and optimized sorting optional. It will become more important to avoid unnecessary sorting once isorecursive types have been implemented because they will make the sorting more complicated.
* Warn about and ignore empty local/param names in name section (#4426)Alon Zakai2022-01-071-3/+17
| | | | | | | Fixes the crash in #4418 Also replace the .at() there with better logic to handle imported functions. See WebAssembly/wabt#1799 for details on why wabt sometimes emits this.
* Turn an assertion on not colliding with an internal name into an error (#4422)Alon Zakai2022-01-051-1/+4
| | | | | | Without this, the result in a build without assertions might be quite confusing. See #4410 Also make the internal names more obviously internal names.
* Add binary format parse check for imported function types (#4423)Alon Zakai2022-01-051-1/+7
| | | | | Without this we hit an assertion later, which is less clear. See #4413
* [EH] Fixup nested pops after reading stacky binary (#4420)Heejin Ahn2022-01-041-0/+5
| | | | | | When reading stacky code in the binary reader, we create `block`s to make it fit into Binaryen AST, within which `pop`s can be nested, making the resulting AST invalid. This PR runs the fixup function after reading each `Try` to fix this.
* Add binary format parse checking for ref.as input type (#4389)Alon Zakai2021-12-161-0/+3
| | | | | | | If that type is not valid then we cannot even create and finalize the node, which means we'd hit an assertion inside finalize(), before we reach the validator. Fixes #4383
* Add requireFunctionContext in necessary places (#4388)Alon Zakai2021-12-141-0/+4
| | | Fixes #4384
* [EH] Fix binary parsing for catchless try + inner delegate (#4370)Heejin Ahn2021-12-061-7/+0
| | | | | | | | | | | | | | | | | | | | | | We do some postprocessing after parsing `Try` to make sure `delegate` only targets `try`s and not `block`s: https://github.com/WebAssembly/binaryen/blob/9659f9b07c1196447edee68fe04c8d7dd2480652/src/wasm/wasm-binary.cpp#L6404-L6426 But in case the outer `try` has neither of `catch` nor `delegate`, the previous code just return prematurely, skipping the postprocessing part, resulting in a binary parsing error. This PR removes that early-exiting code. Some test outputs have changed because `try`s are assigned labels after the early exit. But those labels can be removed by other optimization passes when there is no inner `rethrow` or `delegate` that targets them. (On a side note, the restriction that `delegate` cannot target a `block` has been removed a few months ago in the spec, so if a `delegate` targets a `block`, it means it is just rethrown from that block. But I still think this is a convenient invariant to hold at least within the binaryen IR. I'm planning to allow parsing of `delegate` targeting `block`s later, but I will make them point to `try` when read in the IR. At the moment the LLVM toolchain does not generate such code.)
* Modernize code to C++17 (#3104)Max Graey2021-11-221-47/+33
|
* Change from storing Signature to HeapType on CallIndirect (#4352)Thomas Lively2021-11-221-2/+3
| | | | | | | | | | | | With nominal function types, this change makes it so that we preserve the identity of the function type used with call_indirect instructions rather than recreating a function heap type, which may or may not be the same as the originally parsed heap type, from the function signature during module writing. This will simplify the type system implementation by removing the need to store a "canonical" nominal heap type for each unique signature. We previously depended on those canonical types to avoid creating multiple duplicate function types during module writing, but now we aren't creating any new function types at all.
* Add support for relaxed-simd instructions (#4320)Ng Zhi An2021-11-151-0/+68
| | | | | | | | | | | | | | | | | | | | | This adds relaxed-simd instructions based on the current status of the proposal https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md. Binary opcodes are based on what is listed in https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md#binary-format. Text names are not fixed yet, and some sort sort of names that maps to the non-relaxed versions are chosen for this prototype. Support for these instructions have been added to LLVM via builtins, adding support here will allow Emscripten to successfully compile files that use those builtins. Interpreter support has also been added, and they delegate to the non-relaxed versions of the instructions. Most instructions are implemented in the interpreter the same way as the non-relaxed simd128 instructions, except for fma/fms, which is always fused.
* Update to C++17 and use std::optional for getSuperType (#4203)Derek Schuff2021-10-181-4/+3
| | | This sets the C++ standard variable in the build to C++17, and makes use of std::optional (a C++17 library feature) in one place, to test that it's working.
* Add table.grow operation (#4245)Max Graey2021-10-181-0/+23
|
* Switch from "extends" to M4 nominal syntax (#4248)Thomas Lively2021-10-141-1/+3
| | | | | | | | Switch from "extends" to M4 nominal syntax Change all test inputs from using the old (extends $super) syntax to using the new *_subtype syntax for their inputs and also update the printer to emit the new syntax. Add a new test explicitly testing the old notation to make sure it keeps working until we remove support for it.
* Minor fixes in binary type name emitting (#4239)Alon Zakai2021-10-131-2/+3
| | | | | | | | | | | Add an assert on not emitting a null name (which would cause a crash a few lines down on trying to read its bytes). I hit that when writing a buggy pass that updated field names. Also fix the case of a type not having a name but some of its fields having names. We can't test that atm since our text format requires types to have names anyhow, so this is a fix for a possible future where we do allow parsing non-named types.
* Add table.size operation (#4224)Max Graey2021-10-081-2/+22
|
* Add table.set operation (#4215)Max Graey2021-10-071-0/+18
|
* Update nominal binary format to match milestone 4 (#4211)Thomas Lively2021-10-041-14/+37
| | | | | | | | Update the binary format used in --nominal mode to match the format of nominal types in milestone 4. In particular, types without declared supertypes are now emitted using the nominal type codes with either `func` or `data` as their supertypes. This change is hopefully enough to get --nominal mode code running on V8's milestone 4 implementation until the rest of the type system changes can be implemented for use without --nominal.
* Fix roundtripping specialized element segments of table zero (#4212)Alon Zakai2021-10-051-1/+6
| | | | | Before this fix, the first table (index 0) is counted as its element segment having "no table index" even when its type is not funcref, which could break things if that table had a more specialized type.
* Implement table.get (#4195)Alon Zakai2021-09-301-0/+19
| | | | Adds the part of the spec test suite that this passes (without table.set we can't do it all).
* Add feature flag for relaxed-simd (#4183)Ng Zhi An2021-09-231-0/+4
|
* [Wasm GC] Implement static (rtt-free) StructNew, ArrayNew, ArrayInit (#4172)Alon Zakai2021-09-231-40/+71
| | | | | | | | | See #4149 This modifies the test added in #4163 which used static casts on dynamically-created structs and arrays. That was technically not valid (as we won't want users to "mix" the two forms). This makes that test 100% static, which both fixes the test and gives test coverage to the new instructions added here.
* [Wasm GC] Add static variants of ref.test, ref.cast, and br_on_cast* (#4163)Alon Zakai2021-09-201-12/+31
| | | | | | | | | | | | These variants take a HeapType that is the type we intend to cast to, and do not take an RTT. These are intended to be more statically optimizable. For now though this PR just implements the minimum to get them parsing and to get through the optimizer without crashing. Spec: https://docs.google.com/document/d/1afthjsL_B9UaMqCA5ekgVmOm75BVFu6duHNsN9-gnXw/edit# See #4149
* Support new dylink.0 custom section format (#4141)Sam Clegg2021-09-111-7/+81
| | | | | | | See also: spec change: https://github.com/WebAssembly/tool-conventions/pull/170 llvm change: https://reviews.llvm.org/D109595 wabt change: https://github.com/WebAssembly/wabt/pull/1707 emscripten change: https://github.com/emscripten-core/emscripten/pull/15019
* [Wasm GC] ArrayInit support (#4138)Alon Zakai2021-09-101-0/+19
| | | | | | | array.init is like array.new_with_rtt except that it takes as arguments the values to initialize the array with (as opposed to a size and an optional initial value). Spec: https://docs.google.com/document/d/1afthjsL_B9UaMqCA5ekgVmOm75BVFu6duHNsN9-gnXw/edit#
* Support specialized function types in element segments (#4109)Alon Zakai2021-09-021-8/+5
| | | | | | 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.
* Handle extra info in dylink section (#4112)Sam Clegg2021-08-311-35/+15
| | | | | If extra data is found in this section simply propagate it. Also, remove some dead code from wasm-binary.cpp.
* Fix signed_ field initialization in Load. (#4075)Alon Zakai2021-08-121-6/+0
| | | | | | | | | | | This was being set in the creation of Loads in the binary reader, but forgotten in the SIMD logic - which ends up creating a Load with type v128, and signed_ was uninitialized. Very hard to test this, but I saw it "break" hash value computation which is how I noticed this. Also initialize the I31 sign field. Now all of them in wasm.h are properly initialized.