Instructions¶
Instructions are classified by stack types
The types describe the required input stack with operand types
Note
For example, the instruction
Typing extends to instruction sequences
For some instructions, the typing rules do not fully constrain the type, and therefore allow for multiple types. Such instructions are called polymorphic. Two degrees of polymorphism can be distinguished:
value-polymorphic: the value type
of one or several individual operands is unconstrained. That is the case for all parametric instructions like and .stack-polymorphic: the entire (or most of the) stack type
of the instruction is unconstrained. That is the case for all control instructions that perform an unconditional control transfer, such as , , , and .
In both cases, the unconstrained types or type sequences can be chosen arbitrarily, as long as they meet the constraints imposed for the surrounding parts of the program.
Note
For example, the
and
are valid, with
The
is valid by assuming type
is invalid, because there is no possible type to pick for the
The Appendix describes a type checking algorithm that efficiently implements validation of instruction sequences as prescribed by the rules given here.
Numeric Instructions¶
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
Reference Instructions¶
¶
The instruction is valid with type
.
Note
In future versions of WebAssembly, there may be reference types for which no null reference is allowed.
¶
The instruction is valid with type
, for any reference type .
¶
The function
must be defined in the context.The function index
must be contained in .The instruction is valid with type
.
Vector Instructions¶
Vector instructions can have a prefix to describe the shape of the operand. Packed numeric types,
The following auxiliary function denotes the number of lanes in a vector shape, i.e., its dimension:
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
For all
, in , must be smaller than .The instruction is valid with type
.
¶
Let
be .The instruction is valid with type
.
¶
The lane index
must be smaller than .The instruction is valid with type
.
¶
The lane index
must be smaller than .Let
be .The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
¶
The instruction is valid with type
.
Parametric Instructions¶
¶
The instruction is valid with type
, for any operand type .
Note
Both
¶
If
is present, then:The length of
must be .Then the instruction is valid with type
.
Else:
The instruction is valid with type
, for any operand type that matches some number type or vector type.
Note
In future versions of WebAssembly,
Variable Instructions¶
¶
The local
must be defined in the context.Let
be the value type .Then the instruction is valid with type
.
¶
The local
must be defined in the context.Let
be the value type .Then the instruction is valid with type
.
¶
The local
must be defined in the context.Let
be the value type .Then the instruction is valid with type
.
¶
The global
must be defined in the context.Let
be the global type .Then the instruction is valid with type
.
¶
The global
must be defined in the context.Let
be the global type .The mutability
must be .Then the instruction is valid with type
.
Table Instructions¶
¶
The table
must be defined in the context.Let
be the table type .Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .Then the instruction is valid with type
.
¶
The table
must be defined in the context.Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .The table
must be defined in the context.Let
be the table type .The reference type
must be the same as .Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .The element segment
must be defined in the context.Let
be the reference type .The reference type
must be the same as .Then the instruction is valid with type
.
¶
The element segment
must be defined in the context.Then the instruction is valid with type
.
Memory Instructions¶
¶
The memory
must be defined in the context.The alignment
must not be larger than the bit width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than the bit width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The lane index
must be smaller than .The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The lane index
must be smaller than .The memory
must be defined in the context.The alignment
must not be larger than .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The data segment
must be defined in the context.Then the instruction is valid with type
.
¶
The data segment
must be defined in the context.Then the instruction is valid with type
.
Atomic Memory Instructions¶
¶
The memory
must be defined in the context.The alignment
must be equal to the width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to the width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to the width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to the width of divided by .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.The alignment
must be equal to .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Let
be the memory type .The alignment
must be equal to .Then the instruction is valid with type
.
¶
The memory
must be defined in the context.Let
be the memory type .The alignment
must be equal to divided by .Then the instruction is valid with type
.
¶
The instruction is valid with type
.
Note
The
Control Instructions¶
¶
The instruction is valid with type
.
¶
The instruction is valid with type
, for any sequences of operand types and .
Note
The
¶
The block type must be valid as some function type
.Let
be the same context as , but with the result type prepended to the vector.Under context
, the instruction sequence must be valid with type .Then the compound instruction is valid with type
.
Note
The notation
¶
The block type must be valid as some function type
.Let
be the same context as , but with the result type prepended to the vector.Under context
, the instruction sequence must be valid with type .Then the compound instruction is valid with type
.
Note
The notation
¶
The block type must be valid as some function type
.Let
be the same context as , but with the result type prepended to the vector.Under context
, the instruction sequence must be valid with type .Under context
, the instruction sequence must be valid with type .Then the compound instruction is valid with type
.
Note
The notation
¶
The label
must be defined in the context.Let
be the result type .Then the instruction is valid with type
, for any sequences of operand types and .
Note
The label index space in the context
The
¶
The label
must be defined in the context.Let
be the result type .Then the instruction is valid with type
.
Note
The label index space in the context
¶
The label
must be defined in the context.For all
in , the label must be defined in the context.There must be a sequence
of operand types, such that:For each operand type
in and corresponding type in , matches .For all
in , and for each operand type in and corresponding type in , matches .
Then the instruction is valid with type
, for any sequences of operand types and .
Note
The label index space in the context
The
¶
The return type
must not be absent in the context.Let
be the result type of .Then the instruction is valid with type
, for any sequences of operand types and .
Note
The
¶
The function
must be defined in the context.Then the instruction is valid with type
.
¶
The table
must be defined in the context.Let
be the table type .The reference type
must be .The type
must be defined in the context.Let
be the function type .Then the instruction is valid with type
.
Instruction Sequences¶
Typing of instruction sequences is defined recursively.
Empty Instruction Sequence: ¶
The empty instruction sequence is valid with type
, for any sequence of operand types .
Non-empty Instruction Sequence: ¶
The instruction sequence
must be valid with type , for some sequences of operand types and .The instruction
must be valid with type , for some sequences of operand types and .There must be a sequence of operand types
, such that where the type sequence is as long as .For each operand type
in and corresponding type in , matches .Then the combined instruction sequence is valid with type
.
Expressions¶
Expressions
¶
The instruction sequence
must be valid with some stack type .For each operand type
in and corresponding value type in , matches .Then the expression is valid with result type
.
Constant Expressions¶
In a constant expression
all instructions in must be constant.A constant instruction
must be:either of the form
,or of the form
,or of the form
,or of the form
, in which case must be a global type of the form .
Note
Currently, constant expressions occurring in globals, element, or data segments are further constrained in that contained
The definition of constant expression may be extended in future versions of WebAssembly.