Upgrade wasm-tools crates, namely the component model (#4715)
* Upgrade wasm-tools crates, namely the component model This commit pulls in the latest versions of all of the `wasm-tools` family of crates. There were two major changes that happened in `wasm-tools` in the meantime: * bytecodealliance/wasm-tools#697 - this commit introduced a new API for more efficiently reading binary operators from a wasm binary. The old `Operator`-based reading was left in place, however, and continues to be what Wasmtime uses. I hope to update Wasmtime in a future PR to use this new API, but for now the biggest change is... * bytecodealliance/wasm-tools#703 - this commit was a major update to the component model AST. This commit almost entirely deals with the fallout of this change. The changes made to the component model were: 1. The `unit` type no longer exists. This was generally a simple change where the `Unit` case in a few different locations were all removed. 2. The `expected` type was renamed to `result`. This similarly was relatively lightweight and mostly just a renaming on the surface. I took this opportunity to rename `val::Result` to `val::ResultVal` and `types::Result` to `types::ResultType` to avoid clashing with the standard library types. The `Option`-based types were handled with this as well. 3. The payload type of `variant` and `result` types are now optional. This affected many locations that calculate flat type representations, ABI information, etc. The `#[derive(ComponentType)]` macro now specifically handles Rust-defined `enum` types which have no payload to the equivalent in the component model. 4. Functions can now return multiple parameters. This changed the signature of invoking component functions because the return value is now bound by `ComponentNamedList` (renamed from `ComponentParams`). This had a large effect in the tests, fuzz test case generation, etc. 5. Function types with 2-or-more parameters/results must uniquely name all parameters/results. This mostly affected the text format used throughout the tests. I haven't added specifically new tests for multi-return but I changed a number of tests to use it. Additionally I've updated the fuzzers to all exercise multi-return as well so I think we should get some good coverage with that. * Update version numbers * Use crates.io
This commit is contained in:
@@ -66,10 +66,10 @@ fn typecheck() -> Result<()> {
|
||||
(func (export "take-string") (param string)
|
||||
(canon lift (core func $i "take-string") (memory $i "memory") (realloc (func $i "realloc")))
|
||||
)
|
||||
(func (export "take-two-args") (param s32) (param (list u8))
|
||||
(func (export "take-two-args") (param "a" s32) (param "b" (list u8))
|
||||
(canon lift (core func $i "two-args") (memory $i "memory") (realloc (func $i "realloc")))
|
||||
)
|
||||
(func (export "ret-tuple") (result (tuple u8 s8))
|
||||
(func (export "ret-tuple") (result "a" u8) (result "b" s8)
|
||||
(canon lift (core func $i "ret-one") (memory $i "memory") (realloc (func $i "realloc")))
|
||||
)
|
||||
(func (export "ret-tuple1") (result (tuple u32))
|
||||
@@ -96,29 +96,34 @@ fn typecheck() -> Result<()> {
|
||||
let ret_tuple1 = instance.get_func(&mut store, "ret-tuple1").unwrap();
|
||||
let ret_string = instance.get_func(&mut store, "ret-string").unwrap();
|
||||
let ret_list_u8 = instance.get_func(&mut store, "ret-list-u8").unwrap();
|
||||
assert!(thunk.typed::<(), u32, _>(&store).is_err());
|
||||
assert!(thunk.typed::<(), (u32,), _>(&store).is_err());
|
||||
assert!(thunk.typed::<(u32,), (), _>(&store).is_err());
|
||||
assert!(thunk.typed::<(), (), _>(&store).is_ok());
|
||||
assert!(tuple_thunk.typed::<(), (), _>(&store).is_err());
|
||||
assert!(tuple_thunk.typed::<((),), (), _>(&store).is_ok());
|
||||
assert!(tuple_thunk.typed::<((),), (), _>(&store).is_err());
|
||||
assert!(tuple_thunk.typed::<((),), ((),), _>(&store).is_ok());
|
||||
assert!(take_string.typed::<(), (), _>(&store).is_err());
|
||||
assert!(take_string.typed::<(String,), (), _>(&store).is_ok());
|
||||
assert!(take_string.typed::<(&str,), (), _>(&store).is_ok());
|
||||
assert!(take_string.typed::<(&[u8],), (), _>(&store).is_err());
|
||||
assert!(take_two_args.typed::<(), (), _>(&store).is_err());
|
||||
assert!(take_two_args.typed::<(i32, &[u8]), u32, _>(&store).is_err());
|
||||
assert!(take_two_args
|
||||
.typed::<(i32, &[u8]), (u32,), _>(&store)
|
||||
.is_err());
|
||||
assert!(take_two_args.typed::<(u32, &[u8]), (), _>(&store).is_err());
|
||||
assert!(take_two_args.typed::<(i32, &[u8]), (), _>(&store).is_ok());
|
||||
assert!(ret_tuple.typed::<(), (), _>(&store).is_err());
|
||||
assert!(ret_tuple.typed::<(), (u8,), _>(&store).is_err());
|
||||
assert!(ret_tuple.typed::<(), (u8, i8), _>(&store).is_ok());
|
||||
assert!(ret_tuple1.typed::<(), (u32,), _>(&store).is_ok());
|
||||
assert!(ret_tuple1.typed::<(), u32, _>(&store).is_err());
|
||||
assert!(ret_tuple1.typed::<(), ((u32,),), _>(&store).is_ok());
|
||||
assert!(ret_tuple1.typed::<(), (u32,), _>(&store).is_err());
|
||||
assert!(ret_string.typed::<(), (), _>(&store).is_err());
|
||||
assert!(ret_string.typed::<(), WasmStr, _>(&store).is_ok());
|
||||
assert!(ret_list_u8.typed::<(), WasmList<u16>, _>(&store).is_err());
|
||||
assert!(ret_list_u8.typed::<(), WasmList<i8>, _>(&store).is_err());
|
||||
assert!(ret_list_u8.typed::<(), WasmList<u8>, _>(&store).is_ok());
|
||||
assert!(ret_string.typed::<(), (WasmStr,), _>(&store).is_ok());
|
||||
assert!(ret_list_u8
|
||||
.typed::<(), (WasmList<u16>,), _>(&store)
|
||||
.is_err());
|
||||
assert!(ret_list_u8.typed::<(), (WasmList<i8>,), _>(&store).is_err());
|
||||
assert!(ret_list_u8.typed::<(), (WasmList<u8>,), _>(&store).is_ok());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -262,140 +267,140 @@ fn integers() -> Result<()> {
|
||||
// Zero can be returned as any integer
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u8, _>(&mut store, "ret-u8")?
|
||||
.get_typed_func::<(), (u8,), _>(&mut store, "ret-u8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i8, _>(&mut store, "ret-s8")?
|
||||
.get_typed_func::<(), (i8,), _>(&mut store, "ret-s8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u16, _>(&mut store, "ret-u16")?
|
||||
.get_typed_func::<(), (u16,), _>(&mut store, "ret-u16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i16, _>(&mut store, "ret-s16")?
|
||||
.get_typed_func::<(), (i16,), _>(&mut store, "ret-s16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u32, _>(&mut store, "ret-u32")?
|
||||
.get_typed_func::<(), (u32,), _>(&mut store, "ret-u32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i32, _>(&mut store, "ret-s32")?
|
||||
.get_typed_func::<(), (i32,), _>(&mut store, "ret-s32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u64, _>(&mut store, "ret-u64")?
|
||||
.get_typed_func::<(), (u64,), _>(&mut store, "ret-u64")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i64, _>(&mut store, "ret-s64")?
|
||||
.get_typed_func::<(), (i64,), _>(&mut store, "ret-s64")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0
|
||||
(0,)
|
||||
);
|
||||
|
||||
// Returning -1 should reinterpret the bytes as defined by each type.
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u8, _>(&mut store, "retm1-u8")?
|
||||
.get_typed_func::<(), (u8,), _>(&mut store, "retm1-u8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0xff
|
||||
(0xff,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i8, _>(&mut store, "retm1-s8")?
|
||||
.get_typed_func::<(), (i8,), _>(&mut store, "retm1-s8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
-1
|
||||
(-1,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u16, _>(&mut store, "retm1-u16")?
|
||||
.get_typed_func::<(), (u16,), _>(&mut store, "retm1-u16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0xffff
|
||||
(0xffff,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i16, _>(&mut store, "retm1-s16")?
|
||||
.get_typed_func::<(), (i16,), _>(&mut store, "retm1-s16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
-1
|
||||
(-1,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u32, _>(&mut store, "retm1-u32")?
|
||||
.get_typed_func::<(), (u32,), _>(&mut store, "retm1-u32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0xffffffff
|
||||
(0xffffffff,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i32, _>(&mut store, "retm1-s32")?
|
||||
.get_typed_func::<(), (i32,), _>(&mut store, "retm1-s32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
-1
|
||||
(-1,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u64, _>(&mut store, "retm1-u64")?
|
||||
.get_typed_func::<(), (u64,), _>(&mut store, "retm1-u64")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
0xffffffff_ffffffff
|
||||
(0xffffffff_ffffffff,)
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i64, _>(&mut store, "retm1-s64")?
|
||||
.get_typed_func::<(), (i64,), _>(&mut store, "retm1-s64")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
-1
|
||||
(-1,)
|
||||
);
|
||||
|
||||
// Returning 100000 should chop off bytes as necessary
|
||||
let ret: u32 = 100000;
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u8, _>(&mut store, "retbig-u8")?
|
||||
.get_typed_func::<(), (u8,), _>(&mut store, "retbig-u8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret as u8,
|
||||
(ret as u8,),
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i8, _>(&mut store, "retbig-s8")?
|
||||
.get_typed_func::<(), (i8,), _>(&mut store, "retbig-s8")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret as i8,
|
||||
(ret as i8,),
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u16, _>(&mut store, "retbig-u16")?
|
||||
.get_typed_func::<(), (u16,), _>(&mut store, "retbig-u16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret as u16,
|
||||
(ret as u16,),
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i16, _>(&mut store, "retbig-s16")?
|
||||
.get_typed_func::<(), (i16,), _>(&mut store, "retbig-s16")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret as i16,
|
||||
(ret as i16,),
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), u32, _>(&mut store, "retbig-u32")?
|
||||
.get_typed_func::<(), (u32,), _>(&mut store, "retbig-u32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret,
|
||||
(ret,),
|
||||
);
|
||||
assert_eq!(
|
||||
instance
|
||||
.get_typed_func::<(), i32, _>(&mut store, "retbig-s32")?
|
||||
.get_typed_func::<(), (i32,), _>(&mut store, "retbig-s32")?
|
||||
.call_and_post_return(&mut store, ())?,
|
||||
ret as i32,
|
||||
(ret as i32,),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@@ -486,23 +491,24 @@ fn floats() -> Result<()> {
|
||||
let component = Component::new(&engine, component)?;
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
|
||||
let f32_to_u32 = instance.get_typed_func::<(f32,), u32, _>(&mut store, "f32-to-u32")?;
|
||||
let f64_to_u64 = instance.get_typed_func::<(f64,), u64, _>(&mut store, "f64-to-u64")?;
|
||||
let u32_to_f32 = instance.get_typed_func::<(u32,), f32, _>(&mut store, "u32-to-f32")?;
|
||||
let u64_to_f64 = instance.get_typed_func::<(u64,), f64, _>(&mut store, "u64-to-f64")?;
|
||||
let f32_to_u32 = instance.get_typed_func::<(f32,), (u32,), _>(&mut store, "f32-to-u32")?;
|
||||
let f64_to_u64 = instance.get_typed_func::<(f64,), (u64,), _>(&mut store, "f64-to-u64")?;
|
||||
let u32_to_f32 = instance.get_typed_func::<(u32,), (f32,), _>(&mut store, "u32-to-f32")?;
|
||||
let u64_to_f64 = instance.get_typed_func::<(u64,), (f64,), _>(&mut store, "u64-to-f64")?;
|
||||
|
||||
assert_eq!(f32_to_u32.call(&mut store, (1.0,))?, 1.0f32.to_bits());
|
||||
assert_eq!(f32_to_u32.call(&mut store, (1.0,))?, (1.0f32.to_bits(),));
|
||||
f32_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(f64_to_u64.call(&mut store, (2.0,))?, 2.0f64.to_bits());
|
||||
assert_eq!(f64_to_u64.call(&mut store, (2.0,))?, (2.0f64.to_bits(),));
|
||||
f64_to_u64.post_return(&mut store)?;
|
||||
assert_eq!(u32_to_f32.call(&mut store, (3.0f32.to_bits(),))?, 3.0);
|
||||
assert_eq!(u32_to_f32.call(&mut store, (3.0f32.to_bits(),))?, (3.0,));
|
||||
u32_to_f32.post_return(&mut store)?;
|
||||
assert_eq!(u64_to_f64.call(&mut store, (4.0f64.to_bits(),))?, 4.0);
|
||||
assert_eq!(u64_to_f64.call(&mut store, (4.0f64.to_bits(),))?, (4.0,));
|
||||
u64_to_f64.post_return(&mut store)?;
|
||||
|
||||
assert_eq!(
|
||||
u32_to_f32
|
||||
.call(&mut store, (CANON_32BIT_NAN | 1,))?
|
||||
.0
|
||||
.to_bits(),
|
||||
CANON_32BIT_NAN
|
||||
);
|
||||
@@ -510,19 +516,20 @@ fn floats() -> Result<()> {
|
||||
assert_eq!(
|
||||
u64_to_f64
|
||||
.call(&mut store, (CANON_64BIT_NAN | 1,))?
|
||||
.0
|
||||
.to_bits(),
|
||||
CANON_64BIT_NAN
|
||||
CANON_64BIT_NAN,
|
||||
);
|
||||
u64_to_f64.post_return(&mut store)?;
|
||||
|
||||
assert_eq!(
|
||||
f32_to_u32.call(&mut store, (f32::from_bits(CANON_32BIT_NAN | 1),))?,
|
||||
CANON_32BIT_NAN
|
||||
(CANON_32BIT_NAN,)
|
||||
);
|
||||
f32_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(
|
||||
f64_to_u64.call(&mut store, (f64::from_bits(CANON_64BIT_NAN | 1),))?,
|
||||
CANON_64BIT_NAN
|
||||
(CANON_64BIT_NAN,)
|
||||
);
|
||||
f64_to_u64.post_return(&mut store)?;
|
||||
|
||||
@@ -551,18 +558,18 @@ fn bools() -> Result<()> {
|
||||
let component = Component::new(&engine, component)?;
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
|
||||
let u32_to_bool = instance.get_typed_func::<(u32,), bool, _>(&mut store, "u32-to-bool")?;
|
||||
let bool_to_u32 = instance.get_typed_func::<(bool,), u32, _>(&mut store, "bool-to-u32")?;
|
||||
let u32_to_bool = instance.get_typed_func::<(u32,), (bool,), _>(&mut store, "u32-to-bool")?;
|
||||
let bool_to_u32 = instance.get_typed_func::<(bool,), (u32,), _>(&mut store, "bool-to-u32")?;
|
||||
|
||||
assert_eq!(bool_to_u32.call(&mut store, (false,))?, 0);
|
||||
assert_eq!(bool_to_u32.call(&mut store, (false,))?, (0,));
|
||||
bool_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(bool_to_u32.call(&mut store, (true,))?, 1);
|
||||
assert_eq!(bool_to_u32.call(&mut store, (true,))?, (1,));
|
||||
bool_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(u32_to_bool.call(&mut store, (0,))?, false);
|
||||
assert_eq!(u32_to_bool.call(&mut store, (0,))?, (false,));
|
||||
u32_to_bool.post_return(&mut store)?;
|
||||
assert_eq!(u32_to_bool.call(&mut store, (1,))?, true);
|
||||
assert_eq!(u32_to_bool.call(&mut store, (1,))?, (true,));
|
||||
u32_to_bool.post_return(&mut store)?;
|
||||
assert_eq!(u32_to_bool.call(&mut store, (2,))?, true);
|
||||
assert_eq!(u32_to_bool.call(&mut store, (2,))?, (true,));
|
||||
u32_to_bool.post_return(&mut store)?;
|
||||
|
||||
Ok(())
|
||||
@@ -590,13 +597,13 @@ fn chars() -> Result<()> {
|
||||
let component = Component::new(&engine, component)?;
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
|
||||
let u32_to_char = instance.get_typed_func::<(u32,), char, _>(&mut store, "u32-to-char")?;
|
||||
let char_to_u32 = instance.get_typed_func::<(char,), u32, _>(&mut store, "char-to-u32")?;
|
||||
let u32_to_char = instance.get_typed_func::<(u32,), (char,), _>(&mut store, "u32-to-char")?;
|
||||
let char_to_u32 = instance.get_typed_func::<(char,), (u32,), _>(&mut store, "char-to-u32")?;
|
||||
|
||||
let mut roundtrip = |x: char| -> Result<()> {
|
||||
assert_eq!(char_to_u32.call(&mut store, (x,))?, x as u32);
|
||||
assert_eq!(char_to_u32.call(&mut store, (x,))?, (x as u32,));
|
||||
char_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(u32_to_char.call(&mut store, (x as u32,))?, x);
|
||||
assert_eq!(u32_to_char.call(&mut store, (x as u32,))?, (x,));
|
||||
u32_to_char.post_return(&mut store)?;
|
||||
Ok(())
|
||||
};
|
||||
@@ -610,7 +617,7 @@ fn chars() -> Result<()> {
|
||||
let u32_to_char = |store: &mut Store<()>| {
|
||||
Linker::new(&engine)
|
||||
.instantiate(&mut *store, &component)?
|
||||
.get_typed_func::<(u32,), char, _>(&mut *store, "u32-to-char")
|
||||
.get_typed_func::<(u32,), (char,), _>(&mut *store, "u32-to-char")
|
||||
};
|
||||
let err = u32_to_char(&mut store)?
|
||||
.call(&mut store, (0xd800,))
|
||||
@@ -656,7 +663,7 @@ fn tuple_result() -> Result<()> {
|
||||
|
||||
(type $result (tuple s8 u16 float32 float64))
|
||||
(func (export "tuple")
|
||||
(param s8) (param u16) (param float32) (param float64) (result $result)
|
||||
(param "a" s8) (param "b" u16) (param "c" float32) (param "d" float64) (result $result)
|
||||
(canon lift (core func $i "foo") (memory $i "memory"))
|
||||
)
|
||||
(func (export "invalid") (result $result)
|
||||
@@ -672,12 +679,12 @@ fn tuple_result() -> Result<()> {
|
||||
|
||||
let input = (-1, 100, 3.0, 100.0);
|
||||
let output = instance
|
||||
.get_typed_func::<(i8, u16, f32, f64), (i8, u16, f32, f64), _>(&mut store, "tuple")?
|
||||
.get_typed_func::<(i8, u16, f32, f64), ((i8, u16, f32, f64),), _>(&mut store, "tuple")?
|
||||
.call_and_post_return(&mut store, input)?;
|
||||
assert_eq!(input, output);
|
||||
assert_eq!((input,), output);
|
||||
|
||||
let invalid_func =
|
||||
instance.get_typed_func::<(), (i8, u16, f32, f64), _>(&mut store, "invalid")?;
|
||||
instance.get_typed_func::<(), ((i8, u16, f32, f64),), _>(&mut store, "invalid")?;
|
||||
let err = invalid_func.call(&mut store, ()).err().unwrap();
|
||||
assert!(
|
||||
err.to_string().contains("pointer out of bounds of memory"),
|
||||
@@ -753,29 +760,29 @@ fn strings() -> Result<()> {
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
|
||||
let list8_to_str =
|
||||
instance.get_typed_func::<(&[u8],), WasmStr, _>(&mut store, "list8-to-str")?;
|
||||
instance.get_typed_func::<(&[u8],), (WasmStr,), _>(&mut store, "list8-to-str")?;
|
||||
let str_to_list8 =
|
||||
instance.get_typed_func::<(&str,), WasmList<u8>, _>(&mut store, "str-to-list8")?;
|
||||
instance.get_typed_func::<(&str,), (WasmList<u8>,), _>(&mut store, "str-to-list8")?;
|
||||
let list16_to_str =
|
||||
instance.get_typed_func::<(&[u16],), WasmStr, _>(&mut store, "list16-to-str")?;
|
||||
instance.get_typed_func::<(&[u16],), (WasmStr,), _>(&mut store, "list16-to-str")?;
|
||||
let str_to_list16 =
|
||||
instance.get_typed_func::<(&str,), WasmList<u16>, _>(&mut store, "str-to-list16")?;
|
||||
instance.get_typed_func::<(&str,), (WasmList<u16>,), _>(&mut store, "str-to-list16")?;
|
||||
|
||||
let mut roundtrip = |x: &str| -> Result<()> {
|
||||
let ret = list8_to_str.call(&mut store, (x.as_bytes(),))?;
|
||||
let ret = list8_to_str.call(&mut store, (x.as_bytes(),))?.0;
|
||||
assert_eq!(ret.to_str(&store)?, x);
|
||||
list8_to_str.post_return(&mut store)?;
|
||||
|
||||
let utf16 = x.encode_utf16().collect::<Vec<_>>();
|
||||
let ret = list16_to_str.call(&mut store, (&utf16[..],))?;
|
||||
let ret = list16_to_str.call(&mut store, (&utf16[..],))?.0;
|
||||
assert_eq!(ret.to_str(&store)?, x);
|
||||
list16_to_str.post_return(&mut store)?;
|
||||
|
||||
let ret = str_to_list8.call(&mut store, (x,))?;
|
||||
let ret = str_to_list8.call(&mut store, (x,))?.0;
|
||||
assert_eq!(ret.iter(&store).collect::<Result<Vec<_>>>()?, x.as_bytes());
|
||||
str_to_list8.post_return(&mut store)?;
|
||||
|
||||
let ret = str_to_list16.call(&mut store, (x,))?;
|
||||
let ret = str_to_list16.call(&mut store, (x,))?.0;
|
||||
assert_eq!(ret.iter(&store).collect::<Result<Vec<_>>>()?, utf16,);
|
||||
str_to_list16.post_return(&mut store)?;
|
||||
|
||||
@@ -788,27 +795,29 @@ fn strings() -> Result<()> {
|
||||
roundtrip("💝")?;
|
||||
roundtrip("Löwe 老虎 Léopard")?;
|
||||
|
||||
let ret = list8_to_str.call(&mut store, (b"\xff",))?;
|
||||
let ret = list8_to_str.call(&mut store, (b"\xff",))?.0;
|
||||
let err = ret.to_str(&store).unwrap_err();
|
||||
assert!(err.to_string().contains("invalid utf-8"), "{}", err);
|
||||
list8_to_str.post_return(&mut store)?;
|
||||
|
||||
let ret = list8_to_str.call(&mut store, (b"hello there \xff invalid",))?;
|
||||
let ret = list8_to_str
|
||||
.call(&mut store, (b"hello there \xff invalid",))?
|
||||
.0;
|
||||
let err = ret.to_str(&store).unwrap_err();
|
||||
assert!(err.to_string().contains("invalid utf-8"), "{}", err);
|
||||
list8_to_str.post_return(&mut store)?;
|
||||
|
||||
let ret = list16_to_str.call(&mut store, (&[0xd800],))?;
|
||||
let ret = list16_to_str.call(&mut store, (&[0xd800],))?.0;
|
||||
let err = ret.to_str(&store).unwrap_err();
|
||||
assert!(err.to_string().contains("unpaired surrogate"), "{}", err);
|
||||
list16_to_str.post_return(&mut store)?;
|
||||
|
||||
let ret = list16_to_str.call(&mut store, (&[0xdfff],))?;
|
||||
let ret = list16_to_str.call(&mut store, (&[0xdfff],))?.0;
|
||||
let err = ret.to_str(&store).unwrap_err();
|
||||
assert!(err.to_string().contains("unpaired surrogate"), "{}", err);
|
||||
list16_to_str.post_return(&mut store)?;
|
||||
|
||||
let ret = list16_to_str.call(&mut store, (&[0xd800, 0xff00],))?;
|
||||
let ret = list16_to_str.call(&mut store, (&[0xd800, 0xff00],))?.0;
|
||||
let err = ret.to_str(&store).unwrap_err();
|
||||
assert!(err.to_string().contains("unpaired surrogate"), "{}", err);
|
||||
list16_to_str.post_return(&mut store)?;
|
||||
@@ -856,24 +865,24 @@ fn many_parameters() -> Result<()> {
|
||||
)
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(type $result (tuple (list u8) u32))
|
||||
(type $t (func
|
||||
(param s8) ;; offset 0, size 1
|
||||
(param u64) ;; offset 8, size 8
|
||||
(param float32) ;; offset 16, size 4
|
||||
(param u8) ;; offset 20, size 1
|
||||
(param unit) ;; offset 21, size 0
|
||||
(param s16) ;; offset 22, size 2
|
||||
(param string) ;; offset 24, size 8
|
||||
(param (list u32)) ;; offset 32, size 8
|
||||
(param bool) ;; offset 40, size 1
|
||||
(param bool) ;; offset 41, size 1
|
||||
(param char) ;; offset 44, size 4
|
||||
(param (list bool)) ;; offset 48, size 8
|
||||
(param (list char)) ;; offset 56, size 8
|
||||
(param (list string)) ;; offset 64, size 8
|
||||
(param "p1" s8) ;; offset 0, size 1
|
||||
(param "p2" u64) ;; offset 8, size 8
|
||||
(param "p3" float32) ;; offset 16, size 4
|
||||
(param "p4" u8) ;; offset 20, size 1
|
||||
(param "p5" (tuple)) ;; offset 21, size 0
|
||||
(param "p6" s16) ;; offset 22, size 2
|
||||
(param "p7" string) ;; offset 24, size 8
|
||||
(param "p8" (list u32)) ;; offset 32, size 8
|
||||
(param "p9" bool) ;; offset 40, size 1
|
||||
(param "pa" bool) ;; offset 41, size 1
|
||||
(param "pb" char) ;; offset 44, size 4
|
||||
(param "pc" (list bool)) ;; offset 48, size 8
|
||||
(param "pd" (list char)) ;; offset 56, size 8
|
||||
(param "pe" (list string)) ;; offset 64, size 8
|
||||
|
||||
(result $result)
|
||||
(result "all-memory" (list u8))
|
||||
(result "pointer" u32)
|
||||
))
|
||||
(func (export "many-param") (type $t)
|
||||
(canon lift
|
||||
@@ -1000,16 +1009,16 @@ fn some_traps() -> Result<()> {
|
||||
)
|
||||
|
||||
(type $t (func
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param string)
|
||||
(param "s1" string)
|
||||
(param "s2" string)
|
||||
(param "s3" string)
|
||||
(param "s4" string)
|
||||
(param "s5" string)
|
||||
(param "s6" string)
|
||||
(param "s7" string)
|
||||
(param "s8" string)
|
||||
(param "s9" string)
|
||||
(param "s10" string)
|
||||
))
|
||||
(func (export "take-many-unreachable") (type $t)
|
||||
(canon lift (core func $i "take-many") (memory $i "memory") (realloc (func $i "realloc")))
|
||||
@@ -1246,7 +1255,7 @@ fn char_bool_memory() -> Result<()> {
|
||||
)
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(func (export "ret-tuple") (param u32) (param u32) (result (tuple bool char))
|
||||
(func (export "ret-tuple") (param "a" u32) (param "b" u32) (result "c" bool) (result "d" char)
|
||||
(canon lift (core func $i "ret-tuple")
|
||||
(memory $i "memory")
|
||||
(realloc (func $i "realloc")))
|
||||
@@ -1328,10 +1337,10 @@ fn string_list_oob() -> Result<()> {
|
||||
let mut store = Store::new(&engine, ());
|
||||
let ret_list_u8 = Linker::new(&engine)
|
||||
.instantiate(&mut store, &component)?
|
||||
.get_typed_func::<(), WasmList<u8>, _>(&mut store, "ret-list-u8")?;
|
||||
.get_typed_func::<(), (WasmList<u8>,), _>(&mut store, "ret-list-u8")?;
|
||||
let ret_string = Linker::new(&engine)
|
||||
.instantiate(&mut store, &component)?
|
||||
.get_typed_func::<(), WasmStr, _>(&mut store, "ret-string")?;
|
||||
.get_typed_func::<(), (WasmStr,), _>(&mut store, "ret-string")?;
|
||||
|
||||
let err = ret_list_u8.call(&mut store, ()).err().unwrap();
|
||||
assert!(err.to_string().contains("out of bounds"), "{}", err);
|
||||
@@ -1373,8 +1382,8 @@ fn tuples() -> Result<()> {
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(func (export "foo")
|
||||
(param (tuple s32 float64))
|
||||
(param (tuple s8))
|
||||
(param "a" (tuple s32 float64))
|
||||
(param "b" (tuple s8))
|
||||
(result (tuple u16))
|
||||
(canon lift (core func $i "foo"))
|
||||
)
|
||||
@@ -1385,8 +1394,8 @@ fn tuples() -> Result<()> {
|
||||
let component = Component::new(&engine, component)?;
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
|
||||
let foo = instance.get_typed_func::<((i32, f64), (i8,)), (u16,), _>(&mut store, "foo")?;
|
||||
assert_eq!(foo.call(&mut store, ((0, 1.0), (2,)))?, (3,));
|
||||
let foo = instance.get_typed_func::<((i32, f64), (i8,)), ((u16,),), _>(&mut store, "foo")?;
|
||||
assert_eq!(foo.call(&mut store, ((0, 1.0), (2,)))?, ((3,),));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1444,35 +1453,35 @@ fn option() -> Result<()> {
|
||||
)
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(func (export "option-unit-to-u32") (param (option unit)) (result u32)
|
||||
(func (export "option-unit-to-u32") (param (option (tuple))) (result u32)
|
||||
(canon lift (core func $i "pass0"))
|
||||
)
|
||||
(func (export "option-u8-to-tuple") (param (option u8)) (result (tuple u32 u32))
|
||||
(func (export "option-u8-to-tuple") (param (option u8)) (result "a" u32) (result "b" u32)
|
||||
(canon lift (core func $i "pass1") (memory $i "memory"))
|
||||
)
|
||||
(func (export "option-u32-to-tuple") (param (option u32)) (result (tuple u32 u32))
|
||||
(func (export "option-u32-to-tuple") (param (option u32)) (result "a" u32) (result "b" u32)
|
||||
(canon lift (core func $i "pass1") (memory $i "memory"))
|
||||
)
|
||||
(func (export "option-string-to-tuple") (param (option string)) (result (tuple u32 string))
|
||||
(func (export "option-string-to-tuple") (param (option string)) (result "a" u32) (result "b" string)
|
||||
(canon lift
|
||||
(core func $i "pass2")
|
||||
(memory $i "memory")
|
||||
(realloc (func $i "realloc"))
|
||||
)
|
||||
)
|
||||
(func (export "to-option-unit") (param u32) (result (option unit))
|
||||
(func (export "to-option-unit") (param u32) (result (option (tuple)))
|
||||
(canon lift (core func $i "pass0"))
|
||||
)
|
||||
(func (export "to-option-u8") (param u32) (param u32) (result (option u8))
|
||||
(func (export "to-option-u8") (param "a" u32) (param "b" u32) (result (option u8))
|
||||
(canon lift (core func $i "pass1") (memory $i "memory"))
|
||||
)
|
||||
(func (export "to-option-u32") (param u32) (param u32) (result (option u32))
|
||||
(func (export "to-option-u32") (param "a" u32) (param "b" u32) (result (option u32))
|
||||
(canon lift
|
||||
(core func $i "pass1")
|
||||
(memory $i "memory")
|
||||
)
|
||||
)
|
||||
(func (export "to-option-string") (param u32) (param string) (result (option string))
|
||||
(func (export "to-option-string") (param "a" u32) (param "b" string) (result (option string))
|
||||
(canon lift
|
||||
(core func $i "pass2")
|
||||
(memory $i "memory")
|
||||
@@ -1488,10 +1497,10 @@ fn option() -> Result<()> {
|
||||
let linker = Linker::new(&engine);
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let option_unit_to_u32 =
|
||||
instance.get_typed_func::<(Option<()>,), u32, _>(&mut store, "option-unit-to-u32")?;
|
||||
assert_eq!(option_unit_to_u32.call(&mut store, (None,))?, 0);
|
||||
instance.get_typed_func::<(Option<()>,), (u32,), _>(&mut store, "option-unit-to-u32")?;
|
||||
assert_eq!(option_unit_to_u32.call(&mut store, (None,))?, (0,));
|
||||
option_unit_to_u32.post_return(&mut store)?;
|
||||
assert_eq!(option_unit_to_u32.call(&mut store, (Some(()),))?, 1);
|
||||
assert_eq!(option_unit_to_u32.call(&mut store, (Some(()),))?, (1,));
|
||||
option_unit_to_u32.post_return(&mut store)?;
|
||||
|
||||
let option_u8_to_tuple = instance
|
||||
@@ -1534,49 +1543,49 @@ fn option() -> Result<()> {
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_option_unit =
|
||||
instance.get_typed_func::<(u32,), Option<()>, _>(&mut store, "to-option-unit")?;
|
||||
assert_eq!(to_option_unit.call(&mut store, (0,))?, None);
|
||||
instance.get_typed_func::<(u32,), (Option<()>,), _>(&mut store, "to-option-unit")?;
|
||||
assert_eq!(to_option_unit.call(&mut store, (0,))?, (None,));
|
||||
to_option_unit.post_return(&mut store)?;
|
||||
assert_eq!(to_option_unit.call(&mut store, (1,))?, Some(()));
|
||||
assert_eq!(to_option_unit.call(&mut store, (1,))?, (Some(()),));
|
||||
to_option_unit.post_return(&mut store)?;
|
||||
let err = to_option_unit.call(&mut store, (2,)).unwrap_err();
|
||||
assert!(err.to_string().contains("invalid option"), "{}", err);
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_option_u8 =
|
||||
instance.get_typed_func::<(u32, u32), Option<u8>, _>(&mut store, "to-option-u8")?;
|
||||
assert_eq!(to_option_u8.call(&mut store, (0x00_00, 0))?, None);
|
||||
instance.get_typed_func::<(u32, u32), (Option<u8>,), _>(&mut store, "to-option-u8")?;
|
||||
assert_eq!(to_option_u8.call(&mut store, (0x00_00, 0))?, (None,));
|
||||
to_option_u8.post_return(&mut store)?;
|
||||
assert_eq!(to_option_u8.call(&mut store, (0x00_01, 0))?, Some(0));
|
||||
assert_eq!(to_option_u8.call(&mut store, (0x00_01, 0))?, (Some(0),));
|
||||
to_option_u8.post_return(&mut store)?;
|
||||
assert_eq!(to_option_u8.call(&mut store, (0xfd_01, 0))?, Some(0xfd));
|
||||
assert_eq!(to_option_u8.call(&mut store, (0xfd_01, 0))?, (Some(0xfd),));
|
||||
to_option_u8.post_return(&mut store)?;
|
||||
assert!(to_option_u8.call(&mut store, (0x00_02, 0)).is_err());
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_option_u32 =
|
||||
instance.get_typed_func::<(u32, u32), Option<u32>, _>(&mut store, "to-option-u32")?;
|
||||
assert_eq!(to_option_u32.call(&mut store, (0, 0))?, None);
|
||||
instance.get_typed_func::<(u32, u32), (Option<u32>,), _>(&mut store, "to-option-u32")?;
|
||||
assert_eq!(to_option_u32.call(&mut store, (0, 0))?, (None,));
|
||||
to_option_u32.post_return(&mut store)?;
|
||||
assert_eq!(to_option_u32.call(&mut store, (1, 0))?, Some(0));
|
||||
assert_eq!(to_option_u32.call(&mut store, (1, 0))?, (Some(0),));
|
||||
to_option_u32.post_return(&mut store)?;
|
||||
assert_eq!(
|
||||
to_option_u32.call(&mut store, (1, 0x1234fead))?,
|
||||
Some(0x1234fead)
|
||||
(Some(0x1234fead),)
|
||||
);
|
||||
to_option_u32.post_return(&mut store)?;
|
||||
assert!(to_option_u32.call(&mut store, (2, 0)).is_err());
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_option_string = instance
|
||||
.get_typed_func::<(u32, &str), Option<WasmStr>, _>(&mut store, "to-option-string")?;
|
||||
let ret = to_option_string.call(&mut store, (0, ""))?;
|
||||
.get_typed_func::<(u32, &str), (Option<WasmStr>,), _>(&mut store, "to-option-string")?;
|
||||
let ret = to_option_string.call(&mut store, (0, ""))?.0;
|
||||
assert!(ret.is_none());
|
||||
to_option_string.post_return(&mut store)?;
|
||||
let ret = to_option_string.call(&mut store, (1, ""))?;
|
||||
let ret = to_option_string.call(&mut store, (1, ""))?.0;
|
||||
assert_eq!(ret.unwrap().to_str(&store)?, "");
|
||||
to_option_string.post_return(&mut store)?;
|
||||
let ret = to_option_string.call(&mut store, (1, "cheesecake"))?;
|
||||
let ret = to_option_string.call(&mut store, (1, "cheesecake"))?.0;
|
||||
assert_eq!(ret.unwrap().to_str(&store)?, "cheesecake");
|
||||
to_option_string.post_return(&mut store)?;
|
||||
assert!(to_option_string.call(&mut store, (2, "")).is_err());
|
||||
@@ -1637,24 +1646,24 @@ fn expected() -> Result<()> {
|
||||
)
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(func (export "take-expected-unit") (param (expected unit unit)) (result u32)
|
||||
(func (export "take-expected-unit") (param (result)) (result u32)
|
||||
(canon lift (core func $i "pass0"))
|
||||
)
|
||||
(func (export "take-expected-u8-f32") (param (expected u8 float32)) (result (tuple u32 u32))
|
||||
(func (export "take-expected-u8-f32") (param (result u8 (error float32))) (result "a" u32) (result "b" u32)
|
||||
(canon lift (core func $i "pass1") (memory $i "memory"))
|
||||
)
|
||||
(type $list (list u8))
|
||||
(func (export "take-expected-string") (param (expected string $list)) (result (tuple u32 string))
|
||||
(func (export "take-expected-string") (param (result string (error $list))) (result "a" u32) (result "b" string)
|
||||
(canon lift
|
||||
(core func $i "pass2")
|
||||
(memory $i "memory")
|
||||
(realloc (func $i "realloc"))
|
||||
)
|
||||
)
|
||||
(func (export "to-expected-unit") (param u32) (result (expected unit unit))
|
||||
(func (export "to-expected-unit") (param u32) (result (result))
|
||||
(canon lift (core func $i "pass0"))
|
||||
)
|
||||
(func (export "to-expected-s16-f32") (param u32) (param u32) (result (expected s16 float32))
|
||||
(func (export "to-expected-s16-f32") (param "a" u32) (param "b" u32) (result (result s16 (error float32)))
|
||||
(canon lift
|
||||
(core func $i "pass1")
|
||||
(memory $i "memory")
|
||||
@@ -1669,11 +1678,11 @@ fn expected() -> Result<()> {
|
||||
let mut store = Store::new(&engine, ());
|
||||
let linker = Linker::new(&engine);
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let take_expected_unit =
|
||||
instance.get_typed_func::<(Result<(), ()>,), u32, _>(&mut store, "take-expected-unit")?;
|
||||
assert_eq!(take_expected_unit.call(&mut store, (Ok(()),))?, 0);
|
||||
let take_expected_unit = instance
|
||||
.get_typed_func::<(Result<(), ()>,), (u32,), _>(&mut store, "take-expected-unit")?;
|
||||
assert_eq!(take_expected_unit.call(&mut store, (Ok(()),))?, (0,));
|
||||
take_expected_unit.post_return(&mut store)?;
|
||||
assert_eq!(take_expected_unit.call(&mut store, (Err(()),))?, 1);
|
||||
assert_eq!(take_expected_unit.call(&mut store, (Err(()),))?, (1,));
|
||||
take_expected_unit.post_return(&mut store)?;
|
||||
|
||||
let take_expected_u8_f32 = instance
|
||||
@@ -1702,27 +1711,29 @@ fn expected() -> Result<()> {
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_expected_unit =
|
||||
instance.get_typed_func::<(u32,), Result<(), ()>, _>(&mut store, "to-expected-unit")?;
|
||||
assert_eq!(to_expected_unit.call(&mut store, (0,))?, Ok(()));
|
||||
instance.get_typed_func::<(u32,), (Result<(), ()>,), _>(&mut store, "to-expected-unit")?;
|
||||
assert_eq!(to_expected_unit.call(&mut store, (0,))?, (Ok(()),));
|
||||
to_expected_unit.post_return(&mut store)?;
|
||||
assert_eq!(to_expected_unit.call(&mut store, (1,))?, Err(()));
|
||||
assert_eq!(to_expected_unit.call(&mut store, (1,))?, (Err(()),));
|
||||
to_expected_unit.post_return(&mut store)?;
|
||||
let err = to_expected_unit.call(&mut store, (2,)).unwrap_err();
|
||||
assert!(err.to_string().contains("invalid expected"), "{}", err);
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let to_expected_s16_f32 = instance
|
||||
.get_typed_func::<(u32, u32), Result<i16, f32>, _>(&mut store, "to-expected-s16-f32")?;
|
||||
assert_eq!(to_expected_s16_f32.call(&mut store, (0, 0))?, Ok(0));
|
||||
.get_typed_func::<(u32, u32), (Result<i16, f32>,), _>(&mut store, "to-expected-s16-f32")?;
|
||||
assert_eq!(to_expected_s16_f32.call(&mut store, (0, 0))?, (Ok(0),));
|
||||
to_expected_s16_f32.post_return(&mut store)?;
|
||||
assert_eq!(to_expected_s16_f32.call(&mut store, (0, 100))?, Ok(100));
|
||||
assert_eq!(to_expected_s16_f32.call(&mut store, (0, 100))?, (Ok(100),));
|
||||
to_expected_s16_f32.post_return(&mut store)?;
|
||||
assert_eq!(
|
||||
to_expected_s16_f32.call(&mut store, (1, 1.0f32.to_bits()))?,
|
||||
Err(1.0)
|
||||
(Err(1.0),)
|
||||
);
|
||||
to_expected_s16_f32.post_return(&mut store)?;
|
||||
let ret = to_expected_s16_f32.call(&mut store, (1, CANON_32BIT_NAN | 1))?;
|
||||
let ret = to_expected_s16_f32
|
||||
.call(&mut store, (1, CANON_32BIT_NAN | 1))?
|
||||
.0;
|
||||
assert_eq!(ret.unwrap_err().to_bits(), CANON_32BIT_NAN);
|
||||
to_expected_s16_f32.post_return(&mut store)?;
|
||||
assert!(to_expected_s16_f32.call(&mut store, (2, 0)).is_err());
|
||||
@@ -1768,10 +1779,13 @@ fn fancy_list() -> Result<()> {
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(type $a (option u8))
|
||||
(type $b (expected unit string))
|
||||
(type $b (result (error string)))
|
||||
(type $input (list (tuple $a $b)))
|
||||
(type $output (tuple u32 u32 (list u8)))
|
||||
(func (export "take") (param $input) (result $output)
|
||||
(func (export "take")
|
||||
(param $input)
|
||||
(result "ptr" u32)
|
||||
(result "len" u32)
|
||||
(result "list" (list u8))
|
||||
(canon lift
|
||||
(core func $i "take")
|
||||
(memory $i "memory")
|
||||
@@ -1873,9 +1887,9 @@ fn invalid_alignment() -> Result<()> {
|
||||
(core instance $i (instantiate $m))
|
||||
|
||||
(func (export "many-params")
|
||||
(param string) (param string) (param string) (param string)
|
||||
(param string) (param string) (param string) (param string)
|
||||
(param string) (param string) (param string) (param string)
|
||||
(param "s1" string) (param "s2" string) (param "s3" string) (param "s4" string)
|
||||
(param "s5" string) (param "s6" string) (param "s7" string) (param "s8" string)
|
||||
(param "s9" string) (param "s10" string) (param "s11" string) (param "s12" string)
|
||||
(canon lift
|
||||
(core func $i "take-i32")
|
||||
(memory $i "memory")
|
||||
@@ -1929,7 +1943,7 @@ fn invalid_alignment() -> Result<()> {
|
||||
);
|
||||
|
||||
let err = instance(&mut store)?
|
||||
.get_typed_func::<(), WasmStr, _>(&mut store, "string-ret")?
|
||||
.get_typed_func::<(), (WasmStr,), _>(&mut store, "string-ret")?
|
||||
.call(&mut store, ())
|
||||
.err()
|
||||
.unwrap();
|
||||
@@ -1940,7 +1954,7 @@ fn invalid_alignment() -> Result<()> {
|
||||
);
|
||||
|
||||
let err = instance(&mut store)?
|
||||
.get_typed_func::<(), WasmList<u32>, _>(&mut store, "list-u32-ret")?
|
||||
.get_typed_func::<(), (WasmList<u32>,), _>(&mut store, "list-u32-ret")?
|
||||
.call(&mut store, ())
|
||||
.err()
|
||||
.unwrap();
|
||||
@@ -2073,8 +2087,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
};
|
||||
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<u8>, _>(&mut store, "list-u8")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<u8>,), _>(&mut store, "list-u8")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2083,8 +2098,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<i8>, _>(&mut store, "list-i8")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<i8>,), _>(&mut store, "list-i8")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2094,8 +2110,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
);
|
||||
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<u16>, _>(&mut store, "list-u16")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<u16>,), _>(&mut store, "list-u16")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2110,8 +2127,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<i16>, _>(&mut store, "list-i16")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<i16>,), _>(&mut store, "list-i16")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2126,8 +2144,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<u32>, _>(&mut store, "list-u32")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<u32>,), _>(&mut store, "list-u32")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2138,8 +2157,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<i32>, _>(&mut store, "list-i32")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<i32>,), _>(&mut store, "list-i32")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2150,8 +2170,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<u64>, _>(&mut store, "list-u64")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<u64>,), _>(&mut store, "list-u64")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2160,8 +2181,9 @@ fn raw_slice_of_various_types() -> Result<()> {
|
||||
]
|
||||
);
|
||||
let list = instance
|
||||
.get_typed_func::<(), WasmList<i64>, _>(&mut store, "list-i64")?
|
||||
.call_and_post_return(&mut store, ())?;
|
||||
.get_typed_func::<(), (WasmList<i64>,), _>(&mut store, "list-i64")?
|
||||
.call_and_post_return(&mut store, ())?
|
||||
.0;
|
||||
assert_eq!(
|
||||
list.as_le_slice(&store),
|
||||
[
|
||||
@@ -2194,11 +2216,11 @@ fn lower_then_lift() -> Result<()> {
|
||||
let component = Component::new(&engine, component)?;
|
||||
let mut store = Store::new(&engine, ());
|
||||
let mut linker = Linker::new(&engine);
|
||||
linker.root().func_wrap("f", || Ok(2u32))?;
|
||||
linker.root().func_wrap("f", || Ok((2u32,)))?;
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
|
||||
let f = instance.get_typed_func::<(), i32, _>(&mut store, "f")?;
|
||||
assert_eq!(f.call(&mut store, ())?, 2);
|
||||
let f = instance.get_typed_func::<(), (i32,), _>(&mut store, "f")?;
|
||||
assert_eq!(f.call(&mut store, ())?, (2,));
|
||||
|
||||
// First test strings when the import/export ABI happen to line up
|
||||
let component = format!(
|
||||
@@ -2272,11 +2294,11 @@ fn lower_then_lift() -> Result<()> {
|
||||
.root()
|
||||
.func_wrap("s2", |store: StoreContextMut<'_, ()>, x: WasmStr| {
|
||||
assert_eq!(x.to_str(&store)?, "hello");
|
||||
Ok(u32::MAX)
|
||||
Ok((u32::MAX,))
|
||||
})?;
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
|
||||
let f = instance.get_typed_func::<(&str,), WasmStr, _>(&mut store, "f")?;
|
||||
let f = instance.get_typed_func::<(&str,), (WasmStr,), _>(&mut store, "f")?;
|
||||
let err = f.call(&mut store, ("hello",)).err().unwrap();
|
||||
assert!(
|
||||
err.to_string().contains("return pointer not aligned"),
|
||||
@@ -2339,7 +2361,7 @@ fn errors_that_poison_instance() -> Result<()> {
|
||||
assert_poisoned(f3.call(&mut store, ("x",)));
|
||||
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let f4 = instance.get_typed_func::<(), WasmStr, _>(&mut store, "f4")?;
|
||||
let f4 = instance.get_typed_func::<(), (WasmStr,), _>(&mut store, "f4")?;
|
||||
assert!(f4.call(&mut store, ()).is_err());
|
||||
assert_poisoned(f4.call(&mut store, ()));
|
||||
|
||||
@@ -2414,7 +2436,7 @@ fn run_export_with_internal_adapter() -> Result<()> {
|
||||
let mut store = Store::new(&engine, ());
|
||||
let linker = Linker::new(&engine);
|
||||
let instance = linker.instantiate(&mut store, &component)?;
|
||||
let run = instance.get_typed_func::<(), u32, _>(&mut store, "run")?;
|
||||
assert_eq!(run.call(&mut store, ())?, 5);
|
||||
let run = instance.get_typed_func::<(), (u32,), _>(&mut store, "run")?;
|
||||
assert_eq!(run.call(&mut store, ())?, (5,));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user