Types

Simple types, such as number types are universally valid. However, restrictions apply to most other types, such as reference types, function types, as well as the limits of table types and memory types, which must be checked during validation.

Moreover, block types are converted to plain function types for ease of processing.

Number Types

Number types are always valid.

Cnumtypeok

Vector Types

Vector types are always valid.

Cvectypeok

Heap Types

Concrete heap types are only valid when the type index is, while abstract ones are vacuously valid.

absheaptype

  • The heap type is valid.

Cabsheaptypeok

typeidx

  • The type C.types[typeidx] must be defined in the context.

  • Then the heap type is valid.

C.types[typeidx]=deftypeCtypeidxok

Reference Types

Reference types are valid when the referenced heap type is.

ref null? heaptype

  • The heap type heaptype must be valid.

  • Then the reference type is valid.

CheaptypeokCref null? heaptypeok

Value Types

Valid value types are either valid number types, valid vector types, or valid reference types.

Block Types

Block types may be expressed in one of two forms, both of which are converted to instruction types by the following rules.

typeidx

  • The type C.types[typeidx] must be defined in the context.

  • The expansion of C.funcs[typeidx] must be a function type func [t1][t2].

  • Then the block type is valid as instruction type [t1][t2].

expand(C.types[typeidx])=func [t1][t2]Ctypeidx:[t1][t2]

[valtype?]

  • The value type valtype must either be absent, or valid.

  • Then the block type is valid as instruction type [][valtype?].

(Cvaltypeok)?C[valtype?]:[][valtype?]

Result Types

[t]

  • Each value type ti in the type sequence t must be valid.

  • Then the result type is valid.

(Ctok)C[t]ok

Instruction Types

[t1]x[t2]

C[t1]okC[t2]ok(C.locals[x]=localtype)C[t1]x[t2]ok

Function Types

[t1][t2]

C[t1]okC[t2]okC[t1][t2]ok

Composite Types

func functype

CfunctypeokCfunc functypeok

struct fieldtype

(Cftok)Cstruct ftok

array fieldtype

  • The field type fieldtype must be valid.

  • Then the composite type is valid.

CftokCarray ftok

Field Types

mut storagetype

CstokCmut stok

packedtype

  • The packed type is valid.

Cpackedtypeok

Recursive Types

Recursive types are validated for a specific type index that denotes the index of the type defined by the recursive group.

rec subtype

  • Either the sequence subtype is empty.

  • Or:

  • Then the recursive type is valid for the type index x.

Crec ϵ ok(x)Csubtype ok(x)Crec subtype ok(x+1)Crec subtype subtype ok(x)

sub final? y comptype

|y|1(y<x)(unroll(C.types[y])=sub y comptype)Ccomptypeok(Ccomptypecomptype)Csub final? y comptype ok(x)

Note

The side condition on the index ensures that a declared supertype is a previously defined types, preventing cyclic subtype hierarchies.

Future versions of WebAssembly may allow more than one supertype.

Defined Types

rectype.i

Crectype ok(x)rectype=rec subtypeni<nCrectype.iok

Limits

Limits must have meaningful bounds that are within a given range.

{min n,max m?}

  • The value of n must not be larger than k.

  • If the maximum m? is not empty, then:

    • Its value must not be larger than k.

    • Its value must not be smaller than n.

  • Then the limit is valid within range k.

nk(mk)?(nm)?C{min n,max m?}:k

Table Types

limits reftype

  • The limits limits must be valid within range 2321.

  • The reference type reftype must be valid.

  • Then the table type is valid.

Climits:2321CreftypeokClimits reftypeok

Memory Types

limits

  • The limits limits must be valid within range 216.

  • Then the memory type is valid.

Climits:216Climitsok

Global Types

mut valtype

  • The value type valtype must be valid.

  • Then the global type is valid.

CvaltypeokCmut valtypeok

External Types

func deftype

Cdeftypeokexpand(deftype)=func functypeCfunc deftype

table tabletype

CtabletypeokCtable tabletypeok

mem memtype

CmemtypeokCmem memtypeok

global globaltype

CglobaltypeokCglobal globaltypeok

Defaultable Types

A type is defaultable if it has a default value for initialization.

Value Types

Cnumtypedefaultable
Cvectypedefaultable
C(ref null heaptype)defaultable