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.
\(\href{../syntax/types.html#syntax-heaptype}{\mathsf{func}}\)¶
The heap type is valid.
\(\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}}\)¶
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.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{bot}}\)¶
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 type, reference type, or the bottom type.
\(\href{../syntax/types.html#syntax-valtype}{\mathsf{bot}}\)¶
The value type 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.
\(\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.
Let \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) be the function type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}]\).
Then the block type is valid as instruction type \([t_1^\ast] \href{../syntax/types.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 \([] \href{../syntax/types.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.
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{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}\)¶
The function type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be defined in the context.
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.