ValidationContext

ValidationContext

sealed class ValidationContext

Represents the context accrued throughout the validation process.

ValidationContext objects contain the current AstNode being validated, as well as additional context as specified in the WebAssembly Spec.

From the docs:

Validity of an individual definition is specified relative to a context, which collects relevant information about the surrounding module and the definitions in scope:

  • Types: the list of types defined in the current module.
  • Functions: the list of functions declared in the current module, represented by their function type.
  • Tables: the list of tables declared in the current module, represented by their table type.
  • Memories: the list of memories declared in the current module, represented by their memory type.
  • Globals: the list of globals declared in the current module, represented by their global type.
  • Locals: the list of locals declared in the current function (including parameters), represented by their value type.
  • Labels: the stack of labels accessible from the current position, represented by their result type.
  • Return: (the return type of the current function, represented as an optional result type that is absent when no return is allowed, as in free-standing expressions.

In other words, a context contains a sequence of suitable types for each index space, describing each defined entry in that space. Locals, labels and return type are only used for validating instructions in function bodies, and are left empty elsewhere. The label stack is the only part of the context that changes as validation of an instruction sequence proceeds.

Fields

Name Description
open types: AstNodeIndex<Type>
open functions: AstNodeIndex<TypeUse>
open tables: AstNodeIndex<TableType>
open memories: AstNodeIndex<MemoryType>
open globals: AstNodeIndex<GlobalType>

CompanionObject

ValidationContext

sealed class ValidationContext

Represents the context accrued throughout the validation process.

ValidationContext objects contain the current AstNode being validated, as well as additional context as specified in the WebAssembly Spec.

From the docs:

Validity of an individual definition is specified relative to a context, which collects relevant information about the surrounding module and the definitions in scope:

  • Types: the list of types defined in the current module.
  • Functions: the list of functions declared in the current module, represented by their function type.
  • Tables: the list of tables declared in the current module, represented by their table type.
  • Memories: the list of memories declared in the current module, represented by their memory type.
  • Globals: the list of globals declared in the current module, represented by their global type.
  • Locals: the list of locals declared in the current function (including parameters), represented by their value type.
  • Labels: the stack of labels accessible from the current position, represented by their result type.
  • Return: (the return type of the current function, represented as an optional result type that is absent when no return is allowed, as in free-standing expressions.

In other words, a context contains a sequence of suitable types for each index space, describing each defined entry in that space. Locals, labels and return type are only used for validating instructions in function bodies, and are left empty elsewhere. The label stack is the only part of the context that changes as validation of an instruction sequence proceeds.

Fields

Name Description
val EMPTY_MODULE: Module

An empty ValidationContext.Module instance.

val EMPTY_FUNCTION_BODY: FunctionBody

An empty ValidationContext.Function instance.