Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions crates/wit-component/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 10 additions & 10 deletions crates/wit-component/tests/components/async-export/component.wat
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,44 @@
(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)))
(type (;4;) (record (field "a1" 3) (field "a2" 3) (field "a3" 3) (field "a4" 3)))
(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))
(type (;11;) (record (field "a1" 10) (field "a2" 10) (field "a3" 10) (field "a4" 10)))
(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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
(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)))
)
)
(import "foo:foo/bar" (instance $foo:foo/bar (;0;) (type $ty-foo:foo/bar)))
(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)))
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package root:component;

world root {
import foo:foo/bar;
import foo: func(x: future<future<u32>>, y: u32) -> stream<string>;
import foo: async func(x: future<future<u32>>, y: u32) -> stream<string>;

export foo: func(x: future<future<u32>>, y: u32) -> stream<string>;
export foo: async func(x: future<future<u32>>, y: u32) -> stream<string>;
export foo:foo/bar;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package foo:foo;

interface bar {
foo: func(x: future<future<u32>>, y: u32) -> stream<string>;
foo: async func(x: future<future<u32>>, y: u32) -> stream<string>;
}

world module {
import bar;
import foo: func(x: future<future<u32>>, y: u32) -> stream<string>;
import foo: async func(x: future<future<u32>>, y: u32) -> stream<string>;
export bar;
export foo: func(x: future<future<u32>>, y: u32) -> stream<string>;
export foo: async func(x: future<future<u32>>, y: u32) -> stream<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package root:component;

world root {
export foo: func(s: string);
export foo: async func(s: string);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package foo:foo;

world module {
export foo: func(s: string);
export foo: async func(s: string);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions crates/wit-component/tests/components/threading/module.wit
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Loading