Documentation
¶
Index ¶
- Constants
- Variables
- type AliasDef
- type BorrowDesc
- type Canon
- type CanonOpt
- type Component
- func (c *Component) CoreModuleSpaceLen() int
- func (c *Component) Dump(w io.Writer) error
- func (c *Component) ResolveComponent(idx uint32) (def *Component, importName string, err error)
- func (c *Component) ResolveComponentInstance(idx uint32) (int, bool)
- func (c *Component) ResolveCoreModule(idx uint32) (owner *Component, moduleIdx uint32, err error)
- func (c *Component) ResolveType(idx uint32) (TypeDesc, error)
- func (c *Component) ResourceDefIndex(idx uint32) uint32
- type ComponentDesc
- type ComponentFuncSpaceEntry
- type ComponentFuncSpaceEntryKind
- type ComponentInstanceSpaceEntry
- type ComponentInstanceSpaceEntryKind
- type ComponentSpaceEntry
- type ComponentSpaceEntryKind
- type CoreFuncSpaceEntry
- type CoreFuncSpaceEntryKind
- type CoreInlineExport
- type CoreInstance
- type CoreInstantiateArg
- type CoreModule
- type CoreModuleSpaceEntry
- type CoreModuleSpaceEntryKind
- type EnumDesc
- type Export
- type FlagsDesc
- type FuncDesc
- type FuncParam
- type FuncResult
- type FuncResults
- type FutureDesc
- type Import
- type InlineExport
- type Instance
- type InstanceDesc
- type InstantiateArg
- type ListDesc
- type OptionDesc
- type OwnDesc
- type PrimitiveDesc
- type RawSection
- type RecordDesc
- type RecordField
- type ResourceDesc
- type ResultDesc
- type Start
- type StreamDesc
- type TupleDesc
- type Type
- type TypeDesc
- type TypeRef
- type TypeSpaceEntry
- type TypeSpaceEntryKind
- type VariantCase
- type VariantDesc
Constants ¶
const ( CanonKindLift byte = 0x00 CanonKindLower byte = 0x01 CanonKindResourceNew byte = 0x02 CanonKindResourceDrop byte = 0x03 CanonKindResourceRep byte = 0x04 CanonKindResourceDropAsync byte = 0x07 CanonKindTaskCancel byte = 0x05 CanonKindSubtaskCancel byte = 0x06 CanonKindTaskReturn byte = 0x09 CanonKindContextGet byte = 0x0a CanonKindContextSet byte = 0x0b CanonKindThreadYield byte = 0x0c CanonKindSubtaskDrop byte = 0x0d CanonKindStreamNew byte = 0x0e CanonKindStreamRead byte = 0x0f CanonKindStreamWrite byte = 0x10 CanonKindStreamCancelRead byte = 0x11 CanonKindStreamCancelWrite byte = 0x12 CanonKindStreamDropReadable byte = 0x13 CanonKindStreamDropWritable byte = 0x14 CanonKindFutureNew byte = 0x15 CanonKindFutureRead byte = 0x16 CanonKindFutureWrite byte = 0x17 CanonKindFutureCancelRead byte = 0x18 CanonKindFutureCancelWrite byte = 0x19 CanonKindFutureDropReadable byte = 0x1a CanonKindFutureDropWritable byte = 0x1b CanonKindErrorContextNew byte = 0x1c CanonKindErrorContextDebugMessage byte = 0x1d CanonKindErrorContextDrop byte = 0x1e CanonKindWaitableSetNew byte = 0x1f CanonKindWaitableSetWait byte = 0x20 CanonKindWaitableSetPoll byte = 0x21 CanonKindWaitableSetDrop byte = 0x22 CanonKindWaitableJoin byte = 0x23 CanonKindBackpressureInc byte = 0x24 CanonKindBackpressureDec byte = 0x25 CanonKindThreadIndex byte = 0x26 CanonKindThreadNewIndirect byte = 0x27 CanonKindThreadSuspend byte = 0x29 CanonKindThreadYieldThenResume byte = 0x2b )
CanonKind names the byte values Canon.Kind takes -- the first byte of each entry in the canonical-function section (id 0x08). 0x00-0x04 were already implemented; 0x05 and up are the Phase 0 async additions. Verified against wasm-tools 1.253 (`wasm-tools dump`) on internal/component/binary/testdata/ async/*.wasm -- see decodeCanonSection and canonKindName.
0x07 (resource.drop async) was added in Phase 3 -- see docs/component-model-async-phase3-design.md §4.4; its payload (a single typeidx) is byte-identical to 0x03's, verified against fresh wasm-tools output the same way as every other kind in this table.
CanonKindThreadYield/Index/NewIndirect/Suspend/YieldThenResume are the five thread.* builtins actually exercised by the vendored async .wast suites (cancellable, sync-barges-in, trap-if-sync-and-waitable-set, trap-if- block-and-sync); their opcodes and payload grammars are taken from the component-model spec's design/mvp/Binary.md canon-definitions EBNF (the 🧵/🔀 threads-proposal entries), cross-checked against `wasm-tools dump` on those four fixtures. The REMAINING thread.* opcodes (0x28 resume-later, 0x2a/0x2c/0x2d suspend/yield-then-promote, 0x40-0x42 spawn-ref/spawn- indirect/available-parallelism) are deliberately NOT added here: no vendored suite decodes one, so their byte layouts are unverified against a real fixture -- add them (and their decode case) only once a suite that actually needs them shows up. Decoding these five is NOT the same as implementing thread.* execution (no runtime support exists for any of them -- see stream_builtins.go/async_builtins.go's absence of a thread.yield/thread.new-indirect host func); every suite that reaches one at CALL time (not just decode) still traps or hangs on its own, real gap.
Variables ¶
var ( ErrInvalidMagicNumber = errors.New("invalid magic number") ErrInvalidVersion = errors.New("invalid version header") ErrInvalidLayer = errors.New("invalid layer header (expected component layer 0x01 0x00)") ErrInvalidSectionID = errors.New("invalid section id") ErrTruncatedBinary = errors.New("truncated binary") )
Functions ¶
This section is empty.
Types ¶
type AliasDef ¶
type AliasDef struct {
Sort byte // sort of the aliased item: 0x00 = core, 0x01 = func, 0x02 = value, 0x03 = type, 0x04 = component, 0x05 = instance
TargetKind byte // 0x00 = export, 0x01 = core export, 0x02 = outer
InstanceIdx uint32 // for export/core export targets
Name string // for export/core export targets
OuterCount uint32 // for outer targets
OuterIndex uint32 // for outer targets
// CoreSort is the core:sort discriminator byte that follows Sort when
// Sort == 0x00 (i.e. this alias names a core-level item): 0x00 func,
// 0x01 table, 0x02 memory, 0x03 global, 0x04 tag, 0x10 type, 0x11
// module, 0x12 instance. It is meaningless (and left at its zero value,
// 0x00) when Sort != 0x00.
//
// A core-export alias (Sort == 0x00, TargetKind == 0x01) needs this to
// tell a core-func alias apart from a core-memory/table/global alias --
// see internal/component/instance, which used to disambiguate by
// probing the instantiated target module's exports (a name that
// resolves to a Function is a func alias) because this field didn't
// exist; that probe is now a fallback for AliasDefs built by hand
// (e.g. in tests) rather than by decodeAliasSection.
CoreSort byte
}
AliasDef represents an alias binding (section 6).
type BorrowDesc ¶
type BorrowDesc struct {
ResourceType uint32
}
BorrowDesc represents a borrowed handle to a resource.
func (BorrowDesc) Kind ¶
func (BorrowDesc) Kind() string
type Canon ¶
type Canon struct {
Kind byte // one of the CanonKind* constants
CoreFuncIdx uint32 // used for lift (0x00)
FuncIdx uint32 // used for lower (0x01) and for result indices in Start
Opts []CanonOpt
TypeIdx uint32 // lift's type index; resource.*'s type index; the
// Async is the async_:bool payload of subtask.cancel, stream.cancel-read/
// -write, and future.cancel-read/-write.
Async bool
// Cancellable is waitable-set.wait/poll's cancellable:bool payload, and
// (decode-only -- see CanonKindThreadYield's doc) thread.yield/thread.
// suspend/thread.yield-then-resume's identically-shaped cancel:bool.
Cancellable bool
// TableIdx is thread.new-indirect's tbl:<core:tableidx> payload
// (decode-only). TypeIdx doubles as its ft:<typeidx> payload.
TableIdx uint32
// MemIdx is waitable-set.wait/poll's memory index. (error-context.new/
// debug-message also take a memory, but via the existing Opts memory
// option (0x03), same as lift/lower -- they don't need this field.)
MemIdx uint32
// CoreValType is context.get/context.set's `ty` payload: a single CORE
// valtype byte (e.g. 0x7f = i32), not a component valtype -- same
// encoding as ResourceDesc.Rep. See coreValtypeName.
CoreValType byte
// Slot is context.get/context.set's `slot` payload (a context-storage
// index, not a type or func index).
Slot uint32
// TaskReturnResult is task.return's result list. Verified via
// `wasm-tools dump`/round-trip probes (not just the fixtures) that this
// is encoded with the EXACT SAME grammar as a functype's result list
// (readResultListDesc): tag 0x00 + one valtype ("unnamed", e.g. `(result
// u32)`), or tag 0x01 + vec(labelvaltype) ("named", empty for a
// no-result task.return). This resolves the brief's flagged ambiguity:
// task.return's `(result ...)` clause is NOT a bare option<valtype> --
// bytes `09 00 79 00` decode as tag=0x00 (unnamed) valtype=0x79 (u32)
// then an empty opts vec, while a no-result task.return encodes as
// `09 01 00 00` (tag=0x01 named-list, count=0, then empty opts vec).
TaskReturnResult FuncResults
}
Canon represents a canonical lift/lower binding (section 8).
type CanonOpt ¶
type CanonOpt struct {
Kind byte // 0x00-0x07 (and potentially more)
Idx uint32 // for options that carry an index
}
CanonOpt represents a canonical option.
type Component ¶
type Component struct {
// Types contains the type definitions from the type section (section 7)
// only, in that section's declaration order. This is NOT the full
// component type index space that canon TypeIdx and export/instance type
// references index into -- that space also includes type-sort aliases
// and imported types, interleaved with Types in overall declaration
// order. See TypeSpace and ResolveType.
Types []Type
// TypeSpace is the component's full type index space: one entry per
// type-index-producing definition (type-section deftype, type-sort
// alias, or imported type), in overall declaration order across
// sections. Use ResolveType to resolve a type index through it rather
// than indexing Types or TypeSpace directly. See typespace.go.
TypeSpace []TypeSpaceEntry
// Imports contains the import bindings.
Imports []Import
// Exports contains the export bindings.
Exports []Export
// ComponentFuncSpace is the component's func index space, one entry per
// func-producing definition (func import / func alias / canon lift / func
// export) in overall declaration order across sections. See
// componentfuncspace.go.
ComponentFuncSpace []ComponentFuncSpaceEntry
// ComponentInstanceSpace is the component's instance index space, one
// entry per instance-producing definition (instance import / instance
// definition / instance alias / instance export) in overall declaration
// order across sections. See componentinstancespace.go.
ComponentInstanceSpace []ComponentInstanceSpaceEntry
// ComponentSpace is the component's COMPONENT index space, one entry per
// component-producing definition (component import / nested component
// definition / component alias / component export) in overall declaration
// order across sections. An instance definition's ComponentIdx indexes
// this, not NestedComponents. See componentspace.go.
ComponentSpace []ComponentSpaceEntry
// CoreModules are embedded core wasm modules (section 1) only, in that
// section's declaration order. This is NOT the core module index space a
// core:instance's ModuleIdx indexes -- that space also includes core-
// module outer aliases (section 6, sort core 0x00 / core:sort module
// 0x11), interleaved with CoreModules in overall declaration order. See
// CoreModuleSpace and ResolveCoreModule.
CoreModules []CoreModule
// CoreModuleSpace is the component's core module index space: one entry
// per core-module-index-producing definition (section-1 embedded module or
// section-6 core-module outer alias), in overall declaration order. Use
// ResolveCoreModule rather than indexing CoreModules directly. See
// coremodulespace.go.
CoreModuleSpace []CoreModuleSpaceEntry
// CoreInstances instantiate core modules with arguments (section 2).
CoreInstances []CoreInstance
// Instances instantiate components with arguments (section 5).
Instances []Instance
// NestedComponents are fully embedded sub-components (section 4), decoded
// recursively -- per the Binary.md grammar, section_4(<component>) is a
// complete component binary (its own magic/version/layer preamble plus
// its own sections), not a bare section list. wit-component emits these
// for a world that exports an interface: it packages the lifted core
// funcs into a nested-component "shim" that re-exports them, and the
// top-level export names an Instance (section 5) that instantiates this
// nested component -- see internal/component/instance, which resolves
// that shim to call the funcs it re-exports.
//
// Some real-world nested components (e.g. the wasip2 CLI adapter emitted
// alongside a `wasi:cli/command` world) are far more complex than the
// re-export shim -- they embed their own core module and full
// instantiation graph. Those still decode fine here (this is a purely
// structural, recursive decode with no semantic assumptions), but
// internal/component/instance fails loud rather than trying to
// instantiate them.
NestedComponents []*Component
// Outer is the component this one was decoded from as a section-4 nested
// component (nil for a top-level component). It is what makes an
// `alias outer <count> <idx>` with count > 0 resolvable: the de Bruijn
// count is a number of enclosing components to skip, so resolution walks
// this link that many times and then indexes the resulting component's
// index space of the aliased sort. See ResolveType (typespace.go) and
// ResolveCoreModule (coremodulespace.go).
//
// This makes the Component graph CYCLIC (parent -> NestedComponents ->
// Outer -> parent). reflect.DeepEqual copes; fmt's %#v does not, so never
// dump a whole Component with it.
Outer *Component
// Aliases bring names into scope (section 6).
Aliases []AliasDef
// Canons describe canonical lift/lower bindings (section 8).
Canons []Canon
// CoreFuncSpace is the component's full core func index space, in
// declaration order across the (possibly interleaved) alias and canon
// sections -- see corefuncspace.go. Empty for a Component not produced by
// Decode (e.g. a hand-built binary.Component in a test), matching
// TypeSpace's convention; callers needing the core func index space fall
// back to treating Aliases/Canons as already correctly ordered in that
// case.
CoreFuncSpace []CoreFuncSpaceEntry
// Start is the optional start section that specifies startup behavior (section 9).
Start *Start
// RawSections tracks sections we parse the header for but skip the body.
// Used for sections we don't fully decode yet (e.g., core-type, component decls).
RawSections []RawSection
// Bytes is the complete binary this component was decoded from (the whole
// buffer for a top-level component; the section-4 sub-slice for a nested
// one). CoreModule.Offset/Size index into it, so recursively instantiating
// a NestedComponents entry needs its own Bytes, not the parent's.
Bytes []byte
// Decoded is set true by Decode. It distinguishes a component that went
// through the binary decoder (whose CoreFuncSpace/ComponentFuncSpace/
// TypeSpace are authoritative -- an empty CoreFuncSpace genuinely means no
// core-func-producing aliases/canons) from a hand-built Component value
// (the common shape in tests, which never populates those index spaces).
// The graph engine uses it to tell "legitimately no core funcs" from "index
// spaces were never built"; see graph.go.
Decoded bool
}
Component represents a parsed WebAssembly Component Model container.
func Decode ¶
Decode parses a WebAssembly Component Model container from a reader. It validates the preamble, iterates outer component sections, and decodes type, import, and export sections into Go structs. Other sections are recorded but not fully decoded.
func (*Component) CoreModuleSpaceLen ¶ added in v0.3.0
CoreModuleSpaceLen is the number of indices in the core module index space, applying ResolveCoreModule's hand-built fallback (a Component that never went through Decode has no space, and its CoreModules IS its space).
func (*Component) Dump ¶
Dump writes a human-readable summary of the component to w. It prints the type section, import/export graph, and instantiation graph.
func (*Component) ResolveComponent ¶ added in v0.3.0
ResolveComponent resolves an index in this component's component index space to the component DEFINITION it names.
Exactly one of def/importName is set on success. def is the decoded nested component (possibly one an ENCLOSING component defines, when the index is reached through an `alias outer`). importName is the name of a component IMPORT: the definition is not in this binary at all, and the caller must look up what the embedder supplied for that name -- see internal/component/instance's config.componentArgs.
For a Component that was not produced by Decode (ComponentSpace left empty -- the hand-built shape in tests), idx is resolved directly against NestedComponents, matching this package's behavior before the space existed.
func (*Component) ResolveComponentInstance ¶
ResolveComponentInstance resolves a component instance index to the index in Component.Instances of the instance DEFINITION it ultimately names, following export aliases (an `(export "x" (instance N))` both re-exports instance N and introduces a new instance index aliasing it).
ok is false when the index is out of range, names an imported instance, or names an alias this decoder does not resolve structurally (an outer alias, or an alias of another instance's instance-typed export). Callers that need to distinguish those cases should inspect ComponentInstanceSpace directly.
It returns (0, false) for a component that was not produced by Decode: a hand-built Component has no instance index space at all, and the caller is expected to fall back to its own arithmetic (see instance.go's componentInstanceDef).
func (*Component) ResolveCoreModule ¶ added in v0.3.0
ResolveCoreModule resolves an index in this component's core module index space to the component that actually EMBEDS the module and that component's index into its own CoreModules. The owner is not always c: an `alias outer` names a module embedded by an enclosing component, whose bytes live in the enclosing component's own Bytes (CoreModule.Offset/Size index into it), so callers need the owner, not just an index.
For a Component that was not produced by Decode (CoreModuleSpace left empty -- the common shape for hand-built binary.Component values in tests), idx is resolved directly against CoreModules with c as the owner, matching the behavior this package had before the space existed. Same convention as TypeSpace / CoreFuncSpace.
func (*Component) ResolveType ¶
ResolveType resolves a component type index -- which may name a type-section deftype directly, or (transitively) a type-sort alias -- to its underlying TypeDesc, walking the component's full TypeSpace rather than indexing Types directly (which only covers type-section entries and misresolves the moment any alias or type import precedes a deftype).
It follows alias chains where this decoder has enough structure to do so: an "export" alias (TargetKind 0x00) naming a type-sort entry inline-exported by one of this component's own instances (Instances, section 5, Kind 0x01), and an "outer" alias (TargetKind 0x02) -- both the self-referential form (OuterCount 0, another index in this same TypeSpace) and a genuine de Bruijn reference into an ENCLOSING component's type index space, which walks Component.Outer OuterCount times. Anything else this decoder cannot follow structurally -- most notably a type exported from an *imported* instance (the common real-guest shape, e.g. `alias export $streams "output-stream" (type $ot)`; this package does not decode nested type declarations inside an imported instance type) -- fails loud with an error naming the index and the reason, rather than returning a zero value or panicking. That is the correct outcome for such an index: as documented on OwnDesc/BorrowDesc, own/borrow handle types only ever use their ResourceType index as an opaque tag (never dereferenced through a resolver), so a real guest built this way still instantiates and runs -- see internal/component/instance's package doc.
For a Component that was not produced by Decode (TypeSpace left empty -- the common shape for hand-built binary.Component values in tests), idx is resolved directly against Types instead, matching this method's behavior before TypeSpace existed.
func (*Component) ResourceDefIndex ¶
ResourceDefIndex maps a resource type index to the canonical index where the resource is DEFINED (or the root import it names), following the same TypeSpace links ResolveType does: export-introduces-alias, self "outer" type alias, and an `eq`-bounded type import. A resource is commonly named by several indices in one component -- the deftype that defines it AND the export alias created when it is exported -- while canon resource.new/drop/rep use the deftype and own<R>/borrow<R> in a lifted signature use the export alias. Reducing every alias of one resource to this single index gives a stable per-component identity. Returns idx unchanged for anything it cannot resolve further (a plain import, an opaque alias, or a hand-built Component with no TypeSpace) -- which is the right stable tag for those.
type ComponentDesc ¶
type ComponentDesc struct {
}
ComponentDesc represents a component type (collection of declarations).
func (ComponentDesc) Kind ¶
func (ComponentDesc) Kind() string
type ComponentFuncSpaceEntry ¶
type ComponentFuncSpaceEntry struct {
Kind ComponentFuncSpaceEntryKind
Import uint32 // index into Component.Imports (Kind == ComponentFuncFromImport)
Alias uint32 // index into Component.Aliases (Kind == ComponentFuncFromAlias)
Canon uint32 // index into Component.Canons (Kind == ComponentFuncFromCanonLift)
Export uint32 // index into Component.Exports (Kind == ComponentFuncFromExport)
}
ComponentFuncSpaceEntry is one entry in the component's func index space. Exactly one of Import/Alias/Canon/Export is meaningful, selected by Kind.
type ComponentFuncSpaceEntryKind ¶
type ComponentFuncSpaceEntryKind byte
ComponentFuncSpaceEntryKind distinguishes what produced a component func index-space entry.
const ( // ComponentFuncFromImport: a func import (section 10, sort func). ComponentFuncFromImport ComponentFuncSpaceEntryKind = iota // ComponentFuncFromAlias: a func alias (section 6, Sort == 0x01). ComponentFuncFromAlias // ComponentFuncFromCanonLift: a canon lift (section 8, Kind == 0x00). ComponentFuncFromCanonLift // ComponentFuncFromExport: a func export (section 11, sort func) -- an // alias of the exported func into the next func index. ComponentFuncFromExport )
type ComponentInstanceSpaceEntry ¶
type ComponentInstanceSpaceEntry struct {
Kind ComponentInstanceSpaceEntryKind
Import uint32 // index into Component.Imports (Kind == ComponentInstanceFromImport)
Instance uint32 // index into Component.Instances (Kind == ComponentInstanceFromDefinition)
Alias uint32 // index into Component.Aliases (Kind == ComponentInstanceFromAlias)
Export uint32 // index into Component.Exports (Kind == ComponentInstanceFromExport)
}
ComponentInstanceSpaceEntry is one entry in the component's instance index space. Exactly one of Import/Instance/Alias/Export is meaningful, selected by Kind.
type ComponentInstanceSpaceEntryKind ¶
type ComponentInstanceSpaceEntryKind byte
ComponentInstanceSpaceEntryKind distinguishes what produced a component instance index-space entry.
const ( // ComponentInstanceFromImport: an instance import (section 10, sort instance). ComponentInstanceFromImport ComponentInstanceSpaceEntryKind = iota // ComponentInstanceFromDefinition: an instance definition (section 5). ComponentInstanceFromDefinition // ComponentInstanceFromAlias: an instance alias (section 6, Sort == 0x05). ComponentInstanceFromAlias // ComponentInstanceFromExport: an instance export (section 11, sort // instance) -- an alias of the exported instance into the next instance // index. ComponentInstanceFromExport )
type ComponentSpaceEntry ¶ added in v0.3.0
type ComponentSpaceEntry struct {
Kind ComponentSpaceEntryKind
Import uint32 // index into Component.Imports (ComponentFromImport)
Component uint32 // index into Component.NestedComponents (ComponentFromDefinition)
Alias uint32 // index into Component.Aliases (ComponentFromAlias)
Export uint32 // index into Component.Exports (ComponentFromExport)
}
ComponentSpaceEntry is one entry in the component index space. Exactly one of Import/Component/Alias/Export is meaningful, selected by Kind.
type ComponentSpaceEntryKind ¶ added in v0.3.0
type ComponentSpaceEntryKind byte
This file implements the COMPONENT index space -- the space an instance definition's `(instantiate <componentidx> ...)` names, and the last of the component-level index spaces this package models (see typespace.go, corefuncspace.go, componentfuncspace.go, componentinstancespace.go, coremodulespace.go).
Per the component-model binary format it is populated, in declaration order across sections, by every definition that yields a component:
- a component import (section 10, externdesc sort component 0x04)
- a nested component (section 4)
- a component alias (section 6, Sort == 0x04) -- `alias outer`
- a component export (section 11, externdesc sort component 0x04), since "all exports (of all sorts) introduce a new index that aliases the exported definition"
Equating the space with NestedComponents (section 4) alone is what made types.11.wast fail to instantiate: its nested `$c` defines NO nested component of its own, imports one (`(import "x" (component ...))`) and then does `(instantiate 0)` -- index 0 being that import. A component-sort import is a component DEFINITION (code) the embedder supplies, not an instance: the importing component instantiates it itself, with its own args, at its own instance section. See internal/component/instance's config.componentArgs.
const ( // ComponentFromImport: a component import (section 10, sort component 0x04). ComponentFromImport ComponentSpaceEntryKind = iota // ComponentFromDefinition: a nested component (section 4). ComponentFromDefinition // ComponentFromAlias: a component alias (section 6, Sort == 0x04). ComponentFromAlias // ComponentFromExport: a component export (section 11, sort component // 0x04) -- an alias of the exported component into the next component index. ComponentFromExport )
type CoreFuncSpaceEntry ¶
type CoreFuncSpaceEntry struct {
Kind CoreFuncSpaceEntryKind
// Alias is the index into Component.Aliases, valid when
// Kind == CoreFuncFromAlias.
Alias uint32
// Canon is the index into Component.Canons, valid when
// Kind == CoreFuncFromCanon.
Canon uint32
}
CoreFuncSpaceEntry is one entry in the component's core func index space. Exactly one of Alias, Canon is meaningful, selected by Kind.
type CoreFuncSpaceEntryKind ¶
type CoreFuncSpaceEntryKind byte
CoreFuncSpaceEntryKind distinguishes what produced a core func index-space entry.
const ( // CoreFuncFromAlias marks an entry produced by a core-level func alias // (section 6, Sort == 0x00, CoreSort == 0x00). CoreFuncFromAlias CoreFuncSpaceEntryKind = iota // CoreFuncFromCanon marks an entry produced by a canon that yields a new // core func: every Canon.Kind except lift (0x00) -- see decodeComponent's // canon-section case. CoreFuncFromCanon )
type CoreInlineExport ¶
type CoreInlineExport struct {
Name string
Sort byte // core:sort: 0x00 func, 0x01 table, 0x02 memory, 0x03 global, 0x04 tag, 0x10 type, 0x11 module, 0x12 instance
CoreSortIdx uint32
}
CoreInlineExport represents an inlined export in a core instance.
type CoreInstance ¶
type CoreInstance struct {
Kind byte // 0x00 = instantiate, 0x01 = inline exports
ModuleIdx uint32 // used if Kind == 0x00
Args []CoreInstantiateArg
Exports []CoreInlineExport
}
CoreInstance represents a core module instantiation (section 2).
type CoreInstantiateArg ¶
CoreInstantiateArg represents an argument to instantiate a core module.
type CoreModule ¶
type CoreModule struct {
Offset int // byte offset in the component binary
Size int // byte length of the core module
}
CoreModule represents an embedded core wasm module (section 1). The binary is stored as an offset and size; it is not parsed here, as wazy's core decoder handles that separately.
type CoreModuleSpaceEntry ¶ added in v0.3.0
type CoreModuleSpaceEntry struct {
Kind CoreModuleSpaceEntryKind
Module uint32 // index into Component.CoreModules (Kind == CoreModuleFromDefinition)
Alias uint32 // index into Component.Aliases (Kind == CoreModuleFromAlias)
}
CoreModuleSpaceEntry is one entry in the component's core module index space. Exactly one of Module/Alias is meaningful, selected by Kind.
type CoreModuleSpaceEntryKind ¶ added in v0.3.0
type CoreModuleSpaceEntryKind byte
CoreModuleSpaceEntryKind distinguishes what produced a core module index space entry.
const ( // CoreModuleFromDefinition: an embedded core module (section 1). CoreModuleFromDefinition CoreModuleSpaceEntryKind = iota // CoreModuleFromAlias: a core-module alias (section 6, Sort == 0x00 core, // CoreSort == 0x11 module). CoreModuleFromAlias )
type Export ¶
type Export struct {
// Name is the export name.
Name string
// ExternType distinguishes the export kind.
ExternType byte
// ExternIndex is the index into the appropriate namespace.
ExternIndex uint32
}
Export represents a component export binding.
type FlagsDesc ¶
type FlagsDesc struct {
Names []string
}
FlagsDesc represents a flags type (set of named booleans).
type FuncDesc ¶
type FuncDesc struct {
Params []FuncParam
Results FuncResults
// Async is true for an `async func` component-func type (deftype tag 0x43,
// vs the synchronous 0x40). A canon lift/lower's own async CanonOpt (0x06)
// is separate; the Canonical ABI requires the two to agree, but that
// cross-check is a validation concern, not decode.
Async bool
}
FuncDesc represents a function type.
type FuncResult ¶
type FuncResults ¶
type FuncResults struct {
Unnamed *TypeRef // non-nil if tag was 0x00
Named []FuncResult // non-empty if tag was 0x01
}
FuncResults captures the two forms of result lists: - Unnamed: a single unnamed result (tag 0x00) - Named: zero or more named results (tag 0x01)
type FutureDesc ¶
type FutureDesc struct {
Element *TypeRef // nil if the future carries no element type
}
FutureDesc represents a `future<T>` (or bare `future` with no element) async-ABI type. Element is nil for the bare form. Same opaque-handle treatment as StreamDesc.
func (FutureDesc) Kind ¶
func (FutureDesc) Kind() string
type Import ¶
type Import struct {
// Name is the import name (e.g., "wasi:io/streams#input-stream").
Name string
// ExternType distinguishes the import kind (e.g., component, instance, func, value, type, module).
ExternType byte
// ExternIndex is the index into the appropriate namespace (e.g., component index, function index).
ExternIndex uint32
// TypeEqIndex, valid when ExternType == 0x03 (type) and TypeEqBound is
// true, is the component type index this type import is declared equal to
// (an `import "x" (type (eq N))` bound, what wit-component/cargo-component
// emit for a world's exported types). Such an import resolves through to
// type N -- see typespace.go's resolveTypeDepth -- rather than being
// opaque. A `sub` (resource) type bound leaves TypeEqBound false.
TypeEqIndex uint32
TypeEqBound bool
}
Import represents a component import binding.
type InlineExport ¶
InlineExport represents an inlined export in an instance.
type Instance ¶
type Instance struct {
Kind byte // 0x00 = instantiate, 0x01 = inline exports
ComponentIdx uint32 // used if Kind == 0x00
Args []InstantiateArg
Exports []InlineExport
}
Instance represents a component instance (section 5).
type InstanceDesc ¶
InstanceDesc represents an instance type (collection of exports).
func (InstanceDesc) Kind ¶
func (InstanceDesc) Kind() string
type InstantiateArg ¶
InstantiateArg represents an argument to instantiate a component.
type ListDesc ¶
type ListDesc struct {
Element TypeRef
}
ListDesc represents a list (unbounded array).
type OptionDesc ¶
type OptionDesc struct {
Element TypeRef
}
OptionDesc represents an optional value.
func (OptionDesc) Kind ¶
func (OptionDesc) Kind() string
type OwnDesc ¶
type OwnDesc struct {
ResourceType uint32
}
OwnDesc represents owned handle to a resource.
type PrimitiveDesc ¶
type PrimitiveDesc struct {
Prim string // "bool", "s8", "u8", "s16", "u16", "s32", "u32", "s64", "u64", "f32", "f64", "char", "string"
}
PrimitiveDesc represents a primitive value type (bool, s32, u64, string, etc.).
func (PrimitiveDesc) Kind ¶
func (p PrimitiveDesc) Kind() string
type RawSection ¶
RawSection represents a section header we parsed but did not fully decode.
type RecordDesc ¶
type RecordDesc struct {
Fields []RecordField
}
RecordDesc represents a record type (struct-like) with named fields.
func (RecordDesc) Kind ¶
func (RecordDesc) Kind() string
type RecordField ¶
type ResourceDesc ¶
type ResourceDesc struct {
Rep TypeRef // representation type (usually a primitive)
Dtor *uint32 // optional destructor function index
}
ResourceDesc represents a resource type.
func (ResourceDesc) Kind ¶
func (ResourceDesc) Kind() string
type ResultDesc ¶
ResultDesc represents a result type (success or error).
func (ResultDesc) Kind ¶
func (ResultDesc) Kind() string
type StreamDesc ¶
type StreamDesc struct {
Element *TypeRef // nil if the stream carries no element type
}
StreamDesc represents a `stream<T>` (or bare `stream` with no element) async-ABI type. Element is nil for the bare form. Phase 0 treats a stream value as an opaque i32 handle throughout the ABI layer (like own/borrow); Element is recorded for completeness but not otherwise consumed until stream/future runtime support lands.
func (StreamDesc) Kind ¶
func (StreamDesc) Kind() string
type TupleDesc ¶
type TupleDesc struct {
Elements []TypeRef
}
TupleDesc represents a tuple (unnamed record).
type Type ¶
type Type struct {
// Index is the type index in the type section.
Index uint32
// Kind is a human-readable string representation ("func", "record", "variant", etc.).
// For now, we stub most kinds.
Kind string
// Descriptor is the full semantic representation of the type (enum, record, func, etc).
// It is set during parsing and contains the complete structure for ABI and other uses.
Descriptor TypeDesc
// Raw holds the raw bytes of this type definition (for round-trip verification).
Raw []byte
}
Type represents a value type in the component type section. For now, we store the raw index and a textual kind for easier debugging.
type TypeDesc ¶
type TypeDesc interface {
// Kind returns the human-readable kind string for this descriptor
// (e.g. "func", "record", "u32"). This is the single source of truth
// for Type.Kind; there is no separate walk that derives it.
Kind() string
// contains filtered or unexported methods
}
TypeDesc represents a full component type descriptor, capturing the complete structure of a deftype. It is built by walking the component binary, mirroring the exact byte-consumption of the existing walker but also recording the semantic structure for use by the Canonical ABI and other tools.
type TypeRef ¶
type TypeRef struct {
// Exactly one of these must be set.
Primitive string // e.g. "bool", "u32", "string", etc.; empty means use TypeIndex
TypeIndex *uint32
}
TypeRef is either a reference to a primitive type (encoded as a byte name) or an index into the type table.
type TypeSpaceEntry ¶
type TypeSpaceEntry struct {
Kind TypeSpaceEntryKind
// Def is the index into Types, valid when Kind == TypeSpaceDef.
Def uint32
// Alias is the index into Aliases, valid when Kind == TypeSpaceAlias.
Alias uint32
// Import is the index into Imports, valid when Kind == TypeSpaceImport.
Import uint32
// Export is the index into Exports, valid when Kind == TypeSpaceExport.
Export uint32
}
TypeSpaceEntry is one entry in the component's full type index space. Exactly one of Def, Alias, Import is meaningful, selected by Kind.
type TypeSpaceEntryKind ¶
type TypeSpaceEntryKind byte
TypeSpaceEntryKind distinguishes what produced a component type-index-space entry.
const ( // TypeSpaceDef marks an entry produced by a type-section (id 7) deftype. TypeSpaceDef TypeSpaceEntryKind = iota // TypeSpaceAlias marks an entry produced by a type-sort alias (id 6, // Sort == 0x03). TypeSpaceAlias // TypeSpaceImport marks an entry produced by an import whose externdesc // names a type (id 10, ExternType == 0x03). TypeSpaceImport // TypeSpaceExport marks an entry produced by an export whose sort is type // (id 11, ExternType == 0x03) -- "export introduces an alias" of the // exported type. TypeSpaceExport )
type VariantCase ¶
type VariantDesc ¶
type VariantDesc struct {
Cases []VariantCase
}
VariantDesc represents a discriminated union.
func (VariantDesc) Kind ¶
func (VariantDesc) Kind() string