pub struct ModuleTranslation<'data> {
    pub module: Module,
    pub function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>,
    pub exported_signatures: Vec<SignatureIndex>,
    pub debuginfo: DebugInfoData<'data>,
    pub has_unparsed_debuginfo: bool,
    pub data: Vec<Cow<'data, [u8]>>,
    pub data_align: Option<u64>,
    pub passive_data: Vec<&'data [u8]>,
    /* 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.

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

References to the function bodies.

exported_signatures: Vec<SignatureIndex>

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: Vec<Cow<'data, [u8]>>

List of data segments found in this module which should be concatenated together for the final compiled artifact.

These data segments, when concatenated, are indexed by the MemoryInitializer type.

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.

passive_data: Vec<&'data [u8]>

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

Implementations

Attempts to convert segmented memory initialization into static initialization for the module that this translation represents.

If this module’s memory initialization is not compatible with paged initialization then this won’t change anything. Otherwise if it is compatible then the memory_initialization field will be updated.

Takes a page_size argument in order to ensure that all initialization is page-aligned for mmap-ability, and max_image_size_always_allowed to control how we decide whether to use static init.

We will try to avoid generating very sparse images, which are possible if e.g. a module has an initializer at offset 0 and a very high offset (say, 1 GiB). To avoid this, we use a dual condition: we always allow images less than max_image_size_always_allowed, and the embedder of Wasmtime can set this if desired to ensure that static init should always be done if the size of the module or its heaps is otherwise bounded by the system. We also allow images with static init data bigger than that, but only if it is “dense”, defined as having at least half (50%) of its pages with some data.

We could do something slightly better by building a dense part and keeping a sparse list of outlier/leftover segments (see issue #3820). This would also allow mostly-static init of modules that have some dynamically-placed data segments. But, for now, this is sufficient to allow a system that “knows what it’s doing” to always get static init.

Attempts to convert the module’s table initializers to FuncTable form where possible. This enables lazy table initialization later by providing a one-to-one map of initial table values, without having to parse all segments.

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.