Fixes #2418: Enhance wiggle to generate its UserErrorConverstion trait with a function that returns Result<abi_err, String> (#2419)

* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance wiggle to generate its UserErrorConverstion trait with a function that returns
a Result<abi_err, String>.  This enhancement allows hostcall implementations using wiggle
to return an actionable error to the instance (the abi_err) or to terminate the instance
using the String as fatal error information.

* Enhance the wiggle/wasmtime integration to leverage new work in ab7e9c6.  Hostcall
implementations generated by wiggle now return an Result<abi_error, Trap>.  As a
result, hostcalls experiencing fatal errors may trap, thereby terminating the
wasmtime instance.  This enhancement has been performed for both wasi snapshot1
and wasi snapshot0.

* Update wasi-nn crate to reflect enhancement in issue #2418.

* Update wiggle test-helpers for wiggle enhancement made in issue #2418.

* Address PR feedback; omit verbose return statement.

* Address PR feedback; manually format within a proc macro.

* Address PR feedback; manually format proc macro.

* Restore return statements to wasi.rs.

* Restore return statements in funcs.rs.

* Address PR feedback; omit TODO and fix formatting.

* Ok-wrap error type in assert statement.
This commit is contained in:
Tanya L. Crenshaw
2020-11-24 12:06:57 -08:00
committed by GitHub
parent 128c3bd749
commit b06ed39c1e
18 changed files with 84 additions and 84 deletions

View File

@@ -105,7 +105,7 @@ impl ReduceExcusesExcercise {
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, types::Errno::Ok.into(), "reduce excuses errno");
assert_eq!(res, Ok(types::Errno::Ok.into()), "reduce excuses errno");
let expected = *self
.excuse_values
@@ -183,7 +183,7 @@ impl PopulateExcusesExcercise {
self.array_ptr_loc.ptr as i32,
self.elements.len() as i32,
);
assert_eq!(res, types::Errno::Ok.into(), "populate excuses errno");
assert_eq!(res, Ok(types::Errno::Ok.into()), "populate excuses errno");
let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> =
host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32));
@@ -309,7 +309,7 @@ impl SumElementsExercise {
self.start_ix as i32,
self.return_loc.ptr as i32,
);
assert_eq!(res, types::Errno::Ok.into(), "sum_of_element errno");
assert_eq!(res, Ok(types::Errno::Ok.into()), "sum_of_element errno");
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
let result = result_ptr.read().expect("read result");
@@ -330,7 +330,7 @@ impl SumElementsExercise {
);
assert_eq!(
res,
types::Errno::InvalidArg.into(),
Ok(types::Errno::InvalidArg.into()),
"out of bounds sum_of_element errno"
);
@@ -346,7 +346,7 @@ impl SumElementsExercise {
if self.start_ix <= self.end_ix {
assert_eq!(
res,
types::Errno::Ok.into(),
Ok(types::Errno::Ok.into()),
"expected ok sum_of_elements errno"
);
let result_ptr = host_memory.ptr::<i32>(self.return_loc.ptr);
@@ -367,7 +367,7 @@ impl SumElementsExercise {
} else {
assert_eq!(
res,
types::Errno::InvalidArg.into(),
Ok(types::Errno::InvalidArg.into()),
"expected error out-of-bounds sum_of_elements"
);
}
@@ -384,7 +384,7 @@ impl SumElementsExercise {
);
assert_eq!(
res,
types::Errno::InvalidArg.into(),
Ok(types::Errno::InvalidArg.into()),
"out of bounds sum_of_elements errno"
);
}