Implement RFC 11: Redesigning Wasmtime's APIs (#2897)

Implement Wasmtime's new API as designed by RFC 11. This is quite a large commit which has had lots of discussion externally, so for more information it's best to read the RFC thread and the PR thread.
This commit is contained in:
Alex Crichton
2021-06-03 09:10:53 -05:00
committed by GitHub
parent a5a28b1c5b
commit 7a1b7cdf92
233 changed files with 13349 additions and 11997 deletions

View File

@@ -32,7 +32,7 @@ impl_errno!(types::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(&self, e: RichError) -> Result<types::Errno, wiggle::Trap> {
fn errno_from_rich_error(&mut self, e: RichError) -> Result<types::Errno, wiggle::Trap> {
wiggle::tracing::debug!(
rich_error = wiggle::tracing::field::debug(&e),
"error conversion"
@@ -49,7 +49,7 @@ impl<'a> types::UserErrorConversion for WasiCtx<'a> {
}
impl<'a> one_error_conversion::OneErrorConversion for WasiCtx<'a> {
fn foo(&self, strike: u32, _s: &types::S) -> Result<types::T, RichError> {
fn foo(&mut self, strike: u32, _s: &types::S) -> Result<types::T, RichError> {
// We use the argument to this function to exercise all of the
// possible error cases we could hit here
match strike {
@@ -78,12 +78,12 @@ fn main() {
env_logger::init();
}
let ctx = WasiCtx::new();
let mut ctx = WasiCtx::new();
let host_memory = HostMemory::new();
// Exercise each of the branches in `foo`.
// Start with the success case:
let r0 = one_error_conversion::foo(&ctx, &host_memory, 0, 0, 8);
let r0 = one_error_conversion::foo(&mut ctx, &host_memory, 0, 0, 8);
assert_eq!(
r0,
Ok(types::Errno::Ok as i32),
@@ -92,7 +92,7 @@ fn main() {
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
// First error case:
let r1 = one_error_conversion::foo(&ctx, &host_memory, 1, 0, 8);
let r1 = one_error_conversion::foo(&mut ctx, &host_memory, 1, 0, 8);
assert_eq!(
r1,
Ok(types::Errno::PicketLine as i32),
@@ -105,7 +105,7 @@ fn main() {
);
// Second error case:
let r2 = one_error_conversion::foo(&ctx, &host_memory, 2, 0, 8);
let r2 = one_error_conversion::foo(&mut ctx, &host_memory, 2, 0, 8);
assert_eq!(
r2,
Ok(types::Errno::InvalidArg as i32),