* 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.
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
//! Contains the macro-generated implementation of wasi-nn from the its witx definition file.
|
|
use crate::ctx::WasiNnCtx;
|
|
use crate::ctx::WasiNnError;
|
|
|
|
// Generate the traits and types of wasi-nn in several Rust modules (e.g. `types`).
|
|
wiggle::from_witx!({
|
|
witx: ["$WASI_ROOT/phases/ephemeral/witx/wasi_ephemeral_nn.witx"],
|
|
ctx: WasiNnCtx,
|
|
errors: { errno => WasiNnError }
|
|
});
|
|
|
|
use types::Errno;
|
|
|
|
/// Wiggle generates code that performs some input validation on the arguments passed in by users of
|
|
/// wasi-nn. Here we convert the validation error into one (or more, eventually) of the error
|
|
/// variants defined in the witx.
|
|
impl types::GuestErrorConversion for WasiNnCtx {
|
|
fn into_errno(&self, e: wiggle::GuestError) -> Errno {
|
|
eprintln!("Guest error: {:?}", e);
|
|
Errno::InvalidArgument
|
|
}
|
|
}
|
|
|
|
impl<'a> types::UserErrorConversion for WasiNnCtx {
|
|
fn errno_from_wasi_nn_error(&self, e: WasiNnError) -> Result<Errno, String> {
|
|
eprintln!("Host error: {:?}", e);
|
|
match e {
|
|
WasiNnError::OpenvinoError(_) => unimplemented!(),
|
|
WasiNnError::GuestError(_) => unimplemented!(),
|
|
WasiNnError::UsageError(_) => unimplemented!(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Additionally, we must let Wiggle know which of our error codes represents a successful operation.
|
|
impl wiggle::GuestErrorType for Errno {
|
|
fn success() -> Self {
|
|
Self::Success
|
|
}
|
|
}
|