summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* [Wasm GC] Add a isNonNullable() convenience method. NFC (#3978)Alon Zakai2021-07-121-1/+1
|
* [Memory64] further memory limit fixes (#3865)Wouter van Oortmerssen2021-07-091-3/+10
| | | That were somehow missed.. triggered by emscripten tests
* [Wasm GC] Add support for non-nullable locals in binary reading (#3955)Alon Zakai2021-07-021-7/+11
| | | | | | | We only tested that feature on the text format. For binary support, the reader needs to know that the feature is enabled, so that it allows non-nullable locals in that case (i.e., does not apply the workarounds to remove them). Fixes #3953
* Apply features from the commandline first (#3960)Alon Zakai2021-07-021-40/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | As suggested in https://github.com/WebAssembly/binaryen/pull/3955#issuecomment-871016647 This applies commandline features first. If the features section is present, and disallows some of them, then we warn. Otherwise, the features can combine (for example, a wasm may enable feature X because it has to use it, and a user can simply add the flag for feature Y if they want the optimizer to try to use it; both flags will then be enabled). This is important because in some cases we need to know the features before parsing the wasm, in the case that the wasm does not use the features section. In particular, non-nullable GC locals have an effect during parsing. (Typed function references also does, but we found a way to apply its effect all the time, that is, always use the refined type, and that happened to not break the case where the feature is disabled - but such a workaround is not possible with non-nullable locals.) To make this less error-prone, add a FeatureSet input as a parameter to WasmBinaryBuilder. That is, when building a module, we must give it the features to use while doing so. This will unblock #3955 . That PR will also add a test for the actual usage of a feature during loading (the test can only be added there, after that PR unbreaks things).
* Preserve Function HeapTypes (#3952)Thomas Lively2021-06-301-8/+8
| | | | | | | | | 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 attribute's encoding uint8 (#3949)Heejin Ahn2021-06-221-4/+4
| | | | | | | | | | | This changes the encoding of the `attribute` field, which currently only contains the value `0` denoting this tag is for an exception, from `varuint32` to `uint8`. This field is effectively unused at the moment and reserved for future use, and it is not likely to need `varuint32` even in future. See https://github.com/WebAssembly/exception-handling/pull/162. This does not change any encoded binaries because `0` is encoded in the same way both in `varuint32` and `uint8`.
* [EH] Make tag's attribute encoding detail (#3947)Heejin Ahn2021-06-211-7/+5
| | | | | | | | | 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.
* [EH] Replace event with tag (#3937)Heejin Ahn2021-06-181-54/+54
| | | | | | | | | | | 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] rtt.fresh_sub (#3936)Alon Zakai2021-06-171-2/+6
| | | | | | | | | | This is the same as rtt.sub, but creates a "new" rtt each time. See https://docs.google.com/document/d/1DklC3qVuOdLHSXB5UXghM_syCh-4cMinQ50ICiXnK3Q/edit# The old Literal implementation of rtts becomes a little more complex here, as it was designed for the original spec where only structure matters. It may be worth a complete redesign there, but for now as the spec is in flux I think the approach here is good enough.
* Parsing and emitting nominal types (#3933)Thomas Lively2021-06-151-6/+26
| | | | | | | Adds a `--nominal` option to switch the type machinery from equirecursive to nominal. Implements binary and text parsing and emitting of nominal types using new type constructor opcodes and an `(extends $super)` text syntax extension. When not in nominal mode, these extensions will still be parsed but will not have any effect and will not be used when emitting.
* [EH] Allow catch/delegate-less trys (#3924)Heejin Ahn2021-06-101-5/+7
| | | | This removes the restriction that `try` should have at least one `catch`/`catch_all`/`delegate`. See WebAssembly/exception-handling#157.
* Store signatures as HeapTypes when parsing binaries (#3929)Thomas Lively2021-06-101-21/+32
| | | | | | | When parsing func.ref instructions, we need to get the HeapType corresponding to the referenced function's signature. Since constructing HeapTypes from Signatures can be expensive under equirecursive typing, keep track of the original function signature HeapTypes directly during parsing rather than storing them as Signatures.
* [Wasm GC] Add negated BrOn* operations (#3913)Alon Zakai2021-06-021-1/+19
| | | | | | They are basically the flip versions. The only interesting part in the impl is that their returned typed and sent types are different. Spec: https://docs.google.com/document/d/1DklC3qVuOdLHSXB5UXghM_syCh-4cMinQ50ICiXnK3Q/edit
* [Wasm GC] Add experimental array.copy (#3911)Alon Zakai2021-05-271-0/+21
| | | | | | | | Spec for it is here: https://docs.google.com/document/d/1DklC3qVuOdLHSXB5UXghM_syCh-4cMinQ50ICiXnK3Q/edit# Also reorder some things in wasm.h that were not in the canonical order (that has no effect, but it is confusing to read).
* [wasm-split] Add an option to emit only the module names (#3901)Thomas Lively2021-05-251-2/+8
| | | | | | Even when other names are stripped, it can be useful for wasm-split to preserve the module name so that the split modules can be differentiated in stack traces. Adding this option to wasm-split requires adding similar options to ModuleWriter and WasmBinaryWriter.
* [Wasm GC] Do not inline a function with an RTT parameter (#3808)Alon Zakai2021-04-141-1/+1
| | | | | Inlined parameters become locals, and rtts cannot be handled as locals, unlike non-nullable values which we can at least fix up. So do not inline functions with rtt params.
* Rename SIMD extending load instructions (#3798)Daniel Wirtz2021-04-121-6/+6
| | | | | | | | | Renames the SIMD instructions * LoadExtSVec8x8ToVecI16x8 -> Load8x8SVec128 * LoadExtUVec8x8ToVecI16x8 -> Load8x8UVec128 * LoadExtSVec16x4ToVecI32x4 -> Load16x4SVec128 * LoadExtUVec16x4ToVecI32x4 -> Load16x4UVec128 * LoadExtSVec32x2ToVecI64x2 -> Load32x2SVec128 * LoadExtUVec32x2ToVecI64x2 -> Load32x2UVec128
* Update SIMD binary constants (#3799)Daniel Wirtz2021-04-121-60/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Updates binary constants of SIMD instructions to match new opcodes: * I16x8LoadExtSVec8x8 -> V128Load8x8S * I16x8LoadExtUVec8x8 -> V128Load8x8U * I32x4LoadExtSVec16x4 -> V128Load16x4S * I32x4LoadExtUVec16x4 -> V128Load16x4U * I64x2LoadExtSVec32x2 -> V128Load32x2S * I64x2LoadExtUVec32x2 -> V128Load32x2U * V8x16LoadSplat -> V128Load8Splat * V16x8LoadSplat -> V128Load16Splat * V32x4LoadSplat -> V128Load32Splat * V64x2LoadSplat -> V128Load64Splat * V8x16Shuffle -> I8x16Shuffle * V8x16Swizzle -> I8x16Swizzle * V128AndNot -> V128Andnot * F32x4DemoteZeroF64x2 -> F32x4DemoteF64x2Zero * I8x16NarrowSI16x8 -> I8x16NarrowI16x8S * I8x16NarrowUI16x8 -> I8x16NarrowI16x8U * I16x8ExtAddPairWiseSI8x16 -> I16x8ExtaddPairwiseI8x16S * I16x8ExtAddPairWiseUI8x16 -> I16x8ExtaddPairwiseI8x16U * I32x4ExtAddPairWiseSI16x8 -> I32x4ExtaddPairwiseI16x8S * I32x4ExtAddPairWiseUI16x8 -> I32x4ExtaddPairwiseI16x8U * I16x8Q15MulrSatS -> I16x8Q15mulrSatS * I16x8NarrowSI32x4 -> I16x8NarrowI32x4S * I16x8NarrowUI32x4 -> I16x8NarrowI32x4U * I16x8ExtendLowSI8x16 -> I16x8ExtendLowI8x16S * I16x8ExtendHighSI8x16 -> I16x8ExtendHighI8x16S * I16x8ExtendLowUI8x16 -> I16x8ExtendLowI8x16U * I16x8ExtendHighUI8x16 -> I16x8ExtendHighI8x16U * I16x8ExtMulLowSI8x16 -> I16x8ExtmulLowI8x16S * I16x8ExtMulHighSI8x16 -> I16x8ExtmulHighI8x16S * I16x8ExtMulLowUI8x16 -> I16x8ExtmulLowI8x16U * I16x8ExtMulHighUI8x16 -> I16x8ExtmulHighI8x16U * I32x4ExtendLowSI16x8 -> I32x4ExtendLowI16x8S * I32x4ExtendHighSI16x8 -> I32x4ExtendHighI16x8S * I32x4ExtendLowUI16x8 -> I32x4ExtendLowI16x8U * I32x4ExtendHighUI16x8 -> I32x4ExtendHighI16x8U * I32x4DotSVecI16x8 -> I32x4DotI16x8S * I32x4ExtMulLowSI16x8 -> I32x4ExtmulLowI16x8S * I32x4ExtMulHighSI16x8 -> I32x4ExtmulHighI16x8S * I32x4ExtMulLowUI16x8 -> I32x4ExtmulLowI16x8U * I32x4ExtMulHighUI16x8 -> I32x4ExtmulHighI16x8U * I64x2ExtendLowSI32x4 -> I64x2ExtendLowI32x4S * I64x2ExtendHighSI32x4 -> I64x2ExtendHighI32x4S * I64x2ExtendLowUI32x4 -> I64x2ExtendLowI32x4U * I64x2ExtendHighUI32x4 -> I64x2ExtendHighI32x4U * I64x2ExtMulLowSI32x4 -> I64x2ExtmulLowI32x4S * I64x2ExtMulHighSI32x4 -> I64x2ExtmulHighI32x4S * I64x2ExtMulLowUI32x4 -> I64x2ExtmulLowI32x4U * I64x2ExtMulHighUI32x4 -> I64x2ExtmulHighI32x4U * F32x4PMin -> F32x4Pmin * F32x4PMax -> F32x4Pmax * F64x2PMin -> F64x2Pmin * F64x2PMax -> F64x2Pmax * I32x4TruncSatSF32x4 -> I32x4TruncSatF32x4S * I32x4TruncSatUF32x4 -> I32x4TruncSatF32x4U * F32x4ConvertSI32x4 -> F32x4ConvertI32x4S * F32x4ConvertUI32x4 -> F32x4ConvertI32x4U * I32x4TruncSatZeroSF64x2 -> I32x4TruncSatF64x2SZero * I32x4TruncSatZeroUF64x2 -> I32x4TruncSatF64x2UZero * F64x2ConvertLowSI32x4 -> F64x2ConvertLowI32x4S * F64x2ConvertLowUI32x4 -> F64x2ConvertLowI32x4U
* 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
* RefFunc: Validate that the type is non-nullable, and avoid possible bugs in ↵Alon Zakai2021-04-081-2/+1
| | | | | | | | the builder (#3790) The builder can receive a HeapType so that callers don't need to set non-nullability themselves. Not NFC as some of the callers were in fact still making it nullable.
* Add v128.load/storeN_lane SIMD instructions to C/JS API (#3784)Daniel Wirtz2021-04-081-8/+8
| | | | | | | | | | | 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)
* Write names subsections by increasing id (#3779)Sam Clegg2021-04-071-27/+33
| | | | | See https://webassembly.github.io/spec/core/appendix/custom.html "Each subsection may occur at most once, and in order of increasing id."