wasmtime_environ::component

Struct Component

Source
pub struct Component {
Show 16 fields pub import_types: PrimaryMap<ImportIndex, (String, TypeDef)>, pub imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>, pub exports: NameMap<String, ExportIndex>, pub export_items: PrimaryMap<ExportIndex, Export>, pub initializers: Vec<GlobalInitializer>, pub num_runtime_instances: u32, pub num_runtime_component_instances: u32, pub num_runtime_memories: u32, pub num_runtime_reallocs: u32, pub num_runtime_post_returns: u32, pub trampolines: PrimaryMap<TrampolineIndex, ModuleInternedTypeIndex>, pub num_lowerings: u32, pub num_resource_tables: usize, pub num_resources: u32, pub imported_resources: PrimaryMap<ResourceIndex, RuntimeImportIndex>, pub defined_resource_instances: PrimaryMap<DefinedResourceIndex, RuntimeComponentInstanceIndex>,
}
Expand description

Run-time-type-information about a Component, its structure, and how to instantiate it.

This type is intended to mirror the Module type in this crate which provides all the runtime information about the structure of a module and how it works.

NB: Lots of the component model is not yet implemented in the runtime so this is going to undergo a lot of churn.

Fields§

§import_types: PrimaryMap<ImportIndex, (String, TypeDef)>

A list of typed values that this component imports.

Note that each name is given an ImportIndex here for the next map to refer back to.

§imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>

A list of “flattened” imports that are used by this instance.

This import map represents extracting imports, as necessary, from the general imported types by this component. The flattening here refers to extracting items from instances. Currently the flat imports are either a host function or a core wasm module.

For example if ImportIndex(0) pointed to an instance then this import map represent extracting names from that map, for example extracting an exported module or an exported function.

Each import item is keyed by a RuntimeImportIndex which is referred to by types below whenever something refers to an import. The value for each RuntimeImportIndex in this map is the ImportIndex for where this items comes from (which can be associated with a name above in the import_types array) as well as the list of export names if ImportIndex refers to an instance. The export names array represents recursively fetching names within an instance.

§exports: NameMap<String, ExportIndex>

This component’s own root exports from the component itself.

§export_items: PrimaryMap<ExportIndex, Export>

All exports of this component and exported instances of this component.

This is indexed by ExportIndex for fast lookup and Export::Instance will refer back into this list.

§initializers: Vec<GlobalInitializer>

Initializers that must be processed when instantiating this component.

This list of initializers does not correspond directly to the component itself. The general goal with this is that the recursive nature of components is “flattened” with an array like this which is a linear sequence of instructions of how to instantiate a component. This will have instantiations, for example, in addition to entries which initialize VMComponentContext fields with previously instantiated instances.

§num_runtime_instances: u32

The number of runtime instances (maximum RuntimeInstanceIndex) created when instantiating this component.

§num_runtime_component_instances: u32

Same as num_runtime_instances, but for RuntimeComponentInstanceIndex instead.

§num_runtime_memories: u32

The number of runtime memories (maximum RuntimeMemoryIndex) needed to instantiate this component.

Note that this many memories will be stored in the VMComponentContext and each memory is intended to be unique (e.g. the same memory isn’t stored in two different locations).

§num_runtime_reallocs: u32

The number of runtime reallocs (maximum RuntimeReallocIndex) needed to instantiate this component.

Note that this many function pointers will be stored in the VMComponentContext.

§num_runtime_post_returns: u32

Same as num_runtime_reallocs, but for post-return functions.

§trampolines: PrimaryMap<TrampolineIndex, ModuleInternedTypeIndex>

WebAssembly type signature of all trampolines.

§num_lowerings: u32

The number of lowered host functions (maximum LoweredIndex) needed to instantiate this component.

§num_resource_tables: usize

Maximal number of tables that required at runtime for resource-related information in this component.

§num_resources: u32

Total number of resources both imported and defined within this component.

§imported_resources: PrimaryMap<ResourceIndex, RuntimeImportIndex>

Metadata about imported resources and where they are within the runtime imports array.

This map is only as large as the number of imported resources.

§defined_resource_instances: PrimaryMap<DefinedResourceIndex, RuntimeComponentInstanceIndex>

Metadata about which component instances defined each resource within this component.

This is used to determine which set of instance flags are inspected when testing reentrance.

Implementations§

Source§

impl Component

Source

pub fn defined_resource_index( &self, idx: ResourceIndex, ) -> Option<DefinedResourceIndex>

Attempts to convert a resource index into a defined index.

Returns None if idx is for an imported resource in this component or Some if it’s a locally defined resource.

Source

pub fn resource_index(&self, idx: DefinedResourceIndex) -> ResourceIndex

Converts a defined resource index to a component-local resource index which includes all imports.

Trait Implementations§

Source§

impl Debug for Component

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Component

Source§

fn default() -> Component

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Component

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Component

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,