Types¶
Various entities in WebAssembly are classified by types. Types are checked during validation, instantiation, and possibly execution.
Number Types¶
Number types classify numeric values.
The types
The types
Number types are transparent, meaning that their bit patterns can be observed. Values of number type can be stored in memories.
Conventions¶
The notation
denotes the bit width of a number type . That is, and .
Vector Types¶
Vector types classify vectors of numeric values processed by vector instructions (also known as SIMD instructions, single instruction multiple data).
The type
Vector types, like number types are transparent, meaning that their bit patterns can be observed. Values of vector type can be stored in memories.
Conventions¶
The notation
for bit width extends to vector types as well, that is, .
Heap Types¶
Heap types classify objects in the runtime store.
The type
The type
A concrete heap type consists of a type index and classifies an object of the respective type defined in some module.
A concrete heap type can also consist of a function type directly. However, this form is representable in neither the binary format nor the text format, such that it cannot be used in a program; it only occurs during validation or execution, as the result of substituting a type index with its definition.
The type
A type of any form is closed when it does not contain a heap type that is a type index, i.e., all type indices have been substituted with their defined type.
Convention¶
denotes the parallel substitution of type indices with function types , provided in type . is shorthand for the substitution where in type .
Reference Types¶
Reference types classify values that are first-class references to objects in the runtime store.
A reference type is characterised by the heap type it points to.
In addition, a reference type of the form
Reference types are opaque, meaning that neither their size nor their bit pattern can be observed. Values of reference type can be stored in tables.
Conventions¶
The reference type
is an abbreviation for .The reference type
is an abbreviation for .
Value Types¶
Value types classify the individual values that WebAssembly code can compute with and the values that a variable accepts.
They are either number types, vector types, reference types, or the unique bottom type, written
The type
Conventions¶
The meta variable
ranges over value types or subclasses thereof where clear from context.
Result Types¶
Result types classify the result of executing instructions or functions, which is a sequence of values, written with brackets.
Instruction Types¶
Instruction types classify the behaviour of instructions or instruction sequences, by describing how they manipulate the operand stack and the initialization status of locals:
An instruction type
Note
Instruction types are only used for validation, they do not occur in programs.
Local Types¶
Local types classify locals, by describing their value type as well as their initialization status:
Note
Local types are only used for validation, they do not occur in programs.
Function Types¶
Function types classify the signature of functions, mapping a vector of parameters to a vector of results. They are also used to classify the inputs and outputs of instructions.
Defined Types¶
Defined types are the ones that can be defined in a module, assigning them a type index.
Note
Future versions of WebAssembly may introduce additional forms of defined types.
Limits¶
Limits classify the size range of resizeable storage associated with memory types and table types.
If no maximum is given, the respective storage can grow to any size.
Memory Types¶
Memory types classify linear memories and their size range.
The limits constrain the minimum and optionally the maximum size of a memory. The limits are given in units of page size.
Table Types¶
Table types classify tables over elements of reference type within a size range.
Like memories, tables are constrained by limits for their minimum and optionally maximum size. The limits are given in numbers of entries.
Note
In future versions of WebAssembly, additional element types may be introduced.
Global Types¶
Global types classify global variables, which hold a value and can either be mutable or immutable.
External Types¶
External types classify imports and external values with their respective types.
Conventions¶
The following auxiliary notation is defined for sequences of external types. It filters out entries of a specific kind in an order-preserving fashion: