Types

Number Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-numtype}{\mathtt{numtype}}} & ::= & \mbox{‘}\mathtt{i32}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}} \\ & & | & \mbox{‘}\mathtt{i64}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle64}} \\ & & | & \mbox{‘}\mathtt{f32}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{f\scriptstyle32}} \\ & & | & \mbox{‘}\mathtt{f64}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{f\scriptstyle64}} \\ \end{array}\end{split}\]

Vector Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-vectype}{\mathtt{vectype}}} & ::= & \mbox{‘}\mathtt{v128}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-vectype}{\mathsf{v\scriptstyle128}} \\ \end{array}\end{split}\]

Heap Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-absheaptype}{\mathtt{absheaptype}}} & ::= & \mbox{‘}\mathtt{any}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{any}} \\ & & | & \mbox{‘}\mathtt{eq}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}} \\ & & | & \mbox{‘}\mathtt{i31}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{i\scriptstyle31}} \\ & & | & \mbox{‘}\mathtt{struct}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{struct}} \\ & & | & \mbox{‘}\mathtt{array}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{array}} \\ & & | & \mbox{‘}\mathtt{none}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{none}} \\ & & | & \mbox{‘}\mathtt{func}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{func}} \\ & & | & \mbox{‘}\mathtt{nofunc}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{nofunc}} \\ & & | & \mbox{‘}\mathtt{exn}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{exn}} \\ & & | & \mbox{‘}\mathtt{noexn}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{noexn}} \\ & & | & \mbox{‘}\mathtt{extern}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}} \\ & & | & \mbox{‘}\mathtt{noextern}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{noextern}} \\[0.8ex] & {{\href{../text/types.html#text-heaptype}{\mathtt{heaptype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & {\mathit{ht}}{:}{\href{../text/types.html#text-absheaptype}{\mathtt{absheaptype}}} & \quad\Rightarrow\quad{} & {\mathit{ht}} \\ & & | & x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & x \\ \end{array}\end{split}\]

Reference Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-null}{\mathtt{null}}} & ::= & \mbox{‘}\mathtt{null}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-reftype}{\mathsf{null}} \\[0.8ex] & {{\href{../text/types.html#text-reftype}{\mathtt{reftype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~{\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}^?}{:}{{\href{../text/types.html#text-null}{\mathtt{null}}}^?}~~{\mathit{ht}}{:}{{\href{../text/types.html#text-heaptype}{\mathtt{heaptype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~{\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}^?}~{\mathit{ht}} \\ & & | & \dots \\ \end{array}\end{split}\]

Abbreviations

There are shorthands for references to abstract heap types.

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-reftype}{\mathtt{reftype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots \\ & & | & \mbox{‘}\mathtt{anyref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{any}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{eqref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{eq}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{i31ref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{i31}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{structref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{struct}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{arrayref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{array}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{nullref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{none}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{funcref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{func}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{nullfuncref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{nofunc}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{exnref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{exn}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{nullexnref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{noexn}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{externref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{extern}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ & & | & \mbox{‘}\mathtt{nullexternref}\mbox{’} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{ref}\mbox{’}~~\mbox{‘}\mathtt{null}\mbox{’}~~\mbox{‘}\mathtt{noextern}\mbox{’}~~\mbox{‘}\mathtt{)}\mbox{’} \\ \end{array}\end{split}\]

Value Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & {\mathit{nt}}{:}{\href{../text/types.html#text-numtype}{\mathtt{numtype}}} & \quad\Rightarrow\quad{} & {\mathit{nt}} \\ & & | & {\mathit{vt}}{:}{\href{../text/types.html#text-vectype}{\mathtt{vectype}}} & \quad\Rightarrow\quad{} & {\mathit{vt}} \\ & & | & {\mathit{rt}}{:}{{\href{../text/types.html#text-reftype}{\mathtt{reftype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & {\mathit{rt}} \\ \end{array}\end{split}\]

Composite Types

Composite types are parsed into their respective abstract representation, paired with the local identifier context generated by their bound field or parameter identifiers:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-comptype}{\mathtt{comptype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{struct}\mbox{’}~~{({\mathit{ft}}, {{\mathit{id}}^?})^\ast}{:}{\href{../text/conventions.html#text-list}{\mathtt{list}}}({{\href{../text/types.html#text-comptype}{\mathtt{field}}}}_{{\href{../text/conventions.html#text-context}{I}}})~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~{{\mathit{ft}}^\ast}, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{fields}}~{({{\mathit{id}}^?})^\ast} \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{array}\mbox{’}~~{\mathit{ft}}{:}{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~{\mathit{ft}}, \{ \begin{array}[t]{@{}l@{}} \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{func}\mbox{’}~~{(t_1, {{\mathit{id}}^?})^\ast}{:}{\href{../text/conventions.html#text-list}{\mathtt{list}}}({{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}})~~{t_2^\ast}{:}{\href{../text/conventions.html#text-list}{\mathtt{list}}}({{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}})~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}, \{ \begin{array}[t]{@{}l@{}} \}\end{array}) \\[0.8ex] & {{\href{../text/types.html#text-comptype}{\mathtt{field}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{field}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~{\mathit{ft}}{:}{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & ({\mathit{ft}}, {{\mathit{id}}^?}) \\ & & | & \dots \\ & {{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{param}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (t, {{\mathit{id}}^?}) \\ & & | & \dots \\ & {{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{result}\mbox{’}~~t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & t \\ & & | & \dots \\[0.8ex] & {{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & {\mathit{zt}}{:}{{\href{../text/types.html#text-storagetype}{\mathtt{storagetype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & {\mathit{zt}} \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{mut}\mbox{’}~~{\mathit{zt}}{:}{{\href{../text/types.html#text-storagetype}{\mathtt{storagetype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-mut}{\mathsf{mut}}~{\mathit{zt}} \\[0.8ex] & {{\href{../text/types.html#text-storagetype}{\mathtt{storagetype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & t \\ & & | & {\mathit{pt}}{:}{\href{../text/types.html#text-packtype}{\mathtt{packtype}}} & \quad\Rightarrow\quad{} & {\mathit{pt}} \\[0.8ex] & {\href{../text/types.html#text-packtype}{\mathtt{packtype}}} & ::= & \mbox{‘}\mathtt{i8}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-storagetype}{\mathsf{i\scriptstyle8}} \\ & & | & \mbox{‘}\mathtt{i16}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-storagetype}{\mathsf{i\scriptstyle16}} \\ \end{array}\end{split}\]

Note

The optional identifier names for parameters in a function type only have documentation purpose. They cannot be referenced from anywhere.

Abbreviations

Multiple anonymous structure fields or parameters or multiple results may be combined into a single declaration:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-comptype}{\mathtt{field}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{field}\mbox{’}~~{{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\equiv\quad{} & {(\mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{field}\mbox{’}~~{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’})^\ast} \\ & {{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{param}\mbox{’}~~{{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\equiv\quad{} & {(\mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{param}\mbox{’}~~{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’})^\ast} \\ & {{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{result}\mbox{’}~~{{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\equiv\quad{} & {(\mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{param}\mbox{’}~~{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’})^\ast} \\ \end{array}\end{split}\]

Recursive Types

Recursive types are parsed into their respective abstract representation, paired with the identifier context generated by their bound identifiers:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-final}{\mathtt{final}}} & ::= & \mbox{‘}\mathtt{final}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-subtype}{\mathsf{final}} \\[0.8ex] & {{\href{../text/types.html#text-subtype}{\mathtt{subtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{sub}\mbox{’}~~{{\mathit{fin}}^?}{:}{{\href{../text/types.html#text-final}{\mathtt{final}}}^?}~~{x^\ast}{:}{\href{../text/conventions.html#text-list}{\mathtt{list}}}({{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}})~~({\mathit{ct}}, {\href{../text/conventions.html#text-context}{I}'}){:}{{\href{../text/types.html#text-comptype}{\mathtt{comptype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~{{\mathit{fin}}^?}~{x^\ast}~{\mathit{ct}}, {\href{../text/conventions.html#text-context}{I}'}) \\ & & | & \dots \\[0.8ex] & {{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{type}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~({\mathit{st}}, {\href{../text/conventions.html#text-context}{I}'}){:}{{\href{../text/types.html#text-subtype}{\mathtt{subtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & ({\mathit{st}}, {\href{../text/conventions.html#text-context}{I}'} \oplus \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{types}}~({{\mathit{id}}^?}) \}\end{array}) \\[0.8ex] & {{\href{../text/types.html#text-rectype}{\mathtt{rectype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{rec}\mbox{’}~~{({\mathit{st}}, {\href{../text/conventions.html#text-context}{I}'})^\ast}{:}{\href{../text/conventions.html#text-list}{\mathtt{list}}}({{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}})~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~{{\mathit{st}}^\ast}, {\mathrm{concat}}_{\mathit{idctxt}}({{\href{../text/conventions.html#text-context}{I}'}^\ast})) \\ & & | & \dots \\ \end{array}\end{split}\]

Abbreviations

Final sub types with no super-types can omit the \(\mbox{‘}\mathtt{sub}\mbox{’}\) keyword and its arguments:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-subtype}{\mathtt{subtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ {{\href{../text/types.html#text-comptype}{\mathtt{comptype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{sub}\mbox{’}~~\mbox{‘}\mathtt{final}\mbox{’}~~{{\href{../text/types.html#text-comptype}{\mathtt{comptype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} \\ \end{array}\end{split}\]

Similarly, singular recursive types can omit the \(\mbox{‘}\mathtt{rec}\mbox{’}\) keyword:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-rectype}{\mathtt{rectype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ {{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{rec}\mbox{’}~~{{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} \\ \end{array}\end{split}\]

Address Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}} & ::= & \mbox{‘}\mathtt{i32}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}} \\ & & | & \mbox{‘}\mathtt{i64}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle64}} \\ & & | & \dots \\ \end{array}\end{split}\]

Abbreviations

The address type can be omitted, in which case it defaults \(\href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}}\):

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}} & ::= & \dots ~~|~~ \epsilon & \quad\equiv\quad{} & \mbox{‘}\mathtt{i32}\mbox{’} \\ \end{array}\end{split}\]

Limits

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-limits}{\mathtt{limits}}}}_{N} & ::= & n{:}{\href{../text/values.html#text-int}{\def\mathdef4028#1{{\mathtt{u}#1}}\mathdef4028{\mathtt{64}}}} & \quad\Rightarrow\quad{} & {}[ n \href{../syntax/types.html#syntax-limits}{\,{..}\,} {2^{N}} ] \\ & & | & n{:}{\href{../text/values.html#text-int}{\def\mathdef4028#1{{\mathtt{u}#1}}\mathdef4028{\mathtt{64}}}}~~m{:}{\href{../text/values.html#text-int}{\def\mathdef4028#1{{\mathtt{u}#1}}\mathdef4028{\mathtt{64}}}} & \quad\Rightarrow\quad{} & {}[ n \href{../syntax/types.html#syntax-limits}{\,{..}\,} m ] \\ \end{array}\end{split}\]

Tag Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-tagtype}{\mathtt{tagtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & (x, {\href{../text/conventions.html#text-context}{I}'}){:}{{\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & x \\ \end{array}\end{split}\]

Global Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & t \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{mut}\mbox{’}~~t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-mut}{\mathsf{mut}}~t \\ \end{array}\end{split}\]

Memory Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-memtype}{\mathtt{memtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & {\mathit{at}}{:}{\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}}~~{\mathit{lim}}{:}{{\href{../text/types.html#text-limits}{\mathtt{limits}}}}_{{|{\mathit{at}}|} - 16} & \quad\Rightarrow\quad{} & {\mathit{at}}~{\mathit{lim}}~\href{../syntax/types.html#syntax-memtype}{\mathsf{page}} \\ \end{array}\end{split}\]

Table Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & {\mathit{at}}{:}{\href{../text/types.html#text-addrtype}{\mathtt{addrtype}}}~~{\mathit{lim}}{:}{{\href{../text/types.html#text-limits}{\mathtt{limits}}}}_{{|{\mathit{at}}|}}~~{\mathit{rt}}{:}{{\href{../text/types.html#text-reftype}{\mathtt{reftype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & \quad\Rightarrow\quad{} & {\mathit{at}}~{\mathit{lim}}~{\mathit{rt}} \\ \end{array}\end{split}\]

External Types

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-externtype}{\mathtt{externtype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{tag}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~{\mathit{jt}}{:}{{\href{../text/types.html#text-tagtype}{\mathtt{tagtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{tag}}~{\mathit{jt}}, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{tags}}~({{\mathit{id}}^?}) \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{global}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~{\mathit{gt}}{:}{{\href{../text/types.html#text-globaltype}{\mathtt{globaltype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~{\mathit{gt}}, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{globals}}~({{\mathit{id}}^?}) \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{memory}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~{\mathit{mt}}{:}{{\href{../text/types.html#text-memtype}{\mathtt{memtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~{\mathit{mt}}, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{mems}}~({{\mathit{id}}^?}) \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{table}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~{\mathit{tt}}{:}{{\href{../text/types.html#text-tabletype}{\mathtt{tabletype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~{\mathit{tt}}, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{tables}}~({{\mathit{id}}^?}) \}\end{array}) \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{func}\mbox{’}~~{{\mathit{id}}^?}{:}{{\href{../text/values.html#text-id}{\mathtt{id}}}^?}~~(x, {\href{../text/conventions.html#text-context}{I}'}){:}{{\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~x, \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{funcs}}~({{\mathit{id}}^?}) \}\end{array}) \\ \end{array}\end{split}\]

Type Uses

A type use is a reference to a type definition. Where it is required to reference a function type, it may optionally be augmented by explicit inlined parameter and result declarations. That allows binding symbolic identifiers to name the local indices of parameters. If inline declarations are given, then their types must match the referenced function type.

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{type}\mbox{’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’} & \quad\Rightarrow\quad{} & (x, {\href{../text/conventions.html#text-context}{I}'}) & \\ &&& \multicolumn{4}{@{}l@{}}{\quad \quad \begin{array}[t]{@{}l@{}} \mbox{if}~ {\href{../text/conventions.html#text-context}{I}}{.}\href{../text/conventions.html#text-context}{\mathsf{typedefs}}{}[x] = \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}) \\ {\land}~ {\href{../text/conventions.html#text-context}{I}'} = \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{locals}}~{(\epsilon)^{{|{t_1^\ast}|}}} \}\end{array} \\ \end{array} } \\ & & | & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{type}\mbox{’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’}~~{(t_1, {{\mathit{id}}^?})^\ast}{:}{{{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~{t_2^\ast}{:}{{{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast} & \quad\Rightarrow\quad{} & (x, {\href{../text/conventions.html#text-context}{I}'}) & \\ &&& \multicolumn{4}{@{}l@{}}{\quad \quad \begin{array}[t]{@{}l@{}} \mbox{if}~ {\href{../text/conventions.html#text-context}{I}}{.}\href{../text/conventions.html#text-context}{\mathsf{typedefs}}{}[x] = \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}) \\ {\land}~ {\href{../text/conventions.html#text-context}{I}'} = \{ \begin{array}[t]{@{}l@{}} \href{../text/conventions.html#text-context}{\mathsf{locals}}~{({{\mathit{id}}^?})^\ast} \}\end{array} \\ {\land}~ {\vdash}\, {\href{../text/conventions.html#text-context}{I}'} : \mathsf{ok} \\ \end{array} } \\ & & | & \dots \\ \end{array}\end{split}\]

Note

If inline declarations are given, their types must be syntactically equal to the types from the indexed definition; possible type substitutions from other definitions that might make them equal are not taken into account. This is to simplify syntactic pre-processing.

The synthesized attribute of a \({\mathtt{typeuse}}\) is a pair consisting of both the used type index and the local identifier context containing possible parameter identifiers.

Note

Both productions overlap for the case that the function type is \(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~\epsilon \href{../syntax/types.html#syntax-comptype}{\rightarrow} \epsilon\). However, in that case, they also produce the same results, so that the choice is immaterial.

The well-formedness condition on \({\href{../text/conventions.html#text-context}{I}'}\) ensures that the parameters do not contain duplicate identifiers.

Abbreviations

A type use may also be replaced entirely by inline parameter and result declarations. In that case, a type index is automatically inserted:

\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} & {{\href{../text/types.html#text-typeuse}{\mathtt{typeuse}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ {(t_1, {{\mathit{id}}^?})^\ast}{:}{{{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~{t_2^\ast}{:}{{{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast} & \quad\equiv\quad{} & \mbox{‘}\mathtt{(}\mbox{’}~~\mbox{‘}\mathtt{type}\mbox{’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘}\mathtt{)}\mbox{’}~~{{{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~{{{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast} & \\ &&& \multicolumn{4}{@{}l@{}}{\quad \quad \begin{array}[t]{@{}l@{}} \mbox{if}~ {\href{../text/conventions.html#text-context}{I}}{.}\href{../text/conventions.html#text-context}{\mathsf{typedefs}}{}[x] = \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}) \\ {\land}~ ({\href{../text/conventions.html#text-context}{I}}{.}\href{../text/conventions.html#text-context}{\mathsf{typedefs}}{}[i] \neq \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~(\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}))^{i<x} \\ \end{array} } \\ \end{array}\end{split}\]

where \(x\) is the smallest existing type index whose recursive type definition parses into a singular, final function type with the same parameters and results. If no such index exists, then a new recursive type of the same form is inserted at the end of the module.

Abbreviations are expanded in the order they appear, such that previously inserted type definitions are reused by consecutive expansions.