diff --git a/Cargo.lock b/Cargo.lock index 3d651c0be..6239f550d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -458,7 +458,7 @@ dependencies = [ "log", "smallvec", "thiserror", - "wasmparser 0.73.1", + "wasmparser 0.75.0", ] [[package]] @@ -2678,15 +2678,15 @@ checksum = "a950e6a618f62147fd514ff445b2a0b53120d382751960797f85f058c7eda9b9" [[package]] name = "wasmparser" -version = "0.73.1" +version = "0.75.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8526ab131cbc49495a483c98954913ae7b83551adacab5e294cf77992e70ee7" +checksum = "4580b6be7329cfc3277131fc8363044990effb57b3ce93ef304ca70ad4339c64" [[package]] name = "wast" -version = "22.0.0" +version = "33.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe1220ed7f824992b426a76125a3403d048eaf0f627918e97ade0d9b9d510d20" +checksum = "1d04fe175c7f78214971293e7d8875673804e736092206a3a4544dbc12811c1b" dependencies = [ "leb128", ] @@ -2795,7 +2795,7 @@ dependencies = [ [[package]] name = "witx" -version = "0.8.8" +version = "0.9.0" dependencies = [ "anyhow", "log", diff --git a/lucet-wiggle/generate/Cargo.toml b/lucet-wiggle/generate/Cargo.toml index ec768fbf4..fa67c0532 100644 --- a/lucet-wiggle/generate/Cargo.toml +++ b/lucet-wiggle/generate/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" [dependencies] wiggle-generate = { path = "../../wasmtime/crates/wiggle/generate", version = "0.23.0" } lucet-module = { path = "../../lucet-module", version = "0.7.0-dev" } -witx = { path = "../../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.8.4" } +witx = { path = "../../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.9" } quote = "1.0" proc-macro2 = "1.0" heck = "*" diff --git a/lucet-wiggle/generate/src/lib.rs b/lucet-wiggle/generate/src/lib.rs index 0ba655b78..d518d946c 100644 --- a/lucet-wiggle/generate/src/lib.rs +++ b/lucet-wiggle/generate/src/lib.rs @@ -3,7 +3,7 @@ pub use config::Config; use heck::SnakeCase; use lucet_module::bindings::Bindings; -use proc_macro2::{Ident, TokenStream}; +use proc_macro2::{Ident, Span, TokenStream}; use quote::{format_ident, quote}; pub fn hostcall_name(m: &witx::Module, f: &witx::InterfaceFunc) -> String { @@ -40,34 +40,34 @@ pub fn generate( let fs = doc.modules().map(|m| { let fs = m.funcs().map(|f| { let name = format_ident!("{}", hostcall_name(&m, &f)); - let coretype = f.core_type(); - let func_args = coretype.args.iter().map(|a| { - let name = names.func_core_arg(a); - let atom = names.atom_type(a.repr()); + let (params, results) = f.wasm_signature(); + let arg_names = (0..params.len()) + .map(|i| Ident::new(&format!("arg{}", i), Span::call_site())) + .collect::>(); + let func_args = params.iter().enumerate().map(|(i, ty)| { + let name = &arg_names[i]; + let atom = names.wasm_type(*ty); quote!(#name: #atom) }); - let call_args = coretype.args.iter().map(|a| { - let name = names.func_core_arg(a); - quote!(#name) - }); - let rets = coretype - .ret - .as_ref() - .map(|r| { - let atom = names.atom_type(r.repr()); - quote!(#atom) - }) - .unwrap_or(quote!(())); + let ret_ty = match results.len() { + 0 => quote!(()), + 1 => names.wasm_type(results[0]), + _ => panic!( + "lucet-wiggle only supports 0 or 1 result type. function {} has: {:?}", + hostcall_name(&m, &f), + results + ), + }; let mod_name = names.module(&m.name); let method_name = names.func(&f.name); quote! { #[lucet_hostcall] #[no_mangle] - pub fn #name(vmctx: &lucet_runtime::vmctx::Vmctx, #(#func_args),*) -> #rets { + pub fn #name(vmctx: &lucet_runtime::vmctx::Vmctx, #(#func_args),*) -> #ret_ty { { #pre_hook } let memory = lucet_wiggle::runtime::LucetMemory::new(vmctx); let mut ctx: #ctx_type = #ctx_constructor; - let r = super::#mod_name::#method_name(&ctx, &memory, #(#call_args),*); + let r = super::#mod_name::#method_name(&ctx, &memory, #(#arg_names),*); { #post_hook } match r { Ok(r) => { r }, diff --git a/lucet-wiggle/macro/Cargo.toml b/lucet-wiggle/macro/Cargo.toml index 10a6c2292..71bcd70de 100644 --- a/lucet-wiggle/macro/Cargo.toml +++ b/lucet-wiggle/macro/Cargo.toml @@ -14,6 +14,6 @@ proc-macro = true [dependencies] lucet-wiggle-generate = { path = "../generate", version = "0.7.0-dev" } wiggle-generate = { path = "../../wasmtime/crates/wiggle/generate", version = "0.23.0" } -witx = { path = "../../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.8.8" } +witx = { path = "../../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.9" } syn = { version = "1.0", features = ["full"] } quote = "1.0" diff --git a/lucetc/Cargo.toml b/lucetc/Cargo.toml index 6522f6610..84b5f6ae1 100644 --- a/lucetc/Cargo.toml +++ b/lucetc/Cargo.toml @@ -26,7 +26,7 @@ cranelift-wasm = { path = "../wasmtime/cranelift/wasm", version = "0.70.0" } target-lexicon = "0.11" lucet-module = { path = "../lucet-module", version = "=0.7.0-dev" } lucet-wiggle-generate = { path = "../lucet-wiggle/generate", version = "=0.7.0-dev" } -witx = { path = "../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.8.5" } +witx = { path = "../wasmtime/crates/wasi-common/WASI/tools/witx", version = "0.9" } wasmparser = "0.59.0" clap="2.32" diff --git a/lucetc/src/validate.rs b/lucetc/src/validate.rs index 52cd2dd9f..ba0c3bc2d 100644 --- a/lucetc/src/validate.rs +++ b/lucetc/src/validate.rs @@ -4,7 +4,7 @@ use thiserror::Error; use witx::Id; pub use cranelift_wasm::{WasmFuncType, WasmType}; -pub use witx::{AtomType, Document, WitxError}; +pub use witx::{Document, WitxError}; #[derive(Debug, Error, Clone, PartialEq, Eq)] pub enum Error { @@ -187,7 +187,7 @@ impl Validator { .ok_or(not_found.clone())? .func(&Id::new(field)) .ok_or(not_found)?; - let spec_type = witx_to_functype(&func.core_type()); + let spec_type = witx_to_functype(&func); if &spec_type != type_ { Err(Error::ImportTypeError { module: module.to_owned(), @@ -235,25 +235,25 @@ impl Validator { } } -fn witx_to_functype(coretype: &witx::CoreFuncType) -> WasmFuncType { - fn atom_to_type(atom: &witx::AtomType) -> WasmType { +fn witx_to_functype(func: &witx::InterfaceFunc) -> WasmFuncType { + fn atom_to_type(atom: &witx::WasmType) -> WasmType { match atom { - witx::AtomType::I32 => WasmType::I32, - witx::AtomType::I64 => WasmType::I64, - witx::AtomType::F32 => WasmType::F32, - witx::AtomType::F64 => WasmType::F64, + witx::WasmType::I32 => WasmType::I32, + witx::WasmType::I64 => WasmType::I64, + witx::WasmType::F32 => WasmType::F32, + witx::WasmType::F64 => WasmType::F64, } } - let params = coretype - .args + let (params, results) = func.wasm_signature(); + let params = params .iter() - .map(|a| atom_to_type(&a.repr())) + .map(|a| atom_to_type(&a)) .collect::>() .into_boxed_slice(); - let returns = if let Some(ref r) = coretype.ret { - vec![atom_to_type(&r.repr())].into_boxed_slice() - } else { - vec![].into_boxed_slice() + let returns = match results.len() { + 0 => vec![].into_boxed_slice(), + 1 => vec![atom_to_type(&results[0])].into_boxed_slice(), + _ => unimplemented!("multiple result types"), }; WasmFuncType { params, returns } } diff --git a/lucetc/tests/wasm.rs b/lucetc/tests/wasm.rs index d9806719d..b60fc64d1 100644 --- a/lucetc/tests/wasm.rs +++ b/lucetc/tests/wasm.rs @@ -640,7 +640,7 @@ mod validate { let b = stub_wasi_bindings(); let witx = " -(typename $errno (enum u8 $inval)) +(typename $errno (enum (@witx tag u8) $inval)) (module $wasi_snapshot_preview1 (import \"memory\" (memory)) ;;; Read command-line argument data. @@ -648,7 +648,7 @@ mod validate { (@interface func (export \"args_get\") (param $argv (@witx pointer (@witx pointer u8))) (param $argv_buf (@witx pointer u8)) - (result $error $errno) + (result $error (expected (error $errno))) ) )"; let v = Validator::builder() diff --git a/wasmtime b/wasmtime index aed6de32d..0cc4a3d44 160000 --- a/wasmtime +++ b/wasmtime @@ -1 +1 @@ -Subproject commit aed6de32d4e5603a7f85619d84099a9a05cb7a7c +Subproject commit 0cc4a3d445473e3b82ae23ed13994a90b6efbea9