Components
Sorts
A component’s definitions define objects, each of which is of one of
the following sorts:
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(coresort)} & \href{../syntax/components.html#syntax-coresort}{\mathit{core{:}sort}} &::=&
\href{../syntax/components.html#syntax-coresort}{\mathsf{func}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{table}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{memory}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{global}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{type}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{module}} | \href{../syntax/components.html#syntax-coresort}{\mathsf{instance}}\\
\def\mathdef2256#1{{}}\mathdef2256{(sort)} & \href{../syntax/components.html#syntax-sort}{\mathit{sort}} &::=&
\href{../syntax/components.html#syntax-sort}{\mathsf{core}}~\href{../syntax/components.html#syntax-coresort}{\mathit{core{:}sort}}\\&&|&
\href{../syntax/components.html#syntax-sort}{\mathsf{func}} | \href{../syntax/components.html#syntax-sort}{\mathsf{value}} | \href{../syntax/components.html#syntax-sort}{\mathsf{type}} | \href{../syntax/components.html#syntax-sort}{\mathsf{component}} | \href{../syntax/components.html#syntax-sort}{\mathsf{instance}}
\end{array}\end{split}\]
Indices
Each object defined by a component exists within an index space made
up of all objects of the same sort. Unlike in Core WebAssembly, a
component definition may only refer to objects that were defined prior
to it in the current component. Future definitions refer to past
definitions by means of an index into the appropriate index space:
\[\begin{split}\begin{array}{llll}
\def\mathdef2256#1{{}}\mathdef2256{(coremoduleidx)} & \href{../syntax/components.html#syntax-coremoduleidx}{\mathit{core{:}moduleidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(coreinstanceidx)} & \href{../syntax/components.html#syntax-coreinstanceidx}{\mathit{core{:}instanceidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(componentidx)} & \href{../syntax/components.html#syntax-componentidx}{\mathit{componentidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(instanceidx)} & \href{../syntax/components.html#syntax-instanceidx}{\mathit{instanceidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(funcidx)} & \href{../syntax/components.html#syntax-funcidx}{\mathit{funcidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(corefuncidx)} & \href{../syntax/components.html#syntax-corefuncidx}{\mathit{core{:}funcidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(valueidx)} & \href{../syntax/components.html#syntax-valueidx}{\mathit{valueidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(typeidx)} & \href{../syntax/components.html#syntax-typeidx}{\mathit{typeidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\def\mathdef2256#1{{}}\mathdef2256{(coretypeidx)} & \href{../syntax/components.html#syntax-coretypeidx}{\mathit{core{:}typeidx}} &::=& \href{../syntax/values.html#syntax-int}{\mathit{u32}}
\end{array}\end{split}\]
\[\begin{split}\begin{array}{llll}
\def\mathdef2256#1{{}}\mathdef2256{(coresortidx)} & \href{../syntax/components.html#syntax-coresortidx}{\mathit{core{:}sortidx}} &::=& \{ \href{../syntax/components.html#syntax-coretypeidx}{\mathsf{sort}}~\href{../syntax/components.html#syntax-coresort}{\mathit{core{:}sort}}, \href{../syntax/components.html#syntax-coretypeidx}{\mathsf{idx}}~\href{../syntax/values.html#syntax-int}{\mathit{u32}} \}\\
\def\mathdef2256#1{{}}\mathdef2256{(sortidx)} & \href{../syntax/components.html#syntax-sortidx}{\mathit{sortidx}} &::=& \{ \href{../syntax/components.html#syntax-sortidx}{\mathsf{sort}}~\href{../syntax/components.html#syntax-sort}{\mathit{sort}}, \href{../syntax/components.html#syntax-sortidx}{\mathsf{idx}}~\href{../syntax/values.html#syntax-int}{\mathit{u32}} \}
\end{array}\end{split}\]
Definitions
Each object within a component is defined by a definition, of which
there are several kinds:
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(definition)} & \href{../syntax/components.html#syntax-definition}{\mathit{definition}} &::=&
\href{../syntax/components.html#syntax-definition}{\mathsf{core\_module}}~\href{https://webassembly.github.io/spec/core/syntax/modules.html#syntax-module}{\mathit{core{:}}\mathit{module}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{core\_instance}}~\href{../syntax/components.html#syntax-coreinstance}{\mathit{core{:}instance}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{core\_type}}~\href{../syntax/types.html#syntax-coredeftype}{\mathit{core{:}deftype}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{component}}~\href{../syntax/components.html#syntax-component}{\mathit{component}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{instance}}~\href{../syntax/components.html#syntax-instance}{\mathit{instance}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{alias}}~\href{../syntax/types.html#syntax-alias}{\mathit{alias}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{type}}~\href{../syntax/types.html#syntax-deftype}{\mathit{deftype}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{canon}}~\href{../syntax/components.html#syntax-canon}{\mathit{canon}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{start}}~\href{../syntax/components.html#syntax-start}{\mathit{start}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{import}}~\href{../syntax/components.html#syntax-import}{\mathit{import}}\\&&|&
\href{../syntax/components.html#syntax-definition}{\mathsf{export}}~\href{../syntax/components.html#syntax-export}{\mathit{export}}\\
\end{array}\end{split}\]
Core instances
A core instance may be defined either by instantiating a core module
with other core instances taking the place of its first-level imports,
or by creating a core module from whole cloth by combining core
definitions already present in our index space:
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(coreinstance)} & \href{../syntax/components.html#syntax-coreinstance}{\mathit{core{:}instance}} &::=&
\href{../syntax/components.html#syntax-coreinstance}{\mathsf{instantiate}}~\href{../syntax/components.html#syntax-coremoduleidx}{\mathit{core{:}moduleidx}}~\href{../syntax/components.html#syntax-coreinstantiatearg}{\mathit{core{:}instantiatearg}}^{*}\\&&|&
\href{../syntax/components.html#syntax-coreinstance}{\mathsf{exports}}~\href{../syntax/components.html#syntax-coreexport}{\mathit{core{:}export}}^{*}\\
\def\mathdef2256#1{{}}\mathdef2256{(coreinstantiatearg)} & \href{../syntax/components.html#syntax-coreinstantiatearg}{\mathit{core{:}instantiatearg}} &::=&
\{ \href{../syntax/components.html#syntax-coreinstantiatearg}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}, \href{../syntax/components.html#syntax-coreinstantiatearg}{\mathsf{instance}}~\href{../syntax/components.html#syntax-coreinstanceidx}{\mathit{core{:}instanceidx}} \}\\
\def\mathdef2256#1{{}}\mathdef2256{(coreexport)} & \href{../syntax/components.html#syntax-coreexport}{\mathit{core{:}export}} &::=& \{ \href{../syntax/components.html#syntax-coreexport}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}, \href{../syntax/components.html#syntax-coreexport}{\mathsf{def}}~\href{../syntax/components.html#syntax-coresortidx}{\mathit{core{:}sortidx}} \}\\
\end{array}\end{split}\]
Components
A component is merely a sequence of definitions:
\[\begin{array}{llll}
\def\mathdef2256#1{{}}\mathdef2256{(component)} & \href{../syntax/components.html#syntax-component}{\mathit{component}} &::=& \href{../syntax/components.html#syntax-definition}{\mathit{definition}}^{*}
\end{array}\]
Instances
Component-level instance declarations are nearly identical to
core-level instance declarations, with the caveat that more sorts of
definitions may be supplied as imports:
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(instance)} & \href{../syntax/components.html#syntax-instance}{\mathit{instance}} &::=&
\href{../syntax/components.html#syntax-instance}{\mathsf{instantiate}}~\href{../syntax/components.html#syntax-componentidx}{\mathit{componentidx}}~\href{../syntax/components.html#syntax-instantiatearg}{\mathit{instantiatearg}}^{*}\\&&|&
\href{../syntax/components.html#syntax-instance}{\mathsf{exports}}~\href{../syntax/components.html#syntax-export}{\mathit{export}}^{*}\\
\def\mathdef2256#1{{}}\mathdef2256{(instantiatearg)} & \href{../syntax/components.html#syntax-instantiatearg}{\mathit{instantiatearg}} &::=&
\{ \href{../syntax/components.html#syntax-instantiatearg}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}, \href{../syntax/components.html#syntax-instantiatearg}{\mathsf{arg}}~\href{../syntax/components.html#syntax-sortidx}{\mathit{sortidx}} \}
\end{array}\end{split}\]
Aliases
An alias definition copies a definition from some other module,
component, or instance into an index space of the current component:
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(alias)} & \href{../syntax/types.html#syntax-alias}{\mathit{alias}} &::=& \{ \href{../syntax/types.html#syntax-alias}{\mathsf{sort}}~\href{../syntax/components.html#syntax-sort}{\mathit{sort}}, \href{../syntax/types.html#syntax-alias}{\mathsf{target}}~\href{../syntax/components.html#syntax-aliastarget}{\mathit{aliastarget}} \}\\
\def\mathdef2256#1{{}}\mathdef2256{(aliastarget)} & \href{../syntax/components.html#syntax-aliastarget}{\mathit{aliastarget}} &::=&
\href{../syntax/components.html#syntax-aliastarget}{\mathsf{export}}~\href{../syntax/components.html#syntax-instanceidx}{\mathit{instanceidx}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}\\&&|&
\href{../syntax/components.html#syntax-aliastarget}{\mathsf{core\_export}}~\href{../syntax/components.html#syntax-coreinstanceidx}{\mathit{core{:}instanceidx}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}\\&&|&
\href{../syntax/components.html#syntax-aliastarget}{\mathsf{outer}}~\href{../syntax/values.html#syntax-int}{\mathit{u32}}~\href{../syntax/values.html#syntax-int}{\mathit{u32}}\\
\end{array}\end{split}\]
Canonical definitions
Canonical definitions are the only way to convert between Core
WebAssembly functions and component-level shared-nothing functions
which produce and consume values of type \(valtype\). A canon
lift definition converts a core WebAssembly function into a
component-level function which may be exported or used to satisfy the
imports of another component; a canon lower definition converts an
lifted function (often imported) into a core function.
\[\begin{split}\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(canon)} & \href{../syntax/components.html#syntax-canon}{\mathit{canon}} &::=&
\href{../syntax/components.html#syntax-canon}{\mathsf{lift}}~\href{https://webassembly.github.io/spec/core/syntax/modules.html#syntax-funcidx}{\mathit{core{:}}\mathit{funcidx}}~\href{../syntax/components.html#syntax-canonopt}{\mathit{canonopt}}^{*}~\href{../syntax/components.html#syntax-typeidx}{\mathit{typeidx}}\\&&|&
\href{../syntax/components.html#syntax-canon}{\mathsf{lower}}~\href{../syntax/components.html#syntax-funcidx}{\mathit{funcidx}}~\href{../syntax/components.html#syntax-canonopt}{\mathit{canonopt}}^{*}\\
\def\mathdef2256#1{{}}\mathdef2256{(canonopt)} & \href{../syntax/components.html#syntax-canonopt}{\mathit{canonopt}} &::=&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{string\_encoding\_utf8}}\\&&|&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{string\_encoding\_utf16}}\\&&|&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{string\_encoding\_latin1{+}utf16}}\\&&|&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{memory}}~\href{https://webassembly.github.io/spec/core/syntax/modules.html#syntax-memidx}{\mathit{core{:}}\mathit{memidx}}\\&&|&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{realloc}}~\href{https://webassembly.github.io/spec/core/syntax/modules.html#syntax-funcidx}{\mathit{core{:}}\mathit{funcidx}}\\&&|&
\href{../syntax/components.html#syntax-canonopt}{\mathsf{post\_return}}~\href{https://webassembly.github.io/spec/core/syntax/modules.html#syntax-funcidx}{\mathit{core{:}}\mathit{funcidx}}\\
\end{array}\end{split}\]
Start definitions
A start definition specifies a component function which this component
would like to see called at instantiation type in order to do some
sort of initialization.
\[\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(start)} & \href{../syntax/components.html#syntax-start}{\mathit{start}} &::=& \{ \href{../syntax/components.html#syntax-start}{\mathsf{func}}~\href{../syntax/components.html#syntax-funcidx}{\mathit{funcidx}}, \href{../syntax/components.html#syntax-start}{\mathsf{args}}~\href{../syntax/components.html#syntax-valueidx}{\mathit{valueidx}}^{*} \}
\end{array}\]
Imports
Since an imported value is described entirely by its type, an actual
import definition is effectively the same thing as an import
declaration:
\[\begin{array}{llcl}
\def\mathdef2256#1{{}}\mathdef2256{(import)} & \href{../syntax/components.html#syntax-import}{\mathit{import}} &::=& \href{../syntax/types.html#syntax-importdecl}{\mathit{importdecl}}
\end{array}\]
Exports
An export definition is simply a name and a reference to another
definition to export:
\[\begin{array}{llll}
\def\mathdef2256#1{{}}\mathdef2256{(export)} & \href{../syntax/components.html#syntax-export}{\mathit{export}} &::=& \{ \href{../syntax/components.html#syntax-export}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}, \href{../syntax/components.html#syntax-export}{\mathsf{def}}~\href{../syntax/components.html#syntax-sortidx}{\mathit{sortidx}} \}
\end{array}\]