summaryrefslogtreecommitdiff
path: root/src/wasm
Commit message (Collapse)AuthorAgeFilesLines
...
* Validator: Validate intrinsics (#4880)Alon Zakai2022-08-161-8/+55
| | | | | | | | | | call.without.effects has a specific form, where the last parameter is a function reference, and that function reference must have the right type for the other parameters if called with them: (call $call.without.effects (..i32..) (..f64..) (..function reference, which takes params i32 and f64..)
* LegalizeJSInterface: Look for get/setTempRet0 as exports (#4881)Sam Clegg2022-08-151-2/+0
| | | | | | This allows emscripten to move these helper functions from JS library imports to native wasm exports. See https://github.com/emscripten-core/emscripten/issues/7273
* Function-level pass-debug mode 2 validation (#4897)Alon Zakai2022-08-121-0/+17
| | | | | | In BINARYEN_PASS_DEBUG=2 we save the module before each pass, and if validation fails afterwards, we print the module before. This PR does the same for function-parallel passes - in that case, we can actually show the specific function that broke validation, as opposed to the whole module.
* [EH] Pop should be supertype of tag type (#4901)Heejin Ahn2022-08-111-1/+1
| | | | `pop`s type should be a supertype, not a subtype, of the tag's type within `catch`.
* [Strings] Fix string.new_wtf16_array (#4894)Alon Zakai2022-08-102-2/+11
| | | Like the 8-bit array variants, it takes 3 parameters.
* [Strings] Linear memory string operations should emit a memory index (#4893)Alon Zakai2022-08-102-12/+31
| | | | | | | For now this index is always 0, but we must emit it. Also clean up the wat test a little - we don't have validation yet, but we should not validate without a memory in that file.
* [Wasm GC] GC-prefixed opcodes are int8, not LEBs (#4889)Alon Zakai2022-08-092-61/+61
| | | | | | This starts to matter with strings, it turns out. This change should make us runnable in v8. Spec: https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#instructions-1
* [Strings] string.new.array methods have start:end arguments (#4888)Alon Zakai2022-08-092-1/+12
|
* Remove metadata generation from wasm-emscripten-finalize (#4863)Sam Clegg2022-08-071-236/+0
| | | | This is no longer needed by emscripten as of: https://github.com/emscripten-core/emscripten/pull/16529
* wasm-emscripten-finalize: Remove em_js/em_asm start/stop symbols when ↵Sam Clegg2022-08-051-0/+9
| | | | | | | | stripping data segments. (#4876) This avoid a fatal crash in `--post-emscripten` where it tries to remove data that is no longer part of the file. This fixes bug introduced by #4871 that causes emscripten tests to fail.
* Remove RTTs (#4848)Thomas Lively2022-08-058-754/+50
| | | | | | | RTTs were removed from the GC spec and if they are added back in in the future, they will be heap types rather than value types as in our implementation. Updating our implementation to have RTTs be heap types would have been more work than deleting them for questionable benefit since we don't know how long it will be before they are specced again.
* Cleanup em_asm/em_js strings as part of PostEmscripten (#4871)Sam Clegg2022-08-041-90/+5
| | | | Rather than doing it as a side effect of dumping the metadata in wasm-emscripten-finalize.
* wasm-emscripten-finalize: Remove __start/__stop_em_js exports (#4870)Sam Clegg2022-08-031-0/+3
| | | | | | | | We already remove `__start_em_asm` and `__stop_em_asm`. This change is needed since I want to start exporting `__start_em_js` and `__stop_em_js` from emscripten without causing regressions. As a followup I'm planning on moving all of the em_js and em_asm stripping code it PostEmscripten.cpp.
* Remove support for parsing `let` (#4864)Thomas Lively2022-08-031-64/+2
| | | | | It has been removed from the typed function references proposal, so we no longer need to support it. Maintaining the test for `let` was difficult because Binaryen could not emit either text or binary that actually used it.
* Update reference type Literal constructors to use HeapType (#4857)Thomas Lively2022-08-011-4/+2
| | | | | | We already require non-null literals to have non-null types, but with this change we can enforce that constraint by construction. Also remove the default behavior of creating a function reference literal with heap type `func`, since there is always a more specific function type to use.
* Changing ref maps in wasm-binary to use a value of a vector of Name* (#4830)Ashley Nelson2022-07-261-37/+14
| | | | | | | | | | | * Changing ref maps in wasm-binary to use a value of a vector of Name* * clang-format * Update src/wasm/wasm-binary.cpp Co-authored-by: Thomas Lively <7121787+tlively@users.noreply.github.com> Co-authored-by: Thomas Lively <7121787+tlively@users.noreply.github.com>
* Update reference type shorthands in binary output (#4828)Thomas Lively2022-07-251-26/+31
| | | | | | | | | Add support for emitting the string type reference shorthands, which had previously been omitted accidentally due to the `default` case in that switch. Also avoid emitting shorthands for non-nullable reference types as a first step towards transitioning the shorthands to represent nullable types instead. Not emitting these shorthands at all will give V8 the flexibility it needs to change its interpretation of the shorthands without breaking any workflows using Binaryen.
* [Wasm GC] Properly represent nulls in i31 (#4819)Alon Zakai2022-07-251-6/+6
| | | | | The encoding here is simple: we store i31 values in the literal.i32 field. The top bit says if a value exists, which means literal.i32 == 0 is the same as null.
* [Strings] GC variants for string.encode (#4817)Alon Zakai2022-07-214-3/+45
|
* Remove basic reference types (#4802)Thomas Lively2022-07-208-240/+106
| | | | | | | | | Basic reference types like `Type::funcref`, `Type::anyref`, etc. made it easy to accidentally forget to handle reference types with the same basic HeapTypes but the opposite nullability. In principle there is nothing special about the types with shorthands except in the binary and text formats. Removing these shorthands from the internal type representation by removing all basic reference types makes some code more complicated locally, but simplifies code globally and encourages properly handling both nullable and non-nullable reference types.
* [Strings] Add string.new GC variants (#4813)Alon Zakai2022-07-194-4/+53
|
* [Strings] stringview_wtf16.length (#4809)Alon Zakai2022-07-182-0/+5
| | | | This measures the length of a view, so it seems simplest to make it a sub-operation of the existing measure instruction.
* [Strings] stringview_*.slice (#4805)Alon Zakai2022-07-155-0/+97
| | | | | | | Unfortunately one slice is the same as python [start:end], using 2 params, and the other slice is one param, [CURR:CURR+num] (where CURR is implied by the current state in the iter). So we can't use a single class here. Perhaps a different name would be good, like slice vs substring (like JS does), but I picked names to match the current spec.
* [Strings] stringview access operations (#4798)Alon Zakai2022-07-135-0/+173
|
* [Parser][NFC] Refactor to use context callbacks (#4799)Thomas Lively2022-07-121-442/+514
| | | | | | | | | | | | | | | | | The parser functions previously both parsed the input and controlled what was done with the results using `constexpr` if-else chains. As the number of parsing contexts grew, these if-else chains became increasingly complex and distracting from the core parsing logic of the parsing functions. To simplify the code, refactor the parsing functions to replace the `constexpr` if-else chains with unconditional calls to methods on the context. To avoid duplicating most method definitions for multiple parsing contexts, introduce new utility contexts that implement common methods and (ab)use inheritance and multiple inheritance to reuse their methods from the main parsing contexts. This change will also make it easier to reuse the parser code for entirely different purposes in the future by providing new context implementations. For example, V8 could reuse the code and provide different parser contexts that construct V8-internal data structures rather than Binaryen data structures.
* [Strings] string.as (#4797)Alon Zakai2022-07-125-0/+68
|
* [Parser] Start to parse instructions (#4789)Thomas Lively2022-07-111-28/+890
| | | | | | | | | | | | | | | | | | | | | Update gen-s-parser.py to produce a second version of its parsing code that works with the new wat parser. The new version automatically replaces the `s` element argument in the existing parser with the `ctx` and `in` arguments used by the new parser, so adding new instructions will not require any additional work in gen-s-parser.py after this change. Also add stub `make***` functions to the new wat parser, with a few filled out, namely `makeNop`, `makeUnreachable`, `makeConst`, and `makeRefNull`. Update the `global` parser to parse global initializer instructions and update wat-kitchen-sink.wast to demonstrate that the instructions are parsed correctly. Adding new instruction classes will require adding a new `make***` function to wat-parser.cpp in additional to wasm-s-parser.{h,cpp} after this change, but adding a trivial failing implementation is good enough for the time being, so I don't expect this to appreciably increase our maintenance burden in the near term. The infrastructure for parsing folded instructions, instructions with operands, and control flow instructions will be implemented in future PRs.
* [Parser] Parse rec groups (#4785)Thomas Lively2022-07-081-8/+42
|
* [Strings] string.is_usv_sequence (#4783)Alon Zakai2022-07-082-0/+5
| | | | | | | This implements it as a StringMeasure opcode. They do have the same number of operands, same trapping behavior, and same return type. They both get a string and do some inspection of it to return an i32. Perhaps the name could be StringInspect or something like that, rather than StringMeasure..? But I think for now this might be good enough, and the spec may change anyhow later.
* [Strings] string.eq (#4781)Alon Zakai2022-07-084-0/+30
|
* [Parser] Parse standard subtype declarations (#4778)Thomas Lively2022-07-081-49/+92
| | | | Parse type definitions with the format `(type $t (sub $super ...))`. Update the test to use hybrid types so that the subtypes are reflected in the test output.
* [Strings] string.concat (#4777)Alon Zakai2022-07-084-0/+31
|
* [Strings] string.encode (#4776)Alon Zakai2022-07-074-0/+74
|
* Group reference types in binary format. (#4774)Alon Zakai2022-07-071-0/+23
| | | | | | | | | | | | Grouping all references together makes it easier for baseline compilers to zero out memory (as the zeroing out may be different for MVP types vs. references). This puts all references together, either at the start or the end. As a heuristic for that we see if the first local is a reference. As the optimizer will sort locals by frequency, this ensures that the most-frequent local stays in index 0. Fixes #4773. See more details there
* [Strings] string.measure (#4775)Alon Zakai2022-07-074-6/+77
|
* [Strings] Add string.const (#4768)Alon Zakai2022-07-064-0/+113
| | | | | 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-303-0/+10
|
* [Strings] Print shorthand types where possible (#4763)Alon Zakai2022-06-291-1/+17
|
* [Strings] Add string.new* instructions (#4761)Alon Zakai2022-06-294-0/+80
| | | | | | This is the first instruction from the Strings proposal. This includes everything but interpreter support.
* [Strings] Add string proposal types (#4755)Alon Zakai2022-06-294-0/+91
| | | | | | | | This starts to implement the Wasm Strings proposal https://github.com/WebAssembly/stringref/blob/main/proposals/stringref/Overview.md This just adds the types.
* [Parser] Parse struct and array types (#4745)Thomas Lively2022-06-221-13/+176
| | | | | | | | | Parse struct and array type definitions along with field names. Only the most basic definitions are parsed for now; subtype definitions (both nominal prototype and standard formats) and recursion groups are left to follow-on PRs. Since there is no official standard for the text format for GC type definitions, attempt to define a grammar that allows abbreviations that we already use widely, such as making `(field ... )` optional except for named fields.
* First class Data Segments (#4733)Ashley Nelson2022-06-215-84/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* [Parser][NFC] Small code cleanups (#4729)Thomas Lively2022-06-143-8/+8
| | | | Apply cleanups suggested by aheejin in post-merge code review of previous parser PRs.
* Fix an unused variable warning (#4728)walkingeyerobot2022-06-141-0/+1
|
* [NFC] Optimize non-equirecursive LUB calculations (#4722)Thomas Lively2022-06-141-89/+148
| | | | | | | | | | | | | | | | | | | Equirecursive LUB calculations potentially require building new recursive heap types that did not already exist in the system, so they have a complicated code path that uses a TypeBuilder to construct a LUB from the ground up. In contrast, nominal and isorecursive LUB calculations never introduce new heap types, so computing their LUBs is much simpler. Previously we were using the same code path with the TypeBuilder for all type systems out of convenience, but this commit factors out the LUB calculations for nominal and isorecursive types into a separate code path that does not use a TypeBuilder. Not only should this make LUB calculations faster for GC workloads, it also avoids a mysterious race condition during parallel LUB calculations with isorecursive types that resulted in a temporary type escaping from one thread and being used-after-free from another thread. It would be good to fix that bug properly, but it is very difficult to investigate. Sweeping it under the rug instead is the best trade off for now. Fixes #4719.
* [Parser] Parse function types (#4718)Thomas Lively2022-06-141-11/+369
| | | | | | Begin implementing the second phase of parsing, parsing of type definitions. Extend `valtype` to parse both user-defined and built in ref types, add `type` as a top-level module field, and implement parsers for params, results, and functype definitions.
* [Parser] Begin parsing modules (#4716)Thomas Lively2022-06-103-4/+668
| | | | | | | | | | | Implement the basic infrastructure for the full WAT parser with just enough detail to parse basic modules that contain only imported globals. Parsing functions correspond to elements of the grammar in the text specification and are templatized over context types that correspond to each phase of parsing. Errors are explicitly propagated via `Result<T>` and `MaybeResult<T>` types. Follow-on PRs will implement additional phases of parsing and parsing for new elements in the grammar.
* Update relaxed SIMD instructionsThomas Lively2022-06-073-17/+1
| | | | | Update the opcodes for all relaxed SIMD instructions and remove the unsigned dot product instructions that are no longer in the proposal.