Path: blob/main/crates/environ/src/component/artifacts.rs
1692 views
//! Definitions of compilation artifacts of the component compilation process1//! which are serialized with `bincode` into output ELF files.23use crate::{4CompiledModuleInfo, FunctionLoc, PrimaryMap, StaticModuleIndex,5component::{Component, ComponentTypes, TrampolineIndex, TypeComponentIndex},6};7use serde_derive::{Deserialize, Serialize};89/// Serializable state that's stored in a compilation artifact.10#[derive(Serialize, Deserialize)]11pub struct ComponentArtifacts {12/// The type of this component.13pub ty: TypeComponentIndex,14/// Information all kept available at runtime as-is.15pub info: CompiledComponentInfo,16/// Type information for this component and all contained modules.17pub types: ComponentTypes,18/// Serialized metadata about all included core wasm modules.19pub static_modules: PrimaryMap<StaticModuleIndex, CompiledModuleInfo>,20}2122/// Runtime state that a component retains to support its operation.23#[derive(Serialize, Deserialize)]24pub struct CompiledComponentInfo {25/// Type information calculated during translation about this component.26pub component: Component,2728/// Where lowered function trampolines are located within the `text`29/// section of `code_memory`.30///31/// These are the32///33/// 1. Wasm-call,34/// 2. array-call35///36/// function pointers that end up in a `VMFuncRef` for each37/// lowering.38pub trampolines: PrimaryMap<TrampolineIndex, AllCallFunc<FunctionLoc>>,3940/// The location of the wasm-to-array trampoline for the `resource.drop`41/// intrinsic.42pub resource_drop_wasm_to_array_trampoline: Option<FunctionLoc>,43}4445/// A triple of related functions/trampolines variants with differing calling46/// conventions: `{wasm,array}_call`.47///48/// Generic so we can use this with either the `Box<dyn Any + Send>`s that49/// implementations of the compiler trait return or with `FunctionLoc`s inside50/// an object file, for example.51#[derive(Clone, Copy, Default, Serialize, Deserialize)]52pub struct AllCallFunc<T> {53/// The function exposing the Wasm calling convention.54pub wasm_call: T,55/// The function exposing the array calling convention.56pub array_call: T,57}5859impl<T> AllCallFunc<T> {60/// Map an `AllCallFunc<T>` into an `AllCallFunc<U>`.61pub fn map<U>(self, mut f: impl FnMut(T) -> U) -> AllCallFunc<U> {62AllCallFunc {63wasm_call: f(self.wasm_call),64array_call: f(self.array_call),65}66}67}686970