Commit Graph

20 Commits

Author SHA1 Message Date
Jelle Raaijmakers
fa1417114e LibWasm: Implement call_ref and return_call_ref instructions
These are part of the typed function references proposal, which is now
widely used by toolchains like wasm-bindgen. This makes sites like
wordsalad.online load in Ladybird.
2026-03-07 16:05:20 +01:00
Jelle Raaijmakers
f764b881bc LibWasm: Add reference type subtyping to the validator
The typed function references proposal requires subtype checking: e.g.
(ref $t) is a subtype of (ref func), and a non-nullable reference is a
subtype of its nullable counterpart. This is needed for correct
validation of `call_ref` and `return_call_ref`.
2026-03-07 16:05:20 +01:00
Jelle Raaijmakers
f78fa73a48 LibWasm: Remove unused current_module field 2026-03-07 16:05:20 +01:00
Marcus Nilsson
21c827e8af LibWasm: Parse and validate array types
This patch makes this parse
```wat
(module
  (type $a (array i32))
)
```
2026-02-10 13:00:16 +01:00
Marcus Nilsson
27a66c33c5 LibWasm: Validate struct types and type section
Spec tests struct.{3,4} are enabled again as they are now correctly
validated.
2026-02-10 13:00:16 +01:00
Marcus Nilsson
5fa9747105 LibWasm: Parse and validate typeuse references
This adds parsing of `(ref typeidx)` and validates that `typeidx` is a
valid index. Currently, nullability of the reference is lost.

A bug causing the code below to fail parsing has been fixed.
```wat
(module
  (type $T (struct (field i32) (field f32)))
  (type $T1 (struct (field i32) (field f32)))
  (; many more types... ;)
  (type $T64 (struct (field i32) (field f32)))
  (type $f (func (result (ref null $T64))))
)
```

The spec tests type-equivalence.{0,1,3,13} have been disabled as they
were previously false positives.
2026-02-10 13:00:16 +01:00
Marcus Nilsson
bfa51c2555 LibWasm: Parse struct types and support multiple types in type section
This patch adds support for parsing structs in the type section.

It also removes the assumption that all types in the type section are
function types, adding appropriate validation.

Spec tests struct.3 and struct.4 have been disable as this would
require expanding `ValueType` to include more heap-types.
2026-02-04 14:29:22 +01:00
Ali Mohammad Pur
9a74bf87d8 LibWasm: Minimize runtime overhead for block/branch ops
Preevaluate arity and params to avoid pointer chasing at exec time.
2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
921373a045 LibWasm: Implement call argument forwarding using call records 2026-02-02 14:11:49 +01:00
Ali Mohammad Pur
b89ecfc6bc LibWasm: Split parameters from locals 2026-02-02 14:11:49 +01:00
Undefine
7bccd65b4a LibWasm: Make sure try_table creates a new frame while validating
The spec says that while validating this opcode a new label should
be pushed.

Fixes a crash in instance.wast on WPT.
2025-10-19 17:28:11 +02:00
Undefine
07c86542b6 LibWasm: Properly read and validate limits for I64 memories and tables
Since memory64 got merged into the spec the minimum value for limits
is now actualy 64-bit and the maximum sizes for memories and tables
for I64 address types were increased.

Fixes 5 tests in memory64.wast nad 8 tests in table64.wast on WPT.
2025-10-19 17:28:11 +02:00
Ali Mohammad Pur
d99f663b1a LibWasm: Implement parsing/validation for proposal exception-handling
Actual execution traps for now.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
8138c2f48b LibWasm: Follow the updated spec on instantiation
The spec now permits access to all globals for all segment initializers,
as well as previously-defined globals for the global initializers.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
ddb35dcb5f LibWasm: Accept proposal 'memory64' (but don't actually run it)
This is a WIP implementation.
2025-10-15 01:26:29 +02:00
Ali Mohammad Pur
c0223befe1 LibWasm: Avoid frequent re/deallocations while validating expressions
Freeing and reallocating these vectors was ~6% of runtime when
validating some web-based game.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
f7bdc596b4 LibWasm: Avoid allocations for the label stack as much as possible
Namely, find an upper bound at validation time so we can allocate the
space when entering the frame.

Also drop labels at once instead of popping them off one at a time now
that we're using a Vector.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
8af095f797 LibWasm: Make Wasm::Validator::Stack hold a Vector instead of inheriting 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
dc67f0ad4e LibWasm: Hold on to the stack depth for expressions in the validator
This allows preallocating the value stack when pushing frames, avoiding
repeated reallocs and copies.
2025-08-08 12:54:06 +02:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00