Update wasm-tools crates (#4246)

This commit updates the wasm-tools family of crates, notably pulling in
the refactorings and updates from bytecodealliance/wasm-tools#621 for
the latest iteration of the component model. This commit additionally
updates all support for the component model for these changes, notably:

* Many bits and pieces of type information was refactored. Many
  `FooTypeIndex` namings are now `TypeFooIndex`. Additionally there is
  now `TypeIndex` as well as `ComponentTypeIndex` for the two type index
  spaces in a component.

* A number of new sections are now processed to handle the core and
  component variants.

* Internal maps were split such as the `funcs` map into
  `component_funcs` and `funcs` (same for `instances`).

* Canonical options are now processed individually instead of one bulk
  `into` definition.

Overall this was not a major update to the internals of handling the
component model in Wasmtime. Instead this was mostly a surface-level
refactoring to make sure that everything lines up with the new binary
format for components.

* All text syntax used in tests was updated to the new syntax.
This commit is contained in:
Alex Crichton
2022-06-09 11:16:07 -05:00
committed by GitHub
parent c15c3061ca
commit 7d7ddceb17
32 changed files with 1201 additions and 1078 deletions

View File

@@ -20,7 +20,7 @@ wasmtime-cache = { path = "../cache", version = "=0.39.0", optional = true }
wasmtime-fiber = { path = "../fiber", version = "=0.39.0", optional = true }
wasmtime-cranelift = { path = "../cranelift", version = "=0.39.0", optional = true }
target-lexicon = { version = "0.12.0", default-features = false }
wasmparser = "0.85.0"
wasmparser = "0.86.0"
anyhow = "1.0.19"
region = "2.2.0"
libc = "0.2"

View File

@@ -5,7 +5,7 @@ use anyhow::{Context, Result};
use std::mem::MaybeUninit;
use std::ptr::NonNull;
use std::sync::Arc;
use wasmtime_environ::component::{CanonicalOptions, ComponentTypes, CoreExport, FuncTypeIndex};
use wasmtime_environ::component::{CanonicalOptions, ComponentTypes, CoreExport, TypeFuncIndex};
use wasmtime_environ::FuncIndex;
use wasmtime_runtime::{Export, ExportFunction, VMTrampoline};
@@ -78,7 +78,7 @@ pub struct Func(Stored<FuncData>);
pub struct FuncData {
trampoline: VMTrampoline,
export: ExportFunction,
ty: FuncTypeIndex,
ty: TypeFuncIndex,
types: Arc<ComponentTypes>,
options: Options,
instance: Instance,
@@ -89,7 +89,7 @@ impl Func {
store: &mut StoreOpaque,
instance: &Instance,
data: &InstanceData,
ty: FuncTypeIndex,
ty: TypeFuncIndex,
func: &CoreExport<FuncIndex>,
options: &CanonicalOptions,
) -> Func {

View File

@@ -7,7 +7,7 @@ use std::mem::MaybeUninit;
use std::panic::{self, AssertUnwindSafe};
use std::ptr::NonNull;
use std::sync::Arc;
use wasmtime_environ::component::{ComponentTypes, FuncTypeIndex, StringEncoding};
use wasmtime_environ::component::{ComponentTypes, StringEncoding, TypeFuncIndex};
use wasmtime_runtime::component::{VMComponentContext, VMLowering, VMLoweringCallee};
use wasmtime_runtime::{VMCallerCheckedAnyfunc, VMMemoryDefinition, VMOpaqueContext};
@@ -38,7 +38,7 @@ pub trait IntoComponentFunc<T, Params, Return> {
pub struct HostFunc {
entrypoint: VMLoweringCallee,
typecheck: fn(FuncTypeIndex, &ComponentTypes) -> Result<()>,
typecheck: fn(TypeFuncIndex, &ComponentTypes) -> Result<()>,
func: Box<dyn Any + Send + Sync>,
}
@@ -56,7 +56,7 @@ impl HostFunc {
})
}
pub fn typecheck(&self, ty: FuncTypeIndex, types: &ComponentTypes) -> Result<()> {
pub fn typecheck(&self, ty: TypeFuncIndex, types: &ComponentTypes) -> Result<()> {
(self.typecheck)(ty, types)
}
@@ -69,7 +69,7 @@ impl HostFunc {
}
}
fn typecheck<P, R>(ty: FuncTypeIndex, types: &ComponentTypes) -> Result<()>
fn typecheck<P, R>(ty: TypeFuncIndex, types: &ComponentTypes) -> Result<()>
where
P: ComponentParams + Lift,
R: Lower,

View File

@@ -4,7 +4,7 @@ use crate::types::matching;
use crate::Module;
use anyhow::{anyhow, bail, Context, Result};
use wasmtime_environ::component::{
ComponentInstanceType, ComponentTypes, FuncTypeIndex, ModuleType, TypeDef,
ComponentTypes, TypeComponentInstance, TypeDef, TypeFuncIndex, TypeModule,
};
pub struct TypeChecker<'a> {
@@ -23,16 +23,19 @@ impl TypeChecker<'_> {
Definition::Instance(actual) => self.instance(&self.types[t], actual),
_ => bail!("expected instance found {}", actual.desc()),
},
TypeDef::Func(t) => match actual {
TypeDef::ComponentFunc(t) => match actual {
Definition::Func(actual) => self.func(t, actual),
_ => bail!("expected func found {}", actual.desc()),
},
TypeDef::Component(_) => bail!("expected component found {}", actual.desc()),
TypeDef::Interface(_) => bail!("expected type found {}", actual.desc()),
// not possible for valid components to import
TypeDef::CoreFunc(_) => unreachable!(),
}
}
fn module(&self, expected: &ModuleType, actual: &Module) -> Result<()> {
fn module(&self, expected: &TypeModule, actual: &Module) -> Result<()> {
let actual_types = actual.types();
let actual = actual.env_module();
@@ -63,7 +66,7 @@ impl TypeChecker<'_> {
Ok(())
}
fn instance(&self, expected: &ComponentInstanceType, actual: &NameMap) -> Result<()> {
fn instance(&self, expected: &TypeComponentInstance, actual: &NameMap) -> Result<()> {
// Like modules, every export in the expected type must be present in
// the actual type. It's ok, though, to have extra exports in the actual
// type.
@@ -79,7 +82,7 @@ impl TypeChecker<'_> {
Ok(())
}
fn func(&self, expected: FuncTypeIndex, actual: &HostFunc) -> Result<()> {
fn func(&self, expected: TypeFuncIndex, actual: &HostFunc) -> Result<()> {
actual.typecheck(expected, self.types)
}
}