Implementation Limitations¶
Implementations typically impose additional restrictions on a number of aspects of a WebAssembly module or execution. These may stem from:
physical resource limits,
constraints imposed by the embedder or its environment,
limitations of selected implementation strategies.
This section lists allowed limitations. Where restrictions take the form of numeric limits, no minimum requirements are given, nor are the limits assumed to be concrete, fixed numbers. However, it is expected that all implementations have “reasonably” large limits to enable common applications.
Note
A conforming implementation is not allowed to leave out individual features. However, designated subsets of WebAssembly may be specified in the future.
Syntactic Limits¶
Structure¶
An implementation may impose restrictions on the following dimensions of a module:
the number of element segments in a module
the number of data segments in a module
the number of parameters in a function type
the number of results in a function type
the number of parameters in a block type
the number of results in a block type
the size of a function body
the size of a structured control instruction
the number of structured control instructions in a function
the nesting depth of structured control instructions
the number of label indices in a \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}\) instruction
the length of an element segment
the length of a data segment
the length of a name
the range of characters in a name
If the limits of an implementation are exceeded for a given module, then the implementation may reject the validation, compilation, or instantiation of that module with an embedder-specific error.
Binary Format¶
For a module given in binary format, additional limitations may be imposed on the following dimensions:
Text Format¶
For a module given in text format, additional limitations may be imposed on the following dimensions:
the size of the source text
the size of any syntactic element
the size of an individual token
the nesting depth of folded instructions
the length of symbolic identifiers
the range of literal characters allowed in the source text
Validation¶
An implementation may defer validation of individual functions until they are first invoked.
If a function turns out to be invalid, then the invocation, and every consecutive call to the same function, results in a trap.
Note
This is to allow implementations to use interpretation or just-in-time compilation for functions. The function must still be fully validated before execution of its body begins.
Execution¶
Restrictions on the following dimensions may be imposed during execution of a WebAssembly program:
the number of allocated module instances
the number of allocated function instances
the number of allocated table instances
the number of allocated memory instances
the number of allocated global instances
the size of a table instance
the size of a memory instance
the number of threads in the global configuration
the number of suspended threads in the global configuration
If the runtime limits of an implementation are exceeded during execution of a computation, then it may terminate that computation and report an embedder-specific error to the invoking code.
Some of the above limits may already be verified during instantiation, in which case an implementation may report exceedance in the same manner as for syntactic limits.
Note
Concrete limits are usually not fixed but may be dependent on specifics, interdependent, vary over time, or depend on other implementation- or embedder-specific situations or events.