diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs index 02f43fd349..4cf2782164 100644 --- a/crates/wasmparser/src/validator/component.rs +++ b/crates/wasmparser/src/validator/component.rs @@ -395,6 +395,18 @@ impl CanonicalOptions { Ok(self) } + fn check_asyncness(&self, ty: &ComponentFuncType, offset: usize) -> Result<()> { + // The `async` canonical ABI option is only allowed with `async`-typed + // functions. + if self.concurrency.is_async() && !ty.async_ { + bail!( + offset, + "the `async` canonical option requires an async function type", + ); + } + Ok(()) + } + pub(crate) fn check_core_type( &self, types: &mut TypeAlloc, @@ -1303,6 +1315,7 @@ impl ComponentState { // export signature let mut options = self.check_options(types, options, offset)?; options.check_lift(types, self, core_ty_id, offset)?; + options.check_asyncness(ty, offset)?; let func_ty = ty.lower(types, &options, Abi::Lift, offset)?; let lowered_core_ty_id = func_ty.intern(types, offset); @@ -1359,6 +1372,8 @@ impl ComponentState { // the expected canonical ABI import signature. let options = self.check_options(types, options, offset)?; options.check_lower(offset)?; + options.check_asyncness(ty, offset)?; + let func_ty = ty.lower(types, &options, Abi::Lower, offset)?; let ty_id = func_ty.intern(types, offset); diff --git a/crates/wit-component/src/dummy.rs b/crates/wit-component/src/dummy.rs index 047df7b4fd..006f0d0044 100644 --- a/crates/wit-component/src/dummy.rs +++ b/crates/wit-component/src/dummy.rs @@ -90,6 +90,7 @@ fn push_imported_func( func: &Function, mangling: ManglingAndAbi, ) { + let mangling = mangling.for_func(func); let sig = resolve.wasm_signature(mangling.import_variant(), func); let (module, name) = resolve.wasm_import_name(mangling, WasmImport::Func { interface, func }); @@ -352,6 +353,7 @@ fn push_func_export( func: &Function, mangling: ManglingAndAbi, ) { + let mangling = mangling.for_func(func); let sig = resolve.wasm_signature(mangling.export_variant(), func); let name = resolve.wasm_export_name( mangling, diff --git a/crates/wit-component/tests/components/async-builtins/component.wat b/crates/wit-component/tests/components/async-builtins/component.wat index 7714a09eb3..6dfcaff555 100644 --- a/crates/wit-component/tests/components/async-builtins/component.wat +++ b/crates/wit-component/tests/components/async-builtins/component.wat @@ -235,17 +235,17 @@ (with "" (instance $fixup-args)) ) ) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;33;))) (func $foo (;0;) (type 0) (canon lift (core func $"[async-lift-stackful]foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (export $"#func1 foo" (@name "foo") (;1;) "foo" (func $foo)) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;34;))) (func $"#func2 foo" (@name "foo") (;2;) (type 1) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (component $foo:foo/bar-shim-component (;0;) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (import "import-func-foo" (func (;0;) (type 0))) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (export (;1;) "foo" (func 0) (func (type 1))) ) (instance $foo:foo/bar-shim-instance (;0;) (instantiate $foo:foo/bar-shim-component diff --git a/crates/wit-component/tests/components/async-builtins/component.wit.print b/crates/wit-component/tests/components/async-builtins/component.wit.print index 8c6e69aa82..341135f54f 100644 --- a/crates/wit-component/tests/components/async-builtins/component.wit.print +++ b/crates/wit-component/tests/components/async-builtins/component.wit.print @@ -1,6 +1,6 @@ package root:component; world root { - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; export foo:foo/bar; } diff --git a/crates/wit-component/tests/components/async-builtins/module.wit b/crates/wit-component/tests/components/async-builtins/module.wit index f0629ae1d2..282a35754d 100644 --- a/crates/wit-component/tests/components/async-builtins/module.wit +++ b/crates/wit-component/tests/components/async-builtins/module.wit @@ -1,10 +1,10 @@ package foo:foo; interface bar { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; } world module { export bar; - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/async-export-with-callback/component.wat b/crates/wit-component/tests/components/async-export-with-callback/component.wat index 9b1e4e6702..3dae51b527 100644 --- a/crates/wit-component/tests/components/async-export-with-callback/component.wat +++ b/crates/wit-component/tests/components/async-export-with-callback/component.wat @@ -32,20 +32,20 @@ ) (core instance $main (;0;) (instantiate $main)) (alias core export $main "memory" (core memory $memory (;0;))) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift]foo" (core func $"[async-lift]foo" (;0;))) (alias core export $main "cabi_realloc" (core func $cabi_realloc (;1;))) (alias core export $main "[callback][async-lift]foo" (core func $"[callback][async-lift]foo" (;2;))) (func $foo (;0;) (type 0) (canon lift (core func $"[async-lift]foo") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async (callback $"[callback][async-lift]foo"))) (export $"#func1 foo" (@name "foo") (;1;) "foo" (func $foo)) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift]foo:foo/bar#foo" (core func $"[async-lift]foo:foo/bar#foo" (;3;))) (alias core export $main "[callback][async-lift]foo:foo/bar#foo" (core func $"[callback][async-lift]foo:foo/bar#foo" (;4;))) (func $"#func2 foo" (@name "foo") (;2;) (type 1) (canon lift (core func $"[async-lift]foo:foo/bar#foo") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async (callback $"[callback][async-lift]foo:foo/bar#foo"))) (component $foo:foo/bar-shim-component (;0;) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (import "import-func-foo" (func (;0;) (type 0))) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (export (;1;) "foo" (func 0) (func (type 1))) ) (instance $foo:foo/bar-shim-instance (;0;) (instantiate $foo:foo/bar-shim-component diff --git a/crates/wit-component/tests/components/async-export-with-callback/component.wit.print b/crates/wit-component/tests/components/async-export-with-callback/component.wit.print index 8c6e69aa82..341135f54f 100644 --- a/crates/wit-component/tests/components/async-export-with-callback/component.wit.print +++ b/crates/wit-component/tests/components/async-export-with-callback/component.wit.print @@ -1,6 +1,6 @@ package root:component; world root { - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; export foo:foo/bar; } diff --git a/crates/wit-component/tests/components/async-export-with-callback/module.wit b/crates/wit-component/tests/components/async-export-with-callback/module.wit index f0629ae1d2..282a35754d 100644 --- a/crates/wit-component/tests/components/async-export-with-callback/module.wit +++ b/crates/wit-component/tests/components/async-export-with-callback/module.wit @@ -1,10 +1,10 @@ package foo:foo; interface bar { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; } world module { export bar; - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/async-export/component.wat b/crates/wit-component/tests/components/async-export/component.wat index 0fdd38ccc1..734af763b1 100644 --- a/crates/wit-component/tests/components/async-export/component.wat +++ b/crates/wit-component/tests/components/async-export/component.wat @@ -35,24 +35,24 @@ (type (;2;) (record (field "a1" 1) (field "a2" 1) (field "a3" 1) (field "a4" 1))) (core instance $main (;0;) (instantiate $main)) (alias core export $main "memory" (core memory $memory (;0;))) - (type (;3;) (func (param "s" string) (result string))) + (type (;3;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;0;))) (alias core export $main "cabi_realloc" (core func $cabi_realloc (;1;))) (func $foo (;0;) (type 3) (canon lift (core func $"[async-lift-stackful]foo") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async)) (export $"#func1 foo" (@name "foo") (;1;) "foo" (func $foo)) - (type (;4;) (func (param "s" string) (result string))) + (type (;4;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;2;))) (func $"#func2 foo" (@name "foo") (;2;) (type 4) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#foo") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async)) - (type (;5;) (func (result string))) + (type (;5;) (func async (result string))) (alias core export $main "[async-lift-stackful]foo:foo/bar#get-string" (core func $"[async-lift-stackful]foo:foo/bar#get-string" (;3;))) (func $get-string (;3;) (type 5) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#get-string") (memory $memory) string-encoding=utf8 async)) - (type (;6;) (func (result 2))) + (type (;6;) (func async (result 2))) (alias core export $main "[async-lift-stackful]foo:foo/bar#get-big" (core func $"[async-lift-stackful]foo:foo/bar#get-big" (;4;))) (func $get-big (;4;) (type 6) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#get-big") (memory $memory) async)) (component $foo:foo/bar-shim-component (;0;) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (import "import-func-foo" (func (;0;) (type 0))) - (type (;1;) (func (result string))) + (type (;1;) (func async (result string))) (import "import-func-get-string" (func (;1;) (type 1))) (type (;2;) (record (field "a1" u8) (field "a2" u8) (field "a3" u8) (field "a4" u8))) (import "import-type-big3" (type (;3;) (eq 2))) @@ -60,7 +60,7 @@ (import "import-type-big2" (type (;5;) (eq 4))) (type (;6;) (record (field "a1" 5) (field "a2" 5) (field "a3" 5) (field "a4" 5))) (import "import-type-big" (type (;7;) (eq 6))) - (type (;8;) (func (result 7))) + (type (;8;) (func async (result 7))) (import "import-func-get-big" (func (;2;) (type 8))) (type (;9;) (record (field "a1" u8) (field "a2" u8) (field "a3" u8) (field "a4" u8))) (export (;10;) "big3" (type 9)) @@ -68,11 +68,11 @@ (export (;12;) "big2" (type 11)) (type (;13;) (record (field "a1" 12) (field "a2" 12) (field "a3" 12) (field "a4" 12))) (export (;14;) "big" (type 13)) - (type (;15;) (func (param "s" string) (result string))) + (type (;15;) (func async (param "s" string) (result string))) (export (;3;) "foo" (func 0) (func (type 15))) - (type (;16;) (func (result string))) + (type (;16;) (func async (result string))) (export (;4;) "get-string" (func 1) (func (type 16))) - (type (;17;) (func (result 14))) + (type (;17;) (func async (result 14))) (export (;5;) "get-big" (func 2) (func (type 17))) ) (instance $foo:foo/bar-shim-instance (;0;) (instantiate $foo:foo/bar-shim-component diff --git a/crates/wit-component/tests/components/async-export/component.wit.print b/crates/wit-component/tests/components/async-export/component.wit.print index 8c6e69aa82..341135f54f 100644 --- a/crates/wit-component/tests/components/async-export/component.wit.print +++ b/crates/wit-component/tests/components/async-export/component.wit.print @@ -1,6 +1,6 @@ package root:component; world root { - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; export foo:foo/bar; } diff --git a/crates/wit-component/tests/components/async-export/module.wit b/crates/wit-component/tests/components/async-export/module.wit index fa8466e3b3..d964a0cab7 100644 --- a/crates/wit-component/tests/components/async-export/module.wit +++ b/crates/wit-component/tests/components/async-export/module.wit @@ -19,12 +19,12 @@ interface bar { a3: u8, a4: u8, } - foo: func(s: string) -> string; - get-string: func() -> string; - get-big: func() -> big; + foo: async func(s: string) -> string; + get-string: async func() -> string; + get-big: async func() -> big; } world module { export bar; - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/async-import/component.wat b/crates/wit-component/tests/components/async-import/component.wat index 2b01843886..8a45f494fc 100644 --- a/crates/wit-component/tests/components/async-import/component.wat +++ b/crates/wit-component/tests/components/async-import/component.wat @@ -1,12 +1,12 @@ (component (type $ty-foo:foo/bar (;0;) (instance - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (export (;0;) "foo" (func (type 0))) ) ) (import "foo:foo/bar" (instance $foo:foo/bar (;0;) (type $ty-foo:foo/bar))) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (import "foo" (func $foo (;0;) (type 1))) (core module $main (;0;) (type (;0;) (func (param i32 i32 i32) (result i32))) diff --git a/crates/wit-component/tests/components/async-import/component.wit.print b/crates/wit-component/tests/components/async-import/component.wit.print index d820bfa480..acedee2f58 100644 --- a/crates/wit-component/tests/components/async-import/component.wit.print +++ b/crates/wit-component/tests/components/async-import/component.wit.print @@ -2,5 +2,5 @@ package root:component; world root { import foo:foo/bar; - import foo: func(s: string) -> string; + import foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/async-import/module.wit b/crates/wit-component/tests/components/async-import/module.wit index 1f18c69192..3cfb19cc35 100644 --- a/crates/wit-component/tests/components/async-import/module.wit +++ b/crates/wit-component/tests/components/async-import/module.wit @@ -1,10 +1,10 @@ package foo:foo; interface bar { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; } world module { import bar; - import foo: func(s: string) -> string; + import foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/async-streams-and-futures/component.wat b/crates/wit-component/tests/components/async-streams-and-futures/component.wat index 89acf9b0a4..271b0bdc5c 100644 --- a/crates/wit-component/tests/components/async-streams-and-futures/component.wat +++ b/crates/wit-component/tests/components/async-streams-and-futures/component.wat @@ -4,7 +4,7 @@ (type (;0;) (future u32)) (type (;1;) (future 0)) (type (;2;) (stream string)) - (type (;3;) (func (param "x" 1) (param "y" u32) (result 2))) + (type (;3;) (func async (param "x" 1) (param "y" u32) (result 2))) (export (;0;) "foo" (func (type 3))) ) ) @@ -12,7 +12,7 @@ (type (;1;) (future u32)) (type (;2;) (future 1)) (type (;3;) (stream string)) - (type (;4;) (func (param "x" 2) (param "y" u32) (result 3))) + (type (;4;) (func async (param "x" 2) (param "y" u32) (result 3))) (import "foo" (func $foo (;0;) (type 4))) (core module $main (;0;) (type (;0;) (func (param i32 i32 i32) (result i32))) @@ -623,19 +623,19 @@ (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;113;))) (func $"#func2 foo" (@name "foo") (;2;) (type 4) (canon lift (core func $"[async-lift-stackful]foo") async)) (export $"#func3 foo" (@name "foo") (;3;) "foo" (func $"#func2 foo")) - (type (;9;) (func (param "x" 8) (param "y" u32) (result 6))) + (type (;9;) (func async (param "x" 8) (param "y" u32) (result 6))) (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;114;))) (func $"#func4 foo" (@name "foo") (;4;) (type 9) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#foo") async)) (component $foo:foo/bar-shim-component (;0;) (type (;0;) (future u32)) (type (;1;) (future 0)) (type (;2;) (stream string)) - (type (;3;) (func (param "x" 1) (param "y" u32) (result 2))) + (type (;3;) (func async (param "x" 1) (param "y" u32) (result 2))) (import "import-func-foo" (func (;0;) (type 3))) (type (;4;) (future u32)) (type (;5;) (future 4)) (type (;6;) (stream string)) - (type (;7;) (func (param "x" 5) (param "y" u32) (result 6))) + (type (;7;) (func async (param "x" 5) (param "y" u32) (result 6))) (export (;1;) "foo" (func 0) (func (type 7))) ) (instance $foo:foo/bar-shim-instance (;1;) (instantiate $foo:foo/bar-shim-component diff --git a/crates/wit-component/tests/components/async-streams-and-futures/component.wit.print b/crates/wit-component/tests/components/async-streams-and-futures/component.wit.print index 9dc12adbd9..cd1e9baf8a 100644 --- a/crates/wit-component/tests/components/async-streams-and-futures/component.wit.print +++ b/crates/wit-component/tests/components/async-streams-and-futures/component.wit.print @@ -2,8 +2,8 @@ package root:component; world root { import foo:foo/bar; - import foo: func(x: future>, y: u32) -> stream; + import foo: async func(x: future>, y: u32) -> stream; - export foo: func(x: future>, y: u32) -> stream; + export foo: async func(x: future>, y: u32) -> stream; export foo:foo/bar; } diff --git a/crates/wit-component/tests/components/async-streams-and-futures/module.wit b/crates/wit-component/tests/components/async-streams-and-futures/module.wit index 4f8b0bb7f4..b35aefab63 100644 --- a/crates/wit-component/tests/components/async-streams-and-futures/module.wit +++ b/crates/wit-component/tests/components/async-streams-and-futures/module.wit @@ -1,12 +1,12 @@ package foo:foo; interface bar { - foo: func(x: future>, y: u32) -> stream; + foo: async func(x: future>, y: u32) -> stream; } world module { import bar; - import foo: func(x: future>, y: u32) -> stream; + import foo: async func(x: future>, y: u32) -> stream; export bar; - export foo: func(x: future>, y: u32) -> stream; + export foo: async func(x: future>, y: u32) -> stream; } diff --git a/crates/wit-component/tests/components/async-task-return-param-string/component.wat b/crates/wit-component/tests/components/async-task-return-param-string/component.wat index 6dd513089f..27f69b7e3a 100644 --- a/crates/wit-component/tests/components/async-task-return-param-string/component.wat +++ b/crates/wit-component/tests/components/async-task-return-param-string/component.wat @@ -70,7 +70,7 @@ (with "" (instance $fixup-args)) ) ) - (type (;0;) (func (param "s" string))) + (type (;0;) (func async (param "s" string))) (alias core export $main "[async-lift]foo" (core func $"[async-lift]foo" (;4;))) (alias core export $main "[callback][async-lift]foo" (core func $"[callback][async-lift]foo" (;5;))) (func $foo (;0;) (type 0) (canon lift (core func $"[async-lift]foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async (callback $"[callback][async-lift]foo"))) diff --git a/crates/wit-component/tests/components/async-task-return-param-string/component.wit.print b/crates/wit-component/tests/components/async-task-return-param-string/component.wit.print index 55439de3ba..56481be2a0 100644 --- a/crates/wit-component/tests/components/async-task-return-param-string/component.wit.print +++ b/crates/wit-component/tests/components/async-task-return-param-string/component.wit.print @@ -1,5 +1,5 @@ package root:component; world root { - export foo: func(s: string); + export foo: async func(s: string); } diff --git a/crates/wit-component/tests/components/async-task-return-param-string/module.wit b/crates/wit-component/tests/components/async-task-return-param-string/module.wit index 3d5fc388a4..d66459c7c5 100644 --- a/crates/wit-component/tests/components/async-task-return-param-string/module.wit +++ b/crates/wit-component/tests/components/async-task-return-param-string/module.wit @@ -1,5 +1,5 @@ package foo:foo; world module { - export foo: func(s: string); + export foo: async func(s: string); } diff --git a/crates/wit-component/tests/components/threading/component.wat b/crates/wit-component/tests/components/threading/component.wat index 1292814d48..bc4041e03c 100644 --- a/crates/wit-component/tests/components/threading/component.wat +++ b/crates/wit-component/tests/components/threading/component.wat @@ -142,17 +142,17 @@ (with "" (instance $fixup-args)) ) ) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo" (core func $"[async-lift-stackful]foo" (;16;))) (func $foo (;0;) (type 0) (canon lift (core func $"[async-lift-stackful]foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (export $"#func1 foo" (@name "foo") (;1;) "foo" (func $foo)) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (alias core export $main "[async-lift-stackful]foo:foo/bar#foo" (core func $"[async-lift-stackful]foo:foo/bar#foo" (;17;))) (func $"#func2 foo" (@name "foo") (;2;) (type 1) (canon lift (core func $"[async-lift-stackful]foo:foo/bar#foo") (memory $memory) (realloc $realloc) string-encoding=utf8 async)) (component $foo:foo/bar-shim-component (;0;) - (type (;0;) (func (param "s" string) (result string))) + (type (;0;) (func async (param "s" string) (result string))) (import "import-func-foo" (func (;0;) (type 0))) - (type (;1;) (func (param "s" string) (result string))) + (type (;1;) (func async (param "s" string) (result string))) (export (;1;) "foo" (func 0) (func (type 1))) ) (instance $foo:foo/bar-shim-instance (;0;) (instantiate $foo:foo/bar-shim-component diff --git a/crates/wit-component/tests/components/threading/component.wit.print b/crates/wit-component/tests/components/threading/component.wit.print index 8c6e69aa82..341135f54f 100644 --- a/crates/wit-component/tests/components/threading/component.wit.print +++ b/crates/wit-component/tests/components/threading/component.wit.print @@ -1,6 +1,6 @@ package root:component; world root { - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; export foo:foo/bar; } diff --git a/crates/wit-component/tests/components/threading/module.wit b/crates/wit-component/tests/components/threading/module.wit index f0629ae1d2..282a35754d 100644 --- a/crates/wit-component/tests/components/threading/module.wit +++ b/crates/wit-component/tests/components/threading/module.wit @@ -1,10 +1,10 @@ package foo:foo; interface bar { - foo: func(s: string) -> string; + foo: async func(s: string) -> string; } world module { export bar; - export foo: func(s: string) -> string; + export foo: async func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/wasm-init-task/component.wat b/crates/wit-component/tests/components/wasm-init-task/component.wat index 6873484fda..3e0aab047b 100644 --- a/crates/wit-component/tests/components/wasm-init-task/component.wat +++ b/crates/wit-component/tests/components/wasm-init-task/component.wat @@ -139,22 +139,24 @@ (alias core export $init-task-wrappers-instance "[async-lift-stackful]async-stackful-argret" (core func $"#core-func11 [async-lift-stackful]async-stackful-argret" (@name "[async-lift-stackful]async-stackful-argret") (;11;))) (alias core export $init-task-wrappers-instance "[async-lift]async-callback-argret" (core func $"#core-func12 [async-lift]async-callback-argret" (@name "[async-lift]async-callback-argret") (;12;))) (alias core export $init-task-wrappers-instance "sync-argret" (core func $"#core-func13 sync-argret" (@name "sync-argret") (;13;))) - (type (;0;) (func)) + (type (;0;) (func async)) (alias core export $main "cabi_realloc" (core func $cabi_realloc (;14;))) (func $async-stackful (;0;) (type 0) (canon lift (core func $"#core-func8 [async-lift-stackful]async-stackful") async)) (export $"#func1 async-stackful" (@name "async-stackful") (;1;) "async-stackful" (func $async-stackful)) (alias core export $main "[callback][async-lift]async-callback" (core func $"[callback][async-lift]async-callback" (;15;))) (func $async-callback (;2;) (type 0) (canon lift (core func $"#core-func9 [async-lift]async-callback") async (callback $"[callback][async-lift]async-callback"))) (export $"#func3 async-callback" (@name "async-callback") (;3;) "async-callback" (func $async-callback)) - (func $sync (;4;) (type 0) (canon lift (core func $"#core-func10 sync"))) + (type (;1;) (func)) + (func $sync (;4;) (type 1) (canon lift (core func $"#core-func10 sync"))) (export $"#func5 sync" (@name "sync") (;5;) "sync" (func $sync)) - (type (;1;) (func (param "s" string) (result string))) - (func $async-stackful-argret (;6;) (type 1) (canon lift (core func $"#core-func11 [async-lift-stackful]async-stackful-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async)) + (type (;2;) (func async (param "s" string) (result string))) + (func $async-stackful-argret (;6;) (type 2) (canon lift (core func $"#core-func11 [async-lift-stackful]async-stackful-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async)) (export $"#func7 async-stackful-argret" (@name "async-stackful-argret") (;7;) "async-stackful-argret" (func $async-stackful-argret)) (alias core export $main "[callback][async-lift]async-callback-argret" (core func $"[callback][async-lift]async-callback-argret" (;16;))) - (func $async-callback-argret (;8;) (type 1) (canon lift (core func $"#core-func12 [async-lift]async-callback-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async (callback $"[callback][async-lift]async-callback-argret"))) + (func $async-callback-argret (;8;) (type 2) (canon lift (core func $"#core-func12 [async-lift]async-callback-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8 async (callback $"[callback][async-lift]async-callback-argret"))) (export $"#func9 async-callback-argret" (@name "async-callback-argret") (;9;) "async-callback-argret" (func $async-callback-argret)) - (func $sync-argret (;10;) (type 1) (canon lift (core func $"#core-func13 sync-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8)) + (type (;3;) (func (param "s" string) (result string))) + (func $sync-argret (;10;) (type 3) (canon lift (core func $"#core-func13 sync-argret") (memory $memory) (realloc $cabi_realloc) string-encoding=utf8)) (export $"#func11 sync-argret" (@name "sync-argret") (;11;) "sync-argret" (func $sync-argret)) (@producers (processed-by "wit-component" "$CARGO_PKG_VERSION") diff --git a/crates/wit-component/tests/components/wasm-init-task/component.wit.print b/crates/wit-component/tests/components/wasm-init-task/component.wit.print index 21ce9f8e96..5a46596f93 100644 --- a/crates/wit-component/tests/components/wasm-init-task/component.wit.print +++ b/crates/wit-component/tests/components/wasm-init-task/component.wit.print @@ -1,10 +1,10 @@ package root:component; world root { - export async-stackful: func(); - export async-callback: func(); + export async-stackful: async func(); + export async-callback: async func(); export sync: func(); - export async-stackful-argret: func(s: string) -> string; - export async-callback-argret: func(s: string) -> string; + export async-stackful-argret: async func(s: string) -> string; + export async-callback-argret: async func(s: string) -> string; export sync-argret: func(s: string) -> string; } diff --git a/crates/wit-component/tests/components/wasm-init-task/module.wit b/crates/wit-component/tests/components/wasm-init-task/module.wit index 3c9d33ed62..58cb9eb2c1 100644 --- a/crates/wit-component/tests/components/wasm-init-task/module.wit +++ b/crates/wit-component/tests/components/wasm-init-task/module.wit @@ -1,10 +1,10 @@ package foo:foo; world module { - export async-stackful: func(); - export async-callback: func(); + export async-stackful: async func(); + export async-callback: async func(); export sync: func(); - export async-stackful-argret: func(s: string) -> string; - export async-callback-argret: func(s: string) -> string; + export async-stackful-argret: async func(s: string) -> string; + export async-callback-argret: async func(s: string) -> string; export sync-argret: func(s: string) -> string; } diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index 76461df98c..0080a7d9dc 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -1279,6 +1279,24 @@ impl ManglingAndAbi { Self::Legacy(_) => Mangling::Legacy, } } + + /// Returns a suitable [`ManglingAndAbi`], based on `self`, to use for + /// `func`. + /// + /// This handles the case where `func` is a synchronous function which means + /// that it's forced to use the sync ABI no matter what. + pub fn for_func(&self, func: &Function) -> Self { + match self { + Self::Standard32 => *self, + Self::Legacy(abi) => { + if !func.kind.is_async() { + Self::Legacy(LiftLowerAbi::Sync) + } else { + Self::Legacy(*abi) + } + } + } + } } impl Function { diff --git a/tests/cli/component-model/async/abi.wast b/tests/cli/component-model/async/abi.wast index ede47c94d0..3117d1a117 100644 --- a/tests/cli/component-model/async/abi.wast +++ b/tests/cli/component-model/async/abi.wast @@ -5,38 +5,38 @@ (core module $libc (memory (export "memory") 1)) (core instance $libc (instantiate $libc)) - ;; func() - (import "f1" (func $f1)) + ;; async func() + (import "f1" (func $f1 async)) (core func $f1 (canon lower (func $f1) async)) (core module $m1 (func (import "" "f") (result i32))) (core instance (instantiate $m1 (with "" (instance (export "f" (func $f1)))))) - ;; func(x: u32) - (import "f2" (func $f2 (param "x" u32))) + ;; async func(x: u32) + (import "f2" (func $f2 async (param "x" u32))) (core func $f2 (canon lower (func $f2) async)) (core module $m2 (func (import "" "f") (param i32) (result i32))) (core instance (instantiate $m2 (with "" (instance (export "f" (func $f2)))))) - ;; func() -> u32 - (import "f3" (func $f3 (result u32))) + ;; async func() -> u32 + (import "f3" (func $f3 async (result u32))) (core func $f3 (canon lower (func $f3) async (memory $libc "memory"))) (core module $m3 (func (import "" "f") (param i32) (result i32))) (core instance (instantiate $m3 (with "" (instance (export "f" (func $f3)))))) - ;; func(x: u32, y: f32, z: string) - (import "f4" (func $f4 (param "x" u32) (param "y" f32) (param "z" string))) + ;; async func(x: u32, y: f32, z: string) + (import "f4" (func $f4 async (param "x" u32) (param "y" f32) (param "z" string))) (core func $f4 (canon lower (func $f4) async (memory $libc "memory"))) (core module $m4 (func (import "" "f") (param i32 f32 i32 i32) (result i32))) (core instance (instantiate $m4 (with "" (instance (export "f" (func $f4)))))) - ;; func() -> f32 - (import "f5" (func $f5 (result f32))) + ;; async func() -> f32 + (import "f5" (func $f5 async (result f32))) (core func $f5 (canon lower (func $f5) async (memory $libc "memory"))) (core module $m5 (func (import "" "f") (param i32) (result i32))) (core instance (instantiate $m5 (with "" (instance (export "f" (func $f5)))))) - ;; func(x: list) -> f32 - (import "f6" (func $f6 (param "x" (list string 6)) (result f32))) + ;; async func(x: list) -> f32 + (import "f6" (func $f6 async (param "x" (list string 6)) (result f32))) (core func $f6 (canon lower (func $f6) async (memory $libc "memory"))) (core module $m6 (func (import "" "f") (param i32 i32) (result i32))) (core instance (instantiate $m6 (with "" (instance (export "f" (func $f6)))))) @@ -44,68 +44,68 @@ ;; async lift, callback abi (component - ;; func() + ;; async func() (core module $m1 (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "f") (result i32) unreachable)) (core instance $m1 (instantiate $m1)) - (func + (func async (canon lift (core func $m1 "f") async (callback (func $m1 "cb")))) - ;; func(x: u32) + ;; async func(x: u32) (core module $m2 (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "f") (param i32) (result i32) unreachable)) (core instance $m2 (instantiate $m2)) - (func (param "x" u32) + (func async (param "x" u32) (canon lift (core func $m2 "f") async (callback (func $m2 "cb")))) - ;; func() -> u32 + ;; async func() -> u32 (core module $m3 (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "f") (result i32) unreachable)) (core instance $m3 (instantiate $m3)) - (func (result u32) + (func async (result u32) (canon lift (core func $m3 "f") async (callback (func $m3 "cb")))) - ;; func(x: f32) + ;; async func(x: f32) (core module $m4 (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "f") (param f32) (result i32) unreachable)) (core instance $m4 (instantiate $m4)) - (func (param "x" f32) + (func async (param "x" f32) (canon lift (core func $m4 "f") async (callback (func $m4 "cb")))) - ;; func(x: f32, y: string) + ;; async func(x: f32, y: string) (core module $m5 (memory (export "memory") 1) (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param f32 i32 i32) (result i32) unreachable)) (core instance $m5 (instantiate $m5)) - (func (param "x" f32) (param "y" string) + (func async (param "x" f32) (param "y" string) (canon lift (core func $m5 "f") async (callback (func $m5 "cb")) (memory $m5 "memory") (realloc (func $m5 "realloc")))) - ;; func(x: list) + ;; async func(x: list) (core module $m6 (memory (export "memory") 1) (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param i32 i32 i32 i32 i32 i32 i32 i32) (result i32) unreachable)) (core instance $m6 (instantiate $m6)) - (func (param "x" (list string 4)) + (func async (param "x" (list string 4)) (canon lift (core func $m6 "f") async (callback (func $m6 "cb")) (memory $m6 "memory") (realloc (func $m6 "realloc")))) - ;; func(x: list) + ;; async func(x: list) (core module $m7 (memory (export "memory") 1) (func (export "cb") (param i32 i32 i32) (result i32) unreachable) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param i32) (result i32) unreachable)) (core instance $m7 (instantiate $m7)) - (func (param "x" (list string 10)) + (func async (param "x" (list string 10)) (canon lift (core func $m7 "f") async (callback (func $m7 "cb")) (memory $m7 "memory") (realloc (func $m7 "realloc")))) ) diff --git a/tests/cli/component-model/async/lift.wast b/tests/cli/component-model/async/lift.wast index 2f2d80fba6..800f4797b5 100644 --- a/tests/cli/component-model/async/lift.wast +++ b/tests/cli/component-model/async/lift.wast @@ -24,7 +24,7 @@ ) (core instance $i (instantiate $m)) - (func (export "foo") (param "p1" u32) (result u32) + (func (export "foo") async (param "p1" u32) (result u32) (canon lift (core func $i "foo") async (callback (func $i "callback"))) ) ) @@ -71,7 +71,7 @@ ) (core instance $i (instantiate $m)) - (func (export "foo") (param "p1" u32) (result u32) + (func (export "foo") async (param "p1" u32) (result u32) (canon lift (core func $i "foo") async (callback (func $i "callback"))) ) ) @@ -118,7 +118,7 @@ ) (core instance $i (instantiate $m)) - (func (export "foo") (result string) + (func (export "foo") async (result string) (canon lift (core func $i "foo") async (callback (func $i "callback"))) ) ) @@ -134,9 +134,23 @@ ) (core instance $i (instantiate $m)) - (func (export "foo") (result (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) + (func (export "foo") async (result (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32)) (canon lift (core func $i "foo") async (callback (func $i "callback"))) ) ) "canonical option `memory` is required" ) + +;; `async` option requires as `async` function type +(assert_invalid + (component + (core module $m + (func (export "callback") (param i32 i32 i32) (result i32) unreachable) + (func (export "foo") (result i32) unreachable) + ) + (core instance $i (instantiate $m)) + + (func (canon lift (core func $i "foo") async (callback (func $i "callback")))) + ) + "the `async` canonical option requires an async function type" +) diff --git a/tests/cli/component-model/async/lower.wast b/tests/cli/component-model/async/lower.wast index fd4730775a..3d1a7b618d 100644 --- a/tests/cli/component-model/async/lower.wast +++ b/tests/cli/component-model/async/lower.wast @@ -2,7 +2,7 @@ ;; async lower (component - (import "foo" (func $foo (param "p1" u32) (result u32))) + (import "foo" (func $foo async (param "p1" u32) (result u32))) (core module $libc (memory (export "memory") 1)) (core instance $libc (instantiate $libc)) (core func $foo (canon lower (func $foo) async (memory $libc "memory"))) @@ -15,7 +15,7 @@ ;; async lower; with incorrectly-typed core function (assert_invalid (component - (import "foo" (func $foo (param "p1" u32) (result u32))) + (import "foo" (func $foo async (param "p1" u32) (result u32))) (core module $libc (memory (export "memory") 1)) (core instance $libc (instantiate $libc)) (core func $foo (canon lower (func $foo) async (memory $libc "memory"))) @@ -30,7 +30,7 @@ ;; async lower; missing memory (assert_invalid (component - (import "foo" (func $foo (param "p1" u32) (result u32))) + (import "foo" (func $foo async (param "p1" u32) (result u32))) (core func $foo (canon lower (func $foo) async)) (core module $m (func (import "" "foo") (param i32) (result i32)) @@ -39,3 +39,12 @@ ) "canonical option `memory` is required" ) + +;; `async` option requires as `async` function type +(assert_invalid + (component + (import "foo" (func $foo)) + (core func $foo (canon lower (func $foo) async)) + ) + "the `async` canonical option requires an async function type" +) diff --git a/tests/cli/component-model/async/stackful.wast b/tests/cli/component-model/async/stackful.wast index bc6688531f..ed4f8b6dde 100644 --- a/tests/cli/component-model/async/stackful.wast +++ b/tests/cli/component-model/async/stackful.wast @@ -73,61 +73,61 @@ ;; async lift, stackful abi (component - ;; func() + ;; async func() (core module $m1 (func (export "f") unreachable)) (core instance $m1 (instantiate $m1)) - (func + (func async (canon lift (core func $m1 "f") async)) - ;; func(x: u32) + ;; async func(x: u32) (core module $m2 (func (export "f") (param i32) unreachable)) (core instance $m2 (instantiate $m2)) - (func (param "x" u32) + (func async (param "x" u32) (canon lift (core func $m2 "f") async)) - ;; func() -> u32 + ;; async func() -> u32 (core module $m3 (func (export "f") unreachable)) (core instance $m3 (instantiate $m3)) - (func (result u32) + (func async (result u32) (canon lift (core func $m3 "f") async)) - ;; func(x: f32) + ;; async func(x: f32) (core module $m4 (func (export "f") (param f32) unreachable)) (core instance $m4 (instantiate $m4)) - (func (param "x" f32) + (func async (param "x" f32) (canon lift (core func $m4 "f") async)) - ;; func(x: f32, y: string) + ;; async func(x: f32, y: string) (core module $m5 (memory (export "memory") 1) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param f32 i32 i32) unreachable)) (core instance $m5 (instantiate $m5)) - (func (param "x" f32) (param "y" string) + (func async (param "x" f32) (param "y" string) (canon lift (core func $m5 "f") async (memory $m5 "memory") (realloc (func $m5 "realloc")))) - ;; func(x: list) + ;; async func(x: list) (core module $m6 (memory (export "memory") 1) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param i32 i32 i32 i32 i32 i32 i32 i32) unreachable)) (core instance $m6 (instantiate $m6)) - (func (param "x" (list string 4)) + (func async (param "x" (list string 4)) (canon lift (core func $m6 "f") async (memory $m6 "memory") (realloc (func $m6 "realloc")))) - ;; func(x: list) + ;; async func(x: list) (core module $m7 (memory (export "memory") 1) (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) (func (export "f") (param i32) unreachable)) (core instance $m7 (instantiate $m7)) - (func (param "x" (list string 10)) + (func async (param "x" (list string 10)) (canon lift (core func $m7 "f") async (memory $m7 "memory") (realloc (func $m7 "realloc")))) ) @@ -139,7 +139,7 @@ ) (core instance $i (instantiate $m)) - (func (export "foo") (param "p1" u32) (result u32) + (func (export "foo") async (param "p1" u32) (result u32) (canon lift (core func $i "foo") async) ) ) diff --git a/tests/snapshots/cli/component-model/async/abi.wast/0.print b/tests/snapshots/cli/component-model/async/abi.wast/0.print index 1f2caa6b3e..a1a00ff129 100644 --- a/tests/snapshots/cli/component-model/async/abi.wast/0.print +++ b/tests/snapshots/cli/component-model/async/abi.wast/0.print @@ -4,7 +4,7 @@ (export "memory" (memory 0)) ) (core instance $libc (;0;) (instantiate $libc)) - (type (;0;) (func)) + (type (;0;) (func async)) (import "f1" (func $f1 (;0;) (type 0))) (core func $f1 (;0;) (canon lower (func $f1) async)) (core module $m1 (;1;) @@ -18,7 +18,7 @@ (with "" (instance 1)) ) ) - (type (;1;) (func (param "x" u32))) + (type (;1;) (func async (param "x" u32))) (import "f2" (func $f2 (;1;) (type 1))) (core func $f2 (;1;) (canon lower (func $f2) async)) (core module $m2 (;2;) @@ -32,7 +32,7 @@ (with "" (instance 3)) ) ) - (type (;2;) (func (result u32))) + (type (;2;) (func async (result u32))) (import "f3" (func $f3 (;2;) (type 2))) (alias core export $libc "memory" (core memory (;0;))) (core func $f3 (;2;) (canon lower (func $f3) async (memory 0))) @@ -47,7 +47,7 @@ (with "" (instance 5)) ) ) - (type (;3;) (func (param "x" u32) (param "y" f32) (param "z" string))) + (type (;3;) (func async (param "x" u32) (param "y" f32) (param "z" string))) (import "f4" (func $f4 (;3;) (type 3))) (alias core export $libc "memory" (core memory (;1;))) (core func $f4 (;3;) (canon lower (func $f4) async (memory 1))) @@ -62,7 +62,7 @@ (with "" (instance 7)) ) ) - (type (;4;) (func (result f32))) + (type (;4;) (func async (result f32))) (import "f5" (func $f5 (;4;) (type 4))) (alias core export $libc "memory" (core memory (;2;))) (core func $f5 (;4;) (canon lower (func $f5) async (memory 2))) @@ -78,7 +78,7 @@ ) ) (type (;5;) (list string 6)) - (type (;6;) (func (param "x" 5) (result f32))) + (type (;6;) (func async (param "x" 5) (result f32))) (import "f6" (func $f6 (;5;) (type 6))) (alias core export $libc "memory" (core memory (;3;))) (core func $f6 (;5;) (canon lower (func $f6) async (memory 3))) diff --git a/tests/snapshots/cli/component-model/async/abi.wast/1.print b/tests/snapshots/cli/component-model/async/abi.wast/1.print index 08815a75a2..78fc5b6dd5 100644 --- a/tests/snapshots/cli/component-model/async/abi.wast/1.print +++ b/tests/snapshots/cli/component-model/async/abi.wast/1.print @@ -12,7 +12,7 @@ ) ) (core instance $m1 (;0;) (instantiate $m1)) - (type (;0;) (func)) + (type (;0;) (func async)) (alias core export $m1 "f" (core func (;0;))) (alias core export $m1 "cb" (core func (;1;))) (func (;0;) (type 0) (canon lift (core func 0) async (callback 1))) @@ -29,7 +29,7 @@ ) ) (core instance $m2 (;1;) (instantiate $m2)) - (type (;1;) (func (param "x" u32))) + (type (;1;) (func async (param "x" u32))) (alias core export $m2 "f" (core func (;2;))) (alias core export $m2 "cb" (core func (;3;))) (func (;1;) (type 1) (canon lift (core func 2) async (callback 3))) @@ -46,7 +46,7 @@ ) ) (core instance $m3 (;2;) (instantiate $m3)) - (type (;2;) (func (result u32))) + (type (;2;) (func async (result u32))) (alias core export $m3 "f" (core func (;4;))) (alias core export $m3 "cb" (core func (;5;))) (func (;2;) (type 2) (canon lift (core func 4) async (callback 5))) @@ -63,7 +63,7 @@ ) ) (core instance $m4 (;3;) (instantiate $m4)) - (type (;3;) (func (param "x" f32))) + (type (;3;) (func async (param "x" f32))) (alias core export $m4 "f" (core func (;6;))) (alias core export $m4 "cb" (core func (;7;))) (func (;3;) (type 3) (canon lift (core func 6) async (callback 7))) @@ -87,7 +87,7 @@ ) ) (core instance $m5 (;4;) (instantiate $m5)) - (type (;4;) (func (param "x" f32) (param "y" string))) + (type (;4;) (func async (param "x" f32) (param "y" string))) (alias core export $m5 "f" (core func (;8;))) (alias core export $m5 "cb" (core func (;9;))) (alias core export $m5 "memory" (core memory (;0;))) @@ -114,7 +114,7 @@ ) (core instance $m6 (;5;) (instantiate $m6)) (type (;5;) (list string 4)) - (type (;6;) (func (param "x" 5))) + (type (;6;) (func async (param "x" 5))) (alias core export $m6 "f" (core func (;11;))) (alias core export $m6 "cb" (core func (;12;))) (alias core export $m6 "memory" (core memory (;1;))) @@ -141,7 +141,7 @@ ) (core instance $m7 (;6;) (instantiate $m7)) (type (;7;) (list string 10)) - (type (;8;) (func (param "x" 7))) + (type (;8;) (func async (param "x" 7))) (alias core export $m7 "f" (core func (;14;))) (alias core export $m7 "cb" (core func (;15;))) (alias core export $m7 "memory" (core memory (;2;))) diff --git a/tests/snapshots/cli/component-model/async/lift.wast.json b/tests/snapshots/cli/component-model/async/lift.wast.json index 3f0237f713..1f18fb1f69 100644 --- a/tests/snapshots/cli/component-model/async/lift.wast.json +++ b/tests/snapshots/cli/component-model/async/lift.wast.json @@ -62,6 +62,13 @@ "filename": "lift.8.wasm", "module_type": "binary", "text": "canonical option `memory` is required" + }, + { + "type": "assert_invalid", + "line": 146, + "filename": "lift.9.wasm", + "module_type": "binary", + "text": "the `async` canonical option requires an async function type" } ] } \ No newline at end of file diff --git a/tests/snapshots/cli/component-model/async/lift.wast/1.print b/tests/snapshots/cli/component-model/async/lift.wast/1.print index 4a323d62df..0878f9a43c 100644 --- a/tests/snapshots/cli/component-model/async/lift.wast/1.print +++ b/tests/snapshots/cli/component-model/async/lift.wast/1.print @@ -12,7 +12,7 @@ ) ) (core instance $i (;0;) (instantiate $m)) - (type (;0;) (func (param "p1" u32) (result u32))) + (type (;0;) (func async (param "p1" u32) (result u32))) (alias core export $i "foo" (core func (;0;))) (alias core export $i "callback" (core func (;1;))) (func (;0;) (type 0) (canon lift (core func 0) async (callback 1))) diff --git a/tests/snapshots/cli/component-model/async/lower.wast.json b/tests/snapshots/cli/component-model/async/lower.wast.json index 1510e5b382..8b81c47eed 100644 --- a/tests/snapshots/cli/component-model/async/lower.wast.json +++ b/tests/snapshots/cli/component-model/async/lower.wast.json @@ -20,6 +20,13 @@ "filename": "lower.2.wasm", "module_type": "binary", "text": "canonical option `memory` is required" + }, + { + "type": "assert_invalid", + "line": 45, + "filename": "lower.3.wasm", + "module_type": "binary", + "text": "the `async` canonical option requires an async function type" } ] } \ No newline at end of file diff --git a/tests/snapshots/cli/component-model/async/lower.wast/0.print b/tests/snapshots/cli/component-model/async/lower.wast/0.print index fee9919556..7bc33ebe3f 100644 --- a/tests/snapshots/cli/component-model/async/lower.wast/0.print +++ b/tests/snapshots/cli/component-model/async/lower.wast/0.print @@ -1,5 +1,5 @@ (component - (type (;0;) (func (param "p1" u32) (result u32))) + (type (;0;) (func async (param "p1" u32) (result u32))) (import "foo" (func $foo (;0;) (type 0))) (core module $libc (;0;) (memory (;0;) 1) diff --git a/tests/snapshots/cli/component-model/async/stackful.wast/6.print b/tests/snapshots/cli/component-model/async/stackful.wast/6.print index 83f4c93847..23aef68447 100644 --- a/tests/snapshots/cli/component-model/async/stackful.wast/6.print +++ b/tests/snapshots/cli/component-model/async/stackful.wast/6.print @@ -7,7 +7,7 @@ ) ) (core instance $m1 (;0;) (instantiate $m1)) - (type (;0;) (func)) + (type (;0;) (func async)) (alias core export $m1 "f" (core func (;0;))) (func (;0;) (type 0) (canon lift (core func 0) async)) (core module $m2 (;1;) @@ -18,7 +18,7 @@ ) ) (core instance $m2 (;1;) (instantiate $m2)) - (type (;1;) (func (param "x" u32))) + (type (;1;) (func async (param "x" u32))) (alias core export $m2 "f" (core func (;1;))) (func (;1;) (type 1) (canon lift (core func 1) async)) (core module $m3 (;2;) @@ -29,7 +29,7 @@ ) ) (core instance $m3 (;2;) (instantiate $m3)) - (type (;2;) (func (result u32))) + (type (;2;) (func async (result u32))) (alias core export $m3 "f" (core func (;2;))) (func (;2;) (type 2) (canon lift (core func 2) async)) (core module $m4 (;3;) @@ -40,7 +40,7 @@ ) ) (core instance $m4 (;3;) (instantiate $m4)) - (type (;3;) (func (param "x" f32))) + (type (;3;) (func async (param "x" f32))) (alias core export $m4 "f" (core func (;3;))) (func (;3;) (type 3) (canon lift (core func 3) async)) (core module $m5 (;4;) @@ -58,7 +58,7 @@ ) ) (core instance $m5 (;4;) (instantiate $m5)) - (type (;4;) (func (param "x" f32) (param "y" string))) + (type (;4;) (func async (param "x" f32) (param "y" string))) (alias core export $m5 "f" (core func (;4;))) (alias core export $m5 "memory" (core memory (;0;))) (alias core export $m5 "realloc" (core func (;5;))) @@ -79,7 +79,7 @@ ) (core instance $m6 (;5;) (instantiate $m6)) (type (;5;) (list string 4)) - (type (;6;) (func (param "x" 5))) + (type (;6;) (func async (param "x" 5))) (alias core export $m6 "f" (core func (;6;))) (alias core export $m6 "memory" (core memory (;1;))) (alias core export $m6 "realloc" (core func (;7;))) @@ -100,7 +100,7 @@ ) (core instance $m7 (;6;) (instantiate $m7)) (type (;7;) (list string 10)) - (type (;8;) (func (param "x" 7))) + (type (;8;) (func async (param "x" 7))) (alias core export $m7 "f" (core func (;8;))) (alias core export $m7 "memory" (core memory (;2;))) (alias core export $m7 "realloc" (core func (;9;))) diff --git a/tests/snapshots/cli/component-model/async/stackful.wast/7.print b/tests/snapshots/cli/component-model/async/stackful.wast/7.print index 854ce4d60f..0cb863e0db 100644 --- a/tests/snapshots/cli/component-model/async/stackful.wast/7.print +++ b/tests/snapshots/cli/component-model/async/stackful.wast/7.print @@ -7,7 +7,7 @@ ) ) (core instance $i (;0;) (instantiate $m)) - (type (;0;) (func (param "p1" u32) (result u32))) + (type (;0;) (func async (param "p1" u32) (result u32))) (alias core export $i "foo" (core func (;0;))) (func (;0;) (type 0) (canon lift (core func 0) async)) (export (;1;) "foo" (func 0))