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:
@@ -2,8 +2,8 @@
|
||||
//
|
||||
// struct VMComponentContext {
|
||||
// magic: u32,
|
||||
// flags: u8,
|
||||
// store: *mut dyn Store,
|
||||
// flags: [VMComponentFlags; component.num_runtime_component_instances],
|
||||
// lowering_anyfuncs: [VMCallerCheckedAnyfunc; component.num_lowerings],
|
||||
// lowerings: [VMLowering; component.num_lowerings],
|
||||
// memories: [*mut VMMemoryDefinition; component.num_memories],
|
||||
@@ -12,7 +12,8 @@
|
||||
// }
|
||||
|
||||
use crate::component::{
|
||||
Component, LoweredIndex, RuntimeMemoryIndex, RuntimePostReturnIndex, RuntimeReallocIndex,
|
||||
Component, LoweredIndex, RuntimeComponentInstanceIndex, RuntimeMemoryIndex,
|
||||
RuntimePostReturnIndex, RuntimeReallocIndex,
|
||||
};
|
||||
use crate::PtrSize;
|
||||
|
||||
@@ -48,11 +49,14 @@ pub struct VMComponentOffsets<P> {
|
||||
pub num_runtime_reallocs: u32,
|
||||
/// The number of post-returns which are recorded in this component for options.
|
||||
pub num_runtime_post_returns: u32,
|
||||
/// Number of component instances internally in the component (always at
|
||||
/// least 1).
|
||||
pub num_runtime_component_instances: u32,
|
||||
|
||||
// precalculated offsets of various member fields
|
||||
magic: u32,
|
||||
flags: u32,
|
||||
store: u32,
|
||||
flags: u32,
|
||||
lowering_anyfuncs: u32,
|
||||
lowerings: u32,
|
||||
memories: u32,
|
||||
@@ -77,9 +81,13 @@ impl<P: PtrSize> VMComponentOffsets<P> {
|
||||
num_runtime_memories: component.num_runtime_memories.try_into().unwrap(),
|
||||
num_runtime_reallocs: component.num_runtime_reallocs.try_into().unwrap(),
|
||||
num_runtime_post_returns: component.num_runtime_post_returns.try_into().unwrap(),
|
||||
num_runtime_component_instances: component
|
||||
.num_runtime_component_instances
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
magic: 0,
|
||||
flags: 0,
|
||||
store: 0,
|
||||
flags: 0,
|
||||
lowering_anyfuncs: 0,
|
||||
lowerings: 0,
|
||||
memories: 0,
|
||||
@@ -114,9 +122,10 @@ impl<P: PtrSize> VMComponentOffsets<P> {
|
||||
|
||||
fields! {
|
||||
size(magic) = 4u32,
|
||||
size(flags) = 1u32,
|
||||
align(u32::from(ret.ptr.size())),
|
||||
size(store) = cmul(2, ret.ptr.size()),
|
||||
size(flags) = cmul(ret.num_runtime_component_instances, ret.size_of_vmcomponent_flags()),
|
||||
align(u32::from(ret.ptr.size())),
|
||||
size(lowering_anyfuncs) = cmul(ret.num_lowerings, ret.ptr.size_of_vmcaller_checked_anyfunc()),
|
||||
size(lowerings) = cmul(ret.num_lowerings, ret.ptr.size() * 2),
|
||||
size(memories) = cmul(ret.num_runtime_memories, ret.ptr.size()),
|
||||
@@ -146,10 +155,17 @@ impl<P: PtrSize> VMComponentOffsets<P> {
|
||||
self.magic
|
||||
}
|
||||
|
||||
/// The size of the `VMComponentFlags` type.
|
||||
#[inline]
|
||||
pub fn size_of_vmcomponent_flags(&self) -> u8 {
|
||||
1
|
||||
}
|
||||
|
||||
/// The offset of the `flags` field.
|
||||
#[inline]
|
||||
pub fn flags(&self) -> u32 {
|
||||
self.flags
|
||||
pub fn flags(&self, index: RuntimeComponentInstanceIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_runtime_component_instances);
|
||||
self.flags + index.as_u32()
|
||||
}
|
||||
|
||||
/// The offset of the `store` field.
|
||||
|
||||
Reference in New Issue
Block a user