unsplat component::Linker::func_wrap args (#5065)

* component::Linker::func_wrap: replace IntoComponentFunc with directly accepting a closure

We find that this makes the Linker::func_wrap type signature much easier
to read. The IntoComponentFunc abstraction was adding a lot of weight to
"splat" a set of arguments from a tuple of types into individual
arguments to the closure. Additionally, making the StoreContextMut
argument optional, or the Result<return> optional, wasn't very
worthwhile.

* Fixes for the new style of closure required by component::Linker::func_wrap

* fix fuzzing generator
This commit is contained in:
Pat Hickey
2022-10-18 07:24:14 -07:00
committed by GitHub
parent 32a7593c94
commit 78ecc17d0f
10 changed files with 107 additions and 176 deletions

View File

@@ -2004,12 +2004,13 @@ fn drop_component_still_works() -> Result<()> {
let component = Component::new(&engine, component)?;
let mut store = Store::new(&engine, 0);
let mut linker = Linker::new(&engine);
linker
.root()
.func_wrap("f", |mut store: StoreContextMut<'_, u32>| -> Result<()> {
linker.root().func_wrap(
"f",
|mut store: StoreContextMut<'_, u32>, _: ()| -> Result<()> {
*store.data_mut() += 1;
Ok(())
})?;
},
)?;
let instance = linker.instantiate(&mut store, &component)?;
(store, instance)
};
@@ -2216,7 +2217,7 @@ fn lower_then_lift() -> Result<()> {
let component = Component::new(&engine, component)?;
let mut store = Store::new(&engine, ());
let mut linker = Linker::new(&engine);
linker.root().func_wrap("f", || Ok((2u32,)))?;
linker.root().func_wrap("f", |_, _: ()| Ok((2u32,)))?;
let instance = linker.instantiate(&mut store, &component)?;
let f = instance.get_typed_func::<(), (i32,), _>(&mut store, "f")?;
@@ -2252,7 +2253,7 @@ fn lower_then_lift() -> Result<()> {
let mut store = Store::new(&engine, ());
linker
.root()
.func_wrap("s", |store: StoreContextMut<'_, ()>, x: WasmStr| {
.func_wrap("s", |store: StoreContextMut<'_, ()>, (x,): (WasmStr,)| {
assert_eq!(x.to_str(&store)?, "hello");
Ok(())
})?;
@@ -2292,7 +2293,7 @@ fn lower_then_lift() -> Result<()> {
let mut store = Store::new(&engine, ());
linker
.root()
.func_wrap("s2", |store: StoreContextMut<'_, ()>, x: WasmStr| {
.func_wrap("s2", |store: StoreContextMut<'_, ()>, (x,): (WasmStr,)| {
assert_eq!(x.to_str(&store)?, "hello");
Ok((u32::MAX,))
})?;