Ivan Mikushin
Wasm GC (Garbage Collection) is a proposal to enable WebAssembly to natively support garbage collected languages. It introduces:
New types:
New heap types and new ways to define types.
New instructions:
~30 new instructions to manipulate reference types.
WAT syntax: (ref null? <heap-type>)
Heap types classify reference types.
Abstract:
any
, eq
, array
, struct
, func
, extern
Unboxed scalars: i31
Bottom: none
, noextern
, nofunc
User-defined (indexed):
Arrays, Structs, Subtypes
extern
and func
– via reference-types,
(ref null? $t)
– via function-references
funcref
== (ref null func)
externref
== (ref null extern)
anyref
== (ref null any)
nullref
== (ref null
none
)
nullexternref
== (ref null
noextern
)
nullfuncref
== (ref null
nofunc
)
eqref
== (ref null eq)
structref
== (ref null struct)
arrayref
== (ref null array)
i31ref
== (ref null i31)
Subtype – a single type, defined as a subtype of other types.
Recursive type group – a group of mutually recursive types that can refer to each other.
The Wasm GC proposal introduces approximately 30 new instructions, including:
i31.*
: For creating and manipulating "unboxed scalars" (31-bit integer values).
array.*
and struct.*
: For creating and manipulating arrays and structs.
ref.*
: For casting and testing values of reference types.
br_on_*
: For conditional branching depending on values of reference types.
extern.*
: For external reference conversion.
Wasm GC Support in wasm-tools:
Begin implementation in Wasmtime
Enable the proposal in the fuzz targets.
Expose the proposal’s new functionality in Wasmtime API.
(what's already done)
Wasm GC Support in wasm-tools:
wasmparser, wasmprinter: Implemented new type support up to user defined structs, and i31.*
instructions.
wasm-encoder: Implemented only necessary things for now: so that it compiles
Wasm GC spec defines:
Current focus:
Implementation in Wasmtime:
– @imikushin