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.
Vector Types¶
Vector types are always valid.
Heap Types¶
Concrete heap types are only valid when the type index is, while abstract ones are vacuously valid.
\(\href{../syntax/types.html#syntax-absheaptype}{\mathit{absheaptype}}\)¶
The heap type is valid.
\(\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}\)¶
The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}]\) must be defined in the context.
Then the heap type is valid.
Reference Types¶
Reference types are valid when the referenced heap type is.
\(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}^?~\href{../syntax/types.html#syntax-heaptype}{\mathit{heaptype}}\)¶
The heap type \(\href{../syntax/types.html#syntax-heaptype}{\mathit{heaptype}}\) must be valid.
Then the reference type is valid.
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.
\(\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}\)¶
The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}]\) must be defined in the context.
The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Then the block type is valid as instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).
\([\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}^?]\)¶
The value type \(\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\) must either be absent, or valid.
Then the block type is valid as instruction type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}^?]\).
Result Types¶
\([t^\ast]\)¶
Each value type \(t_i\) in the type sequence \(t^\ast\) must be valid.
Then the result type is valid.
Instruction Types¶
\([t_1^\ast] \rightarrow_{x^\ast} [t_2^\ast]\)¶
The result type \([t_1^\ast]\) must be valid.
The result type \([t_2^\ast]\) must be valid.
Each local index \(x_i\) in \(x^\ast\) must be defined in the context.
Then the instruction type is valid.
Function Types¶
\([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)¶
The result type \([t_1^\ast]\) must be valid.
The result type \([t_2^\ast]\) must be valid.
Then the function type is valid.
Composite Types¶
\(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~\href{../syntax/types.html#syntax-functype}{\mathit{functype}}\)¶
The function type \(\href{../syntax/types.html#syntax-functype}{\mathit{functype}}\) must be valid.
Then the composite type is valid.
\(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\)¶
For each field type \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) in \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\):
The field type \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) must be valid.
Then the composite type is valid.
\(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\)¶
The field type \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) must be valid.
Then the composite type is valid.
Field Types¶
\(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\)¶
The storage type \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) must be valid.
Then the field type is valid.
\(\href{../syntax/types.html#syntax-packedtype}{\mathit{packedtype}}\)¶
The packed type is valid.
Recursive Types¶
Recursive types are validated for a specific type index that denotes the index of the type defined by the recursive group.
\(\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\)¶
Either the sequence \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\) is empty.
Or:
The first sub type of the sequence \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\) must be valid for the type index \(x\).
The remaining sequence \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\) must be valid for the type index \(x + 1\).
Then the recursive type is valid for the type index \(x\).
\(\href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}^?~y^\ast~\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}\)¶
The composite type \(\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}\) must be valid.
The sequence \(y^\ast\) may be no longer than \(1\).
For every type index \(y_i\) in \(y^\ast\):
The type index \(y_i\) must be smaller than \(x\).
The type index \(y_i\) must exist in the context \(C\).
Let \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}_i\) be the unrolling of the defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y_i]\).
The sub type \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}_i\) must not contain \(\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}\).
Let \(\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'_i\) be the composite type in \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}_i\).
The composite type \(\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}\) must match \(\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'_i\).
Then the sub type is valid for the type index \(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¶
\(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}.i\)¶
The recursive type \(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}\) must be valid for some type index \(x\).
Let \(\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\) be the defined type \(\href{../syntax/types.html#syntax-rectype}{\mathit{rectype}}\).
The number \(i\) must be smaller than the length of the sequence \(\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\) of sub types.
Then the defined type is valid.
Limits¶
Limits must have meaningful bounds that are within a given range.
\(\{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{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\).
Table Types¶
\(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}\)¶
The limits \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}\) must be valid within range \(2^{32}-1\).
The reference type \(\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}\) must be valid.
Then the table type is valid.
Memory Types¶
\(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}\)¶
The limits \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}\) must be valid within range \(2^{16}\).
Then the memory type is valid.
Global Types¶
\(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\)¶
The value type \(\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}\) must be valid.
Then the global type is valid.
External Types¶
\(\href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\)¶
The defined type \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) must be valid.
The defined type \(\href{../valid/conventions.html#syntax-deftype}{\mathit{deftype}}\) must be a function type.
Then the external type is valid.
\(\href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}\)¶
The table type \(\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}\) must be valid.
Then the external type is valid.
\(\href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}\)¶
The memory type \(\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}\) must be valid.
Then the external type is valid.
\(\href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}\)¶
The global type \(\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}\) must be valid.
Then the external type is valid.
Defaultable Types¶
A type is defaultable if it has a default value for initialization.
Value Types¶
A defaultable value type \(t\) must be:
either a number type,
or a vector type,
or a nullable reference type.