Ivan Mikushin, VMware
Staff Engineer @ VMware
Recognized Contributor @ Bytecode Alliance
Working on Wasm GC support in wasm-tools
(as a side-project)
Curiosity ๐บ
Verifiable Computation
Encode algebraic constraints of arithmetic circuit implementing the computation
Hard to use
Easy to create bugs: https://www.zksecurity.xyz/blog/posts/boomerang/
pragma circom 2.0.0;
template A(n){
signal input in;
signal output out;
var array[n];
out <== array[in];
}
component main = A(10);
Error: Non-quadratic constraint was detected statically,
using unknown index will cause the constraint to be
non-quadratic
๐ก Any program execution should be provable
(not just ones in circuit languages)
๐ก In one language (Wasm)
๐ก Just compile everything to Wasm!
What is Wasm GC
Why should I care
Most popular programming languages
๐ฎ will be compiled to Wasm
๐พ require GC
... ๐ฎ will be compiled to Wasm
Empirical law
will (soonโข๏ธ) read:
... ๐พ require GC
What is Wasm GC
โ Why should I care
Garbage Collection
Per Wikipedia:
A form of automatic memory management.
Garbage collector attempts to reclaim allocated memory, that is no longer referenced.
Invented by John McCarthy around 1959 to simplify manual memory management in Lisp.
"proposal to to add garbage collection (GC) support to WebAssembly"
A garbage collector specification
Web-based runtimes already have
high performance GCs
Just need heap types to make use of them
Seamless interoperability between multiple languages
A bunch of new types:
New heap types and new ways to define types.
A bunch of new instructions:
~30 new instructions to manipulate reference types.
(MVP โ Minimum Viable Product)
Reference Types
Heap Types
Subtypes
Recursive Types
New Instructions
Type parameters (polymorphism, generics)
Threads and shared references
Weak references
(a ... ton more)
Reference Types
Heap Types
Subtypes
Recursive Types
New Instructions
A pool of memory used to fulfill memory allocation requests (Wikipedia)
(from Chromium's
extern and func โ from reference-types,
(ref null? $t) โ from function-references
Examples:
(type $A (struct (field (mut i32)) (field i64)))
(type $B (array (mut i32)))
// Go
type A struct {
f0 int32
f1 int64
}
type B []int32
WAT syntax: (ref null? <heap-type>)
Examples:
(type $A (struct)) ;; index = 0
(func $f1 (param (ref null $A)))
(func $f2 (result (ref 0))) ;; same as `(ref $A)`
// Go
type A struct {}
func f1(a *A) {/* */}
func f2() *A {/* */}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)
Examples:
(type $A (struct))
(type $B (sub $A (struct)))
(type $C (sub final $A (struct)))
// Java
class A {}
class B extends A {}
final class C extends A {}
Examples:
(rec
(type $A (struct (field $b (ref null $B))))
(type $B (struct (field $a (ref null $A))))
)
(type $C (struct (field $f0 i32) (field $c (ref null $C))))
// Go
type A struct {
b *B
}
type B struct {
a *A
}
type C struct {
f0 int32
c *C
}
~30 new instructions:
i31.* -- creating and manipulating "unboxed scalars" (31-bit integer values).array.* and struct.* -- creating and manipulating arrays and structs.ref.* -- casting and testing values of reference types.br_on_* -- conditional branching depending on values of reference types.extern.* -- external reference conversion.โ What is Wasm GC
โ Why should I care
WebAssembly Core Specification
Release 2.0 + tail calls + function references + gc
(Draft 2023-08-28)
@imikushin ย โ ย on ๐ (Twitter), GitHub, LinkedIn
Special Thanks to: