Skip to main content

Module

Struct Module 

Source
pub struct Module {
Show 24 fields pub module_index: StaticModuleIndex, pub strings: StringPool, pub name: Option<Atom>, pub initializers: TryVec<Initializer>, pub exports: TryIndexMap<Atom, EntityIndex>, pub startup: ModuleStartup, pub table_initialization: TryPrimaryMap<DefinedTableIndex, TryVec<FuncIndex>>, pub memory_initialization: MemoryInitialization, pub passive_elements: TryPrimaryMap<PassiveElemIndex, (WasmRefType, u64)>, pub runtime_data: TryPrimaryMap<RuntimeDataIndex, Range<u32>>, pub types: TryPrimaryMap<TypeIndex, EngineOrModuleTypeIndex>, pub num_imported_funcs: usize, pub num_imported_tables: usize, pub num_imported_memories: usize, pub num_imported_globals: usize, pub num_imported_tags: usize, pub needs_gc_heap: bool, pub num_escaped_funcs: usize, pub functions: TryPrimaryMap<FuncIndex, FunctionType>, pub tables: TryPrimaryMap<TableIndex, Table>, pub memories: TryPrimaryMap<MemoryIndex, Memory>, pub globals: TryPrimaryMap<GlobalIndex, Global>, pub global_initializers: TryVec<(DefinedGlobalIndex, GlobalConstValue)>, pub tags: TryPrimaryMap<TagIndex, Tag>,
}
Expand description

A translated WebAssembly module, excluding the function bodies and memory initializers.

Fields§

§module_index: StaticModuleIndex

This module’s index.

§strings: StringPool

A pool of strings used in this module.

§name: Option<Atom>

The name of this wasm module, often found in the wasm file.

§initializers: TryVec<Initializer>

All import records, in the order they are declared in the module.

§exports: TryIndexMap<Atom, EntityIndex>

Exported entities.

§startup: ModuleStartup

Whether or not this module has a start function,

§table_initialization: TryPrimaryMap<DefinedTableIndex, TryVec<FuncIndex>>

Precompute per-table static images, if applicable.

This map tracks, for each defined table in this module, the initial precomputed contents of the table. This is only applicable for funcref tables and the TryVec here uses FuncIndex::reserved_value() for null entries. This structure is filled in if table initialization is detected to be infallible as part of ModuleTranslation::finalize_table_init.

§memory_initialization: MemoryInitialization

WebAssembly linear memory initializer.

This will track how memory is initialized, either exclusively via segments or if some memories can be initialized with static images. This is computed during ModuleTranslation::finalize_memory_init.

§passive_elements: TryPrimaryMap<PassiveElemIndex, (WasmRefType, u64)>

WebAssembly passive elements.

This is a map of all passive element segments to their type and the initial size of the segment. Note that the contents of the segment are initialized by compiled code.

§runtime_data: TryPrimaryMap<RuntimeDataIndex, Range<u32>>

Where runtime data segments are located in the module’s image.

Note that this does not directly correspond to either active or passive data segments. Those are massaged during ModuleTranslation::finalize_memory_init into the form used here.

§types: TryPrimaryMap<TypeIndex, EngineOrModuleTypeIndex>

Types declared in the wasm module.

§num_imported_funcs: usize

Number of imported or aliased functions in the module.

§num_imported_tables: usize

Number of imported or aliased tables in the module.

§num_imported_memories: usize

Number of imported or aliased memories in the module.

§num_imported_globals: usize

Number of imported or aliased globals in the module.

§num_imported_tags: usize

Number of imported or aliased tags in the module.

§needs_gc_heap: bool

Does this module need a GC heap to run?

§num_escaped_funcs: usize

Number of functions that “escape” from this module may need to have a VMFuncRef constructed for them.

This is also the number of functions in the functions array below with an func_ref index (and is the maximum func_ref index).

§functions: TryPrimaryMap<FuncIndex, FunctionType>

Types of functions, imported and local.

§tables: TryPrimaryMap<TableIndex, Table>

WebAssembly tables.

§memories: TryPrimaryMap<MemoryIndex, Memory>

WebAssembly linear memory plans.

§globals: TryPrimaryMap<GlobalIndex, Global>

WebAssembly global variables.

§global_initializers: TryVec<(DefinedGlobalIndex, GlobalConstValue)>

“Simple” WebAssembly global initializers for locally-defined globals.

This map does not track initialization of all globals in this module, but only those considered “simple” which can be easily evaluated at compile-time. For example an initialization expression of i32.const N is considered simple. These globals are manually initialized in the host.

This is all in contrast to ModuleTranslation::global_initializers which is processed in compiled code and initialized after the instance has been created.

§tags: TryPrimaryMap<TagIndex, Tag>

WebAssembly exception and control tags.

Implementations§

Source§

impl Module

Source

pub fn new(module_index: StaticModuleIndex) -> Self

Allocates the module data structures.

Source

pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex

Convert a DefinedFuncIndex into a FuncIndex.

Source

pub fn defined_func_index(&self, func: FuncIndex) -> Option<DefinedFuncIndex>

Convert a FuncIndex into a DefinedFuncIndex. Returns None if the index is an imported function.

Source

pub fn is_imported_function(&self, index: FuncIndex) -> bool

Test whether the given function index is for an imported function.

Source

pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex

Convert a DefinedTableIndex into a TableIndex.

Source

pub fn defined_table_index( &self, table: TableIndex, ) -> Option<DefinedTableIndex>

Convert a TableIndex into a DefinedTableIndex. Returns None if the index is an imported table.

Source

pub fn is_exported_table(&self, index: TableIndex) -> bool

Test whether the given table index is for an exported table.

Source

pub fn is_imported_table(&self, index: TableIndex) -> bool

Test whether the given table index is for an imported table.

Source

pub fn memory_index(&self, defined_memory: DefinedMemoryIndex) -> MemoryIndex

Convert a DefinedMemoryIndex into a MemoryIndex.

Source

pub fn defined_memory_index( &self, memory: MemoryIndex, ) -> Option<DefinedMemoryIndex>

Convert a MemoryIndex into a DefinedMemoryIndex. Returns None if the index is an imported memory.

Source

pub fn owned_memory_index(&self, memory: DefinedMemoryIndex) -> OwnedMemoryIndex

Convert a DefinedMemoryIndex into an OwnedMemoryIndex. Returns None if the index is an imported memory.

Source

pub fn is_exported_memory(&self, index: MemoryIndex) -> bool

Test whether the given memory index is for an exported memory.

Source

pub fn is_imported_memory(&self, index: MemoryIndex) -> bool

Test whether the given memory index is for an imported memory.

Source

pub fn global_index(&self, defined_global: DefinedGlobalIndex) -> GlobalIndex

Convert a DefinedGlobalIndex into a GlobalIndex.

Source

pub fn defined_global_index( &self, global: GlobalIndex, ) -> Option<DefinedGlobalIndex>

Convert a GlobalIndex into a DefinedGlobalIndex. Returns None if the index is an imported global.

Source

pub fn is_exported_global(&self, index: GlobalIndex) -> bool

Test whether the given global index is for an exported global.

Source

pub fn is_imported_global(&self, index: GlobalIndex) -> bool

Test whether the given global index is for an imported global.

Source

pub fn is_imported_tag(&self, index: TagIndex) -> bool

Test whether the given tag index is for an imported tag.

Source

pub fn tag_index(&self, defined_tag: DefinedTagIndex) -> TagIndex

Convert a DefinedTagIndex into a TagIndex.

Source

pub fn defined_tag_index(&self, tag: TagIndex) -> Option<DefinedTagIndex>

Convert a TagIndex into a DefinedTagIndex. Returns None if the index is an imported tag.

Source

pub fn imports(&self) -> impl ExactSizeIterator<Item = (&str, &str, EntityType)>

Returns an iterator of all the imports in this module, along with their module name, field name, and type that’s being imported.

Source

pub fn import(&self, i: usize) -> Option<(&str, &str, EntityType)>

Get this module’s ith import.

Source

pub fn type_of(&self, index: EntityIndex) -> EntityType

Returns the type of an item based on its index

Source

pub fn push_tag( &mut self, signature: impl Into<EngineOrModuleTypeIndex>, exception: impl Into<EngineOrModuleTypeIndex>, ) -> TagIndex

Appends a new tag to this module with the given type information.

Source

pub fn push_function( &mut self, signature: impl Into<EngineOrModuleTypeIndex>, ) -> FuncIndex

Appends a new function to this module with the given type information, used for functions that either don’t escape or aren’t certain whether they escape yet.

Source

pub fn defined_func_indices( &self, ) -> impl ExactSizeIterator<Item = DefinedFuncIndex> + use<>

Returns an iterator over all of the defined function indices in this module.

Source

pub fn num_defined_funcs(&self) -> usize

Returns the number of functions defined by this module itself: all functions minus imported functions.

Source

pub fn num_defined_tables(&self) -> usize

Returns the number of tables defined by this module itself: all tables minus imported tables.

Source

pub fn num_defined_memories(&self) -> usize

Returns the number of memories defined by this module itself: all memories minus imported memories.

Source

pub fn num_defined_globals(&self) -> usize

Returns the number of globals defined by this module itself: all globals minus imported globals.

Source

pub fn num_defined_tags(&self) -> usize

Returns the number of tags defined by this module itself: all tags minus imported tags.

Source

pub fn is_valid(&self, index: EntityIndex) -> bool

Tests whether index is valid for this module.

Trait Implementations§

Source§

impl Debug for Module

Source§

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

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

impl<'de> Deserialize<'de> for Module

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 Module

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
Source§

impl TypeTrace for Module

Source§

fn trace<F, E>(&self, func: &mut F) -> Result<(), E>

Visit each edge. Read more
Source§

fn trace_mut<F, E>(&mut self, func: &mut F) -> Result<(), E>
where F: FnMut(&mut EngineOrModuleTypeIndex) -> Result<(), E>,

Visit each edge, mutably. Read more
Source§

fn trace_engine_indices<F, E>(&self, func: &mut F) -> Result<(), E>
where F: FnMut(VMSharedTypeIndex) -> Result<(), E>,

Trace all VMSharedTypeIndex edges, ignoring other edges.
Source§

fn canonicalize_for_runtime_usage<F>(&mut self, module_to_engine: &mut F)

Canonicalize self by rewriting all type references inside self from module-level interned type indices to engine-level interned type indices. Read more
Source§

fn is_canonicalized_for_runtime_usage(&self) -> bool

Is this type canonicalized for runtime usage?
Source§

fn canonicalize_for_hash_consing<F>( &mut self, rec_group_range: Range<ModuleInternedTypeIndex>, module_to_engine: &mut F, )

Canonicalize self by rewriting all type references inside self from module-level interned type indices to either engine-level interned type indices or recgroup-relative indices. Read more
Source§

fn is_canonicalized_for_hash_consing(&self) -> bool

Is this type canonicalized for hash consing?

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Same for T

Source§

type Output = T

Should always be Self
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.