Implement lowered-then-lifted functions (#4327)
* Implement lowered-then-lifted functions This commit is a few features bundled into one, culminating in the implementation of lowered-then-lifted functions for the component model. It's probably not going to be used all that often but this is possible within a valid component so Wasmtime needs to do something relatively reasonable. The main things implemented in this commit are: * Component instances are now assigned a `RuntimeComponentInstanceIndex` to differentiate each one. This will be used in the future to detect fusion (one instance lowering a function from another instance). For now it's used to allocate separate `VMComponentFlags` for each internal component instance. * The `CoreExport<FuncIndex>` of lowered functions was changed to a `CoreDef` since technically a lowered function can use another lowered function as the callee. This ended up being not too difficult to plumb through as everything else was already in place. * A need arose to compile host-to-wasm trampolines which weren't already present. Currently wasm in a component is always entered through a host-to-wasm trampoline but core wasm modules are the source of all the trampolines. In the case of a lowered-then-lifted function there may not actually be any core wasm modules, so component objects now contain necessary trampolines not otherwise provided by the core wasm objects. This feature required splitting a new function into the `Compiler` trait for creating a host-to-wasm trampoline. After doing this core wasm compilation was also updated to leverage this which further enabled compiling trampolines in parallel as opposed to the previous synchronous compilation. * Review comments
This commit is contained in:
@@ -148,12 +148,21 @@ pub trait Compiler: Send + Sync {
|
||||
types: &ModuleTypes,
|
||||
) -> Result<Box<dyn Any + Send>, CompileError>;
|
||||
|
||||
/// Creates a function of type `VMTrampoline` which will then call the
|
||||
/// function pointer argument which has the `ty` type provided.
|
||||
fn compile_host_to_wasm_trampoline(
|
||||
&self,
|
||||
ty: &WasmFuncType,
|
||||
) -> Result<Box<dyn Any + Send>, CompileError>;
|
||||
|
||||
/// Collects the results of compilation into an in-memory object.
|
||||
///
|
||||
/// This function will receive the same `Box<dyn Ayn>` produced as part of
|
||||
/// `compile_function`, as well as the general compilation environment with
|
||||
/// the translation/types. This method is expected to populate information
|
||||
/// in the object file such as:
|
||||
/// the translation. THe `trampolines` argument is generated by
|
||||
/// `compile_host_to_wasm_trampoline` for each of
|
||||
/// `module.exported_signatures`. This method is expected to populate
|
||||
/// information in the object file such as:
|
||||
///
|
||||
/// * Compiled code in a `.text` section
|
||||
/// * Unwind information in Wasmtime-specific sections
|
||||
@@ -163,11 +172,14 @@ pub trait Compiler: Send + Sync {
|
||||
///
|
||||
/// The final result of compilation will contain more sections inserted by
|
||||
/// the compiler-agnostic runtime.
|
||||
///
|
||||
/// This function returns information about the compiled functions (where
|
||||
/// they are in the text section) along with where trampolines are located.
|
||||
fn emit_obj(
|
||||
&self,
|
||||
module: &ModuleTranslation,
|
||||
types: &ModuleTypes,
|
||||
funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>,
|
||||
trampolines: Vec<Box<dyn Any + Send>>,
|
||||
tunables: &Tunables,
|
||||
obj: &mut Object<'static>,
|
||||
) -> Result<(PrimaryMap<DefinedFuncIndex, FunctionInfo>, Vec<Trampoline>)>;
|
||||
|
||||
Reference in New Issue
Block a user