Types¶
Various entities in WebAssembly are classified by types.Types are checked duringvalidation,instantiation, and possiblyexecution.
Number Types¶
Number types classify numeric values.
The types\(\mathsf{i{\scriptstyle 32}}\) and\(\mathsf{i{\scriptstyle 64}}\) classify 32 and 64 bit integers, respectively.Integers are not inherently signed or unsigned, their interpretation is determined by individual operations.
The types\(\mathsf{f{\scriptstyle 32}}\) and\(\mathsf{f{\scriptstyle 64}}\) classify 32 and 64 bit floating-point data, respectively.They correspond to the respective binary floating-point representations, also known assingle anddouble precision, as defined by theIEEE 754 standard (Section 3.3).
Number types aretransparent, meaning that their bit patterns can be observed.Values of number type can be stored inmemories.
Conventions¶
The notation\({|t|}\) denotes thebit width of a number type\(t\).That is,\({|\mathsf{i{\scriptstyle 32}}|} = {|\mathsf{f{\scriptstyle 32}}|} = 32\) and\({|\mathsf{i{\scriptstyle 64}}|} = {|\mathsf{f{\scriptstyle 64}}|} = 64\).
Vector Types¶
Vector types classify vectors ofnumeric values processed by vector instructions (also known asSIMD instructions, single instruction multiple data).
The type\(\mathsf{v{\scriptstyle 128}}\) corresponds to a 128 bit vector of packed integer or floating-point data. The packed datacan be interpreted as signed or unsigned integers, single or double precision floating-pointvalues, or a single 128 bit type. The interpretation is determined by individual operations.
Vector types, likenumber types aretransparent, meaning that their bit patterns can be observed.Values of vector type can be stored inmemories.
Conventions¶
The notation\({|t|}\) forbit width extends to vector types as well, that is,\({|\mathsf{v{\scriptstyle 128}}|} = 128\).
Type Uses¶
Atype use is the use site of atype index referencing acomposite typedefined in amodule.It classifies objects of the respective type.
The syntax of type uses isextended with additional forms for the purpose of specifyingvalidation andexecution.
Heap Types¶
Heap types classify objects in the runtimestore.There are three disjoint hierarchies of heap types:
function types classifyfunctions,
aggregate types classify dynamically allocatedmanaged data, such asstructures,arrays, orunboxed scalars,
external types classifyexternal references possibly owned by theembedder.
The values from the latter two hierarchies are interconvertible by ways of the\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{extern{.}convert\_any}}\) and\(\href{../syntax/instructions.html#syntax-instr-extern}{\mathsf{any{.}convert\_extern}}\) instructions.That is, both type hierarchies are inhabited by an isomorphic set of values, but may have different, incompatible representations in practice.
A heap type is eitherabstract orconcrete.A concrete heap type consists of atype use that classifies an object of the respectivetype defined in a module.Abstract types are denoted by individual keywords.
The type\(\mathsf{func}\) denotes the common supertype of allfunction types, regardless of their concrete definition.Dually, the type\(\mathsf{nofunc}\) denotes the common subtype of allfunction types, regardless of their concrete definition.This type has no values.
The type\(\mathsf{exn}\) denotes the common supertype of allexception references.This type has no concrete subtypes.Dually, the type\(\mathsf{noexn}\) denotes the common subtype of all forms of exception references.This type has no values.
The type\(\mathsf{extern}\) denotes the common supertype of all external references received through theembedder.This type has no concrete subtypes.Dually, the type\(\mathsf{noextern}\) denotes the common subtype of all forms of external references.This type has no values.
The type\(\mathsf{any}\) denotes the common supertype of all aggregate types, as well as possibly abstract values produced byinternalizing an external reference of type\(\mathsf{extern}\).Dually, the type\(\mathsf{none}\) denotes the common subtype of all forms of aggregate types.This type has no values.
The type\(\mathsf{eq}\) is a subtype of\(\mathsf{any}\) that includes all types for which references can be compared, i.e., aggregate values and\(\mathsf{i{\scriptstyle 31}}\).
The types\(\mathsf{struct}\) and\(\mathsf{array}\) denote the common supertypes of allstructure andarray aggregates, respectively.
The type\(\mathsf{i{\scriptstyle 31}}\) denotesunboxed scalars, that is, integers injected into references.Their observable value range is limited to 31 bits.
Note
Values of type\(\mathsf{i{\scriptstyle 31}}\) are not actually allocated in the store,but represented in a way that allows them to be mixed with actual references into the store without ambiguity.Engines need to perform some form ofpointer tagging to achieve this,which is why one bit is reserved.Since this type is to be reliably unboxed on all hardware platforms supported by WebAssembly,it cannot be wider than 32 bits minus the tag bit.
Although the types\(\mathsf{none}\),\(\mathsf{nofunc}\),\(\mathsf{noexn}\), and\(\mathsf{noextern}\) are not inhabited by any values,they can be used to form the types of all nullreferences in their respective hierarchy.For example,\((\mathsf{ref}~\mathsf{null}~\mathsf{nofunc})\) is the generic type of a null reference compatible with all function reference types.
The syntax of abstract heap types isextended with additional forms for the purpose of specifyingvalidation andexecution.
Reference Types¶
Reference types classifyvalues that are first-class references to objects in the runtimestore.
A reference type is characterised by theheap type it points to.
In addition, a reference type of the form\(\mathsf{ref}~\mathsf{null}~{\mathit{ht}}\) isnullable, meaning that it can either be a proper reference to\({\mathit{ht}}\) ornull.Other references arenon-null.
Reference types areopaque, meaning that neither their size nor their bit pattern can be observed.Values of reference type can be stored intables but not inmemories.
Conventions¶
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{anyref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{any}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{eqref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{eq}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{i{\scriptstyle31}ref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{i\scriptstyle31}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{structref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{struct}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{arrayref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{array}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}}\) is an abbreviation for\((\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 reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{exnref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{exn}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{externref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{extern}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{nullref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{none}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{nullfuncref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{nofunc}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{nullexnref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{noexn}})\).
The reference type\(\href{../syntax/types.html#syntax-reftype}{\mathsf{nullexternref}}\) is an abbreviation for\((\href{../syntax/types.html#syntax-reftype}{\mathsf{ref}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{null}}~\href{../syntax/types.html#syntax-heaptype}{\mathsf{noextern}})\).
Value Types¶
Value types classify the individual values that WebAssembly code can compute with and the values that a variable accepts.They are eithernumber types,vector types, orreference types.
The syntax of value types isextended with additional forms for the purpose of specifyingvalidation.
Conventions¶
The meta variable\(t\) ranges over value types or subclasses thereof where clear from context.
Result Types¶
Result types classify the result ofexecutinginstructions orfunctions,which is a sequence of values, written with brackets.
Block Types¶
Block types classify theinput andoutput of structuredcontrol instructions delimitingblocks of instructions.
They are given either as atype index that refers to a suitablefunction type reinterpreted as aninstruction type,or as an optionalvalue type inline,which is a shorthand for the instruction type\(\epsilon \rightarrow {{\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}}^?}\).
Composite Types¶
Composite types are all types composed from simpler types,includingfunction types,structure types andarray types.
Function types classify the signature offunctions,mapping a list of parameters to a list of results.They are also used to classify the inputs and outputs ofinstructions.
Aggregate types like structure or array types consist of a list of possibly mutable, possibly packedfield types describing their components.Structures are heterogeneous, but require static indexing, while arrays need to be homogeneous, but allow dynamic indexing.
Conventions¶
The notation\({|t|}\) for thebit width of avalue type\(t\) extends to packed types as well, that is,\({|\mathsf{i{\scriptstyle 8}}|} = 8\) and\({|\mathsf{i{\scriptstyle 16}}|} = 16\).
The auxiliary function\(\href{../syntax/types.html#aux-unpack}{\mathrm{unpack}}\) maps a storage type to thevalue type obtained when accessing a field:
Recursive Types¶
Recursive types denote a group of mutually recursivecomposite types, each of which can optionally declare a list oftype uses of supertypes that itmatches.Each type can also be declaredfinal, preventing further subtyping.
In amodule, each member of a recursive type is assigned a separatetype index.
Address Types¶
Address types are a subset ofnumber types that classify the values that can be used as offsets intomemories andtables.
Conventions¶
Theminimum of two address types is defined as the address type whosebit width is the minimum of the two.
Limits¶
Limits classify the size range of resizeable storage associated withmemory types andtable types.
If no maximum is present,then the respective storage can grow to any valid size.
Tag Types¶
Tag types classify the signaturetagswith atype use referring to the definition of afunction type that declares the types of parameter and result values associated with the tag.The result type is empty for exception tags.
Global Types¶
Global types classifyglobal variables, which hold a value and can either be mutable or immutable.
Memory Types¶
Memory types classify linearmemories and their size range.
The limits constrain the minimum and optionally the maximum size of a memory.The limits are given in units ofpage size.
Table Types¶
Table types classifytables over elements ofreference type within a size range.
Like memories, tables are constrained by limits for their minimum and optionally maximum size.The limits are given in numbers of entries.
Data Types¶
Data types classifydata segments.Since the contents of a data segment requires no further classification, they merely consist of a universal marker\(\mathsf{ok}\) indicating well-formedness.
Element Types¶
Element types classifyelement segments by thereference type of its elements.
External Types¶
External types classifyimports andexternal addresses with their respective types.
For functions, thetype use has to refer to the definition of afunction type.
Note
Future versions of WebAssembly may have additional uses for tags, and may allow non-empty result types in the function types of tags.
Conventions¶
The following auxiliary notation is defined for sequences of external types.It filters out entries of a specific kind in an order-preserving fashion:
