Types

Note

In some places, possible types include both type constructors or types denoted by type indices. Thus, the binary format for type constructors corresponds to the encodings of small negative \(\href{../binary/values.html#binary-sint}{\href{../syntax/values.html#syntax-int}{\mathit{s}N}}\) values, such that they can unambiguously occur in the same place as (positive) type indices.

Number Types

Number types are encoded by a single byte.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{number type} & \href{../binary/types.html#binary-numtype}{\mathtt{numtype}} &::=& \def\mathdef2332#1{\mathtt{0x#1}}\mathdef2332{7F} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|& \def\mathdef2333#1{\mathtt{0x#1}}\mathdef2333{7E} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|& \def\mathdef2334#1{\mathtt{0x#1}}\mathdef2334{7D} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|& \def\mathdef2335#1{\mathtt{0x#1}}\mathdef2335{7C} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\ \end{array}\end{split}\]

Vector Types

Vector types are also encoded by a single byte.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{vector type} & \href{../binary/types.html#binary-vectype}{\mathtt{vectype}} &::=& \def\mathdef2336#1{\mathtt{0x#1}}\mathdef2336{7B} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}} \\ \end{array}\end{split}\]

Heap Types

Heap types are encoded as either a single byte, or as a type index encoded as a positive signed integer.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{abstract heap type} & \href{../binary/types.html#binary-absheaptype}{\mathtt{absheaptype}} &::=& \def\mathdef2337#1{\mathtt{0x#1}}\mathdef2337{74} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{noexn}} \\ &&|& \def\mathdef2338#1{\mathtt{0x#1}}\mathdef2338{73} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{nofunc}} \\ &&|& \def\mathdef2339#1{\mathtt{0x#1}}\mathdef2339{72} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{noextern}} \\ &&|& \def\mathdef2340#1{\mathtt{0x#1}}\mathdef2340{71} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{none}} \\ &&|& \def\mathdef2341#1{\mathtt{0x#1}}\mathdef2341{70} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{func}} \\ &&|& \def\mathdef2342#1{\mathtt{0x#1}}\mathdef2342{6F} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}} \\ &&|& \def\mathdef2343#1{\mathtt{0x#1}}\mathdef2343{6E} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{any}} \\ &&|& \def\mathdef2344#1{\mathtt{0x#1}}\mathdef2344{6D} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}} \\ &&|& \def\mathdef2345#1{\mathtt{0x#1}}\mathdef2345{6C} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{i31}} \\ &&|& \def\mathdef2346#1{\mathtt{0x#1}}\mathdef2346{6B} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{struct}} \\ &&|& \def\mathdef2347#1{\mathtt{0x#1}}\mathdef2347{6A} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{array}} \\ &&|& \def\mathdef2348#1{\mathtt{0x#1}}\mathdef2348{69} &\Rightarrow& \href{../syntax/types.html#syntax-heaptype}{\mathsf{exn}} \\ \def\mathdef2292#1{{}}\mathdef2292{heap type} & \href{../binary/types.html#binary-heaptype}{\mathtt{heaptype}} &::=& \mathit{ht}{:}\href{../binary/types.html#binary-absheaptype}{\mathtt{absheaptype}} &\Rightarrow& \mathit{ht} \\ &&|& x{:}\href{../binary/values.html#binary-int}{\def\mathdef2303#1{{\mathtt{s}#1}}\mathdef2303{\mathtt{33}}} &\Rightarrow& x & (\mathrel{\mbox{if}} x \geq 0) \\ \end{array}\end{split}\]

Reference Types

Reference types are either encoded by a single byte followed by a heap type, or, as a short form, directly as an abstract heap type.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{reference type} & \href{../binary/types.html#binary-reftype}{\mathtt{reftype}} &::=& \def\mathdef2349#1{\mathtt{0x#1}}\mathdef2349{64}~~\mathit{ht}{:}\href{../binary/types.html#binary-heaptype}{\mathtt{heaptype}} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\mathit{ht} \\ &&|& \def\mathdef2350#1{\mathtt{0x#1}}\mathdef2350{63}~~\mathit{ht}{:}\href{../binary/types.html#binary-heaptype}{\mathtt{heaptype}} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht} \\ &&|& \mathit{ht}{:}\href{../binary/types.html#binary-absheaptype}{\mathtt{absheaptype}} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\mathit{ht} \\ \end{array}\end{split}\]

Value Types

Value types are encoded with their respective encoding as a number type, vector type, or reference type.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{value type} & \href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &::=& t{:}\href{../binary/types.html#binary-numtype}{\mathtt{numtype}} &\Rightarrow& t \\ &&|& t{:}\href{../binary/types.html#binary-vectype}{\mathtt{vectype}} &\Rightarrow& t \\ &&|& t{:}\href{../binary/types.html#binary-reftype}{\mathtt{reftype}} &\Rightarrow& t \\ \end{array}\end{split}\]

Note

The type \(\href{../valid/conventions.html#syntax-valtype-ext}{\mathsf{bot}}\) cannot occur in a module.

Value types can occur in contexts where type indices are also allowed, such as in the case of block types. Thus, the binary format for types corresponds to the signed LEB128 encoding of small negative \(\href{../syntax/values.html#syntax-int}{\mathit{s}N}\) values, so that they can coexist with (positive) type indices in the future.

Result Types

Result types are encoded by the respective vectors of value types.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{result type} & \href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}} &::=& t^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-valtype}{\mathtt{valtype}}) &\Rightarrow& [t^\ast] \\ \end{array}\end{split}\]

Function Types

Function types are encoded by the respective vectors of parameter and result types.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{function type} & \href{../binary/types.html#binary-functype}{\mathtt{functype}} &::=& \mathit{rt}_1{:\,}\href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}}~~\mathit{rt}_2{:\,}\href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}} &\Rightarrow& \mathit{rt}_1 \mathrel{\href{../valid/conventions.html#syntax-instrtype}{\rightarrow}} \mathit{rt}_2 \\ \end{array}\end{split}\]

Aggregate Types

Aggregate types are encoded with their respective field types.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{array type} & \href{../binary/types.html#binary-arraytype}{\mathtt{arraytype}} &::=& \mathit{ft}{:\,}\href{../binary/types.html#binary-fieldtype}{\mathtt{fieldtype}} &\Rightarrow& \mathit{ft} \\ \def\mathdef2292#1{{}}\mathdef2292{structure type} & \href{../binary/types.html#binary-structtype}{\mathtt{structtype}} &::=& \mathit{ft}^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-fieldtype}{\mathtt{fieldtype}}) &\Rightarrow& \mathit{ft}^\ast \\ \def\mathdef2292#1{{}}\mathdef2292{field type} & \href{../binary/types.html#binary-fieldtype}{\mathtt{fieldtype}} &::=& \mathit{st}{:}\href{../binary/types.html#binary-storagetype}{\mathtt{storagetype}}~~m{:}\href{../binary/types.html#binary-mut}{\mathtt{mut}} &\Rightarrow& m~\mathit{st} \\ \def\mathdef2292#1{{}}\mathdef2292{storage type} & \href{../binary/types.html#binary-storagetype}{\mathtt{storagetype}} &::=& t{:}\href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &\Rightarrow& t \\ &&|& t{:}\href{../binary/types.html#binary-packedtype}{\mathtt{packedtype}} &\Rightarrow& t \\ \def\mathdef2292#1{{}}\mathdef2292{packed type} & \href{../binary/types.html#binary-packedtype}{\mathtt{packedtype}} &::=& \def\mathdef2351#1{\mathtt{0x#1}}\mathdef2351{78} &\Rightarrow& \href{../syntax/types.html#syntax-storagetype}{\mathsf{i8}} \\ &&|& \def\mathdef2352#1{\mathtt{0x#1}}\mathdef2352{77} &\Rightarrow& \href{../syntax/types.html#syntax-storagetype}{\mathsf{i16}} \\ \end{array}\end{split}\]

Composite Types

Composite types are encoded by a distinct byte followed by a type encoding of the respective form.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{composite type} & \href{../binary/types.html#binary-comptype}{\mathtt{comptype}} &::=& \def\mathdef2353#1{\mathtt{0x#1}}\mathdef2353{5E}~~\mathit{at}{:}\href{../binary/types.html#binary-arraytype}{\mathtt{arraytype}} &\Rightarrow& \href{../syntax/types.html#syntax-comptype}{\mathsf{array}}~\mathit{at} \\ &&|& \def\mathdef2354#1{\mathtt{0x#1}}\mathdef2354{5F}~~\mathit{st}{:}\href{../binary/types.html#binary-structtype}{\mathtt{structtype}} &\Rightarrow& \href{../syntax/types.html#syntax-comptype}{\mathsf{struct}}~\mathit{st} \\ &&|& \def\mathdef2355#1{\mathtt{0x#1}}\mathdef2355{60}~~\mathit{ft}{:}\href{../binary/types.html#binary-functype}{\mathtt{functype}} &\Rightarrow& \href{../syntax/types.html#syntax-comptype}{\mathsf{func}}~\mathit{ft} \\ \end{array}\end{split}\]

Recursive Types

Recursive types are encoded by the byte \(\def\mathdef2356#1{\mathtt{0x#1}}\mathdef2356{4E}\) followed by a vector of sub types. Additional shorthands are recognized for unary recursions and sub types without super types.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{recursive type} & \href{../binary/types.html#binary-rectype}{\mathtt{rectype}} &::=& \def\mathdef2357#1{\mathtt{0x#1}}\mathdef2357{4E}~~\mathit{st}^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-subtype}{\mathtt{subtype}}) &\Rightarrow& \href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~\mathit{st}^\ast \\ &&|& \mathit{st}{:}\href{../binary/types.html#binary-subtype}{\mathtt{subtype}} &\Rightarrow& \href{../syntax/types.html#syntax-rectype}{\mathsf{rec}}~\mathit{st} \\ \def\mathdef2292#1{{}}\mathdef2292{sub type} & \href{../binary/types.html#binary-subtype}{\mathtt{subtype}} &::=& \def\mathdef2358#1{\mathtt{0x#1}}\mathdef2358{50}~~x^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}})~~\mathit{ct}{:}\href{../binary/types.html#binary-comptype}{\mathtt{comptype}} &\Rightarrow& \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~x^\ast~\mathit{ct} \\ &&|& \def\mathdef2359#1{\mathtt{0x#1}}\mathdef2359{4F}~~x^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}})~~\mathit{ct}{:}\href{../binary/types.html#binary-comptype}{\mathtt{comptype}} &\Rightarrow& \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~x^\ast~\mathit{ct} \\ &&|& \mathit{ct}{:}\href{../binary/types.html#binary-comptype}{\mathtt{comptype}} &\Rightarrow& \href{../syntax/types.html#syntax-subtype}{\mathsf{sub}}~\href{../syntax/types.html#syntax-subtype}{\mathsf{final}}~\epsilon~\mathit{ct} \\ \end{array}\end{split}\]

Limits

Limits are encoded with a preceding flag indicating whether a maximum is present, and a flag for the address type.

\[\begin{split}\begin{array}{llclll} \def\mathdef2292#1{{}}\mathdef2292{limits} & \href{../binary/types.html#binary-limits}{\mathtt{limits}} &::=& \def\mathdef2360#1{\mathtt{0x#1}}\mathdef2360{00}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}} &\Rightarrow& (\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}, \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \}) \\ &&|& \def\mathdef2361#1{\mathtt{0x#1}}\mathdef2361{01}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}} &\Rightarrow& (\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}, \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~m \}) \\ &&|& \def\mathdef2362#1{\mathtt{0x#1}}\mathdef2362{04}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}} &\Rightarrow& (\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}, \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \}) \\ &&|& \def\mathdef2363#1{\mathtt{0x#1}}\mathdef2363{05}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef2299#1{{\mathtt{u}#1}}\mathdef2299{\mathtt{64}}} &\Rightarrow& (\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}, \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~m \}) \end{array}\end{split}\]

Memory Types

Memory types are encoded with their limits.

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef2292#1{{}}\mathdef2292{memory type} & \href{../binary/types.html#binary-memtype}{\mathtt{memtype}} &::=& (\mathit{at},\mathit{lim}){:}\href{../binary/types.html#binary-limits}{\mathtt{limits}} &\Rightarrow& \mathit{at}~\mathit{lim} \\ \end{array}\end{split}\]

Table Types

Table types are encoded with their limits and the encoding of their element reference type.

\[\begin{split}\begin{array}{llclll} \def\mathdef2292#1{{}}\mathdef2292{table type} & \href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &::=& \mathit{et}{:}\href{../binary/types.html#binary-reftype}{\mathtt{reftype}}~~(\mathit{at},\mathit{lim}){:}\href{../binary/types.html#binary-limits}{\mathtt{limits}} &\Rightarrow& \mathit{at}~\mathit{lim}~\mathit{et} \\ \end{array}\end{split}\]

Global Types

Global types are encoded by their value type and a flag for their mutability.

\[\begin{split}\begin{array}{llclll} \def\mathdef2292#1{{}}\mathdef2292{global type} & \href{../binary/types.html#binary-globaltype}{\mathtt{globaltype}} &::=& t{:}\href{../binary/types.html#binary-valtype}{\mathtt{valtype}}~~m{:}\href{../binary/types.html#binary-mut}{\mathtt{mut}} &\Rightarrow& m~t \\ \def\mathdef2292#1{{}}\mathdef2292{mutability} & \href{../binary/types.html#binary-mut}{\mathtt{mut}} &::=& \def\mathdef2364#1{\mathtt{0x#1}}\mathdef2364{00} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}} \\ &&|& \def\mathdef2365#1{\mathtt{0x#1}}\mathdef2365{01} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}} \\ \end{array}\end{split}\]

Tag Types

Tag types are encoded by a type index denoting a function type.

\[\begin{split}\begin{array}{llclll} \def\mathdef2292#1{{}}\mathdef2292{tag type} & \href{../binary/types.html#binary-tagtype}{\mathtt{tagtype}} &::=& \def\mathdef2366#1{\mathtt{0x#1}}\mathdef2366{00}~~x{:}\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}} &\Rightarrow& x \\ \end{array}\end{split}\]

Note

In future versions of WebAssembly, the preceding zero byte may encode additional flags.