Types

Note

In some places, possible types include both type constructors or types denoted by type indices. Thus, the binary format for type constructors corresponds to the encodings of small negative sN values, such that they can unambiguously occur in the same place as (positive) type indices.

Number Types

Number types are encoded by a single byte.

numtype::=0x7Cf64|0x7Df32|0x7Ei64|0x7Fi32

Vector Types

Vector types are also encoded by a single byte.

vectype::=0x7Bv128

Heap Types

Heap types are encoded as either a single byte, or as a type index encoded as a positive signed integer.

absheaptype::=0x69exn|0x6Aarray|0x6Bstruct|0x6Ci31|0x6Deq|0x6Eany|0x6Fextern|0x70func|0x71none|0x72noextern|0x73nofunc|0x74noexnheaptype::=ht:absheaptypeht|x:s33xif x0

Note

The heap type bot cannot occur in a module.

Reference Types

Reference types are either encoded by a single byte followed by a heap type, or, as a short form, directly as an abstract heap type.

reftype::=0x63  ht:heaptyperef null ht|0x64  ht:heaptyperef ht|ht:absheaptyperef null ht

Value Types

Value types are encoded with their respective encoding as a number type, vector type, or reference type.

valtype::=nt:numtypent|vt:vectypevt|rt:reftypert

Note

The value type bot cannot occur in a module.

Value types can occur in contexts where type indices are also allowed, such as in the case of block types. Thus, the binary format for types corresponds to the signed LEB128 encoding of small negative sN values, so that they can coexist with (positive) type indices in the future.

Result Types

Result types are encoded by the respective lists of value types.

resulttype::=t:list(valtype)t

Composite Types

Composite types are encoded by a distinct byte followed by a type encoding of the respective form.

mut::=0x00ϵ|0x01mutcomptype::=0x5E  yt:fieldtypearray yt|0x5F  yt:list(fieldtype)struct yt|0x60  t1:resulttype  t2:resulttypefunc (t1t2)fieldtype::=zt:storagetype  mut?:mutmut? ztstoragetype::=t:valtypet|pt:packtypeptpacktype::=0x77i16|0x78i8

Recursive Types

Recursive types are encoded by the byte 0x4E followed by a list of sub types. Additional shorthands are recognized for unary recursions and sub types without super types.

rectype::=0x4E  st:list(subtype)rec st|st:subtyperec stsubtype::=0x4F  x:list(typeidx)  ct:comptypesub final x ct|0x50  x:list(typeidx)  ct:comptypesub x ct|ct:comptypesub final ϵ ct

Limits

Limits are encoded with a preceding flag indicating whether a maximum is present, and a flag for the address type.

limits::=0x00  n:u64(i32,[n..2641])|0x01  n:u64  m:u64(i64,[n..m])|0x04  n:u64(i32,[n..2641])|0x05  n:u64  m:u64(i64,[n..m])

Memory Types

Memory types are encoded with their limits.

memtype::=(at,lim):limitsat lim page

Table Types

Table types are encoded with their limits and the encoding of their element reference type.

tabletype::=rt:reftype  (at,lim):limitsat lim rt

Global Types

Global types are encoded by their value type and a flag for their mutability.

globaltype::=t:valtype  mut?:mutmut? t

Tag Types

Tag types are encoded by a type index denoting a function type.

tagtype::=0x00  x:typeidxx

Note

In future versions of WebAssembly, the preceding zero byte may encode additional flags.

External Types

External types are encoded by a distiguishing byte followed by an encoding of the respective form of type.

externtype::=0x00  x:typeidxfunc x|0x01  tt:tabletypetable tt|0x02  mt:memtypemem mt|0x03  gt:globaltypeglobal gt|0x04  x:tagtypetag x