Skip to content

Commit

Permalink
Update wasm-tools crates (#9336)
Browse files Browse the repository at this point in the history
* Update wasm-tools crates

* WIT `float32` and `float64` are now hard errors (renamed to `f32` and
  `f64`)
* Stack switching has been implemented in wasm-tools, but not Wasmtime.
* New shared-everything-threads component model intrinsics are not implemented

"Holes" for these new features in wasmparser are now present in Wasmtime
and panics shouldn't be hit because the new proposals aren't enabled in
the validator at this time.

* Fix fuzzer build

* Fix fuzzer tests
  • Loading branch information
alexcrichton authored Sep 30, 2024
1 parent ec3b2d2 commit 6844ed1
Show file tree
Hide file tree
Showing 30 changed files with 678 additions and 553 deletions.
174 changes: 125 additions & 49 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ wit-bindgen = { version = "0.32.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.32.0", default-features = false }

# wasm-tools family:
wasmparser = { version = "0.217.0", default-features = false }
wat = "1.217.0"
wast = "217.0.0"
wasmprinter = "0.217.0"
wasm-encoder = "0.217.0"
wasm-smith = "0.217.0"
wasm-mutate = "0.217.0"
wit-parser = "0.217.0"
wit-component = "0.217.0"
wasmparser = { version = "0.218.0", default-features = false }
wat = "1.218.0"
wast = "218.0.0"
wasmprinter = "0.218.0"
wasm-encoder = "0.218.0"
wasm-smith = "0.218.0"
wasm-mutate = "0.218.0"
wit-parser = "0.218.0"
wit-component = "0.218.0"

# Non-Bytecode Alliance maintained dependencies:
# --------------------------
Expand Down
11 changes: 11 additions & 0 deletions cranelift/wasm/src/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,17 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
"shared-everything-threads operators are not yet implemented"
));
}

Operator::ContNew { .. }
| Operator::ContBind { .. }
| Operator::Suspend { .. }
| Operator::Resume { .. }
| Operator::ResumeThrow { .. }
| Operator::Switch { .. } => {
return Err(wasm_unsupported!(
"stack-switching operators are not yet implemented"
));
}
};
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/component-macro/tests/codegen/floats.wit
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package foo:foo;

interface floats {
float32-param: func(x: float32);
float64-param: func(x: float64);
float32-result: func() -> float32;
float64-result: func() -> float64;
f32-param: func(x: f32);
f64-param: func(x: f64);
f32-result: func() -> f32;
f64-result: func() -> f64;
}

world the-world {
Expand Down
12 changes: 6 additions & 6 deletions crates/component-macro/tests/codegen/lists.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface lists {
list-s16-param: func(x: list<s16>);
list-s32-param: func(x: list<s32>);
list-s64-param: func(x: list<s64>);
list-float32-param: func(x: list<float32>);
list-float64-param: func(x: list<float64>);
list-f32-param: func(x: list<f32>);
list-f64-param: func(x: list<f64>);

list-u8-ret: func() -> list<u8>;
list-u16-ret: func() -> list<u16>;
Expand All @@ -20,8 +20,8 @@ interface lists {
list-s16-ret: func() -> list<s16>;
list-s32-ret: func() -> list<s32>;
list-s64-ret: func() -> list<s64>;
list-float32-ret: func() -> list<float32>;
list-float64-ret: func() -> list<float64>;
list-f32-ret: func() -> list<f32>;
list-f64-ret: func() -> list<f64>;

tuple-list: func(x: list<tuple<u8, s8>>) -> list<tuple<s64, u32>>;
string-list-arg: func(a: list<string>);
Expand Down Expand Up @@ -72,8 +72,8 @@ interface lists {
s32,
u64,
s64,
float32,
float64,
f32,
f64,
char,
>>;
load-store-everything: func(a: load-store-all-sizes) -> load-store-all-sizes;
Expand Down
2 changes: 1 addition & 1 deletion crates/component-macro/tests/codegen/multi-return.wit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface multi-return {
mrb: func() -> ();
mrc: func() -> u32;
mrd: func() -> (a: u32);
mre: func() -> (a: u32, b: float32);
mre: func() -> (a: u32, b: f32);
}

world the-world {
Expand Down
16 changes: 8 additions & 8 deletions crates/component-macro/tests/codegen/variants.wit
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ interface variants {
b: option<tuple<>>,
c: option<u32>,
d: option<e1>,
e: option<float32>,
e: option<f32>,
g: option<option<bool>>,
);
option-result: func() -> tuple<
option<bool>,
option<tuple<>>,
option<u32>,
option<e1>,
option<float32>,
option<f32>,
option<option<bool>>,
>;

variant casts1 {
a(s32),
b(float32),
b(f32),
}

variant casts2 {
a(float64),
b(float32),
a(f64),
b(f32),
}

variant casts3 {
a(float64),
a(f64),
b(u64),
}

Expand All @@ -63,12 +63,12 @@ interface variants {
}

variant casts5 {
a(float32),
a(f32),
b(s64),
}

variant casts6 {
a(tuple<float32, u32>),
a(tuple<f32, u32>),
b(tuple<u32, u32>),
}

Expand Down
124 changes: 56 additions & 68 deletions crates/component-macro/tests/expanded/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ pub mod foo {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
pub trait Host {
fn float32_param(&mut self, x: f32) -> ();
fn float64_param(&mut self, x: f64) -> ();
fn float32_result(&mut self) -> f32;
fn float64_result(&mut self) -> f64;
fn f32_param(&mut self, x: f32) -> ();
fn f64_param(&mut self, x: f64) -> ();
fn f32_result(&mut self) -> f32;
fn f64_result(&mut self) -> f64;
}
pub trait GetHost<
T,
Expand All @@ -210,34 +210,34 @@ pub mod foo {
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/floats")?;
inst.func_wrap(
"float32-param",
"f32-param",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (arg0,): (f32,)| {
let host = &mut host_getter(caller.data_mut());
let r = Host::float32_param(host, arg0);
let r = Host::f32_param(host, arg0);
Ok(r)
},
)?;
inst.func_wrap(
"float64-param",
"f64-param",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (arg0,): (f64,)| {
let host = &mut host_getter(caller.data_mut());
let r = Host::float64_param(host, arg0);
let r = Host::f64_param(host, arg0);
Ok(r)
},
)?;
inst.func_wrap(
"float32-result",
"f32-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::float32_result(host);
let r = Host::f32_result(host);
Ok((r,))
},
)?;
inst.func_wrap(
"float64-result",
"f64-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::float64_result(host);
let r = Host::f64_result(host);
Ok((r,))
},
)?;
Expand All @@ -253,17 +253,17 @@ pub mod foo {
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn float32_param(&mut self, x: f32) -> () {
Host::float32_param(*self, x)
fn f32_param(&mut self, x: f32) -> () {
Host::f32_param(*self, x)
}
fn float64_param(&mut self, x: f64) -> () {
Host::float64_param(*self, x)
fn f64_param(&mut self, x: f64) -> () {
Host::f64_param(*self, x)
}
fn float32_result(&mut self) -> f32 {
Host::float32_result(*self)
fn f32_result(&mut self) -> f32 {
Host::f32_result(*self)
}
fn float64_result(&mut self) -> f64 {
Host::float64_result(*self)
fn f64_result(&mut self) -> f64 {
Host::f64_result(*self)
}
}
}
Expand All @@ -277,17 +277,17 @@ pub mod exports {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
pub struct Guest {
float32_param: wasmtime::component::Func,
float64_param: wasmtime::component::Func,
float32_result: wasmtime::component::Func,
float64_result: wasmtime::component::Func,
f32_param: wasmtime::component::Func,
f64_param: wasmtime::component::Func,
f32_result: wasmtime::component::Func,
f64_result: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
float32_param: wasmtime::component::ComponentExportIndex,
float64_param: wasmtime::component::ComponentExportIndex,
float32_result: wasmtime::component::ComponentExportIndex,
float64_result: wasmtime::component::ComponentExportIndex,
f32_param: wasmtime::component::ComponentExportIndex,
f64_param: wasmtime::component::ComponentExportIndex,
f32_result: wasmtime::component::ComponentExportIndex,
f64_result: wasmtime::component::ComponentExportIndex,
}
impl GuestIndices {
/// Constructor for [`GuestIndices`] which takes a
Expand Down Expand Up @@ -342,15 +342,15 @@ pub mod exports {
})
};
let _ = &mut lookup;
let float32_param = lookup("float32-param")?;
let float64_param = lookup("float64-param")?;
let float32_result = lookup("float32-result")?;
let float64_result = lookup("float64-result")?;
let f32_param = lookup("f32-param")?;
let f64_param = lookup("f64-param")?;
let f32_result = lookup("f32-result")?;
let f64_result = lookup("f64-result")?;
Ok(GuestIndices {
float32_param,
float64_param,
float32_result,
float64_result,
f32_param,
f64_param,
f32_result,
f64_result,
})
}
pub fn load(
Expand All @@ -361,40 +361,28 @@ pub mod exports {
let mut store = store.as_context_mut();
let _ = &mut store;
let _instance = instance;
let float32_param = *_instance
.get_typed_func::<
(f32,),
(),
>(&mut store, &self.float32_param)?
let f32_param = *_instance
.get_typed_func::<(f32,), ()>(&mut store, &self.f32_param)?
.func();
let float64_param = *_instance
.get_typed_func::<
(f64,),
(),
>(&mut store, &self.float64_param)?
let f64_param = *_instance
.get_typed_func::<(f64,), ()>(&mut store, &self.f64_param)?
.func();
let float32_result = *_instance
.get_typed_func::<
(),
(f32,),
>(&mut store, &self.float32_result)?
let f32_result = *_instance
.get_typed_func::<(), (f32,)>(&mut store, &self.f32_result)?
.func();
let float64_result = *_instance
.get_typed_func::<
(),
(f64,),
>(&mut store, &self.float64_result)?
let f64_result = *_instance
.get_typed_func::<(), (f64,)>(&mut store, &self.f64_result)?
.func();
Ok(Guest {
float32_param,
float64_param,
float32_result,
float64_result,
f32_param,
f64_param,
f32_result,
f64_result,
})
}
}
impl Guest {
pub fn call_float32_param<S: wasmtime::AsContextMut>(
pub fn call_f32_param<S: wasmtime::AsContextMut>(
&self,
mut store: S,
arg0: f32,
Expand All @@ -403,13 +391,13 @@ pub mod exports {
wasmtime::component::TypedFunc::<
(f32,),
(),
>::new_unchecked(self.float32_param)
>::new_unchecked(self.f32_param)
};
let () = callee.call(store.as_context_mut(), (arg0,))?;
callee.post_return(store.as_context_mut())?;
Ok(())
}
pub fn call_float64_param<S: wasmtime::AsContextMut>(
pub fn call_f64_param<S: wasmtime::AsContextMut>(
&self,
mut store: S,
arg0: f64,
Expand All @@ -418,35 +406,35 @@ pub mod exports {
wasmtime::component::TypedFunc::<
(f64,),
(),
>::new_unchecked(self.float64_param)
>::new_unchecked(self.f64_param)
};
let () = callee.call(store.as_context_mut(), (arg0,))?;
callee.post_return(store.as_context_mut())?;
Ok(())
}
pub fn call_float32_result<S: wasmtime::AsContextMut>(
pub fn call_f32_result<S: wasmtime::AsContextMut>(
&self,
mut store: S,
) -> wasmtime::Result<f32> {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
(f32,),
>::new_unchecked(self.float32_result)
>::new_unchecked(self.f32_result)
};
let (ret0,) = callee.call(store.as_context_mut(), ())?;
callee.post_return(store.as_context_mut())?;
Ok(ret0)
}
pub fn call_float64_result<S: wasmtime::AsContextMut>(
pub fn call_f64_result<S: wasmtime::AsContextMut>(
&self,
mut store: S,
) -> wasmtime::Result<f64> {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
(f64,),
>::new_unchecked(self.float64_result)
>::new_unchecked(self.f64_result)
};
let (ret0,) = callee.call(store.as_context_mut(), ())?;
callee.post_return(store.as_context_mut())?;
Expand Down
Loading

0 comments on commit 6844ed1

Please sign in to comment.