Skip to main content

ModuleTranslation

Struct ModuleTranslation 

Source
pub struct ModuleTranslation<'data> {
Show 17 fields pub module: Module, pub wasm: &'data [u8], pub wasm_module_offset: u64, pub function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>, pub known_imported_functions: SecondaryMap<FuncIndex, Option<FuncKey>>, pub exported_signatures: Vec<ModuleInternedTypeIndex>, pub debuginfo: DebugInfoData<'data>, pub has_unparsed_debuginfo: bool, pub data_align: Option<u64>, pub runtime_data_map: SecondaryMap<DataIndex, Option<RuntimeDataIndex>>, pub passive_elem_map: SecondaryMap<ElemIndex, Option<PassiveElemIndex>>, pub runtime_data: PrimaryMap<RuntimeDataIndex, Cow<'data, [u8]>>, pub start_func: Option<FuncIndex>, pub global_initializers: Vec<(DefinedGlobalIndex, ConstExpr)>, pub passive_elements: PrimaryMap<PassiveElemIndex, TableSegmentElements>, pub table_initialization: TableInitialization, pub memory_init: MemoryInit<'data>, /* private fields */
}
Expand description

The result of translating via ModuleEnvironment.

Function bodies are not yet translated, and data initializers have not yet been copied out of the original buffer.

Fields§

§module: Module

Module information.

§wasm: &'data [u8]

The input wasm binary.

This can be useful, for example, when modules are parsed from a component and the embedder wants access to the raw wasm modules themselves.

§wasm_module_offset: u64

The byte offset of this module’s Wasm binary within the outer binary (e.g. a component). For standalone modules this is 0. This is used to convert component-relative source locations to module-relative source locations.

§function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>

References to the function bodies.

§known_imported_functions: SecondaryMap<FuncIndex, Option<FuncKey>>

For each imported function, the single statically-known function that always satisfies that import, if any.

This is used to turn what would otherwise be indirect calls through the imports table into direct calls, when possible.

When filled in, this only ever contains FuncKey::DefinedWasmFunction(..)s and FuncKey::Intrinsic(..)s.

§exported_signatures: Vec<ModuleInternedTypeIndex>

A list of type signatures which are considered exported from this module, or those that can possibly be called. This list is sorted, and trampolines for each of these signatures are required.

§debuginfo: DebugInfoData<'data>

DWARF debug information, if enabled, parsed from the module.

§has_unparsed_debuginfo: bool

Set if debuginfo was found but it was not parsed due to Tunables configuration.

§data_align: Option<u64>

The desired alignment of data in the final data section of the object file that we’ll emit.

Note that this is 1 by default but MemoryInitialization::Static might switch this to a higher alignment to facilitate mmap-ing data from an object file into a linear memory.

§runtime_data_map: SecondaryMap<DataIndex, Option<RuntimeDataIndex>>

Map from a data segment to whether it’s a passive data segment or not.

§passive_elem_map: SecondaryMap<ElemIndex, Option<PassiveElemIndex>>

Map from an elem segment to whether it’s a passive elem segment or not.

§runtime_data: PrimaryMap<RuntimeDataIndex, Cow<'data, [u8]>>

List of passive element segments found in this module which will get concatenated for the final artifact.

§start_func: Option<FuncIndex>

The WebAssembly start function, if defined.

§global_initializers: Vec<(DefinedGlobalIndex, ConstExpr)>

Initializers for global values which aren’t considered “simple”.

These initializers are later compiled into a “module startup” function.

§passive_elements: PrimaryMap<PassiveElemIndex, TableSegmentElements>

Definitions of all passive elements found within a module.

This maps passive element segments to their definition, either functions or expressions-basd.

§table_initialization: TableInitialization

WebAssembly table initialization data, per table.

This keeps track of all per-table initialization (e.g. initial value for non-null tables) as well as active element segments. This is processed and refined by ModuleTranslation::finalize_table_init after translation.

§memory_init: MemoryInit<'data>

WebAssembly memory initialization.

This is held here in an Unprocessed form during translation, and then this is later finished with ModuleTranslation::finalize_memory_init.

Implementations§

Source§

impl<'data> ModuleTranslation<'data>

Source

pub fn new(module_index: StaticModuleIndex) -> Self

Create a new translation for the module with the given index.

Source

pub fn branch_hints(&self, func: FuncIndex) -> Option<BranchHintReader<'data>>

Returns the BranchHintReader for func, if the section attached any.

Source

pub fn get_types(&self) -> &Types

Returns a reference to the type information of the current module.

Source

pub fn module_index(&self) -> StaticModuleIndex

Get this translation’s module’s index.

Source§

impl ModuleTranslation<'_>

Source

pub fn finalize_memory_init( &mut self, tunables: &Tunables, page_size: u64, max_image_size_always_allowed: u64, types: &mut ModuleTypesBuilder, )

Called after translation is complete this will finalize the memory initialization strategy for this module.

This will notably use Self::try_static_init to attempt to massage data segments to being CoW-init-friendly. Afterwards the self.memory_init field is transitioned from Unprocessed to Processed.

Source

pub fn finalize_table_init( &mut self, tunables: &Tunables, types: &mut ModuleTypesBuilder, )

Finalizes the initialization of tables.

This is invoked after translation and notably uses Self::try_func_table_init to attempt to optimize initialization of tables into static precomputed images.

Auto Trait Implementations§

§

impl<'data> Freeze for ModuleTranslation<'data>

§

impl<'data> RefUnwindSafe for ModuleTranslation<'data>

§

impl<'data> Send for ModuleTranslation<'data>

§

impl<'data> Sync for ModuleTranslation<'data>

§

impl<'data> Unpin for ModuleTranslation<'data>

§

impl<'data> UnsafeUnpin for ModuleTranslation<'data>

§

impl<'data> UnwindSafe for ModuleTranslation<'data>

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> 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.