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 instruction types for ease of processing.
Number Types¶
The number type \({\href{../syntax/types.html#syntax-numtype}{\mathit{numtype}}}\) is always valid.
Vector Types¶
The vector type \({\href{../syntax/types.html#syntax-vectype}{\mathit{vectype}}}\) is always valid.
Type Uses¶
The type use \({\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}}\) is valid if:
The type \(C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[{\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}}]\) exists.
Heap Types¶
The heap type \({\href{../syntax/types.html#syntax-absheaptype}{\mathit{absheaptype}}}\) is always valid.
Reference Types¶
The reference type \((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~{\mathsf{null}^?}~{\href{../syntax/types.html#syntax-heaptype}{\mathit{heaptype}}})\) is valid if:
Value Types¶
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is valid if:
Either:
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is of the form \({\href{../syntax/types.html#syntax-numtype}{\mathit{numtype}}}\).
The number type \({\href{../syntax/types.html#syntax-numtype}{\mathit{numtype}}}\) is valid.
Or:
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is of the form \({\href{../syntax/types.html#syntax-vectype}{\mathit{vectype}}}\).
The vector type \({\href{../syntax/types.html#syntax-vectype}{\mathit{vectype}}}\) is valid.
Or:
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is of the form \({\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}}\).
The reference type \({\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}}\) is valid.
Or:
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is of the form \(\href{../valid/conventions.html#syntax-valtype-ext}{\mathsf{bot}}\).
Result Types¶
The result type \({t^\ast}\) is valid if:
For all \(t\) in \({t^\ast}\):
The value type \(t\) is valid.
Block Types¶
Block types may be expressed in one of two forms, both of which are converted to instruction types by the following rules.
The block type \({\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}}\) is valid as the instruction type \({t_1^\ast}~\rightarrow~{t_2^\ast}\) if:
The type \(C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[{\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}}]\) exists.
The expansion of the type \(C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[{\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}}]\) is the composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast}~\href{../syntax/types.html#syntax-comptype}{\rightarrow}~{t_2^\ast})\).
The block type \({{\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}^?}\) is valid as the instruction type \(\epsilon~\rightarrow~{{\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}^?}\) if:
If \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is defined, then:
The value type \({\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}\) is valid.
Instruction Types¶
The instruction type \({t_1^\ast}~{\mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}}_{{x^\ast}}\,{t_2^\ast}\) is valid if:
The result type \({t_1^\ast}\) is valid.
The result type \({t_2^\ast}\) is valid.
For all \(x\) in \({x^\ast}\):
The local \(C{.}\href{../valid/conventions.html#context}{\mathsf{locals}}{}[x]\) exists.
Composite Types¶
The composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~{{\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}}^\ast})\) is valid if:
For all \({\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}}\) in \({{\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}}^\ast}\):
The field type \({\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}}\) is valid.
The composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~{\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}})\) is valid if:
The field type \({\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}}\) is valid.
The composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast}~\href{../syntax/types.html#syntax-comptype}{\rightarrow}~{t_2^\ast})\) is valid if:
The result type \({t_1^\ast}\) is valid.
The result type \({t_2^\ast}\) is valid.
The field type \(({\mathsf{mut}^?}~{\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}})\) is valid if:
The storage type \({\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}}\) is valid.
The packed type \({\href{../syntax/types.html#syntax-packtype}{\mathit{packtype}}}\) is always valid.
Recursive Types¶
Recursive types are validated with respect to the first type index defined by the recursive group.
\(\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}^\ast\)¶
The recursive type \((\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~{{\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}}^\ast})\) is valid for the type index \(x\) if:
Either:
The sub type sequence \({{\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}}^\ast}\) is empty.
Or:
The sub type sequence \({{\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}}^\ast}\) is of the form \({\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}}_1~{{\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}'}^\ast}\).
The sub type \({\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}}_1\) is valid for the type index \(x\).
The recursive type \((\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~{{\href{../syntax/types.html#syntax-subtype}{\mathit{subtype}}'}^\ast})\) is valid for the type index \(x + 1\).
\(\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 sub type \((\href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~{\mathsf{final}^?}~{x^\ast}~{\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}})\) is valid for the type index \(x_0\) if:
The length of \({x^\ast}\) is less than or equal to \(1\).
For all \(x\) in \({x^\ast}\):
The index \(x\) is less than \(x_0\).
The type \(C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x]\) exists.
The sub type \({\href{../valid/conventions.html#aux-unroll-deftype}{\mathrm{unroll}}}(C{.}\href{../valid/conventions.html#context}{\mathsf{types}}{}[x])\) is of the form \((\href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~{{x'}^\ast}~{\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'})\).
\({{\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'}^\ast}\) is the concatenation of all such \({\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'}\).
The composite type \({\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}}\) is valid.
For all \({\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'}\) in \({{\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'}^\ast}\):
The composite type \({\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}}\) matches the composite type \({\href{../syntax/types.html#syntax-comptype}{\mathit{comptype}}'}\).
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.
Limits¶
Limits must have meaningful bounds that are within a given range.
The limits range \({}[ n \href{../syntax/types.html#syntax-limits}{\,{..}\,} m ]\) is valid within \(k\) if:
\(n\) is less than or equal to \(m\).
\(m\) is less than or equal to \(k\).
Tag Types¶
The tag type \({\href{../syntax/types.html#syntax-typeuse}{\mathit{typeuse}}}\) is valid if:
The type use \({\href{../syntax/types.html#syntax-typeuse}{\mathit{typeuse}}}\) is valid.
The expansion of the context \(C\) is the composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast}~\href{../syntax/types.html#syntax-comptype}{\rightarrow}~{t_2^\ast})\).
Global Types¶
The global type \(({\mathsf{mut}^?}~t)\) is valid if:
The value type \(t\) is valid.
Memory Types¶
The memory type \(({\href{../syntax/types.html#syntax-addrtype}{\mathit{addrtype}}}~{\href{../syntax/types.html#syntax-limits}{\mathit{limits}}}~\href{../syntax/types.html#syntax-memtype}{\mathsf{page}})\) is valid if:
The limits range \({\href{../syntax/types.html#syntax-limits}{\mathit{limits}}}\) is valid within \({2^{16}}\).
Table Types¶
The table type \(({\href{../syntax/types.html#syntax-addrtype}{\mathit{addrtype}}}~{\href{../syntax/types.html#syntax-limits}{\mathit{limits}}}~{\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}})\) is valid if:
The limits range \({\href{../syntax/types.html#syntax-limits}{\mathit{limits}}}\) is valid within \({2^{32}} - 1\).
The reference type \({\href{../syntax/types.html#syntax-reftype}{\mathit{reftype}}}\) is valid.
External Types¶
The external type \((\href{../syntax/types.html#syntax-externtype}{\mathsf{tag}}~{\href{../syntax/types.html#syntax-tagtype}{\mathit{tagtype}}})\) is valid if:
The external type \((\href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~{\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}})\) is valid if:
The global type \({\href{../syntax/types.html#syntax-globaltype}{\mathit{globaltype}}}\) is valid.
The external type \((\href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~{\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}})\) is valid if:
The memory type \({\href{../syntax/types.html#syntax-memtype}{\mathit{memtype}}}\) is valid.
The external type \((\href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~{\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}})\) is valid if:
The table type \({\href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}}}\) is valid.
The external type \((\href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~{\href{../syntax/types.html#syntax-typeuse}{\mathit{typeuse}}})\) is valid if:
The type use \({\href{../syntax/types.html#syntax-typeuse}{\mathit{typeuse}}}\) is valid.
The expansion of the context \(C\) is the composite type \((\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast}~\href{../syntax/types.html#syntax-comptype}{\rightarrow}~{t_2^\ast})\).