Types¶
Various entities in WebAssembly are classified by types. Types are checked during validation, instantiation, and possibly execution.
Number Types¶
Number types classify numeric values.
The types
The types
Number types are transparent, meaning that their bit patterns can be observed. Values of number type can be stored in memories.
Conventions¶
The notation
denotes the bit width of a number type . That is, and .
Vector Types¶
Vector types classify vectors of numeric values processed by vector instructions (also known as SIMD instructions, single instruction multiple data).
The type
Vector types, like number types are transparent, meaning that their bit patterns can be observed. Values of vector type can be stored in memories.
Conventions¶
The notation
for bit width extends to vector types as well, that is, .
Heap Types¶
Heap types classify objects in the runtime store. There are three disjoint hierarchies of heap types:
function types classify functions,
aggregate types classify dynamically allocated managed data, such as structures, arrays, or unboxed scalars,
external types classify external references possibly owned by the embedder.
The values from the latter two hierarchies are interconvertible by ways of the
A heap type is either abstract or concrete.
The abstract type
The abstract type
The abstract type
The abstract type
The abstract types
The abstract type
Note
An
Although the types
A concrete heap type consists of a type index and classifies an object of the respective type defined in a module.
The syntax of heap types is extended with additional forms for the purpose of specifying validation and execution.
Reference Types¶
Reference types classify values that are first-class references to objects in the runtime store.
A reference type is characterised by the heap type it points to.
In addition, a reference type of the form
Reference types are opaque, meaning that neither their size nor their bit pattern can be observed. Values of reference type can be stored in tables.
Conventions¶
The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .The reference type
is an abbreviation for .
Value Types¶
Value types classify the individual values that WebAssembly code can compute with and the values that a variable accepts. They are either number types, vector types, or reference types.
The syntax of value types is extended with additional forms for the purpose of specifying validation.
Conventions¶
The meta variable
ranges over value types or subclasses thereof where clear from context.
Result Types¶
Result types classify the result of executing instructions or functions, which is a sequence of values, written with brackets.
Function Types¶
Function types classify the signature of functions, mapping a vector of parameters to a vector of results. They are also used to classify the inputs and outputs of instructions.
Aggregate Types¶
Aggregate types describe compound objects consisting of multiple values. These are either structures or arrays, which both consist of a list of possibly mutable and possibly packed fields. Structures are heterogeneous, but require static indexing, while arrays need to be homogeneous, but allow dynamic indexing.
Conventions¶
The notation
for bit width extends to packed types as well, that is, and .The auxiliary function
maps a storage type to the value type obtained when accessing a field:
Composite Types¶
Composite types are all types composed from simpler types, including function types and aggregate types.
Recursive Types¶
Recursive types denote a group of mutually recursive composite types, each of which can optionally declare a list of type indices of supertypes that it matches. Each type can also be declared final, preventing further subtyping.
In a module, each member of a recursive type is assigned a separate type index.
The syntax of sub types is generalized for the purpose of specifying validation and execution.
Limits¶
Limits classify the size range of resizeable storage associated with memory types and table types.
If no maximum is given, the respective storage can grow to any size.
Memory Types¶
Memory types classify linear memories and their size range.
The limits constrain the minimum and optionally the maximum size of a memory. The limits are given in units of page size.
Table Types¶
Table types classify tables over elements of reference 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.
Global Types¶
Global types classify global variables, which hold a value and can either be mutable or immutable.
External Types¶
External types classify imports and external values with their respective types.
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: