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: TryPrimaryMap<ImportIndex, (TryString, 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: TryPrimaryMap<RuntimeImportIndex, (ImportIndex, TryVec<TryString>)>,
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: TryPrimaryMap<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: TryVec<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: TryPrimaryMap<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: TryPrimaryMap<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:
202 TryPrimaryMap<DefinedResourceIndex, RuntimeComponentInstanceIndex>,
203
204 /// All canonical options used by this component. Stored as a table here
205 /// from index-to-options so the options can be consulted at runtime.
206 pub options: TryPrimaryMap<OptionsIndex, CanonicalOptions>,
207}
208
209impl Component {
210 /// Attempts to convert a resource index into a defined index.
211 ///
212 /// Returns `None` if `idx` is for an imported resource in this component or
213 /// `Some` if it's a locally defined resource.
214 pub fn defined_resource_index(&self, idx: ResourceIndex) -> Option<DefinedResourceIndex> {
215 let idx = idx
216 .as_u32()
217 .checked_sub(self.imported_resources.len() as u32)?;
218 Some(DefinedResourceIndex::from_u32(idx))
219 }
220
221 /// Converts a defined resource index to a component-local resource index
222 /// which includes all imports.
223 pub fn resource_index(&self, idx: DefinedResourceIndex) -> ResourceIndex {
224 ResourceIndex::from_u32(self.imported_resources.len() as u32 + idx.as_u32())
225 }
226
227 /// Returns the component instance which defines `idx`, or `None` if `idx`
228 /// is imported rather than defined within this component.
229 pub fn defined_resource_instance(
230 &self,
231 idx: ResourceIndex,
232 ) -> Option<RuntimeComponentInstanceIndex> {
233 Some(self.defined_resource_instances[self.defined_resource_index(idx)?])
234 }
235}
236
237/// GlobalInitializer instructions to get processed when instantiating a
238/// component.
239///
240/// The variants of this enum are processed during the instantiation phase of a
241/// component in-order from front-to-back. These are otherwise emitted as a
242/// component is parsed and read and translated.
243//
244// FIXME(#2639) if processing this list is ever a bottleneck we could
245// theoretically use cranelift to compile an initialization function which
246// performs all of these duties for us and skips the overhead of interpreting
247// all of these instructions.
248#[derive(Debug, Serialize, Deserialize)]
249pub enum GlobalInitializer {
250 /// A core wasm module is being instantiated.
251 ///
252 /// This will result in a new core wasm instance being created, which may
253 /// involve running the `start` function of the instance as well if it's
254 /// specified. This largely delegates to the same standard instantiation
255 /// process as the rest of the core wasm machinery already uses.
256 ///
257 /// The second field represents the component instance to which the module
258 /// belongs, if applicable. This will be `None` for adapter modules.
259 InstantiateModule(InstantiateModule, Option<RuntimeComponentInstanceIndex>),
260
261 /// A host function is being lowered, creating a core wasm function.
262 ///
263 /// This initializer entry is intended to be used to fill out the
264 /// `VMComponentContext` and information about this lowering such as the
265 /// cranelift-compiled trampoline function pointer, the host function
266 /// pointer the trampoline calls, and the canonical ABI options.
267 LowerImport {
268 /// The index of the lowered function that's being created.
269 ///
270 /// This is guaranteed to be the `n`th `LowerImport` instruction
271 /// if the index is `n`.
272 index: LoweredIndex,
273
274 /// The index of the imported host function that is being lowered.
275 ///
276 /// It's guaranteed that this `RuntimeImportIndex` points to a function.
277 import: RuntimeImportIndex,
278 },
279
280 /// A core wasm linear memory is going to be saved into the
281 /// `VMComponentContext`.
282 ///
283 /// This instruction indicates that a core wasm linear memory needs to be
284 /// extracted from the `export` and stored into the `VMComponentContext` at
285 /// the `index` specified. This lowering is then used in the future by
286 /// pointers from `CanonicalOptions`.
287 ExtractMemory(ExtractMemory),
288
289 /// Same as `ExtractMemory`, except it's extracting a function pointer to be
290 /// used as a `realloc` function.
291 ExtractRealloc(ExtractRealloc),
292
293 /// Same as `ExtractMemory`, except it's extracting a function pointer to be
294 /// used as an async `callback` function.
295 ExtractCallback(ExtractCallback),
296
297 /// Same as `ExtractMemory`, except it's extracting a function pointer to be
298 /// used as a `post-return` function.
299 ExtractPostReturn(ExtractPostReturn),
300
301 /// A core wasm table is going to be saved into the `VMComponentContext`.
302 ///
303 /// This instruction indicates that s core wasm table needs to be extracted
304 /// from its `export` and stored into the `VMComponentContext` at the
305 /// `index` specified. During this extraction, we will also capture the
306 /// table's containing instance pointer to access the table at runtime. This
307 /// extraction is useful for `thread.spawn-indirect`.
308 ExtractTable(ExtractTable),
309
310 /// Declares a new defined resource within this component.
311 ///
312 /// Contains information about the destructor, for example.
313 Resource(Resource),
314}
315
316/// Metadata for extraction of a memory; contains what's being extracted (the
317/// memory at `export`) and where it's going (the `index` within a
318/// `VMComponentContext`).
319#[derive(Debug, Serialize, Deserialize)]
320pub struct ExtractMemory {
321 /// The index of the memory being defined.
322 pub index: RuntimeMemoryIndex,
323 /// Where this memory is being extracted from.
324 pub export: CoreExport<MemoryIndex>,
325}
326
327/// Same as `ExtractMemory` but for the `realloc` canonical option.
328#[derive(Debug, Serialize, Deserialize)]
329pub struct ExtractRealloc {
330 /// The index of the realloc being defined.
331 pub index: RuntimeReallocIndex,
332 /// Where this realloc is being extracted from.
333 pub def: CoreDef,
334}
335
336/// Same as `ExtractMemory` but for the `callback` canonical option.
337#[derive(Debug, Serialize, Deserialize)]
338pub struct ExtractCallback {
339 /// The index of the callback being defined.
340 pub index: RuntimeCallbackIndex,
341 /// Where this callback is being extracted from.
342 pub def: CoreDef,
343}
344
345/// Same as `ExtractMemory` but for the `post-return` canonical option.
346#[derive(Debug, Serialize, Deserialize)]
347pub struct ExtractPostReturn {
348 /// The index of the post-return being defined.
349 pub index: RuntimePostReturnIndex,
350 /// Where this post-return is being extracted from.
351 pub def: CoreDef,
352}
353
354/// Metadata for extraction of a table.
355#[derive(Debug, Serialize, Deserialize)]
356pub struct ExtractTable {
357 /// The index of the table being defined in a `VMComponentContext`.
358 pub index: RuntimeTableIndex,
359 /// Where this table is being extracted from.
360 pub export: CoreExport<TableIndex>,
361}
362
363/// Different methods of instantiating a core wasm module.
364#[derive(Debug, Serialize, Deserialize)]
365pub enum InstantiateModule {
366 /// A module defined within this component is being instantiated.
367 ///
368 /// Note that this is distinct from the case of imported modules because the
369 /// order of imports required is statically known and can be pre-calculated
370 /// to avoid string lookups related to names at runtime, represented by the
371 /// flat list of arguments here.
372 Static(StaticModuleIndex, TryVec<CoreDef>),
373
374 /// An imported module is being instantiated.
375 ///
376 /// This is similar to `Upvar` but notably the imports are provided as a
377 /// two-level named map since import resolution order needs to happen at
378 /// runtime.
379 Import(
380 RuntimeImportIndex,
381 TryIndexMap<TryString, TryIndexMap<TryString, CoreDef>>,
382 ),
383}
384
385/// Definition of a core wasm item and where it can come from within a
386/// component.
387///
388/// Note that this is sort of a result of data-flow-like analysis on a component
389/// during compile time of the component itself. References to core wasm items
390/// are "compiled" to either referring to a previous instance or to some sort of
391/// lowered host import.
392#[derive(Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
393pub enum CoreDef {
394 /// This item refers to an export of a previously instantiated core wasm
395 /// instance.
396 Export(CoreExport<EntityIndex>),
397 /// This is a reference to a wasm global which represents the
398 /// runtime-managed flags for a wasm instance.
399 InstanceFlags(RuntimeComponentInstanceIndex),
400 /// This is a reference to a Cranelift-generated trampoline which is
401 /// described in the `trampolines` array.
402 Trampoline(TrampolineIndex),
403 /// An intrinsic for compile-time builtins.
404 UnsafeIntrinsic(UnsafeIntrinsic),
405}
406
407impl TryClone for CoreDef {
408 fn try_clone(&self) -> Result<Self, OutOfMemory> {
409 Ok(match self {
410 CoreDef::Export(e) => CoreDef::Export(e.try_clone()?),
411 CoreDef::InstanceFlags(i) => CoreDef::InstanceFlags(*i),
412 CoreDef::Trampoline(i) => CoreDef::Trampoline(*i),
413 CoreDef::UnsafeIntrinsic(i) => CoreDef::UnsafeIntrinsic(*i),
414 })
415 }
416}
417
418impl<T> From<CoreExport<T>> for CoreDef
419where
420 EntityIndex: From<T>,
421{
422 fn from(export: CoreExport<T>) -> CoreDef {
423 CoreDef::Export(export.map_index(|i| i.into()))
424 }
425}
426
427/// Identifier of an exported item from a core WebAssembly module instance.
428///
429/// Note that the `T` here is the index type for exports which can be
430/// identified by index. The `T` is monomorphized with types like
431/// [`EntityIndex`] or [`FuncIndex`].
432#[derive(Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
433pub struct CoreExport<T> {
434 /// The instance that this item is located within.
435 ///
436 /// Note that this is intended to index the `instances` map within a
437 /// component. It's validated ahead of time that all instance pointers
438 /// refer only to previously-created instances.
439 pub instance: RuntimeInstanceIndex,
440
441 /// The item that this export is referencing, either by name or by index.
442 pub item: ExportItem<T>,
443}
444
445impl<T: TryClone> TryClone for CoreExport<T> {
446 fn try_clone(&self) -> Result<Self, OutOfMemory> {
447 Ok(CoreExport {
448 instance: self.instance,
449 item: self.item.try_clone()?,
450 })
451 }
452}
453
454impl<T> CoreExport<T> {
455 /// Maps the index type `T` to another type `U` if this export item indeed
456 /// refers to an index `T`.
457 pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
458 CoreExport {
459 instance: self.instance,
460 item: match self.item {
461 ExportItem::Index(i) => ExportItem::Index(f(i)),
462 ExportItem::Name(s) => ExportItem::Name(s),
463 },
464 }
465 }
466}
467
468/// An index at which to find an item within a runtime instance.
469#[derive(Debug, Serialize, Deserialize, Hash, Eq, PartialEq)]
470pub enum ExportItem<T> {
471 /// An exact index that the target can be found at.
472 ///
473 /// This is used where possible to avoid name lookups at runtime during the
474 /// instantiation process. This can only be used on instances where the
475 /// module was statically known at compile time, however.
476 Index(T),
477
478 /// An item which is identified by a name, so at runtime we need to
479 /// perform a name lookup to determine the index that the item is located
480 /// at.
481 ///
482 /// This is used for instantiations of imported modules, for example, since
483 /// the precise shape of the module is not known.
484 Name(TryString),
485}
486
487impl<T: TryClone> TryClone for ExportItem<T> {
488 fn try_clone(&self) -> Result<Self, OutOfMemory> {
489 Ok(match self {
490 ExportItem::Index(i) => ExportItem::Index(i.try_clone()?),
491 ExportItem::Name(name) => ExportItem::Name(name.try_clone()?),
492 })
493 }
494}
495
496/// Possible exports from a component.
497#[derive(Debug, Serialize, Deserialize)]
498pub enum Export {
499 /// A lifted function being exported which is an adaptation of a core wasm
500 /// function.
501 LiftedFunction {
502 /// The component function type of the function being created.
503 ty: TypeFuncIndex,
504 /// Which core WebAssembly export is being lifted.
505 func: CoreDef,
506 /// Any options, if present, associated with this lifting.
507 options: OptionsIndex,
508 },
509 /// A module defined within this component is exported.
510 ModuleStatic {
511 /// The type of this module
512 ty: TypeModuleIndex,
513 /// Which module this is referring to.
514 index: StaticModuleIndex,
515 },
516 /// A module imported into this component is exported.
517 ModuleImport {
518 /// Module type index
519 ty: TypeModuleIndex,
520 /// Module runtime import index
521 import: RuntimeImportIndex,
522 },
523 /// A nested instance is being exported which has recursively defined
524 /// `Export` items.
525 Instance {
526 /// Instance type index, if such is assigned
527 ty: TypeComponentInstanceIndex,
528 /// Instance export map
529 exports: NameMap<TryString, (ExportIndex, ComponentExternData)>,
530 },
531 /// An exported type from a component or instance, currently only
532 /// informational.
533 Type(TypeDef),
534}
535
536#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
537/// Data is stored in a linear memory.
538pub struct LinearMemoryOptions {
539 /// The memory used by these options, if specified.
540 pub memory: Option<RuntimeMemoryIndex>,
541 /// The realloc function used by these options, if specified.
542 pub realloc: Option<RuntimeReallocIndex>,
543}
544
545/// The data model for objects that are not unboxed in locals.
546#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
547pub enum CanonicalOptionsDataModel {
548 /// Data is stored in GC objects.
549 Gc {},
550
551 /// Data is stored in a linear memory.
552 LinearMemory(LinearMemoryOptions),
553}
554
555/// Canonical ABI options associated with a lifted or lowered function.
556#[derive(Debug, Clone, Serialize, Deserialize)]
557pub struct CanonicalOptions {
558 /// The component instance that this bundle was associated with.
559 pub instance: RuntimeComponentInstanceIndex,
560
561 /// The encoding used for strings.
562 pub string_encoding: StringEncoding,
563
564 /// The async callback function used by these options, if specified.
565 pub callback: Option<RuntimeCallbackIndex>,
566
567 /// The post-return function used by these options, if specified.
568 pub post_return: Option<RuntimePostReturnIndex>,
569
570 /// Whether to use the async ABI for lifting or lowering.
571 pub async_: bool,
572
573 /// The core function type that is being lifted from / lowered to.
574 pub core_type: ModuleInternedTypeIndex,
575
576 /// The data model (GC objects or linear memory) used with these canonical
577 /// options.
578 pub data_model: CanonicalOptionsDataModel,
579}
580
581impl CanonicalOptions {
582 /// Returns the memory referred to by these options, if any.
583 pub fn memory(&self) -> Option<RuntimeMemoryIndex> {
584 match self.data_model {
585 CanonicalOptionsDataModel::Gc {} => None,
586 CanonicalOptionsDataModel::LinearMemory(opts) => opts.memory,
587 }
588 }
589}
590
591/// Possible encodings of strings within the component model.
592#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
593#[expect(missing_docs, reason = "self-describing variants")]
594pub enum StringEncoding {
595 Utf8,
596 Utf16,
597 CompactUtf16,
598}
599
600impl StringEncoding {
601 /// Decodes the `u8` provided back into a `StringEncoding`, if it's valid.
602 pub fn from_u8(val: u8) -> Option<StringEncoding> {
603 if val == StringEncoding::Utf8 as u8 {
604 return Some(StringEncoding::Utf8);
605 }
606 if val == StringEncoding::Utf16 as u8 {
607 return Some(StringEncoding::Utf16);
608 }
609 if val == StringEncoding::CompactUtf16 as u8 {
610 return Some(StringEncoding::CompactUtf16);
611 }
612 None
613 }
614}
615
616/// Possible transcoding operations that must be provided by the host.
617///
618/// Note that each transcoding operation may have a unique signature depending
619/// on the precise operation.
620#[expect(missing_docs, reason = "self-describing variants")]
621#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
622pub enum Transcode {
623 Copy(FixedEncoding),
624 Latin1ToUtf16,
625 Latin1ToUtf8,
626 Utf16ToCompactProbablyUtf16,
627 Utf16ToCompactUtf16,
628 Utf16ToLatin1,
629 Utf16ToUtf8,
630 Utf8ToCompactUtf16,
631 Utf8ToLatin1,
632 Utf8ToUtf16,
633}
634
635impl Transcode {
636 /// The bit that the `Utf16ToCompactProbablyUtf16` host libcall sets in its
637 /// returned length to indicate utf16. The libcall's trampoline moves it to
638 /// the high bit of the destination memory's pointer width, which is the
639 /// guest-visible `latin1+utf16` tag.
640 pub const UTF16_TO_COMPACT_PROBABLY_UTF16_TAG: u32 = 1 << 31;
641
642 /// Get this transcoding's symbol fragment.
643 pub fn symbol_fragment(&self) -> &'static str {
644 match self {
645 Transcode::Copy(x) => match x {
646 FixedEncoding::Utf8 => "copy_utf8",
647 FixedEncoding::Utf16 => "copy_utf16",
648 FixedEncoding::Latin1 => "copy_latin1",
649 },
650 Transcode::Latin1ToUtf16 => "latin1_to_utf16",
651 Transcode::Latin1ToUtf8 => "latin1_to_utf8",
652 Transcode::Utf16ToCompactProbablyUtf16 => "utf16_to_compact_probably_utf16",
653 Transcode::Utf16ToCompactUtf16 => "utf16_to_compact_utf16",
654 Transcode::Utf16ToLatin1 => "utf16_to_latin1",
655 Transcode::Utf16ToUtf8 => "utf16_to_utf8",
656 Transcode::Utf8ToCompactUtf16 => "utf8_to_compact_utf16",
657 Transcode::Utf8ToLatin1 => "utf8_to_latin1",
658 Transcode::Utf8ToUtf16 => "utf8_to_utf16",
659 }
660 }
661
662 /// Returns a human-readable description for this transcoding operation.
663 pub fn desc(&self) -> &'static str {
664 match self {
665 Transcode::Copy(FixedEncoding::Utf8) => "utf8-to-utf8",
666 Transcode::Copy(FixedEncoding::Utf16) => "utf16-to-utf16",
667 Transcode::Copy(FixedEncoding::Latin1) => "latin1-to-latin1",
668 Transcode::Latin1ToUtf16 => "latin1-to-utf16",
669 Transcode::Latin1ToUtf8 => "latin1-to-utf8",
670 Transcode::Utf16ToCompactProbablyUtf16 => "utf16-to-compact-probably-utf16",
671 Transcode::Utf16ToCompactUtf16 => "utf16-to-compact-utf16",
672 Transcode::Utf16ToLatin1 => "utf16-to-latin1",
673 Transcode::Utf16ToUtf8 => "utf16-to-utf8",
674 Transcode::Utf8ToCompactUtf16 => "utf8-to-compact-utf16",
675 Transcode::Utf8ToLatin1 => "utf8-to-latin1",
676 Transcode::Utf8ToUtf16 => "utf8-to-utf16",
677 }
678 }
679}
680
681#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
682#[expect(missing_docs, reason = "self-describing variants")]
683pub enum FixedEncoding {
684 Utf8,
685 Utf16,
686 Latin1,
687}
688
689impl FixedEncoding {
690 /// Returns the byte width of unit loads/stores for this encoding, for
691 /// example the unit length is multiplied by this return value to get the
692 /// byte width of a string.
693 pub fn width(&self) -> u8 {
694 match self {
695 FixedEncoding::Utf8 => 1,
696 FixedEncoding::Utf16 => 2,
697 FixedEncoding::Latin1 => 1,
698 }
699 }
700
701 /// Returns the alignment of strings using this encoding.
702 pub fn align(&self) -> u8 {
703 match self {
704 FixedEncoding::Utf8 => 1,
705 FixedEncoding::Utf16 => 2,
706 FixedEncoding::Latin1 => 2,
707 }
708 }
709}
710
711/// Description of a new resource declared in a `GlobalInitializer::Resource`
712/// variant.
713///
714/// This will have the effect of initializing runtime state for this resource,
715/// namely the destructor is fetched and stored.
716#[derive(Debug, Serialize, Deserialize)]
717pub struct Resource {
718 /// The local index of the resource being defined.
719 pub index: DefinedResourceIndex,
720 /// Core wasm representation of this resource.
721 pub rep: WasmValType,
722 /// Optionally-specified destructor and where it comes from.
723 pub dtor: Option<CoreDef>,
724 /// Which component instance this resource logically belongs to.
725 pub instance: RuntimeComponentInstanceIndex,
726}
727
728/// A list of all possible trampolines that may be required to compile a
729/// component completely.
730///
731/// These trampolines are used often as core wasm definitions and require
732/// Cranelift support to generate these functions. Each trampoline serves a
733/// different purpose for implementing bits and pieces of the component model.
734///
735/// All trampolines have a core wasm function signature associated with them
736/// which is stored in the `Component::trampolines` array.
737///
738/// Note that this type does not implement `Serialize` or `Deserialize` and
739/// that's intentional as this isn't stored in the final compilation artifact.
740#[derive(Debug)]
741pub enum Trampoline {
742 /// Description of a lowered import used in conjunction with
743 /// `GlobalInitializer::LowerImport`.
744 LowerImport {
745 /// The runtime lowering state that this trampoline will access.
746 index: LoweredIndex,
747
748 /// The type of the function that is being lowered, as perceived by the
749 /// component doing the lowering.
750 lower_ty: TypeFuncIndex,
751
752 /// The canonical ABI options used when lowering this function specified
753 /// in the original component.
754 options: OptionsIndex,
755 },
756
757 /// Information about a string transcoding function required by an adapter
758 /// module.
759 ///
760 /// A transcoder is used when strings are passed between adapter modules,
761 /// optionally changing string encodings at the same time. The transcoder is
762 /// implemented in a few different layers:
763 ///
764 /// * Each generated adapter module has some glue around invoking the
765 /// transcoder represented by this item. This involves bounds-checks and
766 /// handling `realloc` for example.
767 /// * Each transcoder gets a cranelift-generated trampoline which has the
768 /// appropriate signature for the adapter module in question. Existence of
769 /// this initializer indicates that this should be compiled by Cranelift.
770 /// * The cranelift-generated trampoline will invoke a "transcoder libcall"
771 /// which is implemented natively in Rust that has a signature independent
772 /// of memory64 configuration options for example.
773 Transcoder {
774 /// The transcoding operation being performed.
775 op: Transcode,
776 /// The linear memory that the string is being read from.
777 from: RuntimeMemoryIndex,
778 /// Whether or not the source linear memory is 64-bit or not.
779 from64: bool,
780 /// The linear memory that the string is being written to.
781 to: RuntimeMemoryIndex,
782 /// Whether or not the destination linear memory is 64-bit or not.
783 to64: bool,
784 },
785
786 /// A `resource.new` intrinsic which will inject a new resource into the
787 /// table specified.
788 ResourceNew {
789 /// The specific component instance which is calling the intrinsic.
790 instance: RuntimeComponentInstanceIndex,
791 /// The type of the resource.
792 ty: TypeResourceTableIndex,
793 },
794
795 /// Same as `ResourceNew`, but for the `resource.rep` intrinsic.
796 ResourceRep {
797 /// The specific component instance which is calling the intrinsic.
798 instance: RuntimeComponentInstanceIndex,
799 /// The type of the resource.
800 ty: TypeResourceTableIndex,
801 },
802
803 /// Same as `ResourceNew`, but for the `resource.drop` intrinsic.
804 ResourceDrop {
805 /// The specific component instance which is calling the intrinsic.
806 instance: RuntimeComponentInstanceIndex,
807 /// The type of the resource.
808 ty: TypeResourceTableIndex,
809 },
810
811 /// A `backpressure.inc` intrinsic.
812 BackpressureInc {
813 /// The specific component instance which is calling the intrinsic.
814 instance: RuntimeComponentInstanceIndex,
815 },
816
817 /// A `backpressure.dec` intrinsic.
818 BackpressureDec {
819 /// The specific component instance which is calling the intrinsic.
820 instance: RuntimeComponentInstanceIndex,
821 },
822
823 /// A `task.return` intrinsic, which returns a result to the caller of a
824 /// lifted export function. This allows the callee to continue executing
825 /// after returning a result.
826 TaskReturn {
827 /// The specific component instance which is calling the intrinsic.
828 instance: RuntimeComponentInstanceIndex,
829 /// Tuple representing the result types this intrinsic accepts.
830 results: TypeTupleIndex,
831 /// The canonical ABI options specified for this intrinsic.
832 options: OptionsIndex,
833 },
834
835 /// A `task.cancel` intrinsic, which acknowledges a `CANCELLED` event
836 /// delivered to a guest task previously created by a call to an async
837 /// export.
838 TaskCancel {
839 /// The specific component instance which is calling the intrinsic.
840 instance: RuntimeComponentInstanceIndex,
841 },
842
843 /// A `waitable-set.new` intrinsic.
844 WaitableSetNew {
845 /// The specific component instance which is calling the intrinsic.
846 instance: RuntimeComponentInstanceIndex,
847 },
848
849 /// A `waitable-set.wait` intrinsic, which waits for at least one
850 /// outstanding async task/stream/future to make progress, returning the
851 /// first such event.
852 WaitableSetWait {
853 /// The specific component instance which is calling the intrinsic.
854 instance: RuntimeComponentInstanceIndex,
855 /// Configuration options for this intrinsic call.
856 options: OptionsIndex,
857 },
858
859 /// A `waitable-set.poll` intrinsic, which checks whether any outstanding
860 /// async task/stream/future has made progress. Unlike `task.wait`, this
861 /// does not block and may return nothing if no such event has occurred.
862 WaitableSetPoll {
863 /// The specific component instance which is calling the intrinsic.
864 instance: RuntimeComponentInstanceIndex,
865 /// Configuration options for this intrinsic call.
866 options: OptionsIndex,
867 },
868
869 /// A `waitable-set.drop` intrinsic.
870 WaitableSetDrop {
871 /// The specific component instance which is calling the intrinsic.
872 instance: RuntimeComponentInstanceIndex,
873 },
874
875 /// A `waitable.join` intrinsic.
876 WaitableJoin {
877 /// The specific component instance which is calling the intrinsic.
878 instance: RuntimeComponentInstanceIndex,
879 },
880
881 /// A `subtask.drop` intrinsic to drop a specified task which has completed.
882 SubtaskDrop {
883 /// The specific component instance which is calling the intrinsic.
884 instance: RuntimeComponentInstanceIndex,
885 },
886
887 /// A `subtask.cancel` intrinsic to drop an in-progress task.
888 SubtaskCancel {
889 /// The specific component instance which is calling the intrinsic.
890 instance: RuntimeComponentInstanceIndex,
891 /// If `false`, block until cancellation completes rather than return
892 /// `BLOCKED`.
893 async_: bool,
894 },
895
896 /// A `stream.new` intrinsic to create a new `stream` handle of the
897 /// specified type.
898 StreamNew {
899 /// The specific component instance which is calling the intrinsic.
900 instance: RuntimeComponentInstanceIndex,
901 /// The table index for the specific `stream` type and caller instance.
902 ty: TypeStreamTableIndex,
903 },
904
905 /// A `stream.read` intrinsic to read from a `stream` of the specified type.
906 StreamRead {
907 /// The specific component instance which is calling the intrinsic.
908 instance: RuntimeComponentInstanceIndex,
909 /// The table index for the specific `stream` type and caller instance.
910 ty: TypeStreamTableIndex,
911 /// Any options (e.g. string encoding) to use when storing values to
912 /// memory.
913 options: OptionsIndex,
914 },
915
916 /// A `stream.write` intrinsic to write to a `stream` of the specified type.
917 StreamWrite {
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 /// Any options (e.g. string encoding) to use when storing values to
923 /// memory.
924 options: OptionsIndex,
925 },
926
927 /// A `stream.cancel-read` intrinsic to cancel an in-progress read from a
928 /// `stream` of the specified type.
929 StreamCancelRead {
930 /// The specific component instance which is calling the intrinsic.
931 instance: RuntimeComponentInstanceIndex,
932 /// The table index for the specific `stream` type and caller instance.
933 ty: TypeStreamTableIndex,
934 /// If `false`, block until cancellation completes rather than return
935 /// `BLOCKED`.
936 async_: bool,
937 },
938
939 /// A `stream.cancel-write` intrinsic to cancel an in-progress write from a
940 /// `stream` of the specified type.
941 StreamCancelWrite {
942 /// The specific component instance which is calling the intrinsic.
943 instance: RuntimeComponentInstanceIndex,
944 /// The table index for the specific `stream` type and caller instance.
945 ty: TypeStreamTableIndex,
946 /// If `false`, block until cancellation completes rather than return
947 /// `BLOCKED`.
948 async_: bool,
949 },
950
951 /// A `stream.drop-readable` intrinsic to drop the readable end of a
952 /// `stream` of the specified type.
953 StreamDropReadable {
954 /// The specific component instance which is calling the intrinsic.
955 instance: RuntimeComponentInstanceIndex,
956 /// The table index for the specific `stream` type and caller instance.
957 ty: TypeStreamTableIndex,
958 },
959
960 /// A `stream.drop-writable` intrinsic to drop the writable end of a
961 /// `stream` of the specified type.
962 StreamDropWritable {
963 /// The specific component instance which is calling the intrinsic.
964 instance: RuntimeComponentInstanceIndex,
965 /// The table index for the specific `stream` type and caller instance.
966 ty: TypeStreamTableIndex,
967 },
968
969 /// A `future.new` intrinsic to create a new `future` handle of the
970 /// specified type.
971 FutureNew {
972 /// The specific component instance which is calling the intrinsic.
973 instance: RuntimeComponentInstanceIndex,
974 /// The table index for the specific `future` type and caller instance.
975 ty: TypeFutureTableIndex,
976 },
977
978 /// A `future.read` intrinsic to read from a `future` of the specified type.
979 FutureRead {
980 /// The specific component instance which is calling the intrinsic.
981 instance: RuntimeComponentInstanceIndex,
982 /// The table index for the specific `future` type and caller instance.
983 ty: TypeFutureTableIndex,
984 /// Any options (e.g. string encoding) to use when storing values to
985 /// memory.
986 options: OptionsIndex,
987 },
988
989 /// A `future.write` intrinsic to write to a `future` of the specified type.
990 FutureWrite {
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 /// Any options (e.g. string encoding) to use when storing values to
996 /// memory.
997 options: OptionsIndex,
998 },
999
1000 /// A `future.cancel-read` intrinsic to cancel an in-progress read from a
1001 /// `future` of the specified type.
1002 FutureCancelRead {
1003 /// The specific component instance which is calling the intrinsic.
1004 instance: RuntimeComponentInstanceIndex,
1005 /// The table index for the specific `future` type and caller instance.
1006 ty: TypeFutureTableIndex,
1007 /// If `false`, block until cancellation completes rather than return
1008 /// `BLOCKED`.
1009 async_: bool,
1010 },
1011
1012 /// A `future.cancel-write` intrinsic to cancel an in-progress write from a
1013 /// `future` of the specified type.
1014 FutureCancelWrite {
1015 /// The specific component instance which is calling the intrinsic.
1016 instance: RuntimeComponentInstanceIndex,
1017 /// The table index for the specific `future` type and caller instance.
1018 ty: TypeFutureTableIndex,
1019 /// If `false`, block until cancellation completes rather than return
1020 /// `BLOCKED`.
1021 async_: bool,
1022 },
1023
1024 /// A `future.drop-readable` intrinsic to drop the readable end of a
1025 /// `future` of the specified type.
1026 FutureDropReadable {
1027 /// The specific component instance which is calling the intrinsic.
1028 instance: RuntimeComponentInstanceIndex,
1029 /// The table index for the specific `future` type and caller instance.
1030 ty: TypeFutureTableIndex,
1031 },
1032
1033 /// A `future.drop-writable` intrinsic to drop the writable end of a
1034 /// `future` of the specified type.
1035 FutureDropWritable {
1036 /// The specific component instance which is calling the intrinsic.
1037 instance: RuntimeComponentInstanceIndex,
1038 /// The table index for the specific `future` type and caller instance.
1039 ty: TypeFutureTableIndex,
1040 },
1041
1042 /// A `error-context.new` intrinsic to create a new `error-context` with a
1043 /// specified debug message.
1044 ErrorContextNew {
1045 /// The specific component instance which is calling the intrinsic.
1046 instance: RuntimeComponentInstanceIndex,
1047 /// The table index for the `error-context` type in the caller instance.
1048 ty: TypeComponentLocalErrorContextTableIndex,
1049 /// String encoding, memory, etc. to use when loading debug message.
1050 options: OptionsIndex,
1051 },
1052
1053 /// A `error-context.debug-message` intrinsic to get the debug message for a
1054 /// specified `error-context`.
1055 ///
1056 /// Note that the debug message might not necessarily match what was passed
1057 /// to `error.new`.
1058 ErrorContextDebugMessage {
1059 /// The specific component instance which is calling the intrinsic.
1060 instance: RuntimeComponentInstanceIndex,
1061 /// The table index for the `error-context` type in the caller instance.
1062 ty: TypeComponentLocalErrorContextTableIndex,
1063 /// String encoding, memory, etc. to use when storing debug message.
1064 options: OptionsIndex,
1065 },
1066
1067 /// A `error-context.drop` intrinsic to drop a specified `error-context`.
1068 ErrorContextDrop {
1069 /// The specific component instance which is calling the intrinsic.
1070 instance: RuntimeComponentInstanceIndex,
1071 /// The table index for the `error-context` type in the caller instance.
1072 ty: TypeComponentLocalErrorContextTableIndex,
1073 },
1074
1075 /// An intrinsic used by FACT-generated modules which will transfer an owned
1076 /// resource from one table to another. Used in component-to-component
1077 /// adapter trampolines.
1078 ResourceTransferOwn,
1079
1080 /// Same as `ResourceTransferOwn` but for borrows.
1081 ResourceTransferBorrow,
1082
1083 /// Same as `ResourceTransferBorrow` but for a destination instance which
1084 /// owns the resource and so receives its representation directly, meaning
1085 /// no destination table is consulted.
1086 ResourceTransferBorrowToOwner {
1087 /// The resource table the borrow is transferred out of.
1088 ty: TypeResourceTableIndex,
1089 },
1090
1091 /// An intrinsic used by FACT-generated modules to prepare a call involving
1092 /// an async-lowered import and/or an async-lifted export.
1093 PrepareCall {
1094 /// The memory used to verify that the memory specified for the
1095 /// `task.return` that is called at runtime matches the one specified in
1096 /// the lifted export.
1097 memory: Option<RuntimeMemoryIndex>,
1098 },
1099
1100 /// An intrinsic used by FACT-generated modules to start a call previously
1101 /// set up with `PrepareCall`.
1102 ///
1103 /// This is used for calls where something async is involved, for example an
1104 /// async function type, an async lift, or an async lower.
1105 ///
1106 /// Note that `PrepareCall` and `StartCall` could theoretically be combined
1107 /// into a single intrinsic, but we separate them to allow the
1108 /// FACT-generated module to optionally call the callee directly without an
1109 /// intermediate host stack frame.
1110 StartCall {
1111 /// The callee's callback, if any.
1112 callback: Option<RuntimeCallbackIndex>,
1113 /// The callee's post-return function, if any.
1114 post_return: Option<RuntimePostReturnIndex>,
1115 },
1116
1117 /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1118 /// ownership of a `future`.
1119 ///
1120 /// Transferring a `future` can either mean giving away the readable end
1121 /// while retaining the writable end or only the former, depending on the
1122 /// ownership status of the `future`.
1123 FutureTransfer,
1124
1125 /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1126 /// ownership of a `stream`.
1127 ///
1128 /// Transferring a `stream` can either mean giving away the readable end
1129 /// while retaining the writable end or only the former, depending on the
1130 /// ownership status of the `stream`.
1131 StreamTransfer,
1132
1133 /// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
1134 /// ownership of an `error-context`.
1135 ///
1136 /// Unlike futures, streams, and resource handles, `error-context` handles
1137 /// are reference counted, meaning that sharing the handle with another
1138 /// component does not invalidate the handle in the original component.
1139 ErrorContextTransfer,
1140
1141 /// An intrinsic used by FACT-generated modules to trap with the specified
1142 /// code.
1143 Trap(Trap),
1144
1145 /// An intrinsic used by FACT-generated modules to get the store's hostcall
1146 /// fuel, which limits how many bytes of strings the host copies.
1147 HostcallFuel,
1148
1149 /// An intrinsic used by FACT-generated modules to push a task onto the
1150 /// stack for a sync-to-sync, guest-to-guest call.
1151 EnterSyncCall,
1152 /// An intrinsic used by FACT-generated modules to pop the task previously
1153 /// pushed by `EnterSyncCall`.
1154 ExitSyncCall,
1155
1156 /// Intrinsic used to implement the `thread.index` component model builtin.
1157 ThreadIndex {
1158 /// The specific component instance which is calling the intrinsic.
1159 instance: RuntimeComponentInstanceIndex,
1160 },
1161
1162 /// Intrinsic used to implement the `thread.new-indirect` component model builtin.
1163 ThreadNewIndirect {
1164 /// The specific component instance which is calling the intrinsic.
1165 instance: RuntimeComponentInstanceIndex,
1166 /// The core function type that the thread's start function must have,
1167 /// as declared by the `thread.new-indirect` built-in.
1168 start_func_ty_idx: ModuleInternedTypeIndex,
1169 /// The index of the table that stores the start function.
1170 start_func_table_idx: RuntimeTableIndex,
1171 },
1172
1173 /// Intrinsic used to implement the `thread.resume-later` component model
1174 /// builtin.
1175 ThreadResumeLater {
1176 /// The specific component instance which is calling the intrinsic.
1177 instance: RuntimeComponentInstanceIndex,
1178 },
1179
1180 /// Intrinsic used to implement the `thread.suspend` component model builtin.
1181 ThreadSuspend {
1182 /// The specific component instance which is calling the intrinsic.
1183 instance: RuntimeComponentInstanceIndex,
1184 },
1185
1186 /// A `thread.yield` intrinsic, which yields control to the host so that other
1187 /// tasks are able to make progress, if any.
1188 ThreadYield {
1189 /// The specific component instance which is calling the intrinsic.
1190 instance: RuntimeComponentInstanceIndex,
1191 },
1192
1193 /// Intrinsic used to implement the `thread.suspend-then-resume` component
1194 /// model builtin.
1195 ThreadSuspendThenResume {
1196 /// The specific component instance which is calling the intrinsic.
1197 instance: RuntimeComponentInstanceIndex,
1198 },
1199
1200 /// Intrinsic used to implement the `thread.yield-then-resume` component
1201 /// model builtin.
1202 ThreadYieldThenResume {
1203 /// The specific component instance which is calling the intrinsic.
1204 instance: RuntimeComponentInstanceIndex,
1205 },
1206
1207 /// Intrinsic used to implement the `thread.suspend-then-promote` component
1208 /// model builtin.
1209 ThreadSuspendThenPromote {
1210 /// The specific component instance which is calling the intrinsic.
1211 instance: RuntimeComponentInstanceIndex,
1212 },
1213
1214 /// Intrinsic used to implement the `thread.yield-then-promote` component
1215 /// model builtin.
1216 ThreadYieldThenPromote {
1217 /// The specific component instance which is calling the intrinsic.
1218 instance: RuntimeComponentInstanceIndex,
1219 },
1220}
1221
1222impl Trampoline {
1223 /// Returns the name to use for the symbol of this trampoline in the final
1224 /// compiled artifact
1225 pub fn symbol_name(&self) -> String {
1226 use Trampoline::*;
1227 match self {
1228 LowerImport { index, .. } => {
1229 format!("component-lower-import[{}]", index.as_u32())
1230 }
1231 Transcoder {
1232 op, from64, to64, ..
1233 } => {
1234 let op = op.symbol_fragment();
1235 let from = if *from64 { "64" } else { "32" };
1236 let to = if *to64 { "64" } else { "32" };
1237 format!("component-transcode-{op}-m{from}-m{to}")
1238 }
1239 ResourceNew { ty, .. } => format!("component-resource-new[{}]", ty.as_u32()),
1240 ResourceRep { ty, .. } => format!("component-resource-rep[{}]", ty.as_u32()),
1241 ResourceDrop { ty, .. } => format!("component-resource-drop[{}]", ty.as_u32()),
1242 BackpressureInc { .. } => format!("backpressure-inc"),
1243 BackpressureDec { .. } => format!("backpressure-dec"),
1244 TaskReturn { .. } => format!("task-return"),
1245 TaskCancel { .. } => format!("task-cancel"),
1246 WaitableSetNew { .. } => format!("waitable-set-new"),
1247 WaitableSetWait { .. } => format!("waitable-set-wait"),
1248 WaitableSetPoll { .. } => format!("waitable-set-poll"),
1249 WaitableSetDrop { .. } => format!("waitable-set-drop"),
1250 WaitableJoin { .. } => format!("waitable-join"),
1251 SubtaskDrop { .. } => format!("subtask-drop"),
1252 SubtaskCancel { .. } => format!("subtask-cancel"),
1253 StreamNew { .. } => format!("stream-new"),
1254 StreamRead { .. } => format!("stream-read"),
1255 StreamWrite { .. } => format!("stream-write"),
1256 StreamCancelRead { .. } => format!("stream-cancel-read"),
1257 StreamCancelWrite { .. } => format!("stream-cancel-write"),
1258 StreamDropReadable { .. } => format!("stream-drop-readable"),
1259 StreamDropWritable { .. } => format!("stream-drop-writable"),
1260 FutureNew { .. } => format!("future-new"),
1261 FutureRead { .. } => format!("future-read"),
1262 FutureWrite { .. } => format!("future-write"),
1263 FutureCancelRead { .. } => format!("future-cancel-read"),
1264 FutureCancelWrite { .. } => format!("future-cancel-write"),
1265 FutureDropReadable { .. } => format!("future-drop-readable"),
1266 FutureDropWritable { .. } => format!("future-drop-writable"),
1267 ErrorContextNew { .. } => format!("error-context-new"),
1268 ErrorContextDebugMessage { .. } => format!("error-context-debug-message"),
1269 ErrorContextDrop { .. } => format!("error-context-drop"),
1270 ResourceTransferOwn => format!("component-resource-transfer-own"),
1271 ResourceTransferBorrow => format!("component-resource-transfer-borrow"),
1272 ResourceTransferBorrowToOwner { ty } => {
1273 format!(
1274 "component-resource-transfer-borrow-to-owner-{}",
1275 ty.as_u32()
1276 )
1277 }
1278 PrepareCall { .. } => format!("component-prepare-call"),
1279 StartCall { .. } => format!("component-start-call"),
1280 FutureTransfer => format!("future-transfer"),
1281 StreamTransfer => format!("stream-transfer"),
1282 ErrorContextTransfer => format!("error-context-transfer"),
1283 Trap(trap) => format!("trap-{}", *trap as u8),
1284 HostcallFuel => format!("hostcall-fuel"),
1285 EnterSyncCall => format!("enter-sync-call"),
1286 ExitSyncCall => format!("exit-sync-call"),
1287 ThreadIndex { .. } => format!("thread-index"),
1288 ThreadNewIndirect { .. } => format!("thread-new-indirect"),
1289 ThreadResumeLater { .. } => format!("thread-resume-later"),
1290 ThreadSuspend { .. } => format!("thread-suspend"),
1291 ThreadYield { .. } => format!("thread-yield"),
1292 ThreadSuspendThenResume { .. } => format!("thread-suspend-then-resume"),
1293 ThreadYieldThenResume { .. } => format!("thread-yield-then-resume"),
1294 ThreadSuspendThenPromote { .. } => format!("thread-suspend-then-promote"),
1295 ThreadYieldThenPromote { .. } => format!("thread-yield-then-promote"),
1296 }
1297 }
1298}