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.
¶
The heap type is valid.
¶
The type
must be defined in the context.Then the heap type is valid.
Reference Types¶
Reference types are valid when the referenced heap type is.
¶
The heap type
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.
¶
The type
must be defined in the context.The expansion of
must be a function type .Then the block type is valid as instruction type
.
¶
The value type
must either be absent, or valid.Then the block type is valid as instruction type
.
Result Types¶
¶
Each value type
in the type sequence must be valid.Then the result type is valid.
Instruction Types¶
¶
The result type
must be valid.The result type
must be valid.Each local index
in must be defined in the context.Then the instruction type is valid.
Function Types¶
¶
The result type
must be valid.The result type
must be valid.Then the function type is valid.
Composite Types¶
¶
The function type
must be valid.Then the composite type is valid.
¶
For each field type
in :The field type
must be valid.
Then the composite type is valid.
¶
The field type
must be valid.Then the composite type is valid.
Field Types¶
¶
The storage type
must be valid.Then the field type is valid.
¶
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.
¶
Either the sequence
is empty.Or:
The first sub type of the sequence
must be valid for the type index .The remaining sequence
must be valid for the type index .
Then the recursive type is valid for the type index
.
¶
The composite type
must be valid.The sequence
may be no longer than .For every type index
in :The type index
must be smaller than .The type index
must exist in the context .Let
be the unrolling of the defined type .The sub type
must not contain .Let
be the composite type in .The composite type
must match .
Then the sub type is valid for the type index
.
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¶
¶
The recursive type
must be valid for some type index .Let
be the defined type .The number
must be smaller than the length of the sequence of sub types.Then the defined type is valid.
Limits¶
Limits must have meaningful bounds that are within a given range.
¶
The value of
must not be larger than .If the maximum
is not empty, then:Its value must not be larger than
.Its value must not be smaller than
.
Then the limit is valid within range
.
Table Types¶
¶
The limits
must be valid within range .The reference type
must be valid.Then the table type is valid.
Memory Types¶
¶
The limits
must be valid within range .Then the memory type is valid.
Global Types¶
¶
The value type
must be valid.Then the global type is valid.
External Types¶
¶
The defined type
must be valid.The defined type
must be a function type.Then the external type is valid.
¶
The table type
must be valid.Then the external type is valid.
¶
The memory type
must be valid.Then the external type is valid.
¶
The global type
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
must be:either a number type,
or a vector type,
or a nullable reference type.