wiggle: make wasmtime a mandatory dep, get rid of own Trap enum (#5137)

* wiggle: no longer need to guard wasmtime integration behind a feature

this existed so we could use wiggle in lucet, but lucet is long EOL

* replace wiggle::Trap with wiggle::wasmtime_crate::Trap

* wiggle tests: unwrap traps because we cant assert_eq on them

* wasi-common: emit a wasmtime::Trap instead of a wiggle::Trap

formally add a dependency on wasmtime here to make it obvious, though
we do now have a transitive one via wiggle no matter what (and therefore
can get rid of the default-features=false on the wiggle dep)

* wasi-nn: use wasmtime::Trap instead of wiggle::Trap

there's no way the implementation of this func is actually
a good idea, it will panic the host process on any error,
but I'll ask @mtr to fix that

* wiggle test-helpers examples: fixes

* wasi-common cant cross compile to wasm32-unknown-emscripten anymore

this was originally for the WASI polyfill for web targets. Those days
are way behind us now.

* wasmtime wont compile for armv7-unknown-linux-gnueabihf either
This commit is contained in:
Pat Hickey
2022-10-27 09:28:10 -07:00
committed by GitHub
parent b20128a6cb
commit 0290a83502
30 changed files with 147 additions and 155 deletions

View File

@@ -34,9 +34,10 @@ impl IntFloatExercise {
let mut ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let e = atoms::int_float_args(&mut ctx, &host_memory, self.an_int as i32, self.an_float);
let e = atoms::int_float_args(&mut ctx, &host_memory, self.an_int as i32, self.an_float)
.unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "int_float_args error");
assert_eq!(e, types::Errno::Ok as i32, "int_float_args error");
}
pub fn strat() -> BoxedStrategy<Self> {
@@ -68,13 +69,14 @@ impl DoubleIntExercise {
&host_memory,
self.input as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
let return_val = host_memory
.ptr::<types::AliasToFloat>(self.return_loc.ptr)
.read()
.expect("failed to read return");
assert_eq!(e, Ok(types::Errno::Ok as i32), "errno");
assert_eq!(e, types::Errno::Ok as i32, "errno");
assert_eq!(return_val, (self.input as f32) * 2.0, "return val");
}

View File

@@ -44,9 +44,10 @@ impl IntFloatExercise {
&host_memory,
self.an_int as i32,
self.an_float,
));
))
.unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "int_float_args error");
assert_eq!(e, types::Errno::Ok as i32, "int_float_args error");
}
pub fn strat() -> BoxedStrategy<Self> {
@@ -78,13 +79,14 @@ impl DoubleIntExercise {
&host_memory,
self.input as i32,
self.return_loc.ptr as i32,
));
))
.unwrap();
let return_val = host_memory
.ptr::<types::AliasToFloat>(self.return_loc.ptr)
.read()
.expect("failed to read return");
assert_eq!(e, Ok(types::Errno::Ok as i32), "errno");
assert_eq!(e, types::Errno::Ok as i32, "errno");
assert_eq!(return_val, (self.input as f32) * 2.0, "return val");
}

View File

@@ -31,7 +31,10 @@ mod convert_just_errno {
/// When the `errors` mapping in witx is non-empty, we need to impl the
/// types::UserErrorConversion trait that wiggle generates from that mapping.
impl<'a> types::UserErrorConversion for WasiCtx<'a> {
fn errno_from_rich_error(&mut self, e: RichError) -> Result<types::Errno, wiggle::Trap> {
fn errno_from_rich_error(
&mut self,
e: RichError,
) -> Result<types::Errno, wiggle::wasmtime_crate::Trap> {
// WasiCtx can collect a Vec<String> log so we can test this. We're
// logging the Display impl that `thiserror::Error` provides us.
self.log.borrow_mut().push(e.to_string());
@@ -62,19 +65,19 @@ mod convert_just_errno {
// Exercise each of the branches in `foo`.
// Start with the success case:
let r0 = one_error_conversion::foo(&mut ctx, &host_memory, 0);
let r0 = one_error_conversion::foo(&mut ctx, &host_memory, 0).unwrap();
assert_eq!(
r0,
Ok(types::Errno::Ok as i32),
types::Errno::Ok as i32,
"Expected return value for strike=0"
);
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
// First error case:
let r1 = one_error_conversion::foo(&mut ctx, &host_memory, 1);
let r1 = one_error_conversion::foo(&mut ctx, &host_memory, 1).unwrap();
assert_eq!(
r1,
Ok(types::Errno::PicketLine as i32),
types::Errno::PicketLine as i32,
"Expected return value for strike=1"
);
assert_eq!(
@@ -84,10 +87,10 @@ mod convert_just_errno {
);
// Second error case:
let r2 = one_error_conversion::foo(&mut ctx, &host_memory, 2);
let r2 = one_error_conversion::foo(&mut ctx, &host_memory, 2).unwrap();
assert_eq!(
r2,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"Expected return value for strike=2"
);
assert_eq!(
@@ -114,7 +117,7 @@ mod convert_multiple_error_types {
// Just like the prior test, except that we have a second errno type. This should mean there
// are two functions in UserErrorConversion.
// Additionally, test that the function "baz" marked noreturn always returns a wiggle::Trap.
// Additionally, test that the function "baz" marked noreturn always returns a wasmtime::Trap.
wiggle::from_witx!({
witx_literal: "
(typename $errno (enum (@witx tag u8) $ok $invalid_arg $picket_line))
@@ -140,13 +143,16 @@ mod convert_multiple_error_types {
// each member of the `errors` mapping.
// Bodies elided.
impl<'a> types::UserErrorConversion for WasiCtx<'a> {
fn errno_from_rich_error(&mut self, _e: RichError) -> Result<types::Errno, wiggle::Trap> {
fn errno_from_rich_error(
&mut self,
_e: RichError,
) -> Result<types::Errno, wiggle::wasmtime_crate::Trap> {
unimplemented!()
}
fn errno2_from_another_rich_error(
&mut self,
_e: AnotherRichError,
) -> Result<types::Errno2, wiggle::Trap> {
) -> Result<types::Errno2, wiggle::wasmtime_crate::Trap> {
unimplemented!()
}
}
@@ -159,7 +165,7 @@ mod convert_multiple_error_types {
fn bar(&mut self, _: u32) -> Result<(), AnotherRichError> {
unimplemented!()
}
fn baz(&mut self, _: u32) -> wiggle::Trap {
fn baz(&mut self, _: u32) -> wiggle::wasmtime_crate::Trap {
unimplemented!()
}
}

View File

@@ -77,8 +77,9 @@ impl ConfigureCarExercise {
self.old_config.bits() as i32,
self.other_config_by_ptr.ptr as i32,
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "configure car errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "configure car errno");
let res_config = host_memory
.ptr::<types::CarConfig>(self.return_ptr_loc.ptr)

View File

@@ -34,9 +34,10 @@ impl HandleExercise {
let mut ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let e = handle_examples::fd_create(&mut ctx, &host_memory, self.return_loc.ptr as i32);
let e =
handle_examples::fd_create(&mut ctx, &host_memory, self.return_loc.ptr as i32).unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "fd_create error");
assert_eq!(e, types::Errno::Ok as i32, "fd_create error");
let h_got: u32 = host_memory
.ptr(self.return_loc.ptr)
@@ -45,15 +46,15 @@ impl HandleExercise {
assert_eq!(h_got, 123, "fd_create return val");
let e = handle_examples::fd_consume(&mut ctx, &host_memory, h_got as i32);
let e = handle_examples::fd_consume(&mut ctx, &host_memory, h_got as i32).unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "fd_consume error");
assert_eq!(e, types::Errno::Ok as i32, "fd_consume error");
let e = handle_examples::fd_consume(&mut ctx, &host_memory, h_got as i32 + 1);
let e = handle_examples::fd_consume(&mut ctx, &host_memory, h_got as i32 + 1).unwrap();
assert_eq!(
e,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"fd_consume invalid error"
);
}

View File

@@ -51,8 +51,9 @@ impl CookieCutterExercise {
&host_memory,
self.cookie as i64,
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "cookie cutter errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "cookie cutter errno");
let is_cookie_start = host_memory
.ptr::<types::Bool>(self.return_ptr_loc.ptr)

View File

@@ -102,9 +102,10 @@ impl ReduceExcusesExcercise {
self.array_ptr_loc.ptr as i32,
self.excuse_ptr_locs.len() as i32,
self.return_ptr_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(res, Ok(types::Errno::Ok as i32), "reduce excuses errno");
assert_eq!(res, types::Errno::Ok as i32, "reduce excuses errno");
let expected = *self
.excuse_values
@@ -181,8 +182,9 @@ impl PopulateExcusesExcercise {
&host_memory,
self.array_ptr_loc.ptr as i32,
self.elements.len() as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "populate excuses errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "populate excuses errno");
let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> =
host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32));
@@ -307,8 +309,9 @@ impl SumElementsExercise {
self.elements.len() as i32,
self.start_ix as i32,
self.return_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "sum_of_element errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "sum_of_element errno");
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
let result = result_ptr.read().expect("read result");
@@ -326,10 +329,11 @@ impl SumElementsExercise {
self.elements.len() as i32,
self.elements.len() as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(
res,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"out of bounds sum_of_element errno"
);
@@ -341,11 +345,12 @@ impl SumElementsExercise {
self.start_ix as i32,
self.end_ix as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
if self.start_ix <= self.end_ix {
assert_eq!(
res,
Ok(types::Errno::Ok as i32),
types::Errno::Ok as i32,
"expected ok sum_of_elements errno"
);
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
@@ -366,7 +371,7 @@ impl SumElementsExercise {
} else {
assert_eq!(
res,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"expected error out-of-bounds sum_of_elements"
);
}
@@ -380,10 +385,11 @@ impl SumElementsExercise {
self.start_ix as i32,
self.elements.len() as i32 + 1,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(
res,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"out of bounds sum_of_elements errno"
);
}

View File

@@ -155,8 +155,9 @@ impl PointersAndEnumsExercise {
self.input2_loc.ptr as i32,
self.input3_loc.ptr as i32,
self.input4_ptr_loc.ptr as i32,
);
assert_eq!(e, Ok(types::Errno::Ok as i32), "errno");
)
.unwrap();
assert_eq!(e, types::Errno::Ok as i32, "errno");
// Implementation of pointers_and_enums writes input3 to the input2_loc:
let written_to_input2_loc: i32 = host_memory

View File

@@ -118,9 +118,10 @@ impl SumOfPairExercise {
&host_memory,
self.input_loc.ptr as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(sum_err, Ok(types::Errno::Ok as i32), "sum errno");
assert_eq!(sum_err, types::Errno::Ok as i32, "sum errno");
let return_val: i64 = host_memory
.ptr(self.return_loc.ptr)
@@ -216,13 +217,10 @@ impl SumPairPtrsExercise {
&host_memory,
self.input_struct_loc.ptr as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(
res,
Ok(types::Errno::Ok as i32),
"sum of pair of ptrs errno"
);
assert_eq!(res, types::Errno::Ok as i32, "sum of pair of ptrs errno");
let doubled: i64 = host_memory
.ptr(self.return_loc.ptr)
@@ -299,9 +297,10 @@ impl SumIntAndPtrExercise {
&host_memory,
self.input_struct_loc.ptr as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(res, Ok(types::Errno::Ok as i32), "sum of int and ptr errno");
assert_eq!(res, types::Errno::Ok as i32, "sum of int and ptr errno");
let doubled: i64 = host_memory
.ptr(self.return_loc.ptr)
@@ -338,9 +337,10 @@ impl ReturnPairInts {
let mut ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let err = records::return_pair_ints(&mut ctx, &host_memory, self.return_loc.ptr as i32);
let err =
records::return_pair_ints(&mut ctx, &host_memory, self.return_loc.ptr as i32).unwrap();
assert_eq!(err, Ok(types::Errno::Ok as i32), "return struct errno");
assert_eq!(err, types::Errno::Ok as i32, "return struct errno");
let return_struct: types::PairInts = host_memory
.ptr(self.return_loc.ptr)
@@ -418,13 +418,10 @@ impl ReturnPairPtrsExercise {
self.input_first_loc.ptr as i32,
self.input_second_loc.ptr as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(
res,
Ok(types::Errno::Ok as i32),
"return pair of ptrs errno"
);
assert_eq!(res, types::Errno::Ok as i32, "return pair of ptrs errno");
let ptr_pair_int_ptrs: types::PairIntPtrs<'_> = host_memory
.ptr(self.return_loc.ptr)
@@ -529,10 +526,11 @@ impl SumArrayExercise {
&host_memory,
self.input_struct_loc.ptr as i32,
self.output_loc.ptr as i32,
);
)
.unwrap();
// should be no error - if hostcall did a GuestError it should eprintln it.
assert_eq!(res, Ok(types::Errno::Ok as i32), "reduce excuses errno");
assert_eq!(res, types::Errno::Ok as i32, "reduce excuses errno");
// Sum is inputs upcasted to u16
let expected: u16 = self.inputs.iter().map(|v| *v as u16).sum();

View File

@@ -86,8 +86,9 @@ impl HelloStringExercise {
self.string_ptr_loc.ptr as i32,
self.test_word.len() as i32,
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "hello string errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "hello string errno");
let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr)
@@ -207,8 +208,9 @@ impl MultiStringExercise {
self.sc_ptr_loc.ptr as i32,
self.c.len() as i32,
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "multi string errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "multi string errno");
let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr)
@@ -285,8 +287,9 @@ impl OverlappingStringExercise {
(self.sa_ptr_loc.ptr + self.offset_c) as i32,
a_len - self.offset_c as i32,
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, Ok(types::Errno::Ok as i32), "multi string errno");
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "multi string errno");
let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr)

View File

@@ -134,9 +134,10 @@ impl GetTagExercise {
&host_memory,
self.input_loc.ptr as i32,
self.return_loc.ptr as i32,
);
)
.unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "get_tag errno");
assert_eq!(e, types::Errno::Ok as i32, "get_tag errno");
let return_val: types::Excuse = host_memory
.ptr(self.return_loc.ptr)
@@ -218,9 +219,10 @@ impl ReasonMultExercise {
&host_memory,
self.input_loc.ptr as i32,
self.multiply_by as i32,
);
)
.unwrap();
assert_eq!(e, Ok(types::Errno::Ok as i32), "reason_mult errno");
assert_eq!(e, types::Errno::Ok as i32, "reason_mult errno");
match self.input {
types::Reason::DogAte(f) => {

View File

@@ -314,7 +314,7 @@ impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
unimplemented!("poll_oneoff")
}
fn proc_exit(&mut self, _rval: types::Exitcode) -> wiggle::Trap {
fn proc_exit(&mut self, _rval: types::Exitcode) -> wiggle::wasmtime_crate::Trap {
unimplemented!("proc_exit")
}