Skip to content

Commit 6e9164c

Browse files
authored
[wit-component] fix task.return name matching (#1979)
`wit-bingen` emits world-level `task.return` imports using a module name of "[export]$root", but `wit-component` was expecting just "$root". This updates `wit-component` to match what `wit-bindgen` emits. Signed-off-by: Joel Dice <[email protected]>
1 parent ad33634 commit 6e9164c

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

crates/wit-component/src/validation.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,6 @@ impl ImportMap {
621621
});
622622
}
623623

624-
if let Some(import) = async_import_for_export(None)? {
625-
return Ok(import);
626-
}
627-
628624
let key = WorldKey::Name(name.to_string());
629625
if let Some(WorldItem::Function(func)) = world.imports.get(&key) {
630626
validate_func(resolve, ty, func, abi)?;
@@ -646,6 +642,15 @@ impl ImportMap {
646642
}
647643
}
648644

645+
if matches!(
646+
module.strip_prefix(names.import_exported_intrinsic_prefix()),
647+
Some(module) if module == names.import_root()
648+
) {
649+
if let Some(import) = async_import_for_export(None)? {
650+
return Ok(import);
651+
}
652+
}
653+
649654
let interface = match module.strip_prefix(names.import_non_root_prefix()) {
650655
Some(name) => name,
651656
None => bail!("unknown or invalid component model import syntax"),

crates/wit-component/tests/components/async-builtins/component.wat

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(type (;4;) (func (param i32 i32) (result i32)))
88
(type (;5;) (func (param i32 i32 i32 i32) (result i32)))
99
(import "$root" "[task-backpressure]" (func (;0;) (type 0)))
10-
(import "$root" "[task-return]foo" (func (;1;) (type 1)))
10+
(import "[export]$root" "[task-return]foo" (func (;1;) (type 1)))
1111
(import "[export]foo:foo/bar" "[task-return]foo" (func (;2;) (type 1)))
1212
(import "$root" "[task-wait]" (func (;3;) (type 2)))
1313
(import "$root" "[task-poll]" (func (;4;) (type 2)))
@@ -87,60 +87,63 @@
8787
)
8888
(core instance (;0;) (instantiate 1))
8989
(core func (;0;) (canon task.backpressure))
90-
(core type (;0;) (func (param i32 i32)))
91-
(core func (;1;) (canon task.return 0))
92-
(alias core export 0 "0" (core func (;2;)))
93-
(alias core export 0 "1" (core func (;3;)))
94-
(core func (;4;) (canon task.yield))
95-
(core func (;5;) (canon subtask.drop))
96-
(alias core export 0 "2" (core func (;6;)))
97-
(alias core export 0 "3" (core func (;7;)))
98-
(core func (;8;) (canon error-context.drop))
90+
(alias core export 0 "0" (core func (;1;)))
91+
(alias core export 0 "1" (core func (;2;)))
92+
(core func (;3;) (canon task.yield))
93+
(core func (;4;) (canon subtask.drop))
94+
(alias core export 0 "2" (core func (;5;)))
95+
(alias core export 0 "3" (core func (;6;)))
96+
(core func (;7;) (canon error-context.drop))
9997
(core instance (;1;)
10098
(export "[task-backpressure]" (func 0))
101-
(export "[task-return]foo" (func 1))
102-
(export "[task-wait]" (func 2))
103-
(export "[task-poll]" (func 3))
104-
(export "[task-yield]" (func 4))
105-
(export "[subtask-drop]" (func 5))
106-
(export "[error-context-new;encoding=utf8]" (func 6))
107-
(export "[error-context-debug-message;encoding=utf8;realloc=cabi_realloc]" (func 7))
108-
(export "[error-context-drop]" (func 8))
99+
(export "[task-wait]" (func 1))
100+
(export "[task-poll]" (func 2))
101+
(export "[task-yield]" (func 3))
102+
(export "[subtask-drop]" (func 4))
103+
(export "[error-context-new;encoding=utf8]" (func 5))
104+
(export "[error-context-debug-message;encoding=utf8;realloc=cabi_realloc]" (func 6))
105+
(export "[error-context-drop]" (func 7))
106+
)
107+
(core type (;0;) (func (param i32 i32)))
108+
(core func (;8;) (canon task.return 0))
109+
(core instance (;2;)
110+
(export "[task-return]foo" (func 8))
109111
)
110112
(core type (;1;) (func (param i32 i32)))
111113
(core func (;9;) (canon task.return 1))
112-
(core instance (;2;)
114+
(core instance (;3;)
113115
(export "[task-return]foo" (func 9))
114116
)
115-
(core instance (;3;) (instantiate 0
117+
(core instance (;4;) (instantiate 0
116118
(with "$root" (instance 1))
117-
(with "[export]foo:foo/bar" (instance 2))
119+
(with "[export]$root" (instance 2))
120+
(with "[export]foo:foo/bar" (instance 3))
118121
)
119122
)
120-
(alias core export 3 "memory" (core memory (;0;)))
123+
(alias core export 4 "memory" (core memory (;0;)))
121124
(alias core export 0 "$imports" (core table (;0;)))
122125
(core func (;10;) (canon task.wait (memory 0)))
123126
(core func (;11;) (canon task.poll (memory 0)))
124127
(core func (;12;) (canon error-context.new (memory 0) string-encoding=utf8))
125-
(alias core export 3 "cabi_realloc" (core func (;13;)))
128+
(alias core export 4 "cabi_realloc" (core func (;13;)))
126129
(core func (;14;) (canon error-context.debug-message (memory 0) (realloc 13) string-encoding=utf8))
127-
(core instance (;4;)
130+
(core instance (;5;)
128131
(export "$imports" (table 0))
129132
(export "0" (func 10))
130133
(export "1" (func 11))
131134
(export "2" (func 12))
132135
(export "3" (func 14))
133136
)
134-
(core instance (;5;) (instantiate 2
135-
(with "" (instance 4))
137+
(core instance (;6;) (instantiate 2
138+
(with "" (instance 5))
136139
)
137140
)
138141
(type (;0;) (func (param "s" string) (result string)))
139-
(alias core export 3 "[async-stackful]foo" (core func (;15;)))
142+
(alias core export 4 "[async-stackful]foo" (core func (;15;)))
140143
(func (;0;) (type 0) (canon lift (core func 15) (memory 0) (realloc 13) string-encoding=utf8 async))
141144
(export (;1;) "foo" (func 0))
142145
(type (;1;) (func (param "s" string) (result string)))
143-
(alias core export 3 "[async-stackful]foo:foo/bar#foo" (core func (;16;)))
146+
(alias core export 4 "[async-stackful]foo:foo/bar#foo" (core func (;16;)))
144147
(func (;2;) (type 1) (canon lift (core func 16) (memory 0) (realloc 13) string-encoding=utf8 async))
145148
(component (;0;)
146149
(type (;0;) (func (param "s" string) (result string)))

crates/wit-component/tests/components/async-builtins/module.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
22
(import "$root" "[task-backpressure]" (func (param i32)))
3-
(import "$root" "[task-return]foo" (func (param i32 i32)))
3+
(import "[export]$root" "[task-return]foo" (func (param i32 i32)))
44
(import "[export]foo:foo/bar" "[task-return]foo" (func (param i32 i32)))
55
(import "$root" "[task-wait]" (func (param i32) (result i32)))
66
(import "$root" "[task-poll]" (func (param i32) (result i32)))

0 commit comments

Comments
 (0)