Instructions

Instructions are classified by instruction types that describe how they manipulate the operand stack and initialize locals: A type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x^\ast} [t_2^\ast]\) describes the required input stack with argument values of types \(t_1^\ast\) that an instruction pops off and the provided output stack with result values of types \(t_2^\ast\) that it pushes back. Moreover, it enumerates the indices \(x^\ast\) of locals that have been set by the instruction. In most cases, this is empty.

Note

For example, the instruction \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) has type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\), consuming two \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) values and producing one. The instruction \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x\) has type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x} []\), provided \(t\) is the type declared for the local \(x\).

Typing extends to instruction sequences \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\). Such a sequence has an instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x^\ast} [t_2^\ast]\) if the accumulative effect of executing the instructions is consuming values of types \(t_1^\ast\) off the operand stack, pushing new values of types \(t_2^\ast\), and setting all locals \(x^\ast\).

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 \(t\) of one or several individual operands is unconstrained. That is the case for all parametric instructions like \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\) and \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\).

  • stack-polymorphic: the entire (or most of the) instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\) of the instruction is unconstrained. That is the case for all control instructions that perform an unconditional control transfer, such as \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\), \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}\), \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}\), and \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\).

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 \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) instruction is valid with type \([t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\), for any possible number type \(t\). Consequently, both instruction sequences

\[(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~2)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~3)~~\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}{}\]

and

\[(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1.0)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~2.0)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~3)~~\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}{}\]

are valid, with \(t\) in the typing of \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) being instantiated to \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) or \(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}\), respectively.

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) instruction is stack-polymorphic, and hence valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\) for any possible sequences of value types \(t_1^\ast\) and \(t_2^\ast\). Consequently,

\[\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}~~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\]

is valid by assuming type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) for the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) instruction. In contrast,

\[\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~0)~~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\]

is invalid, because there is no possible type to pick for the \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) instruction that would make the sequence well-typed.

The Appendix describes a type checking algorithm that efficiently implements validation of instruction sequences as prescribed by the rules given here.

Numeric Instructions

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\)

  • The instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-unop}{\mathit{unop}}\)

  • The instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-unop}{\mathit{unop}} : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-binop}{\mathit{binop}}\)

  • The instruction is valid with type \([t~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-binop}{\mathit{binop}} : [t~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-testop}{\mathit{testop}}\)

  • The instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-testop}{\mathit{testop}} : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-relop}{\mathit{relop}}\)

  • The instruction is valid with type \([t~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-relop}{\mathit{relop}} : [t~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(t_2\mathsf{.}\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}\mathsf{\_}t_1\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\)

  • The instruction is valid with type \([t_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t_2\mathsf{.}\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}\mathsf{\_}t_1\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^? : [t_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2] }\]

Reference Instructions

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht}\)

  • The heap type \(\mathit{ht}\) must be valid.

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})]\).

\[\frac{ C \href{../valid/types.html#valid-heaptype}{\vdash} \mathit{ht} \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~\mathit{ht} : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.func}}~x\)

  • The function \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be defined in the context.

  • Let \(\mathit{dt}\) be the defined type \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\).

  • The function index \(x\) must be contained in \(C.\href{../valid/conventions.html#context}{\mathsf{refs}}\).

  • The instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{dt})]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x] = \mathit{dt} \qquad x \in C.\href{../valid/conventions.html#context}{\mathsf{refs}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.func}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{dt})] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.is\_null}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\), for any valid heap type \(\mathit{ht}\).

\[\frac{ C \href{../valid/types.html#valid-heaptype}{\vdash} \mathit{ht} \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.is\_null}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.as\_non\_null}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht})]\), for any valid heap type \(\mathit{ht}\).

\[\frac{ C \href{../valid/types.html#valid-heaptype}{\vdash} \mathit{ht} \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.as\_non\_null}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht})] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.eq}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}}) (\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.eq}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}})~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.test}}~\mathit{rt}\)

  • The reference type \(\mathit{rt}\) must be valid.

  • Then the instruction is valid with type \([\mathit{rt}'] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) for any valid reference type \(\mathit{rt}'\) for which \(\mathit{rt}\) matches \(\mathit{rt}'\).

\[\frac{ C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt} \mathrel{\mbox{ok}} \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt'} \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt} \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt}' }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.test}}~\mathit{rt} : [\mathit{rt}'] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

Note

The liberty to pick a supertype \(\mathit{rt}'\) allows typing the instruction with the least precise super type of \(\mathit{rt}\) as input, that is, the top type in the corresponding heap subtyping hierarchy.

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.cast}}~\mathit{rt}\)

  • The reference type \(\mathit{rt}\) must be valid.

  • Then the instruction is valid with type \([\mathit{rt}'] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\mathit{rt}]\) for any valid reference type \(\mathit{rt}'\) for which \(\mathit{rt}\) matches \(\mathit{rt}'\).

\[\frac{ C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt} \mathrel{\mbox{ok}} \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt'} \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt} \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt}' }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.cast}}~\mathit{rt} : [\mathit{rt}'] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\mathit{rt}] }\]

Note

The liberty to pick a supertype \(\mathit{rt}'\) allows typing the instruction with the least precise super type of \(\mathit{rt}\) as input, that is, the top type in the corresponding heap subtyping hierarchy.

Aggregate Reference Instructions

\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a structure type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\).

  • For each field type \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) in \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\):

    • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_i\).

    • Let \(t_i\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_i)\).

  • Let \(t^\ast\) be the concatenation of all \(t_i\).

  • Then the instruction is valid with type \([t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st})^\ast }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x : [(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}))^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new\_default}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a structure type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\).

  • For each field type \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) in \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\):

    • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_i\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_i\).

    • Let \(t_i\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_i)\).

    • The type \(t_i\) must be defaultable.

  • Let \(t^\ast\) be the concatenation of all \(t_i\).

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st})^\ast \qquad (C \href{../valid/types.html#valid-defaultable}{\vdash} \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) \href{../valid/types.html#valid-defaultable}{\mathrel{\mbox{defaultable}}})^\ast }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new\_default}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a structure type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast[y]\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • The extension \(\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\) must be present if and only if \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) is a packed type.

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast \qquad \mathit{ft}^\ast[y] = \href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st} \qquad \href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^? = \epsilon \Leftrightarrow \mathit{st} = \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x~y : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})] }\]

\(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.set}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a structure type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}^\ast[y]\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{ft}^\ast \qquad \mathit{ft}^\ast[y] = \href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{st} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.set}}~x~y : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • Then the instruction is valid with type \([t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x : [\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_default}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • The type \(t\) must be defaultable.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}) \qquad C \href{../valid/types.html#valid-defaultable}{\vdash} \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) \href{../valid/types.html#valid-defaultable}{\mathrel{\mbox{defaultable}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • Then the instruction is valid with type \([t^n] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x~n : [\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})^n] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_elem}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\).

  • The storage type \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) must be a reference type \(\mathit{rt}\).

  • The element segment \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\) must exist.

  • Let \(\mathit{rt}'\) be the reference type \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\).

  • The reference type \(\mathit{rt}'\) must match \(\mathit{rt}\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{rt}) \qquad C \href{../valid/matching.html#match-reftype}{\vdash} C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y] \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_elem}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_data}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\) be \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • The type \(t\) must be a numeric type or a vector type.

  • The data segment \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[y]\) must exist.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}) \qquad \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) = \href{../syntax/types.html#syntax-numtype}{\mathit{numtype}} \lor \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) = \href{../syntax/types.html#syntax-vectype}{\mathit{vectype}} \qquad C.\href{../valid/conventions.html#context}{\mathsf{datas}}[y] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_data}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~x)] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • The extension \(\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\) must be present if and only if \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) is a packed type.

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st}) \qquad \href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^? = \epsilon \Leftrightarrow \mathit{st} = \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~x : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.set}}~x : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.len}}\)

  • The the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{array}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.len}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{array}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.fill}}~x\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{st}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.fill}}~x : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st})~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.copy}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_1\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}_1~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_1\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_1\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}_1\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_2\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}_2~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_2\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}_2\).

  • The storage type \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_2\) must match \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}_1\).

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~y)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{st_1}) \qquad \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\mathit{st_2}) \qquad C \href{../valid/matching.html#match-storagetype}{\vdash} \mathit{st_2} \href{../valid/matching.html#match-storagetype}{\leq} \mathit{st_1} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.copy}}~x~y : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~y)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_data}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • Let \(t\) be the value type \(\href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}})\).

  • The value type \(t\) must be a numeric type or a vector type.

  • The data segment \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[y]\) must exist.

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{st}) \qquad \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) = \href{../syntax/types.html#syntax-numtype}{\mathit{numtype}} \lor \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(\mathit{st}) = \href{../syntax/types.html#syntax-vectype}{\mathit{vectype}} \qquad C.\href{../valid/conventions.html#context}{\mathsf{datas}}[y] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_data}}~x~y : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_elem}}~x~y\)

  • The defined type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must exist.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be an array type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • Let the field type \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) be \(\href{../syntax/types.html#syntax-fieldtype}{\mathit{fieldtype}}\).

  • The prefix \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • The storage type \(\href{../syntax/types.html#syntax-storagetype}{\mathit{storagetype}}\) must be a reference type \(\mathit{rt}\).

  • The element segment \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\) must exist.

  • Let \(\mathit{rt}'\) be the reference type \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\).

  • The reference type \(\mathit{rt}'\) must match \(\mathit{rt}\).

  • Then the instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}~\mathit{rt}) \qquad C \href{../valid/matching.html#match-reftype}{\vdash} C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y] \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.init\_elem}}~x~y : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Scalar Reference Instructions

\(\href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{ref.i31}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}})]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{ref.i31}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}})] }\]

\(\href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{i31.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{i31.get}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

External Reference Instructions

\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any.convert\_extern}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})]\) for any \(\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?\) that equals \(\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?\).

\[\frac{ \href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^? = \href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^? }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any.convert\_extern}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})] }\]

\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern.convert\_any}}\)

  • The instruction is valid with type \([(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})]\) for any \(\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?\) that equals \(\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?\).

\[\frac{ \href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^? = \href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^? }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern.convert\_any}} : [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_1^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}_2^?~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})] }\]

Vector Instructions

Vector instructions can have a prefix to describe the shape of the operand. Packed numeric types, \(\href{../syntax/types.html#syntax-storagetype}{\mathsf{i8}}\) and \(\href{../syntax/types.html#syntax-storagetype}{\mathsf{i16}}\), are not value types. An auxiliary function maps such packed type shapes to value types:

\[\begin{array}{lll@{\qquad}l} \href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(t\mathsf{x}N) &=& \href{../syntax/types.html#aux-unpacktype}{\mathrm{unpack}}(t) \end{array}\]

The following auxiliary function denotes the number of lanes in a vector shape, i.e., its dimension:

\[\begin{array}{lll@{\qquad}l} \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(t\mathsf{x}N) &=& N \end{array}\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\)

  • The instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvtestop}{\mathit{vvtestop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvtestop}{\mathit{vvtestop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{swizzle}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{swizzle}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{shuffle}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16}\)

  • For all \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}_i\), in \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16}\), \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}_i\) must be smaller than \(32\).

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ (\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 32)^{16} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{shuffle}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{splat}}\)

  • Let \(t\) be \(\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).

  • The instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{splat}} : [\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extract\_lane}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • The lane index \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) must be smaller than \(\href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})]\).

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extract\_lane}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{replace\_lane}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • The lane index \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) must be smaller than \(\href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).

  • Let \(t\) be \(\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\).

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{replace\_lane}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../valid/instructions.html#aux-unpackshape}{\mathrm{unpack}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vtestop}{\mathit{vtestop}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vtestop}{\mathit{vtestop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}^?\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\mathsf{\_zero}^?\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}^?\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\mathsf{\_zero}^? : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{narrow}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{narrow}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{bitmask}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{bitmask}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{dot}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_s}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{dot}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_s} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extmul}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extmul}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extadd\_pairwise}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • The instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extadd\_pairwise}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

Parametric Instructions

\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\)

  • The instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\), for any valid value type \(t\).

\[\frac{ C \href{../valid/types.html#valid-valtype}{\vdash} t \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}} : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Note

Both \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\) and \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) without annotation are value-polymorphic instructions.

\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}~(t^\ast)^?\)

  • If \(t^\ast\) is present, then:

    • The result type \([t^\ast]\) must be valid.

    • The length of \(t^\ast\) must be \(1\).

    • Then the instruction is valid with type \([t^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast]\).

  • Else:

    • The instruction is valid with type \([t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\), for any valid value type \(t\) that matches some number type or vector type.

\[\frac{ C \href{../valid/types.html#valid-resulttype}{\vdash} [t] \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}~t : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] } \qquad \frac{ C \href{../valid/types.html#valid-resulttype}{\vdash} [t] \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-resulttype}{\vdash} [t] \href{../valid/matching.html#match-resulttype}{\leq} [\href{../syntax/types.html#syntax-numtype}{\mathit{numtype}}] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}} : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] } \qquad \frac{ \vdash t \leq \href{../syntax/types.html#syntax-vectype}{\mathit{vectype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}} : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

Note

In future versions of WebAssembly, \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) may allow more than one value per choice.

Variable Instructions

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.get}}~x\)

  • The local \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) must be defined in the context.

  • Let \(\href{../valid/conventions.html#syntax-init}{\mathit{init}}~t\) be the local type \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\).

  • The initialization status \(\href{../valid/conventions.html#syntax-init}{\mathit{init}}\) must be \(\href{../valid/conventions.html#syntax-init}{\mathsf{set}}\).

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = \href{../valid/conventions.html#syntax-init}{\mathsf{set}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.get}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x\)

  • The local \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) must be defined in the context.

  • Let \(\href{../valid/conventions.html#syntax-init}{\mathit{init}}~t\) be the local type \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\).

  • Then the instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = \href{../valid/conventions.html#syntax-init}{\mathit{init}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.tee}}~x\)

  • The local \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) must be defined in the context.

  • Let \(\href{../valid/conventions.html#syntax-init}{\mathit{init}}~t\) be the local type \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\).

  • Then the instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = \href{../valid/conventions.html#syntax-init}{\mathit{init}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.tee}}~x : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x\)

  • The global \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\) be the global type \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\).

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.set}}~x\)

  • The global \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\) be the global type \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\).

  • The mutability \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) must be \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\).

  • Then the instruction is valid with type \([t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/types.html#syntax-mut}{\mathsf{var}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.set}}~x : [t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Table Instructions

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.size}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.size}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • Then the instruction is valid with type \([t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}~x : [t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}_1~t_1\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}_2~t_2\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y]\).

  • The reference type \(t_2\) must match \(t_1\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}_1~t_1 \qquad C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}_2~t_2 \qquad C \href{../valid/matching.html#match-reftype}{\vdash} t_2 \href{../valid/matching.html#match-valtype}{\leq} t_1 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t_1\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • The element segment \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\) must be defined in the context.

  • Let \(t_2\) be the reference type \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\).

  • The reference type \(t_2\) must match \(t_1\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t_1 \qquad C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y] = t_2 \qquad C \href{../valid/matching.html#match-reftype}{\vdash} t_2 \href{../valid/matching.html#match-valtype}{\leq} t_1 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{elem.drop}}~x\)

  • The element segment \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[x]\) must be defined in the context.

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{elems}}[x] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{elem.drop}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Memory Instructions

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than the bit width of \(t\) divided by \(8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq |t|/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.load}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.load}N\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than the bit width of \(t\) divided by \(8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq |t|/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.store}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.store}N~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{x}M\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8 \cdot M\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 \cdot M }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{x}M\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_splat}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_splat}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_zero}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_zero}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • The lane index \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) must be smaller than \(128/N\).

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 128/N \qquad C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} < N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • The lane index \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) must be smaller than \(128/N\).

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The alignment \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) must not be larger than \(N/8\).

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\).

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 128/N \qquad C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} < N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.size}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.size}} : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}}\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x\)

  • The memory \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) must be defined in the context.

  • The data segment \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x]\) must be defined in the context.

  • Then the instruction is valid with type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{data.drop}}~x\)

  • The data segment \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x]\) must be defined in the context.

  • Then the instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{data.drop}}~x : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Control Instructions

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{nop}}\)

  • The instruction is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{nop}} : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\)

  • The instruction is valid with any valid type of the form \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C \href{../valid/types.html#valid-instrtype}{\vdash} [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) instruction is stack-polymorphic.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • The block type must be valid as some instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Let \(C'\) be the same context as \(C\), but with the result type \([t_2^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.

  • Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Then the compound instruction is valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The notation \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) inserts the new label type at index \(0\), shifting all others.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • The block type must be valid as some instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x^\ast} [t_2^\ast]\).

  • Let \(C'\) be the same context as \(C\), but with the result type \([t_1^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.

  • Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Then the compound instruction is valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_1^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The notation \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) inserts the new label type at index \(0\), shifting all others.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{if}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{else}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • The block type must be valid as some instruction type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Let \(C'\) be the same context as \(C\), but with the result type \([t_2^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.

  • Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast\) must be valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast\) must be valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

  • Then the compound instruction is valid with type \([t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{if}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{else}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The notation \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) inserts the new label type at index \(0\), shifting all others.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([t^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • Then the instruction is valid with any valid type of the form \([t_1^\ast~t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast] \qquad C \href{../valid/types.html#valid-instrtype}{\vdash} [t_1^\ast~t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l : [t_1^\ast~t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The label index space in the context \(C\) contains the most recent label first, so that \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) performs a relative lookup as expected.

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}\) instruction is stack-polymorphic.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_if}}~l\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([t^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • Then the instruction is valid with type \([t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_if}}~l : [t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast] }\]

Note

The label index space in the context \(C\) contains the most recent label first, so that \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) performs a relative lookup as expected.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}~l^\ast~l_N\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N]\) must be defined in the context.

  • For each label \(l_i\) in \(l^\ast\), the label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) must be defined in the context.

  • There must be a sequence \(t^\ast\) of value types, such that:

    • The result type \([t^\ast]\) matches \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N]\).

    • For all \(l_i\) in \(l^\ast\), the result type \([t^\ast]\) matches \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\).

  • Then the instruction is valid with any valid type of the form \([t_1^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ (C \href{../valid/matching.html#match-resulttype}{\vdash} [t^\ast] \href{../valid/matching.html#match-resulttype}{\leq} C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l])^\ast \qquad C \href{../valid/matching.html#match-resulttype}{\vdash} [t^\ast] \href{../valid/matching.html#match-resulttype}{\leq} C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N] \qquad C \href{../valid/types.html#valid-instrtype}{\vdash} [t_1^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}~l^\ast~l_N : [t_1^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The label index space in the context \(C\) contains the most recent label first, so that \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) performs a relative lookup as expected.

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}\) instruction is stack-polymorphic.

Furthermore, the result type \([t^\ast]\) is also chosen non-deterministically in this rule. Although it may seem necessary to compute \([t^\ast]\) as the greatest lower bound of all label types in practice, a simple linear algorithm does not require this.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_null}}~l\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([t^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • Then the instruction is valid with type \([t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht})]\) for any valid heap type \(\mathit{ht}\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast] \qquad C \href{../valid/types.html#valid-heaptype}{\vdash} \mathit{ht} \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_null}}~l : [t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht})] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_non\_null}}~l\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([{t'}^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • The result type \([{t'}^\ast]\) must contain at least one type.

  • Let the value type \(t_l\) be the last element in the sequence \({t'}^\ast\), and \([t^\ast]\) the remainder of the sequence preceding it.

  • The value type \(t_l\) must be a reference type of the form \(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}^?~\mathit{ht}\).

  • Then the instruction is valid with type \([t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht})] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_non\_null}}~l : [t^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht})] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast}}~l~\mathit{rt}_1~\mathit{rt}_2\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([t_l^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • The type sequence \(t_l^\ast\) must be of the form \(t^\ast~\mathit{rt}'\).

  • The reference type \(\mathit{rt}_1\) must be valid.

  • The reference type \(\mathit{rt}_2\) must be valid.

  • The reference type \(\mathit{rt}_2\) must match \(\mathit{rt}_1\).

  • The reference type \(\mathit{rt}_2\) must match \(\mathit{rt}'\).

  • Let \(\mathit{rt}'_1\) be the type difference between \(\mathit{rt}_1\) and \(\mathit{rt}_2\).

  • Then the instruction is valid with type \([t^\ast~\mathit{rt}_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~\mathit{rt}'_1]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast~\mathit{rt}] \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt}_1 \mathrel{\mbox{ok}} \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt}_2 \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt}_2 \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt}_1 \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt}_2 \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast}}~l~\mathit{rt}_1~\mathit{rt}_2 : [t^\ast~\mathit{rt}_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~\mathit{rt}_1\href{../valid/conventions.html#aux-reftypediff}{\setminus}\mathit{rt}_2] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast\_fail}}~l~\mathit{rt}_1~\mathit{rt}_2\)

  • The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.

  • Let \([t_l^\ast]\) be the result type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).

  • The type sequence \(t_l^\ast\) must be of the form \(t^\ast~\mathit{rt}'\).

  • The reference type \(\mathit{rt}_1\) must be valid.

  • The reference type \(\mathit{rt}_2\) must be valid.

  • The reference type \(\mathit{rt}_2\) must match \(\mathit{rt}_1\).

  • Let \(\mathit{rt}'_1\) be the type difference between \(\mathit{rt}_1\) and \(\mathit{rt}_2\).

  • The reference type \(\mathit{rt}'_1\) must match \(\mathit{rt}'\).

  • Then the instruction is valid with type \([t^\ast~\mathit{rt}_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~\mathit{rt}_2]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast~\mathit{rt}] \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt}_1 \mathrel{\mbox{ok}} \qquad C \href{../valid/types.html#valid-reftype}{\vdash} \mathit{rt}_2 \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt}_2 \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt}_1 \qquad C \href{../valid/matching.html#match-reftype}{\vdash} \mathit{rt}_1\href{../valid/conventions.html#aux-reftypediff}{\setminus}\mathit{rt}_2 \href{../valid/matching.html#match-reftype}{\leq} \mathit{rt} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_on\_cast\_fail}}~l~\mathit{rt}_1~\mathit{rt}_2 : [t^\ast~\mathit{rt}_1] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast~\mathit{rt}_2] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\)

  • The return type \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) must not be absent in the context.

  • Let \([t^\ast]\) be the result type of \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\).

  • Then the instruction is valid with any valid type of the form \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{return}} = [t^\ast] \qquad C \href{../valid/types.html#valid-instrtype}{\vdash} [t_1^\ast~t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] \mathrel{\mbox{ok}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}} : [t_1^\ast~t^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

Note

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\) instruction is stack-polymorphic.

\(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) is absent (set to \(\epsilon\)) when validating an expression that is not a function body. This differs from it being set to the empty result type (\([\epsilon]\)), which is the case for functions not returning anything.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call}}~x\)

  • The function \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • Then the instruction is valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call}}~x : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_ref}}~x\)

  • The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • Then the instruction is valid with type \([t_1^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_ref}}~x : [t_1^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_indirect}}~x~y\)

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • The reference type \(t\) must match type \(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{func}}\).

  • The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • Then the instruction is valid with type \([t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast]\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t \qquad C \href{../valid/matching.html#match-valtype}{\vdash} t \href{../valid/matching.html#match-reftype}{\leq} \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{func}} \qquad \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_indirect}}~x~y : [t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_2^\ast] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call}}~x\)

  • The return type \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) must not be absent in the context.

  • The function \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • The result type \([t_2^\ast]\) must match \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\).

  • Then the instruction is valid with any valid type \([t_3^\ast~t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C \href{../valid/matching.html#match-resulttype}{\vdash} [t_2^\ast] \href{../valid/matching.html#match-resulttype}{\leq} C.\href{../valid/conventions.html#context}{\mathsf{return}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call}}~x : [t_3^\ast~t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast] }\]

Note

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call}}\) instruction is stack-polymorphic.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_ref}}~x\)

  • The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • The result type \([t_2^\ast]\) must match \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\).

  • Then the instruction is valid with any valid type \([t_3^\ast~t_1^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast]\).

\[\frac{ \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[x]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C \href{../valid/matching.html#match-resulttype}{\vdash} [t_2^\ast] \href{../valid/matching.html#match-resulttype}{\leq} C.\href{../valid/conventions.html#context}{\mathsf{return}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_ref}}~x : [t_3^\ast~t_1^\ast~(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~x)] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast] }\]

Note

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_ref}}\) instruction is stack-polymorphic.

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_indirect}}~x~y\)

  • The return type \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) must not be empty in the context.

  • The table \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) must be defined in the context.

  • Let \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\) be the table type \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\).

  • The reference type \(t\) must match type \(\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{func}}\).

  • The type \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must be defined in the context.

  • The expansion of \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) must be a function type \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).

  • The result type \([t_2^\ast]\) must match \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\).

  • Then the instruction is valid with type \([t_3^\ast~t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast]\), for any sequences of value types \(t_3^\ast\) and \(t_4^\ast\).

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t \qquad C \href{../valid/matching.html#match-valtype}{\vdash} t \href{../valid/matching.html#match-reftype}{\leq} \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{func}} \qquad \href{../valid/conventions.html#aux-expand-deftype}{\mathrm{expand}}(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]) = \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~[t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C \href{../valid/matching.html#match-resulttype}{\vdash} [t_2^\ast] \href{../valid/matching.html#match-resulttype}{\leq} C.\href{../valid/conventions.html#context}{\mathsf{return}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_indirect}}~x~y : [t_3^\ast~t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t_4^\ast] }\]

Note

The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return\_call\_indirect}}\) instruction is stack-polymorphic.

Instruction Sequences

Typing of instruction sequences is defined recursively.

Empty Instruction Sequence: \(\epsilon\)

  • The empty instruction sequence is valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} []\).

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \epsilon : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [] }\]

Non-empty Instruction Sequence: \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}~{\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}'}^\ast\)

  • The instruction \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}\) must be valid with some type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_1^\ast} [t_2^\ast]\).

  • Let \(C'\) be the same context as \(C\), but with:

    • \(\href{../valid/conventions.html#context}{\mathsf{locals}}\) the same as in C, except that for every local index \(x\) in \(x_1^\ast\), the local type \(\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) has been updated to initialization status \(\href{../valid/conventions.html#syntax-init}{\mathsf{set}}\).

  • Under the context \(C'\), the instruction sequence \({\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}'}^\ast\) must be valid with some type \([t_2^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_2^\ast} [t_3^\ast]\).

  • Then the combined instruction sequence is valid with type \([t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_1^\ast x_2^\ast} [t_3^\ast]\).

\[\begin{split}\frac{ \begin{array}{@{}l@{\qquad}l@{}} C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}} : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_1^\ast} [t_2^\ast] & (C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x_1] = \href{../valid/conventions.html#syntax-init}{\mathit{init}}~t)^\ast \\ C' \href{../valid/instructions.html#valid-instr-seq}{\vdash} {\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}'}^\ast : [t_2^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_2^\ast} [t_3^\ast] & C' = C~(\href{../syntax/conventions.html#notation-replace}{\mathrel{\mbox{with}}} C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x_1] = \href{../valid/conventions.html#syntax-init}{\mathsf{set}}~t)^\ast \end{array} }{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}~{\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}'}^\ast : [t_1^\ast] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}}_{x_1^\ast x_2^\ast} [t_2^\ast~t_3^\ast] }\end{split}\]

Subsumption for \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\)

  • The instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be valid with some type \(\href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}\).

  • The instruction type \(\href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}'\): must be a valid

  • The instruction type \(\href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}\) must match the type \(\href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}'\).

  • Then the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) is also valid with type \(\href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}'\).

\[\frac{ \begin{array}{@{}c@{}} C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}} : \href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}} \qquad C \href{../valid/types.html#valid-instrtype}{\vdash} \href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}' \mathrel{\mbox{ok}} \qquad C \href{../valid/matching.html#match-instrtype}{\vdash} \href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}} \href{../valid/matching.html#match-instrtype}{\leq} \href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}' \end{array} }{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : \href{../valid/conventions.html#syntax-instrtype}{\mathit{instrtype}}' }\]

Note

In combination with the previous rule, subsumption allows to compose instructions whose types would not directly fit otherwise. For example, consider the instruction sequence

\[(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\]

To type this sequence, its subsequence \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) needs to be valid with an intermediate type. But the direct type of \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)\) is \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\), not matching the two inputs expected by \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\). The subsumption rule allows to weaken the type of \((\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)\) to the supertype \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\), such that it can be composed with \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) and yields the intermediate type \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) for the subsequence. That can in turn be composed with the first constant.

Furthermore, subsumption allows to drop init variables \(x^\ast\) from the instruction type in a context where they are not needed, for example, at the end of the body of a block.

Expressions

Expressions \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\) are classified by result types of the form \([t^\ast]\).

\(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • The instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be valid with type \([] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast]\).

  • Then the expression is valid with result type \([t^\ast]\).

\[\frac{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [] \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} [t^\ast] }{ C \href{../valid/instructions.html#valid-expr}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t^\ast] }\]

Constant Expressions

  • In a constant expression \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\) all instructions in \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be constant.

  • A constant instruction \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}\) must be:

    • either of the form \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{ref.i31}}\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.func}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new\_default}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_default}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any.convert\_extern}}\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern.convert\_any}}\),

    • or of the form \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x\), in which case \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) must be a global type of the form \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~t\).

\[\frac{ (C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}})^\ast }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~t }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.null}}~t \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-i31}{\mathsf{ref.i31}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref.func}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-struct}{\mathsf{struct.new\_default}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_default}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-array}{\mathsf{array.new\_fixed}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any.convert\_extern}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern.convert\_any}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]

Note

Currently, constant expressions occurring in globals are further constrained in that contained \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}\) instructions are only allowed to refer to imported or previously defined globals. Constant expressions occurring in tables may only have \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}\) instructions that refer to imported globals. This is enforced in the validation rule for modules by constraining the context \(C\) accordingly.

The definition of constant expression may be extended in future versions of WebAssembly.