Commit graph

16 commits

Author SHA1 Message Date
Ali Mohammad Pur
42c0a430f5 LibWasm: Implement the spec's type matching relations 2026-06-19 17:01:47 +02:00
Ali Mohammad Pur
6d2470dcad LibWasm: Refer to cranelift-compiler by relative path and env override 2026-06-05 19:59:03 +02:00
Ali Mohammad Pur
08221aebab LibWasm: Start execution immediately after validation
This adds a tier-up mechanism at loop edges, making it so we can
seamlessly (ish) transition between interpreted and native code so we
can start running wasm code immediately after validation while
compilation happens in the background, and switching to native code
eventually once we hit a big enough function that would benefit from
being compiled to begin with.
2026-06-05 00:08:11 +02:00
Andreas Kling
164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00
Ali Mohammad Pur
5c1d2004b7 LibWasm: Handle traps emitted from cranelift 2026-06-03 11:51:43 +02:00
Ali Mohammad Pur
68f6c03a67 LibWasm: Correctly handle failed validation 2026-06-03 11:51:43 +02:00
Ali Mohammad Pur
67c03ee103 LibWasm: Declare extern "C" functions instead of disabling the warning
Clang will complain about the diagnostic anyway.
2026-05-31 20:26:22 +02:00
Ali Mohammad Pur
f54ad4ca25 LibWasm: Only build the compiled function table once per module 2026-05-27 09:52:34 +02:00
Ali Mohammad Pur
2419cce8d8 LibWasm+LibWeb: Serialize and save compiled wasm as a cache blob 2026-05-27 09:52:34 +02:00
Ali Mohammad Pur
8e8a8f9270 LibWasm: Tighten the cranelift direct-call lookup paths
Switches the compiled function table from HashMap<u32, ...> to a Vector
indexed by function index. The keys are densely packed up to
functions.size() so the hash probe wasn't buying us anything.

Also drops the bounds check from MemoryInstance::unsafe_get to match
FunctionInstance::unsafe_get; the caller has already proved the address
is in range by the time we get here.
2026-05-27 09:52:34 +02:00
Andreas Kling
f374e72c54 LibWasm: Store try_table catches out of line
TryTableArgs only needs catches for try_table instructions. Reuse the
structured-instruction layout with catch storage in place of the else
target, and keep the catch elements in a FixedArray.

This avoids storing a full Vector inline in every Instruction variant
alternative and keeps the catch storage copyable for the variant.
2026-05-14 12:19:38 +02:00
Andreas Kling
8775f48436 LibWasm: Store structured metadata directly
Validation always fills structured instruction metadata before compiled
expressions are executed. Store the metadata directly instead of using
Optional, and update execution and printing paths accordingly.
2026-05-14 12:19:38 +02:00
Andreas Kling
f22dec54ef LibWasm: Store opcodes in 32 bits
Wasm opcodes only need one byte plus a 24-bit selector for
prefixed instructions. Store them in u32 instead of u64 and reject
selectors that would not fit. Update the Rust opcode generator to
accept the new integer suffixes used by Opcode.h.
2026-05-14 12:19:38 +02:00
Andreas Kling
c9e135cdff LibWasm: Clear FD_CLOEXEC on shm fd before spawning Cranelift child
On macOS, the cranelift JIT compilation step works by creating an
anonymous shared memory segment via shm_open() in the parent process
and passing the fd as an argument to the spawned cranelift-compiler
child. POSIX requires shm_open() to set FD_CLOEXEC on the returned
fd, which caused the child to immediately fail with EBADF when it
tried to read from the inherited fd number.

Clear FD_CLOEXEC after shm_open() so the fd actually survives the
spawn. The Linux memfd_create() path is unaffected since we call it
with flags=0 (no MFD_CLOEXEC), and Windows passes an inheritable
HANDLE instead of an fd.
2026-05-11 09:57:33 +02:00
Ali Mohammad Pur
a36f6abedb LibWasm+LibWeb: Properly track module lifetime with function refs 2026-05-10 16:41:42 +02:00
Ali Mohammad Pur
a33e148339 LibWasm+Meta: Add Cranelift AOT compilation backend
Add an optional Cranelift-based AOT compiler for WebAssembly functions,
enabled via -DENABLE_CRANELIFT_JIT=ON.
2026-05-10 16:41:42 +02:00