Skip to content

Commit 37f05db

Browse files
authored
add [async-lower] prefix to read and write imports (#2371)
I realized that some of my `componentize-py` tests weren't actually testing what they were supposed to, and that was due to the `{stream|future}.{read|write}` intrinsics being lowered synchronously 🤦. This fixes that. Note that we're still lowering the `{stream|future}.cancel-{read|write}` intrinsics synchronously, same as the Rust `wit-bindgen` does. We might need to change that (or make it configurable) for toolchains that actually have a good async cancellation paradigm. Signed-off-by: Joel Dice <[email protected]>
1 parent fac9fb5 commit 37f05db

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

crates/wit-dylib/src/lib.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,49 @@ impl Adapter {
216216
);
217217
let function = func.name.clone();
218218

219-
let import = |me: &mut Self, name, params, results| {
219+
let import = |me: &mut Self, prefix, name, params, results| {
220220
let ty = me.define_ty(params, results);
221-
let import =
222-
me.import_func(&module, &format!("[{kind}-{name}-{ordinal}]{function}"), ty);
221+
let import = me.import_func(
222+
&module,
223+
&format!("{prefix}[{kind}-{name}-{ordinal}]{function}"),
224+
ty,
225+
);
223226
me.push_elem(import)
224227
};
225228

226-
let new_elem_index = import(self, "new", vec![], vec![ValType::I64]);
229+
let new_elem_index = import(self, "", "new", vec![], vec![ValType::I64]);
227230
let read_elem_index = import(
228231
self,
232+
"[async-lower]",
229233
"read",
230234
vec![ValType::I32; arg_count],
231235
vec![ValType::I32],
232236
);
233237
let write_elem_index = import(
234238
self,
239+
"[async-lower]",
235240
"write",
236241
vec![ValType::I32; arg_count],
237242
vec![ValType::I32],
238243
);
239-
let cancel_read_elem_index =
240-
import(self, "cancel-read", vec![ValType::I32], vec![ValType::I32]);
241-
let cancel_write_elem_index =
242-
import(self, "cancel-write", vec![ValType::I32], vec![ValType::I32]);
244+
let cancel_read_elem_index = import(
245+
self,
246+
"",
247+
"cancel-read",
248+
vec![ValType::I32],
249+
vec![ValType::I32],
250+
);
251+
let cancel_write_elem_index = import(
252+
self,
253+
"",
254+
"cancel-write",
255+
vec![ValType::I32],
256+
vec![ValType::I32],
257+
);
243258
let drop_readable_elem_index =
244-
import(self, "drop-readable", vec![ValType::I32], vec![]);
259+
import(self, "", "drop-readable", vec![ValType::I32], vec![]);
245260
let drop_writable_elem_index =
246-
import(self, "drop-writable", vec![ValType::I32], vec![]);
261+
import(self, "", "drop-writable", vec![ValType::I32], vec![]);
247262

248263
PayloadData {
249264
new_elem_index,

0 commit comments

Comments
 (0)