Initial skeleton of some component model processing (#4005)
* Initial skeleton of some component model processing This commit is the first of what will likely be many to implement the component model proposal in Wasmtime. This will be structured as a series of incremental commits, most of which haven't been written yet. My hope is to make this incremental and over time to make this easier to review and easier to test each step in isolation. Here much of the skeleton of how components are going to work in Wasmtime is sketched out. This is not a complete implementation of the component model so it's not all that useful yet, but some things you can do are: * Process the type section into a representation amenable for working with in Wasmtime. * Process the module section and register core wasm modules. * Process the instance section for core wasm modules. * Process core wasm module imports. * Process core wasm instance aliasing. * Ability to compile a component with core wasm embedded. * Ability to instantiate a component with no imports. * Ability to get functions from this component. This is already starting to diverge from the previous module linking representation where a `Component` will try to avoid unnecessary metadata about the component and instead internally only have the bare minimum necessary to instantiate the module. My hope is we can avoid constructing most of the index spaces during instantiation only for it to all ge thrown away. Additionally I'm predicting that we'll need to see through processing where possible to know how to generate adapters and where they are fused. At this time you can't actually call a component's functions, and that's the next PR that I would like to make. * Add tests for the component model support This commit uses the recently updated wasm-tools crates to add tests for the component model added in the previous commit. This involved updating the `wasmtime-wast` crate for component-model changes. Currently the component support there is quite primitive, but enough to at least instantiate components and verify the internals of Wasmtime are all working correctly. Additionally some simple tests for the embedding API have also been added.
This commit is contained in:
@@ -28,8 +28,8 @@ use std::mem;
|
||||
use std::sync::Mutex;
|
||||
use wasmtime_environ::{
|
||||
AddressMapSection, CompileError, FilePos, FlagValue, FunctionBodyData, FunctionInfo,
|
||||
InstructionAddressMap, Module, ModuleTranslation, StackMapInformation, Trampoline, TrapCode,
|
||||
TrapEncodingBuilder, TrapInformation, Tunables, TypeTables, VMOffsets,
|
||||
InstructionAddressMap, Module, ModuleTranslation, ModuleTypes, StackMapInformation, Trampoline,
|
||||
TrapCode, TrapEncodingBuilder, TrapInformation, Tunables, VMOffsets,
|
||||
};
|
||||
|
||||
/// A compiler that compiles a WebAssembly module with Compiler, translating
|
||||
@@ -109,7 +109,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
func_index: DefinedFuncIndex,
|
||||
mut input: FunctionBodyData<'_>,
|
||||
tunables: &Tunables,
|
||||
types: &TypeTables,
|
||||
types: &ModuleTypes,
|
||||
) -> Result<Box<dyn Any + Send>, CompileError> {
|
||||
let isa = &*self.isa;
|
||||
let module = &translation.module;
|
||||
@@ -237,7 +237,7 @@ impl wasmtime_environ::Compiler for Compiler {
|
||||
fn emit_obj(
|
||||
&self,
|
||||
translation: &ModuleTranslation,
|
||||
types: &TypeTables,
|
||||
types: &ModuleTypes,
|
||||
funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>,
|
||||
tunables: &Tunables,
|
||||
obj: &mut Object<'static>,
|
||||
|
||||
@@ -16,8 +16,8 @@ use std::convert::TryFrom;
|
||||
use std::mem;
|
||||
use wasmparser::Operator;
|
||||
use wasmtime_environ::{
|
||||
BuiltinFunctionIndex, MemoryPlan, MemoryStyle, Module, ModuleTranslation, TableStyle, Tunables,
|
||||
TypeTables, VMOffsets, WASM_PAGE_SIZE,
|
||||
BuiltinFunctionIndex, MemoryPlan, MemoryStyle, Module, ModuleTranslation, ModuleTypes,
|
||||
TableStyle, Tunables, VMOffsets, WASM_PAGE_SIZE,
|
||||
};
|
||||
use wasmtime_environ::{FUNCREF_INIT_BIT, FUNCREF_MASK};
|
||||
|
||||
@@ -113,7 +113,7 @@ pub struct FuncEnvironment<'module_environment> {
|
||||
isa: &'module_environment (dyn TargetIsa + 'module_environment),
|
||||
module: &'module_environment Module,
|
||||
translation: &'module_environment ModuleTranslation<'module_environment>,
|
||||
types: &'module_environment TypeTables,
|
||||
types: &'module_environment ModuleTypes,
|
||||
|
||||
/// The Cranelift global holding the vmctx address.
|
||||
vmctx: Option<ir::GlobalValue>,
|
||||
@@ -158,7 +158,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
|
||||
pub fn new(
|
||||
isa: &'module_environment (dyn TargetIsa + 'module_environment),
|
||||
translation: &'module_environment ModuleTranslation<'module_environment>,
|
||||
types: &'module_environment TypeTables,
|
||||
types: &'module_environment ModuleTypes,
|
||||
tunables: &'module_environment Tunables,
|
||||
) -> Self {
|
||||
let builtin_function_signatures = BuiltinFunctionSignatures::new(
|
||||
|
||||
@@ -51,7 +51,7 @@ use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmFuncType, WasmType};
|
||||
use target_lexicon::CallingConvention;
|
||||
use wasmtime_environ::{
|
||||
FilePos, FunctionInfo, InstructionAddressMap, ModuleTranslation, TrapInformation, TypeTables,
|
||||
FilePos, FunctionInfo, InstructionAddressMap, ModuleTranslation, ModuleTypes, TrapInformation,
|
||||
};
|
||||
|
||||
pub use builder::builder;
|
||||
@@ -208,7 +208,7 @@ fn indirect_signature(isa: &dyn TargetIsa, wasm: &WasmFuncType) -> ir::Signature
|
||||
fn func_signature(
|
||||
isa: &dyn TargetIsa,
|
||||
translation: &ModuleTranslation,
|
||||
types: &TypeTables,
|
||||
types: &ModuleTypes,
|
||||
index: FuncIndex,
|
||||
) -> ir::Signature {
|
||||
let func = &translation.module.functions[index];
|
||||
|
||||
Reference in New Issue
Block a user