Prior to funcref, a partial chunk of an invalid module was never needed,
but funcref allows a partially instantiated module to modify imported
tables with references to its own functions, which means we need to keep
the second module alive while that function reference is present within
the imported table.
This was tested by the spectests, but very rarely caught as our GC does
not behave particularly predictably, making it so the offending module
remains in memory just long enough to let the tests pass.
This commit makes it so all function references keep their respective
modules alive.
(cherry picked from commit a60ecea16abe62aae988ba877fdb98466d2919d3)
This gives us free devirtualization of some hot calls inside the
bytecode interpreter. Most notably the did_trap() checks.
Modest performance improvement on the https://figma.com/ landing page.
(cherry picked from commit 2f3128333dcd5a781f35272800631d6cf03803ad)
This brings back the old behaviour of Value::to<short>() (and other
similar calls), which WASI depends on.
To make sure all similar issues are caught in the future, this commit
also introduces an static assertion in Value::to().
(cherry picked from commit 0d05ab2ad0cc56cc6fe9ee647dfcfda44a92b4f2)
These have no declared constructor, so apple clang and clang clang seem
to disagree on some versions.
(cherry picked from commit d2ff92077b2a4ead0a1ef65e7131702e1152cbeb)
Gets fib(30) from 380ms to 340ms.
(cherry picked from commit a58704296cd36d3080dbf8f1be49300de2c25ea9;
amended to comment out two dbgln_if()s that no longer compile after
this change if WASM_TRACE_DEBUG is defined to 1 -- see comments on
LadybirdBrowser/ladybird#960. Likewise, one dbgln_if() in Wasi.cpp
got commented out as well)
Theoretically, the previous "pop, then push" method should be faster,
but it's actually faster to just remove from the stack directly.
(cherry picked from commit a2448308fd90ba0aafd42587a091c0da3c037ba9)
Instead of one stack to hold frames, labels, and values, there is now
three separate stacks. This speeds up fib(30) from 580ms to 480ms.
(cherry picked from commit a3b077c6415e0f4038b8c8da1e1e9c9cc2df5f0a)
Remove `for_each_section_of_type` in favor of making the module's
sections defined as distinct fields. This means it is no longer possible
to have two of the same section (which is invalid in WebAssembly, for
anything other than custom sections).
(cherry picked from commit 23cfee22058880f8251d9627e7f6640d466c37a9)
`Module::functions` created clones of all of the functions in the
module. It provided a _slightly_ better API, but ended up costing around
40ms when instantiating spidermonkey.
(cherry picked from commit dc52998341bb86ad8fb790fb72f943e43b16e8e5)
`swizzle` had the wrong operands, and the vector masking boolean logic
was incorrect in the internal `shuffle_or_0` implementation. `shuffle`
was previously implemented as a dynamic swizzle, when it uses an
immediate operand for lane indices in the spec.
(cherry picked from commit 9cc3e7d32d150dd30d683c1a8cf0bd59676f14ab)
Also make `store_to_memory` take a `MemoryArgument` so that we no longer
have to make "synthetic instructions" in some scenarios.
(cherry picked from commit ea67bc989f58e27a28f473819e4265a0ad0af97f)
Previously we relied on signed overflow, this commit makes the same
behaviour explicit (avoiding UB in the process).
(cherry picked from commit 8c8310f0bddc874a9f7f07c4158f0abc799357d4)
With this we pass an additional ~2100 tests.
We are left with 7106 WASM fails :).
There's still some test cases in the iNxM tests that fail with
this PR, but they are somewhat weird.
(cherry picked from commit b4acd4fb0b7f4105c7ef673ccc00904114c3c468)
Co-authored-by: Diego Frias <styx5242@gmail.com>
Previously the validator put a `v128` on the stack, which is not what
the spec defines.
(cherry picked from commit 0d38572d8bd2a276be1b6066b62efd376ddbd4d6)
After a `memory.grow`, the type of the memory instance should be
updated so potential memory imports on the boundary are unlinkable.
(cherry picked from commit cdb6e834a1c0eaa6e62a9018026a599916332ab3)
Single-type blocktypes previously gave loop labels an arity of 1, even
though they're shorthand for `[] -> [T]`.
(cherry picked from commit ad6a80144c23f9ccdeeccb123a9de85396524040)
As far as I know, they're not in the spec and don't serve any purposes
in the internals of LibWasm.
(cherry picked from commit 5382fbb6171555264e29872029330e1373b39671)
NaN bit patterns are now (hopefully) preserved. `static_cast` does not
preserve the bit pattern of a given NaN, so ideally we'd use some other
sort of cast and avoid `static_cast` altogether, but that's a large
change for this commit. For now, this fixes the issues found in spec
tests.
(cherry picked from commit c882498d4450c4c2e46d77a8ab36afc4eb412c00)
Otherwise we'd hit a VERIFY in AK::SIMD::shuffle() when that operand
contains an out-of-range value, the spec tests indicate that a swizzle
with an out-of-range index should return 0.
The data segment offset should be checked _before_ checking if the
contents of the segment are non-existent.
(cherry picked from commit 78c56d80f90f913e4cbc14c865af308c6af9aeae)
The big improvement included in this commit is stack height mismatch
validation. There are other minor improvements included (related to the
validation algorithm). The method of supporting stack polymorphism has
changed to be more like the spec, which was necessary for confidently
handling stack height mismatches.
See:
https://webassembly.github.io/spec/core/appendix/algorithm.html
(cherry picked from commit 9b58271f8b6de2dbfff416780a54e0322f9c6799)
Previously, the validator had a lot of extraneous information related to
frames. Now, there's just one stack with all the necessary information
derived from it.
(cherry picked from commit ad54b69de9df6ccd44178cbe49779e313f95f273)