wasm_component

Portable WebAssembly Component Model syntax and validation

wasm
webassembly
component-model
wit
Download zip
Author
Version
0.14.0
License
Apache-2.0
Last updated
17 hours ago
Downloads
3

Dependencies

#wasm_component

Portable syntax, binary decoding, canonical ABI modeling, validation, and text tooling for the WebAssembly Component Model.

The module is independent of Wasmoon runtime objects, JIT execution, WASI, and native host bindings. Product runtimes consume its validated component model through their own adapters.

Milky2018/wasmoon/component is the Wasmoon runtime facade, and Milky2018/wasmoon/wit_binding adapts a resolved portable WIT world to a live Wasmoon component instance.

#Packages

  • Milky2018/wasm_component: component types, binary decoding, and canonical ABI helpers.
  • Milky2018/wasm_component/validator: component validation and immutable validation evidence.
  • Milky2018/wasm_component/text: Component Model text parsing and encoding.
  • Milky2018/wasm_component/wit: WIT parsing, resolution, formatting, and Component Model encoding and decoding.

ComponentParseError

pub suberror ComponentParseError {
InvalidMagic
UnexpectedEndOfInput
Leb128TooLarge
NotAComponent
UnsupportedComponentPreamble(Int, Int)
InvalidTypeSection
InvalidInstanceSection
InvalidAliasSection
InvalidCanonSection
InvalidStartSection
UnsupportedCanonOpcode(Int)
InvalidUtf8
UnsupportedTypeOpcode(Int)
}

ComponentParseError::output

fn ComponentParseError::output(self : ComponentParseError, logger : &Logger) -> Unit

ComponentParseError::to_string

fn ComponentParseError::to_string(self : ComponentParseError) -> String

Alias

pub(all) struct Alias {
sort : Sort
target : AliasTarget
} derive(Eq,
Debug
)

impl Show for Alias

Alias::equal

fn Alias::equal(Alias, Alias) -> Bool

Alias::not_equal

fn Alias::not_equal(x : Alias, y : Alias) -> Bool

Alias::output

fn Alias::output(self : Alias, logger : &Logger) -> Unit

Alias::to_repr

Alias::to_string

fn Alias::to_string(self : Alias) -> String

AliasTarget

pub(all) enum AliasTarget {
Export(Int, String)
CoreExport(Int, String)
Outer(Int, Int)
} derive(Eq,
Debug
)

AliasTarget::equal

fn AliasTarget::equal(AliasTarget, AliasTarget) -> Bool

AliasTarget::not_equal

fn AliasTarget::not_equal(x : AliasTarget, y : AliasTarget) -> Bool

BinaryKind

pub(all) enum BinaryKind {
CoreModule
Component
UnknownPreamble(Int, Int)
} derive(Eq,
Debug
)

impl Show for BinaryKind

BinaryKind::equal

fn BinaryKind::equal(BinaryKind, BinaryKind) -> Bool

BinaryKind::not_equal

fn BinaryKind::not_equal(x : BinaryKind, y : BinaryKind) -> Bool

BinaryKind::output

fn BinaryKind::output(self : BinaryKind, logger : &Logger) -> Unit

BinaryKind::to_string

fn BinaryKind::to_string(self : BinaryKind) -> String

Canon

pub(all) enum Canon {
Lift(Int, Array[CanonOpt], Int)
Lower(Int, Array[CanonOpt])
BackpressureInc
BackpressureDec
ContextGet(
ValueType
, Int)
ContextSet(
ValueType
, Int)
TaskReturn(ValType?, Array[CanonOpt])
TaskCancel
ThreadIndex
ThreadYield(Bool)
ThreadSuspendThenResume(Bool)
ThreadYieldThenResume(Bool)
ThreadSuspendThenPromote(Bool)
ThreadYieldThenPromote(Bool)
ThreadResumeLater
ThreadSuspend(Bool)
ThreadNewIndirect(Int, Int)
WaitableSetNew
WaitableSetWait(Bool, Int)
WaitableSetPoll(Bool, Int)
WaitableSetDrop
WaitableJoin
SubtaskCancel(Bool)
SubtaskDrop
StreamNew(Int)
StreamRead(Int, Array[CanonOpt])
StreamWrite(Int, Array[CanonOpt])
StreamCancelRead(Int, Bool)
StreamCancelWrite(Int, Bool)
StreamDropReadable(Int)
StreamDropWritable(Int)
FutureNew(Int)
FutureRead(Int, Array[CanonOpt])
FutureWrite(Int, Array[CanonOpt])
FutureCancelRead(Int, Bool)
FutureCancelWrite(Int, Bool)
FutureDropReadable(Int)
FutureDropWritable(Int)
ErrorContextNew(Array[CanonOpt])
ErrorContextDebugMessage(Array[CanonOpt])
ErrorContextDrop
ResourceNew(Int)
ResourceDrop(Int)
ResourceRep(Int)
} derive(Eq,
Debug
)

impl Show for Canon

Canon::equal

fn Canon::equal(Canon, Canon) -> Bool

Canon::not_equal

fn Canon::not_equal(x : Canon, y : Canon) -> Bool

Canon::output

fn Canon::output(self : Canon, logger : &Logger) -> Unit

Canon::to_repr

Canon::to_string

fn Canon::to_string(self : Canon) -> String

CanonOpt

pub(all) enum CanonOpt {
StringEncoding(StringEncoding)
Memory(Int)
Realloc(Int)
PostReturn(Int)
CoreType(Int)
Gc
Async
Callback(Int)
} derive(Eq,
Debug
)

CanonOpt::equal

fn CanonOpt::equal(CanonOpt, CanonOpt) -> Bool

CanonOpt::not_equal

fn CanonOpt::not_equal(x : CanonOpt, y : CanonOpt) -> Bool

CanonOpt::to_repr

Component

pub(all) struct Component {
binary : ComponentBinary
core_modules : Array[Bytes]
core_instances : Array[Bytes]
core_types : Array[Bytes]
types : Array[TypeDef]
imports : Array[Import]
exports : Array[Export]
instances : Array[Instance]
aliases : Array[Alias]
canons : Array[Canon]
start : Start?
components : Array[Component]
} derive(Eq,
Debug
)

impl Show for Component

Component::equal

fn Component::equal(Component, Component) -> Bool

Component::isolated_copy

fn Component::isolated_copy(self : Component) -> Component raise ComponentParseError

Rebuild a component that shares no mutable state with self.

Component::not_equal

fn Component::not_equal(x : Component, y : Component) -> Bool

Component::output

fn Component::output(self : Component, logger : &Logger) -> Unit

Component::snapshot_bytes

fn Component::snapshot_bytes(self : Component) -> Bytes

Encode the component's immutable binary snapshot.

Bytes is immutable, so validation evidence can retain and expose this value without granting mutation access to the parsed component graph.

Component::to_string

fn Component::to_string(self : Component) -> String

ComponentBinary

pub struct ComponentBinary {
version : Int
layer : Int
sections : Array[Section]
} derive(Eq,
Debug
)

ComponentBinary::equal

ComponentBinary::not_equal

fn ComponentBinary::not_equal(x : ComponentBinary, y : ComponentBinary) -> Bool

ComponentDecl

pub(all) enum ComponentDecl {
CoreType(Bytes)
Type(TypeDef)
AliasOuter(Int, Int, Int)
AliasInstanceExport(Int, Int, String)
Import(String, Array[NameAttribute], ExternDesc)
Export(String, Array[NameAttribute], ExternDesc)
} derive(Eq,
Debug
)

A subset of component type declarations (enough for WIT-encoded components).

ComponentDecl::equal

ComponentDecl::not_equal

fn ComponentDecl::not_equal(x : ComponentDecl, y : ComponentDecl) -> Bool

CoreInlineExport

pub(all) struct CoreInlineExport {
name : String
sortidx : SortIdx
} derive(Eq,
Debug
)

CoreInlineExport::equal

CoreInlineExport::not_equal

fn CoreInlineExport::not_equal(x : CoreInlineExport, y : CoreInlineExport) -> Bool

CoreInstanceDecl

pub(all) struct CoreInstanceDecl {
expr : CoreInstanceExpr
} derive(Eq,
Debug
)

CoreInstanceDecl::equal

CoreInstanceDecl::not_equal

fn CoreInstanceDecl::not_equal(x : CoreInstanceDecl, y : CoreInstanceDecl) -> Bool

CoreInstanceExpr

pub(all) enum CoreInstanceExpr {
Instantiate(Int, Array[CoreInstantiateArg])
InlineExports(Array[CoreInlineExport])
} derive(Eq,
Debug
)

CoreInstanceExpr::equal

CoreInstanceExpr::not_equal

fn CoreInstanceExpr::not_equal(x : CoreInstanceExpr, y : CoreInstanceExpr) -> Bool

CoreInstantiateArg

pub(all) struct CoreInstantiateArg {
name : String
sortidx : SortIdx
} derive(Eq,
Debug
)

CoreInstantiateArg::equal

CoreInstantiateArg::not_equal

Export

pub(all) struct Export {
name : ExportName
attributes : Array[NameAttribute]
sortidx : SortIdx
desc : ExternDesc?
} derive(Eq,
Debug
)

Export::equal

fn Export::equal(Export, Export) -> Bool

Export::not_equal

fn Export::not_equal(x : Export, y : Export) -> Bool

Export::to_repr

ExportName

pub(all) enum ExportName {
Plain(Bytes)
WithVersion(Bytes, Bytes)
} derive(Eq,
Debug
)

ExportName::equal

fn ExportName::equal(ExportName, ExportName) -> Bool

ExportName::not_equal

fn ExportName::not_equal(x : ExportName, y : ExportName) -> Bool

ExternDesc

pub(all) enum ExternDesc {
CoreModuleType(Int)
FuncType(Int)
Value(ValueBound)
Type(TypeBound)
ComponentType(Int)
InstanceType(Int)
} derive(Eq,
Debug
)

impl Show for ExternDesc

ExternDesc::equal

fn ExternDesc::equal(ExternDesc, ExternDesc) -> Bool

ExternDesc::not_equal

fn ExternDesc::not_equal(x : ExternDesc, y : ExternDesc) -> Bool

ExternDesc::output

fn ExternDesc::output(self : ExternDesc, logger : &Logger) -> Unit

ExternDesc::to_string

fn ExternDesc::to_string(self : ExternDesc) -> String

FuncType

pub(all) struct FuncType {
is_async : Bool
params : Array[Param]
result : ValType?
} derive(Eq,
Debug
)

FuncType::equal

fn FuncType::equal(FuncType, FuncType) -> Bool

FuncType::not_equal

fn FuncType::not_equal(x : FuncType, y : FuncType) -> Bool

FuncType::to_repr

Import

pub(all) struct Import {
name : ImportName
attributes : Array[NameAttribute]
desc : ExternDesc
} derive(Eq,
Debug
)

Import::equal

fn Import::equal(Import, Import) -> Bool

Import::not_equal

fn Import::not_equal(x : Import, y : Import) -> Bool

Import::to_repr

ImportName

pub(all) enum ImportName {
Plain(Bytes)
WithVersion(Bytes, Bytes)
} derive(Eq,
Debug
)

ImportName::equal

fn ImportName::equal(ImportName, ImportName) -> Bool

ImportName::not_equal

fn ImportName::not_equal(x : ImportName, y : ImportName) -> Bool

InlineExport

pub(all) struct InlineExport {
name : String
attributes : Array[NameAttribute]
sortidx : SortIdx
} derive(Eq,
Debug
)

InlineExport::equal

InlineExport::not_equal

fn InlineExport::not_equal(x : InlineExport, y : InlineExport) -> Bool

Instance

pub(all) struct Instance {
expr : InstanceExpr
} derive(Eq,
Debug
)

Instance::equal

fn Instance::equal(Instance, Instance) -> Bool

Instance::not_equal

fn Instance::not_equal(x : Instance, y : Instance) -> Bool

Instance::to_repr

InstanceDecl

pub(all) enum InstanceDecl {
CoreType(Bytes)
Type(TypeDef)
AliasOuter(Int, Int, Int)
AliasInstanceExport(Int, Int, String)
Export(String, Array[NameAttribute], ExternDesc)
} derive(Eq,
Debug
)

A subset of instance type declarations (enough for wasmtime/component-spec).

InstanceDecl::equal

InstanceDecl::not_equal

fn InstanceDecl::not_equal(x : InstanceDecl, y : InstanceDecl) -> Bool

InstanceExpr

pub(all) enum InstanceExpr {
Instantiate(Int, Array[InstantiateArg])
InlineExports(Array[InlineExport])
} derive(Eq,
Debug
)

InstanceExpr::equal

InstanceExpr::not_equal

fn InstanceExpr::not_equal(x : InstanceExpr, y : InstanceExpr) -> Bool

InstanceExpr::output

fn InstanceExpr::output(self : InstanceExpr, logger : &Logger) -> Unit

InstanceExpr::to_string

fn InstanceExpr::to_string(self : InstanceExpr) -> String

InstantiateArg

pub(all) struct InstantiateArg {
name : String
sortidx : SortIdx
} derive(Eq,
Debug
)

InstantiateArg::equal

InstantiateArg::not_equal

fn InstantiateArg::not_equal(x : InstantiateArg, y : InstantiateArg) -> Bool

NameAttribute

pub(all) enum NameAttribute {
Implements(Bytes)
VersionSuffix(Bytes)
ExternalId(Bytes)
} derive(Eq,
Debug
)

NameAttribute::equal

NameAttribute::not_equal

fn NameAttribute::not_equal(x : NameAttribute, y : NameAttribute) -> Bool

Param

pub(all) struct Param {
label : String
ty : ValType
} derive(Eq,
Debug
)

Param::equal

fn Param::equal(Param, Param) -> Bool

Param::not_equal

fn Param::not_equal(x : Param, y : Param) -> Bool

Param::to_repr

PrimValType

pub(all) enum PrimValType {
Bool
S8
U8
S16
U16
S32
U32
S64
U64
F32
F64
Char
String
ErrorContext
} derive(Eq,
Debug
)

PrimValType::equal

fn PrimValType::equal(PrimValType, PrimValType) -> Bool

PrimValType::not_equal

fn PrimValType::not_equal(x : PrimValType, y : PrimValType) -> Bool

RecordField

pub(all) struct RecordField {
label : String
ty : ValType
} derive(Eq,
Debug
)

RecordField::equal

fn RecordField::equal(RecordField, RecordField) -> Bool

RecordField::not_equal

fn RecordField::not_equal(x : RecordField, y : RecordField) -> Bool

ResourceKind

pub(all) enum ResourceKind {
GuestDefined
HostDefined
} derive(Eq,
Debug
)

ResourceKind::equal

ResourceKind::not_equal

fn ResourceKind::not_equal(x : ResourceKind, y : ResourceKind) -> Bool

Section

pub struct Section {
id : Int
payload : Bytes
} derive(Eq,
Debug
)

Section::equal

fn Section::equal(Section, Section) -> Bool

Section::not_equal

fn Section::not_equal(x : Section, y : Section) -> Bool

Section::to_repr

Sort

pub(all) enum Sort {
Core(Int)
Func
Value
Type
Component
Instance
} derive(Eq,
Debug
)

Sort::equal

fn Sort::equal(Sort, Sort) -> Bool

Sort::not_equal

fn Sort::not_equal(x : Sort, y : Sort) -> Bool

Sort::to_repr

SortIdx

pub(all) struct SortIdx {
sort : Sort
idx : Int
} derive(Eq,
Debug
)

impl Show for SortIdx

SortIdx::equal

fn SortIdx::equal(SortIdx, SortIdx) -> Bool

SortIdx::not_equal

fn SortIdx::not_equal(x : SortIdx, y : SortIdx) -> Bool

SortIdx::output

fn SortIdx::output(self : SortIdx, logger : &Logger) -> Unit

SortIdx::to_repr

SortIdx::to_string

fn SortIdx::to_string(self : SortIdx) -> String

Start

pub(all) struct Start {
func_idx : Int
args : Array[Int]
results : Int
} derive(Eq,
Debug
)

impl Show for Start

Start::equal

fn Start::equal(Start, Start) -> Bool

Start::not_equal

fn Start::not_equal(x : Start, y : Start) -> Bool

Start::output

fn Start::output(self : Start, logger : &Logger) -> Unit

Start::to_repr

Start::to_string

fn Start::to_string(self : Start) -> String

StringEncoding

pub(all) enum StringEncoding {
Utf8
Utf16
Latin1Utf16
} derive(Eq,
Debug
)

StringEncoding::equal

StringEncoding::not_equal

fn StringEncoding::not_equal(x : StringEncoding, y : StringEncoding) -> Bool

TypeBound

pub(all) enum TypeBound {
Eq(Int)
SubResource
} derive(Eq,
Debug
)

TypeBound::equal

fn TypeBound::equal(TypeBound, TypeBound) -> Bool

TypeBound::not_equal

fn TypeBound::not_equal(x : TypeBound, y : TypeBound) -> Bool

TypeDef

pub(all) enum TypeDef {
DefValType(PrimValType)
FuncType(FuncType)
List(ValType)
FixedList(ValType, Int)
MapType(ValType, ValType)
Record(Array[RecordField])
Variant(Array[VariantCase])
Tuple(Array[ValType])
Flags(Array[String])
Enum(Array[String])
Option(ValType)
Result(ValType?, ValType?)
Own(Int)
Borrow(Int)
Stream(ValType?)
Future(ValType?)
ResourceType(Int, Int, Int?, ResourceKind)
ComponentType(Array[ComponentDecl])
InstanceTypeEmpty
InstanceType(Array[InstanceDecl])
} derive(Eq,
Debug
)

impl Show for TypeDef

TypeDef::equal

fn TypeDef::equal(TypeDef, TypeDef) -> Bool

TypeDef::not_equal

fn TypeDef::not_equal(x : TypeDef, y : TypeDef) -> Bool

TypeDef::output

fn TypeDef::output(self : TypeDef, logger : &Logger) -> Unit

TypeDef::to_repr

TypeDef::to_string

fn TypeDef::to_string(self : TypeDef) -> String

ValType

pub(all) enum ValType {
TypeIdx(Int)
Prim(PrimValType)
} derive(Eq,
Debug
)

ValType::equal

fn ValType::equal(ValType, ValType) -> Bool

ValType::not_equal

fn ValType::not_equal(x : ValType, y : ValType) -> Bool

ValType::to_repr

ValueBound

pub(all) enum ValueBound {
Eq(Int)
Type(ValType)
} derive(Eq,
Debug
)

ValueBound::equal

fn ValueBound::equal(ValueBound, ValueBound) -> Bool

ValueBound::not_equal

fn ValueBound::not_equal(x : ValueBound, y : ValueBound) -> Bool

VariantCase

pub(all) struct VariantCase {
label : String
ty : ValType?
refines : Int?
} derive(Eq,
Debug
)

VariantCase::equal

fn VariantCase::equal(VariantCase, VariantCase) -> Bool

VariantCase::not_equal

fn VariantCase::not_equal(x : VariantCase, y : VariantCase) -> Bool

canonical_flat_types

Return the Canonical ABI flat core value types for one component value.

pointer_type must be I32 or I64 and represents the selected canonical memory. None means the type index is invalid, recursive, or does not name a value type.

canonical_lift_core_func_type

fn canonical_lift_core_func_type(func_type : FuncType, types : Array[TypeDef?], pointer_type :
ValueType
) ->
FuncType
?

Return the Canonical ABI core signature consumed by canon lift.

More than sixteen flat parameters use one indirect pointer. A result with more than one flat value is returned as a pointer to the result area.

canonical_lower_core_func_type

fn canonical_lower_core_func_type(func_type : FuncType, types : Array[TypeDef?], pointer_type :
ValueType
) ->
FuncType
?

Return the Canonical ABI core signature produced by canon lower.

More than sixteen flat parameters use one indirect pointer. A result with more than one flat value appends an indirect result pointer to the core parameters.

parse_alias_section

fn parse_alias_section(payload : Bytes) -> Array[Alias] raise ComponentParseError

parse_canon_section

fn parse_canon_section(payload : Bytes) -> Array[Canon] raise ComponentParseError

parse_component

fn parse_component(bytes : Bytes) -> Component raise ComponentParseError

parse_component_binary

fn parse_component_binary(bytes : Bytes) -> ComponentBinary raise ComponentParseError

parse_core_instance_section

fn parse_core_instance_section(payload : Bytes) -> Array[CoreInstanceDecl] raise ComponentParseError

parse_export_section

fn parse_export_section(payload : Bytes) -> Array[Export] raise ComponentParseError

parse_import_section

fn parse_import_section(payload : Bytes) -> Array[Import] raise ComponentParseError

parse_instance_section

fn parse_instance_section(payload : Bytes) -> Array[Instance] raise ComponentParseError

parse_start_section

fn parse_start_section(payload : Bytes) -> Start raise ComponentParseError

parse_type_section

fn parse_type_section(payload : Bytes) -> Array[TypeDef] raise ComponentParseError

sniff_binary_kind

fn sniff_binary_kind(bytes : Bytes) -> BinaryKind?