Skip to main content

wasmtime_environ/component/
info.rs

1// General runtime type-information about a component.
2//
3// Compared to the `Module` structure for core wasm this type is pretty
4// significantly different. The core wasm `Module` corresponds roughly 1-to-1
5// with the structure of the wasm module itself, but instead a `Component` is
6// more of a "compiled" representation where the original structure is thrown
7// away in favor of a more optimized representation. The considerations for this
8// are:
9//
10// * This representation of a `Component` avoids the need to create a
11//   `PrimaryMap` of some form for each of the index spaces within a component.
12//   This is less so an issue about allocations and more so that this information
13//   generally just isn't needed any time after instantiation. Avoiding creating
14//   these altogether helps components be lighter weight at runtime and
15//   additionally accelerates instantiation.
16//
17// * Components can have arbitrary nesting and internally do instantiations via
18//   string-based matching. At instantiation-time, though, we want to do as few
19//   string-lookups in hash maps as much as we can since they're significantly
20//   slower than index-based lookups. Furthermore while the imports of a
21//   component are not statically known the rest of the structure of the
22//   component is statically known which enables the ability to track precisely
23//   what matches up where and do all the string lookups at compile time instead
24//   of instantiation time.
25//
26// * Finally by performing this sort of dataflow analysis we are capable of
27//   identifying what adapters need trampolines for compilation or fusion. For
28//   example this tracks when host functions are lowered which enables us to
29//   enumerate what trampolines are required to enter into a component.
30//   Additionally (eventually) this will track all of the "fused" adapter
31//   functions where a function from one component instance is lifted and then
32//   lowered into another component instance. Altogether this enables Wasmtime's
33//   AOT-compilation where the artifact from compilation is suitable for use in
34//   running the component without the support of a compiler at runtime.
35//
36// Note, however, that the current design of `Component` has fundamental
37// limitations which it was not designed for. For example there is no feasible
38// way to implement either importing or exporting a component itself from the
39// root component. Currently we rely on the ability to have static knowledge of
40// what's coming from the host which at this point can only be either functions
41// or core wasm modules. Additionally one flat list of initializers for a
42// component are produced instead of initializers-per-component which would
43// otherwise be required to export a component from a component.
44//
45// For now this tradeoff is made as it aligns well with the intended use case
46// for components in an embedding. This may need to be revisited though if the
47// requirements of embeddings change over time.
48
49use crate::component::*;
50use crate::prelude::*;
51use crate::{EntityIndex, ModuleInternedTypeIndex, PrimaryMap, Trap, WasmValType};
52use cranelift_entity::packed_option::PackedOption;
53use serde_derive::{Deserialize, Serialize};
54
55/// Metadata as a result of compiling a component.
56pub struct ComponentTranslation {
57    /// Serializable information that will be emitted into the final artifact.
58    pub component: Component,
59
60    /// Metadata about required trampolines and what they're supposed to do.
61    pub trampolines: PrimaryMap<TrampolineIndex, Trampoline>,
62}
63
64/// Run-time-type-information about a `Component`, its structure, and how to
65/// instantiate it.
66///
67/// This type is intended to mirror the `Module` type in this crate which
68/// provides all the runtime information about the structure of a module and
69/// how it works.
70///
71/// NB: Lots of the component model is not yet implemented in the runtime so
72/// this is going to undergo a lot of churn.
73#[derive(Default, Debug, Serialize, Deserialize)]
74pub struct Component {
75    /// A list of typed values that this component imports.
76    ///
77    /// Note that each name is given an `ImportIndex` here for the next map to
78    /// refer back to.
79    pub import_types: PrimaryMap<ImportIndex, (String, ComponentExtern)>,
80
81    /// A list of "flattened" imports that are used by this instance.
82    ///
83    /// This import map represents extracting imports, as necessary, from the
84    /// general imported types by this component. The flattening here refers to
85    /// extracting items from instances. Currently the flat imports are either a
86    /// host function or a core wasm module.
87    ///
88    /// For example if `ImportIndex(0)` pointed to an instance then this import
89    /// map represent extracting names from that map, for example extracting an
90    /// exported module or an exported function.
91    ///
92    /// Each import item is keyed by a `RuntimeImportIndex` which is referred to
93    /// by types below whenever something refers to an import. The value for
94    /// each `RuntimeImportIndex` in this map is the `ImportIndex` for where
95    /// this items comes from (which can be associated with a name above in the
96    /// `import_types` array) as well as the list of export names if
97    /// `ImportIndex` refers to an instance. The export names array represents
98    /// recursively fetching names within an instance.
99    //
100    // TODO: this is probably a lot of `String` storage and may be something
101    // that needs optimization in the future. For example instead of lots of
102    // different `String` allocations this could instead be a pointer/length
103    // into one large string allocation for the entire component. Alternatively
104    // strings could otherwise be globally intern'd via some other mechanism to
105    // avoid `Linker`-specific intern-ing plus intern-ing here. Unsure what the
106    // best route is or whether such an optimization is even necessary here.
107    pub imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>,
108
109    /// This component's own root exports from the component itself.
110    pub exports: NameMap<TryString, (ExportIndex, ComponentExternData)>,
111
112    /// All exports of this component and exported instances of this component.
113    ///
114    /// This is indexed by `ExportIndex` for fast lookup and `Export::Instance`
115    /// will refer back into this list.
116    pub export_items: PrimaryMap<ExportIndex, Export>,
117
118    /// Initializers that must be processed when instantiating this component.
119    ///
120    /// This list of initializers does not correspond directly to the component
121    /// itself. The general goal with this is that the recursive nature of
122    /// components is "flattened" with an array like this which is a linear
123    /// sequence of instructions of how to instantiate a component. This will
124    /// have instantiations, for example, in addition to entries which
125    /// initialize `VMComponentContext` fields with previously instantiated
126    /// instances.
127    pub initializers: Vec<GlobalInitializer>,
128
129    /// The number of runtime instances (maximum `RuntimeInstanceIndex`) created
130    /// when instantiating this component.
131    pub num_runtime_instances: u32,
132
133    /// Same as `num_runtime_instances`, but for `RuntimeComponentInstanceIndex`
134    /// instead.
135    pub num_runtime_component_instances: u32,
136
137    /// The number of runtime memories (maximum `RuntimeMemoryIndex`) needed to
138    /// instantiate this component.
139    ///
140    /// Note that this many memories will be stored in the `VMComponentContext`
141    /// and each memory is intended to be unique (e.g. the same memory isn't
142    /// stored in two different locations).
143    pub num_runtime_memories: u32,
144
145    /// The number of runtime tables (maximum `RuntimeTableIndex`) needed to
146    /// instantiate this component. See notes on `num_runtime_memories`.
147    pub num_runtime_tables: u32,
148
149    /// The number of runtime reallocs (maximum `RuntimeReallocIndex`) needed to
150    /// instantiate this component.
151    ///
152    /// Note that this many function pointers will be stored in the
153    /// `VMComponentContext`.
154    pub num_runtime_reallocs: u32,
155
156    /// The number of runtime async callbacks (maximum `RuntimeCallbackIndex`)
157    /// needed to instantiate this component.
158    pub num_runtime_callbacks: u32,
159
160    /// Same as `num_runtime_reallocs`, but for post-return functions.
161    pub num_runtime_post_returns: u32,
162
163    /// WebAssembly type signature of all trampolines.
164    pub trampolines: PrimaryMap<TrampolineIndex, ModuleInternedTypeIndex>,
165
166    /// A map from a `UnsafeIntrinsic::index()` to that intrinsic's
167    /// module-interned type.
168    pub unsafe_intrinsics: [PackedOption<ModuleInternedTypeIndex>; UnsafeIntrinsic::len() as usize],
169
170    /// The number of lowered host functions (maximum `LoweredIndex`) needed to
171    /// instantiate this component.
172    pub num_lowerings: u32,
173
174    /// Total number of resources both imported and defined within this
175    /// component.
176    pub num_resources: u32,
177
178    /// Maximal number of tables required at runtime for future-related
179    /// information in this component.
180    pub num_future_tables: usize,
181
182    /// Maximal number of tables required at runtime for stream-related
183    /// information in this component.
184    pub num_stream_tables: usize,
185
186    /// Maximal number of tables required at runtime for error-context-related
187    /// information in this component.
188    pub num_error_context_tables: usize,
189
190    /// Metadata about imported resources and where they are within the runtime
191    /// imports array.
192    ///
193    /// This map is only as large as the number of imported resources.
194    pub imported_resources: PrimaryMap<ResourceIndex, RuntimeImportIndex>,
195
196    /// Metadata about which component instances defined each resource within
197    /// this component.
198    ///
199    /// This is used to determine which set of instance flags are inspected when
200    /// testing reentrance.
201    pub defined_resource_instances: PrimaryMap<DefinedResourceIndex, RuntimeComponentInstanceIndex>,
202
203    /// All canonical options used by this component. Stored as a table here
204    /// from index-to-options so the options can be consulted at runtime.
205    pub options: PrimaryMap<OptionsIndex, CanonicalOptions>,
206}
207
208impl Component {
209    /// Attempts to convert a resource index into a defined index.
210    ///
211    /// Returns `None` if `idx` is for an imported resource in this component or
212    /// `Some` if it's a locally defined resource.
213    pub fn defined_resource_index(&self, idx: ResourceIndex) -> Option<DefinedResourceIndex> {
214        let idx = idx
215            .as_u32()
216            .checked_sub(self.imported_resources.len() as u32)?;
217        Some(DefinedResourceIndex::from_u32(idx))
218    }
219
220    /// Converts a defined resource index to a component-local resource index
221    /// which includes all imports.
222    pub fn resource_index(&self, idx: DefinedResourceIndex) -> ResourceIndex {
223        ResourceIndex::from_u32(self.imported_resources.len() as u32 + idx.as_u32())
224    }
225}
226
227/// GlobalInitializer instructions to get processed when instantiating a
228/// component.
229///
230/// The variants of this enum are processed during the instantiation phase of a
231/// component in-order from front-to-back. These are otherwise emitted as a
232/// component is parsed and read and translated.
233//
234// FIXME(#2639) if processing this list is ever a bottleneck we could
235// theoretically use cranelift to compile an initialization function which
236// performs all of these duties for us and skips the overhead of interpreting
237// all of these instructions.
238#[derive(Debug, Serialize, Deserialize)]
239pub enum GlobalInitializer {
240    /// A core wasm module is being instantiated.
241    ///
242    /// This will result in a new core wasm instance being created, which may
243    /// involve running the `start` function of the instance as well if it's
244    /// specified. This largely delegates to the same standard instantiation
245    /// process as the rest of the core wasm machinery already uses.
246    ///
247    /// The second field represents the component instance to which the module
248    /// belongs, if applicable.  This will be `None` for adapter modules.
249    InstantiateModule(InstantiateModule, Option<RuntimeComponentInstanceIndex>),
250
251    /// A host function is being lowered, creating a core wasm function.
252    ///
253    /// This initializer entry is intended to be used to fill out the
254    /// `VMComponentContext` and information about this lowering such as the
255    /// cranelift-compiled trampoline function pointer, the host function
256    /// pointer the trampoline calls, and the canonical ABI options.
257    LowerImport {
258        /// The index of the lowered function that's being created.
259        ///
260        /// This is guaranteed to be the `n`th `LowerImport` instruction
261        /// if the index is `n`.
262        index: LoweredIndex,
263
264        /// The index of the imported host function that is being lowered.
265        ///
266        /// It's guaranteed that this `RuntimeImportIndex` points to a function.
267        import: RuntimeImportIndex,
268    },
269
270    /// A core wasm linear memory is going to be saved into the
271    /// `VMComponentContext`.
272    ///
273    /// This instruction indicates that a core wasm linear memory needs to be
274    /// extracted from the `export` and stored into the `VMComponentContext` at
275    /// the `index` specified. This lowering is then used in the future by
276    /// pointers from `CanonicalOptions`.
277    ExtractMemory(ExtractMemory),
278
279    /// Same as `ExtractMemory`, except it's extracting a function pointer to be
280    /// used as a `realloc` function.
281    ExtractRealloc(ExtractRealloc),
282
283    /// Same as `ExtractMemory`, except it's extracting a function pointer to be
284    /// used as an async `callback` function.
285    ExtractCallback(ExtractCallback),
286
287    /// Same as `ExtractMemory`, except it's extracting a function pointer to be
288    /// used as a `post-return` function.
289    ExtractPostReturn(ExtractPostReturn),
290
291    /// A core wasm table is going to be saved into the `VMComponentContext`.
292    ///
293    /// This instruction indicates that s core wasm table needs to be extracted
294    /// from its `export` and stored into the `VMComponentContext` at the
295    /// `index` specified. During this extraction, we will also capture the
296    /// table's containing instance pointer to access the table at runtime. This
297    /// extraction is useful for `thread.spawn-indirect`.
298    ExtractTable(ExtractTable),
299
300    /// Declares a new defined resource within this component.
301    ///
302    /// Contains information about the destructor, for example.
303    Resource(Resource),
304}
305
306/// Metadata for extraction of a memory; contains what's being extracted (the
307/// memory at `export`) and where it's going (the `index` within a
308/// `VMComponentContext`).
309#[derive(Debug, Serialize, Deserialize)]
310pub struct ExtractMemory {
311    /// The index of the memory being defined.
312    pub index: RuntimeMemoryIndex,
313    /// Where this memory is being extracted from.
314    pub export: CoreExport<MemoryIndex>,
315}
316
317/// Same as `ExtractMemory` but for the `realloc` canonical option.
318#[derive(Debug, Serialize, Deserialize)]
319pub struct ExtractRealloc {
320    /// The index of the realloc being defined.
321    pub index: RuntimeReallocIndex,
322    /// Where this realloc is being extracted from.
323    pub def: CoreDef,
324}
325
326/// Same as `ExtractMemory` but for the `callback` canonical option.
327#[derive(Debug, Serialize, Deserialize)]
328pub struct ExtractCallback {
329    /// The index of the callback being defined.
330    pub index: RuntimeCallbackIndex,
331    /// Where this callback is being extracted from.
332    pub def: CoreDef,
333}
334
335/// Same as `ExtractMemory` but for the `post-return` canonical option.
336#[derive(Debug, Serialize, Deserialize)]
337pub struct ExtractPostReturn {
338    /// The index of the post-return being defined.
339    pub index: RuntimePostReturnIndex,
340    /// Where this post-return is being extracted from.
341    pub def: CoreDef,
342}
343
344/// Metadata for extraction of a table.
345#[derive(Debug, Serialize, Deserialize)]
346pub struct ExtractTable {
347    /// The index of the table being defined in a `VMComponentContext`.
348    pub index: RuntimeTableIndex,
349    /// Where this table is being extracted from.
350    pub export: CoreExport<TableIndex>,
351}
352
353/// Different methods of instantiating a core wasm module.
354#[derive(Debug, Serialize, Deserialize)]
355pub enum InstantiateModule {
356    /// A module defined within this component is being instantiated.
357    ///
358    /// Note that this is distinct from the case of imported modules because the
359    /// order of imports required is statically known and can be pre-calculated
360    /// to avoid string lookups related to names at runtime, represented by the
361    /// flat list of arguments here.
362    Static(StaticModuleIndex, Box<[CoreDef]>),
363
364    /// An imported module is being instantiated.
365    ///
366    /// This is similar to `Upvar` but notably the imports are provided as a
367    /// two-level named map since import resolution order needs to happen at
368    /// runtime.
369    Import(
370        RuntimeImportIndex,
371        IndexMap<String, IndexMap<String, CoreDef>>,
372    ),
373}
374
375/// Definition of a core wasm item and where it can come from within a
376/// component.
377///
378/// Note that this is sort of a result of data-flow-like analysis on a component
379/// during compile time of the component itself. References to core wasm items
380/// are "compiled" to either referring to a previous instance or to some sort of
381/// lowered host import.
382#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
383pub enum CoreDef {
384    /// This item refers to an export of a previously instantiated core wasm
385    /// instance.
386    Export(CoreExport<EntityIndex>),
387    /// This is a reference to a wasm global which represents the
388    /// runtime-managed flags for a wasm instance.
389    InstanceFlags(RuntimeComponentInstanceIndex),
390    /// This is a reference to a Cranelift-generated trampoline which is
391    /// described in the `trampolines` array.
392    Trampoline(TrampolineIndex),
393    /// An intrinsic for compile-time builtins.
394    UnsafeIntrinsic(UnsafeIntrinsic),
395}
396
397impl<T> From<CoreExport<T>> for CoreDef
398where
399    EntityIndex: From<T>,
400{
401    fn from(export: CoreExport<T>) -> CoreDef {
402        CoreDef::Export(export.map_index(|i| i.into()))
403    }
404}
405
406/// Identifier of an exported item from a core WebAssembly module instance.
407///
408/// Note that the `T` here is the index type for exports which can be
409/// identified by index. The `T` is monomorphized with types like
410/// [`EntityIndex`] or [`FuncIndex`].
411#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
412pub struct CoreExport<T> {
413    /// The instance that this item is located within.
414    ///
415    /// Note that this is intended to index the `instances` map within a
416    /// component. It's validated ahead of time that all instance pointers
417    /// refer only to previously-created instances.
418    pub instance: RuntimeInstanceIndex,
419
420    /// The item that this export is referencing, either by name or by index.
421    pub item: ExportItem<T>,
422}
423
424impl<T> CoreExport<T> {
425    /// Maps the index type `T` to another type `U` if this export item indeed
426    /// refers to an index `T`.
427    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
428        CoreExport {
429            instance: self.instance,
430            item: match self.item {
431                ExportItem::Index(i) => ExportItem::Index(f(i)),
432                ExportItem::Name(s) => ExportItem::Name(s),
433            },
434        }
435    }
436}
437
438/// An index at which to find an item within a runtime instance.
439#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq)]
440pub enum ExportItem<T> {
441    /// An exact index that the target can be found at.
442    ///
443    /// This is used where possible to avoid name lookups at runtime during the
444    /// instantiation process. This can only be used on instances where the
445    /// module was statically known at compile time, however.
446    Index(T),
447
448    /// An item which is identified by a name, so at runtime we need to
449    /// perform a name lookup to determine the index that the item is located
450    /// at.
451    ///
452    /// This is used for instantiations of imported modules, for example, since
453    /// the precise shape of the module is not known.
454    Name(String),
455}
456
457/// Possible exports from a component.
458#[derive(Debug, Serialize, Deserialize)]
459pub enum Export {
460    /// A lifted function being exported which is an adaptation of a core wasm
461    /// function.
462    LiftedFunction {
463        /// The component function type of the function being created.
464        ty: TypeFuncIndex,
465        /// Which core WebAssembly export is being lifted.
466        func: CoreDef,
467        /// Any options, if present, associated with this lifting.
468        options: OptionsIndex,
469    },
470    /// A module defined within this component is exported.
471    ModuleStatic {
472        /// The type of this module
473        ty: TypeModuleIndex,
474        /// Which module this is referring to.
475        index: StaticModuleIndex,
476    },
477    /// A module imported into this component is exported.
478    ModuleImport {
479        /// Module type index
480        ty: TypeModuleIndex,
481        /// Module runtime import index
482        import: RuntimeImportIndex,
483    },
484    /// A nested instance is being exported which has recursively defined
485    /// `Export` items.
486    Instance {
487        /// Instance type index, if such is assigned
488        ty: TypeComponentInstanceIndex,
489        /// Instance export map
490        exports: NameMap<TryString, (ExportIndex, ComponentExternData)>,
491    },
492    /// An exported type from a component or instance, currently only
493    /// informational.
494    Type(TypeDef),
495}
496
497#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
498/// Data is stored in a linear memory.
499pub struct LinearMemoryOptions {
500    /// The memory used by these options, if specified.
501    pub memory: Option<RuntimeMemoryIndex>,
502    /// The realloc function used by these options, if specified.
503    pub realloc: Option<RuntimeReallocIndex>,
504}
505
506/// The data model for objects that are not unboxed in locals.
507#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
508pub enum CanonicalOptionsDataModel {
509    /// Data is stored in GC objects.
510    Gc {},
511
512    /// Data is stored in a linear memory.
513    LinearMemory(LinearMemoryOptions),
514}
515
516/// Canonical ABI options associated with a lifted or lowered function.
517#[derive(Debug, Clone, Serialize, Deserialize)]
518pub struct CanonicalOptions {
519    /// The component instance that this bundle was associated with.
520    pub instance: RuntimeComponentInstanceIndex,
521
522    /// The encoding used for strings.
523    pub string_encoding: StringEncoding,
524
525    /// The async callback function used by these options, if specified.
526    pub callback: Option<RuntimeCallbackIndex>,
527
528    /// The post-return function used by these options, if specified.
529    pub post_return: Option<RuntimePostReturnIndex>,
530
531    /// Whether to use the async ABI for lifting or lowering.
532    pub async_: bool,
533
534    /// The core function type that is being lifted from / lowered to.
535    pub core_type: ModuleInternedTypeIndex,
536
537    /// The data model (GC objects or linear memory) used with these canonical
538    /// options.
539    pub data_model: CanonicalOptionsDataModel,
540}
541
542impl CanonicalOptions {
543    /// Returns the memory referred to by these options, if any.
544    pub fn memory(&self) -> Option<RuntimeMemoryIndex> {
545        match self.data_model {
546            CanonicalOptionsDataModel::Gc {} => None,
547            CanonicalOptionsDataModel::LinearMemory(opts) => opts.memory,
548        }
549    }
550}
551
552/// Possible encodings of strings within the component model.
553#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
554#[expect(missing_docs, reason = "self-describing variants")]
555pub enum StringEncoding {
556    Utf8,
557    Utf16,
558    CompactUtf16,
559}
560
561impl StringEncoding {
562    /// Decodes the `u8` provided back into a `StringEncoding`, if it's valid.
563    pub fn from_u8(val: u8) -> Option<StringEncoding> {
564        if val == StringEncoding::Utf8 as u8 {
565            return Some(StringEncoding::Utf8);
566        }
567        if val == StringEncoding::Utf16 as u8 {
568            return Some(StringEncoding::Utf16);
569        }
570        if val == StringEncoding::CompactUtf16 as u8 {
571            return Some(StringEncoding::CompactUtf16);
572        }
573        None
574    }
575}
576
577/// Possible transcoding operations that must be provided by the host.
578///
579/// Note that each transcoding operation may have a unique signature depending
580/// on the precise operation.
581#[expect(missing_docs, reason = "self-describing variants")]
582#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
583pub enum Transcode {
584    Copy(FixedEncoding),
585    Latin1ToUtf16,
586    Latin1ToUtf8,
587    Utf16ToCompactProbablyUtf16,
588    Utf16ToCompactUtf16,
589    Utf16ToLatin1,
590    Utf16ToUtf8,
591    Utf8ToCompactUtf16,
592    Utf8ToLatin1,
593    Utf8ToUtf16,
594}
595
596impl Transcode {
597    /// Get this transcoding's symbol fragment.
598    pub fn symbol_fragment(&self) -> &'static str {
599        match self {
600            Transcode::Copy(x) => match x {
601                FixedEncoding::Utf8 => "copy_utf8",
602                FixedEncoding::Utf16 => "copy_utf16",
603                FixedEncoding::Latin1 => "copy_latin1",
604            },
605            Transcode::Latin1ToUtf16 => "latin1_to_utf16",
606            Transcode::Latin1ToUtf8 => "latin1_to_utf8",
607            Transcode::Utf16ToCompactProbablyUtf16 => "utf16_to_compact_probably_utf16",
608            Transcode::Utf16ToCompactUtf16 => "utf16_to_compact_utf16",
609            Transcode::Utf16ToLatin1 => "utf16_to_latin1",
610            Transcode::Utf16ToUtf8 => "utf16_to_utf8",
611            Transcode::Utf8ToCompactUtf16 => "utf8_to_compact_utf16",
612            Transcode::Utf8ToLatin1 => "utf8_to_latin1",
613            Transcode::Utf8ToUtf16 => "utf8_to_utf16",
614        }
615    }
616
617    /// Returns a human-readable description for this transcoding operation.
618    pub fn desc(&self) -> &'static str {
619        match self {
620            Transcode::Copy(FixedEncoding::Utf8) => "utf8-to-utf8",
621            Transcode::Copy(FixedEncoding::Utf16) => "utf16-to-utf16",
622            Transcode::Copy(FixedEncoding::Latin1) => "latin1-to-latin1",
623            Transcode::Latin1ToUtf16 => "latin1-to-utf16",
624            Transcode::Latin1ToUtf8 => "latin1-to-utf8",
625            Transcode::Utf16ToCompactProbablyUtf16 => "utf16-to-compact-probably-utf16",
626            Transcode::Utf16ToCompactUtf16 => "utf16-to-compact-utf16",
627            Transcode::Utf16ToLatin1 => "utf16-to-latin1",
628            Transcode::Utf16ToUtf8 => "utf16-to-utf8",
629            Transcode::Utf8ToCompactUtf16 => "utf8-to-compact-utf16",
630            Transcode::Utf8ToLatin1 => "utf8-to-latin1",
631            Transcode::Utf8ToUtf16 => "utf8-to-utf16",
632        }
633    }
634}
635
636#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
637#[expect(missing_docs, reason = "self-describing variants")]
638pub enum FixedEncoding {
639    Utf8,
640    Utf16,
641    Latin1,
642}
643
644impl FixedEncoding {
645    /// Returns the byte width of unit loads/stores for this encoding, for
646    /// example the unit length is multiplied by this return value to get the
647    /// byte width of a string.
648    pub fn width(&self) -> u8 {
649        match self {
650            FixedEncoding::Utf8 => 1,
651            FixedEncoding::Utf16 => 2,
652            FixedEncoding::Latin1 => 1,
653        }
654    }
655
656    /// Returns the alignment of strings using this encoding.
657    pub fn align(&self) -> u8 {
658        match self {
659            FixedEncoding::Utf8 => 1,
660            FixedEncoding::Utf16 => 2,
661            FixedEncoding::Latin1 => 2,
662        }
663    }
664}
665
666/// Description of a new resource declared in a `GlobalInitializer::Resource`
667/// variant.
668///
669/// This will have the effect of initializing runtime state for this resource,
670/// namely the destructor is fetched and stored.
671#[derive(Debug, Serialize, Deserialize)]
672pub struct Resource {
673    /// The local index of the resource being defined.
674    pub index: DefinedResourceIndex,
675    /// Core wasm representation of this resource.
676    pub rep: WasmValType,
677    /// Optionally-specified destructor and where it comes from.
678    pub dtor: Option<CoreDef>,
679    /// Which component instance this resource logically belongs to.
680    pub instance: RuntimeComponentInstanceIndex,
681}
682
683/// A list of all possible trampolines that may be required to compile a
684/// component completely.
685///
686/// These trampolines are used often as core wasm definitions and require
687/// Cranelift support to generate these functions. Each trampoline serves a
688/// different purpose for implementing bits and pieces of the component model.
689///
690/// All trampolines have a core wasm function signature associated with them
691/// which is stored in the `Component::trampolines` array.
692///
693/// Note that this type does not implement `Serialize` or `Deserialize` and
694/// that's intentional as this isn't stored in the final compilation artifact.
695#[derive(Debug)]
696pub enum Trampoline {
697    /// Description of a lowered import used in conjunction with
698    /// `GlobalInitializer::LowerImport`.
699    LowerImport {
700        /// The runtime lowering state that this trampoline will access.
701        index: LoweredIndex,
702
703        /// The type of the function that is being lowered, as perceived by the
704        /// component doing the lowering.
705        lower_ty: TypeFuncIndex,
706
707        /// The canonical ABI options used when lowering this function specified
708        /// in the original component.
709        options: OptionsIndex,
710    },
711
712    /// Information about a string transcoding function required by an adapter
713    /// module.
714    ///
715    /// A transcoder is used when strings are passed between adapter modules,
716    /// optionally changing string encodings at the same time. The transcoder is
717    /// implemented in a few different layers:
718    ///
719    /// * Each generated adapter module has some glue around invoking the
720    ///   transcoder represented by this item. This involves bounds-checks and
721    ///   handling `realloc` for example.
722    /// * Each transcoder gets a cranelift-generated trampoline which has the
723    ///   appropriate signature for the adapter module in question. Existence of
724    ///   this initializer indicates that this should be compiled by Cranelift.
725    /// * The cranelift-generated trampoline will invoke a "transcoder libcall"
726    ///   which is implemented natively in Rust that has a signature independent
727    ///   of memory64 configuration options for example.
728    Transcoder {
729        /// The transcoding operation being performed.
730        op: Transcode,
731        /// The linear memory that the string is being read from.
732        from: RuntimeMemoryIndex,
733        /// Whether or not the source linear memory is 64-bit or not.
734        from64: bool,
735        /// The linear memory that the string is being written to.
736        to: RuntimeMemoryIndex,
737        /// Whether or not the destination linear memory is 64-bit or not.
738        to64: bool,
739    },
740
741    /// A `resource.new` intrinsic which will inject a new resource into the
742    /// table specified.
743    ResourceNew {
744        /// The specific component instance which is calling the intrinsic.
745        instance: RuntimeComponentInstanceIndex,
746        /// The type of the resource.
747        ty: TypeResourceTableIndex,
748    },
749
750    /// Same as `ResourceNew`, but for the `resource.rep` intrinsic.
751    ResourceRep {
752        /// The specific component instance which is calling the intrinsic.
753        instance: RuntimeComponentInstanceIndex,
754        /// The type of the resource.
755        ty: TypeResourceTableIndex,
756    },
757
758    /// Same as `ResourceNew`, but for the `resource.drop` intrinsic.
759    ResourceDrop {
760        /// The specific component instance which is calling the intrinsic.
761        instance: RuntimeComponentInstanceIndex,
762        /// The type of the resource.
763        ty: TypeResourceTableIndex,
764    },
765
766    /// A `backpressure.inc` intrinsic.
767    BackpressureInc {
768        /// The specific component instance which is calling the intrinsic.
769        instance: RuntimeComponentInstanceIndex,
770    },
771
772    /// A `backpressure.dec` intrinsic.
773    BackpressureDec {
774        /// The specific component instance which is calling the intrinsic.
775        instance: RuntimeComponentInstanceIndex,
776    },
777
778    /// A `task.return` intrinsic, which returns a result to the caller of a
779    /// lifted export function.  This allows the callee to continue executing
780    /// after returning a result.
781    TaskReturn {
782        /// The specific component instance which is calling the intrinsic.
783        instance: RuntimeComponentInstanceIndex,
784        /// Tuple representing the result types this intrinsic accepts.
785        results: TypeTupleIndex,
786        /// The canonical ABI options specified for this intrinsic.
787        options: OptionsIndex,
788    },
789
790    /// A `task.cancel` intrinsic, which acknowledges a `CANCELLED` event
791    /// delivered to a guest task previously created by a call to an async
792    /// export.
793    TaskCancel {
794        /// The specific component instance which is calling the intrinsic.
795        instance: RuntimeComponentInstanceIndex,
796    },
797
798    /// A `waitable-set.new` intrinsic.
799    WaitableSetNew {
800        /// The specific component instance which is calling the intrinsic.
801        instance: RuntimeComponentInstanceIndex,
802    },
803
804    /// A `waitable-set.wait` intrinsic, which waits for at least one
805    /// outstanding async task/stream/future to make progress, returning the
806    /// first such event.
807    WaitableSetWait {
808        /// The specific component instance which is calling the intrinsic.
809        instance: RuntimeComponentInstanceIndex,
810        /// Configuration options for this intrinsic call.
811        options: OptionsIndex,
812    },
813
814    /// A `waitable-set.poll` intrinsic, which checks whether any outstanding
815    /// async task/stream/future has made progress.  Unlike `task.wait`, this
816    /// does not block and may return nothing if no such event has occurred.
817    WaitableSetPoll {
818        /// The specific component instance which is calling the intrinsic.
819        instance: RuntimeComponentInstanceIndex,
820        /// Configuration options for this intrinsic call.
821        options: OptionsIndex,
822    },
823
824    /// A `waitable-set.drop` intrinsic.
825    WaitableSetDrop {
826        /// The specific component instance which is calling the intrinsic.
827        instance: RuntimeComponentInstanceIndex,
828    },
829
830    /// A `waitable.join` intrinsic.
831    WaitableJoin {
832        /// The specific component instance which is calling the intrinsic.
833        instance: RuntimeComponentInstanceIndex,
834    },
835
836    /// A `subtask.drop` intrinsic to drop a specified task which has completed.
837    SubtaskDrop {
838        /// The specific component instance which is calling the intrinsic.
839        instance: RuntimeComponentInstanceIndex,
840    },
841
842    /// A `subtask.cancel` intrinsic to drop an in-progress task.
843    SubtaskCancel {
844        /// The specific component instance which is calling the intrinsic.
845        instance: RuntimeComponentInstanceIndex,
846        /// If `false`, block until cancellation completes rather than return
847        /// `BLOCKED`.
848        async_: bool,
849    },
850
851    /// A `stream.new` intrinsic to create a new `stream` handle of the
852    /// specified type.
853    StreamNew {
854        /// The specific component instance which is calling the intrinsic.
855        instance: RuntimeComponentInstanceIndex,
856        /// The table index for the specific `stream` type and caller instance.
857        ty: TypeStreamTableIndex,
858    },
859
860    /// A `stream.read` intrinsic to read from a `stream` of the specified type.
861    StreamRead {
862        /// The specific component instance which is calling the intrinsic.
863        instance: RuntimeComponentInstanceIndex,
864        /// The table index for the specific `stream` type and caller instance.
865        ty: TypeStreamTableIndex,
866        /// Any options (e.g. string encoding) to use when storing values to
867        /// memory.
868        options: OptionsIndex,
869    },
870
871    /// A `stream.write` intrinsic to write to a `stream` of the specified type.
872    StreamWrite {
873        /// The specific component instance which is calling the intrinsic.
874        instance: RuntimeComponentInstanceIndex,
875        /// The table index for the specific `stream` type and caller instance.
876        ty: TypeStreamTableIndex,
877        /// Any options (e.g. string encoding) to use when storing values to
878        /// memory.
879        options: OptionsIndex,
880    },
881
882    /// A `stream.cancel-read` intrinsic to cancel an in-progress read from a
883    /// `stream` of the specified type.
884    StreamCancelRead {
885        /// The specific component instance which is calling the intrinsic.
886        instance: RuntimeComponentInstanceIndex,
887        /// The table index for the specific `stream` type and caller instance.
888        ty: TypeStreamTableIndex,
889        /// If `false`, block until cancellation completes rather than return
890        /// `BLOCKED`.
891        async_: bool,
892    },
893
894    /// A `stream.cancel-write` intrinsic to cancel an in-progress write from a
895    /// `stream` of the specified type.
896    StreamCancelWrite {
897        /// The specific component instance which is calling the intrinsic.
898        instance: RuntimeComponentInstanceIndex,
899        /// The table index for the specific `stream` type and caller instance.
900        ty: TypeStreamTableIndex,
901        /// If `false`, block until cancellation completes rather than return
902        /// `BLOCKED`.
903        async_: bool,
904    },
905
906    /// A `stream.drop-readable` intrinsic to drop the readable end of a
907    /// `stream` of the specified type.
908    StreamDropReadable {
909        /// The specific component instance which is calling the intrinsic.
910        instance: RuntimeComponentInstanceIndex,
911        /// The table index for the specific `stream` type and caller instance.
912        ty: TypeStreamTableIndex,
913    },
914
915    /// A `stream.drop-writable` intrinsic to drop the writable end of a
916    /// `stream` of the specified type.
917    StreamDropWritable {
918        /// The specific component instance which is calling the intrinsic.
919        instance: RuntimeComponentInstanceIndex,
920        /// The table index for the specific `stream` type and caller instance.
921        ty: TypeStreamTableIndex,
922    },
923
924    /// A `future.new` intrinsic to create a new `future` handle of the
925    /// specified type.
926    FutureNew {
927        /// The specific component instance which is calling the intrinsic.
928        instance: RuntimeComponentInstanceIndex,
929        /// The table index for the specific `future` type and caller instance.
930        ty: TypeFutureTableIndex,
931    },
932
933    /// A `future.read` intrinsic to read from a `future` of the specified type.
934    FutureRead {
935        /// The specific component instance which is calling the intrinsic.
936        instance: RuntimeComponentInstanceIndex,
937        /// The table index for the specific `future` type and caller instance.
938        ty: TypeFutureTableIndex,
939        /// Any options (e.g. string encoding) to use when storing values to
940        /// memory.
941        options: OptionsIndex,
942    },
943
944    /// A `future.write` intrinsic to write to a `future` of the specified type.
945    FutureWrite {
946        /// The specific component instance which is calling the intrinsic.
947        instance: RuntimeComponentInstanceIndex,
948        /// The table index for the specific `future` type and caller instance.
949        ty: TypeFutureTableIndex,
950        /// Any options (e.g. string encoding) to use when storing values to
951        /// memory.
952        options: OptionsIndex,
953    },
954
955    /// A `future.cancel-read` intrinsic to cancel an in-progress read from a
956    /// `future` of the specified type.
957    FutureCancelRead {
958        /// The specific component instance which is calling the intrinsic.
959        instance: RuntimeComponentInstanceIndex,
960        /// The table index for the specific `future` type and caller instance.
961        ty: TypeFutureTableIndex,
962        /// If `false`, block until cancellation completes rather than return
963        /// `BLOCKED`.
964        async_: bool,
965    },
966
967    /// A `future.cancel-write` intrinsic to cancel an in-progress write from a
968    /// `future` of the specified type.
969    FutureCancelWrite {
970        /// The specific component instance which is calling the intrinsic.
971        instance: RuntimeComponentInstanceIndex,
972        /// The table index for the specific `future` type and caller instance.
973        ty: TypeFutureTableIndex,
974        /// If `false`, block until cancellation completes rather than return
975        /// `BLOCKED`.
976        async_: bool,
977    },
978
979    /// A `future.drop-readable` intrinsic to drop the readable end of a
980    /// `future` of the specified type.
981    FutureDropReadable {
982        /// The specific component instance which is calling the intrinsic.
983        instance: RuntimeComponentInstanceIndex,
984        /// The table index for the specific `future` type and caller instance.
985        ty: TypeFutureTableIndex,
986    },
987
988    /// A `future.drop-writable` intrinsic to drop the writable end of a
989    /// `future` of the specified type.
990    FutureDropWritable {
991        /// The specific component instance which is calling the intrinsic.
992        instance: RuntimeComponentInstanceIndex,
993        /// The table index for the specific `future` type and caller instance.
994        ty: TypeFutureTableIndex,
995    },
996
997    /// A `error-context.new` intrinsic to create a new `error-context` with a
998    /// specified debug message.
999    ErrorContextNew {
1000        /// The specific component instance which is calling the intrinsic.
1001        instance: RuntimeComponentInstanceIndex,
1002        /// The table index for the `error-context` type in the caller instance.
1003        ty: TypeComponentLocalErrorContextTableIndex,
1004        /// String encoding, memory, etc. to use when loading debug message.
1005        options: OptionsIndex,
1006    },
1007
1008    /// A `error-context.debug-message` intrinsic to get the debug message for a
1009    /// specified `error-context`.
1010    ///
1011    /// Note that the debug message might not necessarily match what was passed
1012    /// to `error.new`.
1013    ErrorContextDebugMessage {
1014        /// The specific component instance which is calling the intrinsic.
1015        instance: RuntimeComponentInstanceIndex,
1016        /// The table index for the `error-context` type in the caller instance.
1017        ty: TypeComponentLocalErrorContextTableIndex,
1018        /// String encoding, memory, etc. to use when storing debug message.
1019        options: OptionsIndex,
1020    },
1021
1022    /// A `error-context.drop` intrinsic to drop a specified `error-context`.
1023    ErrorContextDrop {
1024        /// The specific component instance which is calling the intrinsic.
1025        instance: RuntimeComponentInstanceIndex,
1026        /// The table index for the `error-context` type in the caller instance.
1027        ty: TypeComponentLocalErrorContextTableIndex,
1028    },
1029
1030    /// An intrinsic used by FACT-generated modules which will transfer an owned
1031    /// resource from one table to another. Used in component-to-component
1032    /// adapter trampolines.
1033    ResourceTransferOwn,
1034
1035    /// Same as `ResourceTransferOwn` but for borrows.
1036    ResourceTransferBorrow,
1037
1038    /// An intrinsic used by FACT-generated modules to prepare a call involving
1039    /// an async-lowered import and/or an async-lifted export.
1040    PrepareCall {
1041        /// The memory used to verify that the memory specified for the
1042        /// `task.return` that is called at runtime matches the one specified in
1043        /// the lifted export.
1044        memory: Option<RuntimeMemoryIndex>,
1045    },
1046
1047    /// An intrinsic used by FACT-generated modules to start a call involving a
1048    /// sync-lowered import and async-lifted export.
1049    SyncStartCall {
1050        /// The callee's callback function, if any.
1051        callback: Option<RuntimeCallbackIndex>,
1052    },
1053
1054    /// An intrinsic used by FACT-generated modules to start a call involving
1055    /// an async-lowered import function.
1056    ///
1057    /// Note that `AsyncPrepareCall` and `AsyncStartCall` could theoretically be
1058    /// combined into a single `AsyncCall` intrinsic, but we separate them to
1059    /// allow the FACT-generated module to optionally call the callee directly
1060    /// without an intermediate host stack frame.
1061    AsyncStartCall {
1062        /// The callee's callback, if any.
1063        callback: Option<RuntimeCallbackIndex>,
1064        /// The callee's post-return function, if any.
1065        post_return: Option<RuntimePostReturnIndex>,
1066    },
1067
1068    /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1069    /// ownership of a `future`.
1070    ///
1071    /// Transferring a `future` can either mean giving away the readable end
1072    /// while retaining the writable end or only the former, depending on the
1073    /// ownership status of the `future`.
1074    FutureTransfer,
1075
1076    /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1077    /// ownership of a `stream`.
1078    ///
1079    /// Transferring a `stream` can either mean giving away the readable end
1080    /// while retaining the writable end or only the former, depending on the
1081    /// ownership status of the `stream`.
1082    StreamTransfer,
1083
1084    /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1085    /// ownership of an `error-context`.
1086    ///
1087    /// Unlike futures, streams, and resource handles, `error-context` handles
1088    /// are reference counted, meaning that sharing the handle with another
1089    /// component does not invalidate the handle in the original component.
1090    ErrorContextTransfer,
1091
1092    /// An intrinsic used by FACT-generated modules to trap with the specified
1093    /// code.
1094    Trap(Trap),
1095
1096    /// An intrinsic used by FACT-generated modules to push a task onto the
1097    /// stack for a sync-to-sync, guest-to-guest call.
1098    EnterSyncCall,
1099    /// An intrinsic used by FACT-generated modules to pop the task previously
1100    /// pushed by `EnterSyncCall`.
1101    ExitSyncCall,
1102
1103    /// Intrinsic used to implement the `thread.index` component model builtin.
1104    ThreadIndex {
1105        /// The specific component instance which is calling the intrinsic.
1106        instance: RuntimeComponentInstanceIndex,
1107    },
1108
1109    /// Intrinsic used to implement the `thread.new-indirect` component model builtin.
1110    ThreadNewIndirect {
1111        /// The specific component instance which is calling the intrinsic.
1112        instance: RuntimeComponentInstanceIndex,
1113        /// The type index for the start function of the thread.
1114        start_func_ty_idx: ComponentTypeIndex,
1115        /// The index of the table that stores the start function.
1116        start_func_table_idx: RuntimeTableIndex,
1117    },
1118
1119    /// Intrinsic used to implement the `thread.resume-later` component model
1120    /// builtin.
1121    ThreadResumeLater {
1122        /// The specific component instance which is calling the intrinsic.
1123        instance: RuntimeComponentInstanceIndex,
1124    },
1125
1126    /// Intrinsic used to implement the `thread.suspend` component model builtin.
1127    ThreadSuspend {
1128        /// The specific component instance which is calling the intrinsic.
1129        instance: RuntimeComponentInstanceIndex,
1130    },
1131
1132    /// A `thread.yield` intrinsic, which yields control to the host so that other
1133    /// tasks are able to make progress, if any.
1134    ThreadYield {
1135        /// The specific component instance which is calling the intrinsic.
1136        instance: RuntimeComponentInstanceIndex,
1137    },
1138
1139    /// Intrinsic used to implement the `thread.suspend-then-resume` component
1140    /// model builtin.
1141    ThreadSuspendThenResume {
1142        /// The specific component instance which is calling the intrinsic.
1143        instance: RuntimeComponentInstanceIndex,
1144    },
1145
1146    /// Intrinsic used to implement the `thread.yield-then-resume` component
1147    /// model builtin.
1148    ThreadYieldThenResume {
1149        /// The specific component instance which is calling the intrinsic.
1150        instance: RuntimeComponentInstanceIndex,
1151    },
1152
1153    /// Intrinsic used to implement the `thread.suspend-then-promote` component
1154    /// model builtin.
1155    ThreadSuspendThenPromote {
1156        /// The specific component instance which is calling the intrinsic.
1157        instance: RuntimeComponentInstanceIndex,
1158    },
1159
1160    /// Intrinsic used to implement the `thread.yield-then-promote` component
1161    /// model builtin.
1162    ThreadYieldThenPromote {
1163        /// The specific component instance which is calling the intrinsic.
1164        instance: RuntimeComponentInstanceIndex,
1165    },
1166}
1167
1168impl Trampoline {
1169    /// Returns the name to use for the symbol of this trampoline in the final
1170    /// compiled artifact
1171    pub fn symbol_name(&self) -> String {
1172        use Trampoline::*;
1173        match self {
1174            LowerImport { index, .. } => {
1175                format!("component-lower-import[{}]", index.as_u32())
1176            }
1177            Transcoder {
1178                op, from64, to64, ..
1179            } => {
1180                let op = op.symbol_fragment();
1181                let from = if *from64 { "64" } else { "32" };
1182                let to = if *to64 { "64" } else { "32" };
1183                format!("component-transcode-{op}-m{from}-m{to}")
1184            }
1185            ResourceNew { ty, .. } => format!("component-resource-new[{}]", ty.as_u32()),
1186            ResourceRep { ty, .. } => format!("component-resource-rep[{}]", ty.as_u32()),
1187            ResourceDrop { ty, .. } => format!("component-resource-drop[{}]", ty.as_u32()),
1188            BackpressureInc { .. } => format!("backpressure-inc"),
1189            BackpressureDec { .. } => format!("backpressure-dec"),
1190            TaskReturn { .. } => format!("task-return"),
1191            TaskCancel { .. } => format!("task-cancel"),
1192            WaitableSetNew { .. } => format!("waitable-set-new"),
1193            WaitableSetWait { .. } => format!("waitable-set-wait"),
1194            WaitableSetPoll { .. } => format!("waitable-set-poll"),
1195            WaitableSetDrop { .. } => format!("waitable-set-drop"),
1196            WaitableJoin { .. } => format!("waitable-join"),
1197            SubtaskDrop { .. } => format!("subtask-drop"),
1198            SubtaskCancel { .. } => format!("subtask-cancel"),
1199            StreamNew { .. } => format!("stream-new"),
1200            StreamRead { .. } => format!("stream-read"),
1201            StreamWrite { .. } => format!("stream-write"),
1202            StreamCancelRead { .. } => format!("stream-cancel-read"),
1203            StreamCancelWrite { .. } => format!("stream-cancel-write"),
1204            StreamDropReadable { .. } => format!("stream-drop-readable"),
1205            StreamDropWritable { .. } => format!("stream-drop-writable"),
1206            FutureNew { .. } => format!("future-new"),
1207            FutureRead { .. } => format!("future-read"),
1208            FutureWrite { .. } => format!("future-write"),
1209            FutureCancelRead { .. } => format!("future-cancel-read"),
1210            FutureCancelWrite { .. } => format!("future-cancel-write"),
1211            FutureDropReadable { .. } => format!("future-drop-readable"),
1212            FutureDropWritable { .. } => format!("future-drop-writable"),
1213            ErrorContextNew { .. } => format!("error-context-new"),
1214            ErrorContextDebugMessage { .. } => format!("error-context-debug-message"),
1215            ErrorContextDrop { .. } => format!("error-context-drop"),
1216            ResourceTransferOwn => format!("component-resource-transfer-own"),
1217            ResourceTransferBorrow => format!("component-resource-transfer-borrow"),
1218            PrepareCall { .. } => format!("component-prepare-call"),
1219            SyncStartCall { .. } => format!("component-sync-start-call"),
1220            AsyncStartCall { .. } => format!("component-async-start-call"),
1221            FutureTransfer => format!("future-transfer"),
1222            StreamTransfer => format!("stream-transfer"),
1223            ErrorContextTransfer => format!("error-context-transfer"),
1224            Trap(trap) => format!("trap-{}", *trap as u8),
1225            EnterSyncCall => format!("enter-sync-call"),
1226            ExitSyncCall => format!("exit-sync-call"),
1227            ThreadIndex { .. } => format!("thread-index"),
1228            ThreadNewIndirect { .. } => format!("thread-new-indirect"),
1229            ThreadResumeLater { .. } => format!("thread-resume-later"),
1230            ThreadSuspend { .. } => format!("thread-suspend"),
1231            ThreadYield { .. } => format!("thread-yield"),
1232            ThreadSuspendThenResume { .. } => format!("thread-suspend-then-resume"),
1233            ThreadYieldThenResume { .. } => format!("thread-yield-then-resume"),
1234            ThreadSuspendThenPromote { .. } => format!("thread-suspend-then-promote"),
1235            ThreadYieldThenPromote { .. } => format!("thread-yield-then-promote"),
1236        }
1237    }
1238}