Types
Number Types
\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}}
& {\href{../text/types.html#text-numtype}{\mathtt{numtype}}} & ::= & \mbox{‘\texttt{i32}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}} \\
& & | & \mbox{‘\texttt{i64}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle64}} \\
& & | & \mbox{‘\texttt{f32}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{f\scriptstyle32}} \\
& & | & \mbox{‘\texttt{f64}’} & \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{‘\texttt{v128}’} & \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{‘\texttt{any}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{any}} \\
& & | & \mbox{‘\texttt{eq}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}} \\
& & | & \mbox{‘\texttt{i31}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{i\scriptstyle31}} \\
& & | & \mbox{‘\texttt{struct}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{struct}} \\
& & | & \mbox{‘\texttt{array}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{array}} \\
& & | & \mbox{‘\texttt{none}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{none}} \\
& & | & \mbox{‘\texttt{func}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{func}} \\
& & | & \mbox{‘\texttt{nofunc}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{nofunc}} \\
& & | & \mbox{‘\texttt{exn}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{exn}} \\
& & | & \mbox{‘\texttt{noexn}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{noexn}} \\
& & | & \mbox{‘\texttt{extern}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}} \\
& & | & \mbox{‘\texttt{noextern}’} & \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{‘\texttt{null}’} & \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{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~{\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}^?}~{\mathit{ht}} \\
\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{‘\texttt{anyref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{any}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{eqref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{eq}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{i31ref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{i31}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{structref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{struct}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{arrayref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{array}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{nullref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{none}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{funcref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{func}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{nullfuncref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{nofunc}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{exnref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{exn}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{nullexnref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{noexn}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{externref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{extern}’}~~\mbox{‘\texttt{{)}}’} \\
& & | & \mbox{‘\texttt{nullexternref}’} & \quad\equiv\quad{} & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{ref}’}~~\mbox{‘\texttt{null}’}~~\mbox{‘\texttt{noextern}’}~~\mbox{‘\texttt{{)}}’} \\
\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{‘\texttt{{(}}’}~~\mbox{‘\texttt{struct}’}~~{({\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~{{\mathit{ft}}^\ast}, \{ \href{../text/conventions.html#text-context}{\mathsf{fields}}~{({{\mathit{id}}^?})^\ast} \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{array}’}~~{\mathit{ft}}{:}{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~{\mathit{ft}}, \{ \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{func}’}~~{(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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~{t_1^\ast} \href{../syntax/types.html#syntax-comptype}{\rightarrow} {t_2^\ast}, \{ \}) \\[0.8ex]
& {{\href{../text/types.html#text-comptype}{\mathtt{field}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{field}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & ({\mathit{ft}}, {{\mathit{id}}^?}) \\
& {{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{param}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (t, {{\mathit{id}}^?}) \\
& {{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{result}’}~~t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & t \\[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{‘\texttt{{(}}’}~~\mbox{‘\texttt{mut}’}~~{\mathit{zt}}{:}{{\href{../text/types.html#text-storagetype}{\mathtt{storagetype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} & \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{‘\texttt{i8}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-storagetype}{\mathsf{i\scriptstyle8}} \\
& & | & \mbox{‘\texttt{i16}’} & \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{‘\texttt{{(}}’}~~\mbox{‘\texttt{field}’}~~{{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘\texttt{{)}}’} & \quad\equiv\quad{} & {(\mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{field}’}~~{{\href{../text/types.html#text-fieldtype}{\mathtt{fieldtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’})^\ast} \\
& {{\href{../text/types.html#text-comptype}{\mathtt{param}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{param}’}~~{{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘\texttt{{)}}’} & \quad\equiv\quad{} & {(\mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{param}’}~~{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’})^\ast} \\
& {{\href{../text/types.html#text-comptype}{\mathtt{result}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \dots ~~|~~ \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{result}’}~~{{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}^\ast}~~\mbox{‘\texttt{{)}}’} & \quad\equiv\quad{} & {(\mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{param}’}~~{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’})^\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{‘\texttt{final}’} & \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{‘\texttt{{(}}’}~~\mbox{‘\texttt{sub}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~{{\mathit{fin}}^?}~{x^\ast}~{\mathit{ct}}, {\href{../text/conventions.html#text-context}{I}'}) \\[0.8ex]
& {{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{type}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & ({\mathit{st}}, {\href{../text/conventions.html#text-context}{I}'} \oplus \{ \href{../text/conventions.html#text-context}{\mathsf{types}}~({{\mathit{id}}^?}) \}) \\[0.8ex]
& {{\href{../text/types.html#text-rectype}{\mathtt{rectype}}}}_{{\href{../text/conventions.html#text-context}{I}}} & ::= & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{rec}’}~~{({\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~{{\mathit{st}}^\ast}, {\href{../syntax/conventions.html#notation-concat}{\bigoplus}}\, {{\href{../text/conventions.html#text-context}{I}'}^\ast}) \\
\end{array}\end{split}\]
Abbreviations
Final sub types with no super-types can omit the \(\mbox{‘\texttt{sub}’}\) 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{‘\texttt{{(}}’}~~\mbox{‘\texttt{sub}’}~~\mbox{‘\texttt{final}’}~~{{\href{../text/types.html#text-comptype}{\mathtt{comptype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} \\
\end{array}\end{split}\]
Similarly, singular recursive types can omit the \(\mbox{‘\texttt{rec}’}\) 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{‘\texttt{{(}}’}~~\mbox{‘\texttt{rec}’}~~{{\href{../text/types.html#text-typedef}{\mathtt{typedef}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} \\
\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{‘\texttt{i32}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle32}} \\
& & | & \mbox{‘\texttt{i64}’} & \quad\Rightarrow\quad{} & \href{../syntax/types.html#syntax-numtype}{\mathsf{i\scriptstyle64}} \\
\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{‘\texttt{i32}’} \\
\end{array}\end{split}\]
Limits
\[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}}
& {\href{../text/types.html#text-limits}{\mathtt{limits}}} & ::= & n{:}{\href{../text/values.html#text-int}{\mathtt{u64}}} & \quad\Rightarrow\quad{} & {}[ n \href{../syntax/types.html#syntax-limits}{\,{..}\,} \epsilon ] \\
& & | & n{:}{\href{../text/values.html#text-int}{\mathtt{u64}}}~~m{:}{\href{../text/values.html#text-int}{\mathtt{u64}}} & \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{‘\texttt{{(}}’}~~\mbox{‘\texttt{mut}’}~~t{:}{{\href{../text/types.html#text-valtype}{\mathtt{valtype}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} & \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}}} & \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{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{‘\texttt{{(}}’}~~\mbox{‘\texttt{tag}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{tag}}~{\mathit{jt}}, \{ \href{../text/conventions.html#text-context}{\mathsf{tags}}~({{\mathit{id}}^?}) \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{global}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{global}}~{\mathit{gt}}, \{ \href{../text/conventions.html#text-context}{\mathsf{globals}}~({{\mathit{id}}^?}) \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{memory}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{mem}}~{\mathit{mt}}, \{ \href{../text/conventions.html#text-context}{\mathsf{mems}}~({{\mathit{id}}^?}) \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{table}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{table}}~{\mathit{tt}}, \{ \href{../text/conventions.html#text-context}{\mathsf{tables}}~({{\mathit{id}}^?}) \}) \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{func}’}~~{{\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{‘\texttt{{)}}’} & \quad\Rightarrow\quad{} & (\href{../syntax/types.html#syntax-externtype}{\mathsf{func}}~x, \{ \href{../text/conventions.html#text-context}{\mathsf{funcs}}~({{\mathit{id}}^?}) \}) \\
\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{‘\texttt{{(}}’}~~\mbox{‘\texttt{type}’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’} & \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-rectype}{\mathsf{rec}}~{{\mathit{st}}^\ast}) {.} i \\
{\land}~ {{\mathit{st}}^\ast}{}[i] = \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{locals}}~{(\epsilon)^{{|{t_1^\ast}|}}} \} \\
\end{array}
} \\
& & | & \mbox{‘\texttt{{(}}’}~~\mbox{‘\texttt{type}’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’}~~{(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-rectype}{\mathsf{rec}}~{{\mathit{st}}^\ast}) {.} i \\
{\land}~ {{\mathit{st}}^\ast}{}[i] = \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{locals}}~{({{\mathit{id}}^?})^\ast} \} \\
{\land}~ {\vdash}\, {\href{../text/conventions.html#text-context}{I}'} : \mathsf{ok} \\
\end{array}
} \\
\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{‘\texttt{{(}}’}~~\mbox{‘\texttt{type}’}~~x{:}{{\href{../text/modules.html#text-typeidx}{\mathtt{typeidx}}}}_{{\href{../text/conventions.html#text-context}{I}}}~~\mbox{‘\texttt{{)}}’}~~{{{\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-rectype}{\mathsf{rec}}~(\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}))) {.} 0 \\
{\land}~ ({\href{../text/conventions.html#text-context}{I}}{.}\href{../text/conventions.html#text-context}{\mathsf{typedefs}}{}[i] \neq (\href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~(\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}))) {.} 0)^{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.