Skip to content

Commit f1682df

Browse files
authored
Remove async func support. (#307)
* Remove `async func` support. The `async` keyword has been removed from the [async proposal], in favor of using plain functions that with `future` or `stream` types. See also the [component-model PR to remove the syntax]. This removes the (now) old `async func` suppport from wit-bindgen, to make it easier to develop the current Canonical ABI proposal. [async proposal]: https://docs.google.com/presentation/d/1MNVOZ8hdofO3tI0szg_i-Yoy0N2QPU2C--LzVuoGSlE/edit#slide=id.g1270ef7d5b6_0_111 [component-model PR to remove the syntax]: WebAssembly/component-model#98 * Remove support for the `async` checkbox in wit-bindgen-demo.
1 parent 28ad389 commit f1682df

File tree

36 files changed

+99
-1297
lines changed

36 files changed

+99
-1297
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gen-guest-c/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ impl Generator for C {
977977
}
978978

979979
fn import(&mut self, iface: &Interface, func: &Function) {
980-
assert!(!func.is_async, "async not supported yet");
981980
let prev = mem::take(&mut self.src);
982981
let sig = iface.wasm_signature(AbiVariant::GuestImport, func);
983982

@@ -1053,7 +1052,6 @@ impl Generator for C {
10531052
}
10541053

10551054
fn export(&mut self, iface: &Interface, func: &Function) {
1056-
assert!(!func.is_async, "async not supported yet");
10571055
let prev = mem::take(&mut self.src);
10581056
let sig = iface.wasm_signature(AbiVariant::GuestExport, func);
10591057

crates/gen-guest-rust/src/lib.rs

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ impl Generator for RustWasm {
478478
fn import(&mut self, iface: &Interface, func: &Function) {
479479
let mut sig = FnSig::default();
480480
let param_mode = TypeMode::AllBorrowed("'_");
481-
sig.async_ = func.is_async;
482481
match &func.kind {
483482
FunctionKind::Freestanding => {}
484483
FunctionKind::Static { resource, .. } | FunctionKind::Method { resource, .. } => {
@@ -579,10 +578,6 @@ impl Generator for RustWasm {
579578
self.src.push_str("::*;\n");
580579
}
581580

582-
if func.is_async {
583-
self.src.push_str("let future = async move {\n");
584-
}
585-
586581
let mut f = FunctionBindgen::new(self, params);
587582
iface.call(
588583
AbiVariant::GuestExport,
@@ -597,18 +592,12 @@ impl Generator for RustWasm {
597592
} = f;
598593
assert!(!needs_cleanup_list);
599594
self.src.push_str(&String::from(src));
600-
if func.is_async {
601-
self.src.push_str("};\n");
602-
self.src
603-
.push_str("wit_bindgen_guest_rust::rt::execute(Box::pin(future));\n");
604-
}
605595
self.src.push_str("}\n");
606596

607597
let prev = mem::take(&mut self.src);
608598
self.in_trait = true;
609599
let mut sig = FnSig::default();
610600
sig.private = true;
611-
sig.async_ = func.is_async;
612601
match &func.kind {
613602
FunctionKind::Freestanding => {}
614603
FunctionKind::Static { .. } => sig.use_item_name = true,
@@ -659,11 +648,7 @@ impl Generator for RustWasm {
659648
fn finish_one(&mut self, iface: &Interface, files: &mut Files) {
660649
let mut src = mem::take(&mut self.src);
661650

662-
let any_async = iface.functions.iter().any(|f| f.is_async);
663651
for (name, trait_) in self.traits.iter() {
664-
if any_async {
665-
src.push_str("#[wit_bindgen_guest_rust::async_trait(?Send)]\n");
666-
}
667652
src.push_str("pub trait ");
668653
src.push_str(&name);
669654
src.push_str(" {\n");
@@ -674,9 +659,6 @@ impl Generator for RustWasm {
674659
src.push_str("}\n");
675660

676661
for (id, methods) in trait_.resource_methods.iter() {
677-
if any_async {
678-
src.push_str("#[wit_bindgen_guest_rust::async_trait(?Send)]\n");
679-
}
680662
src.push_str(&format!(
681663
"pub trait {} {{\n",
682664
iface.resources[*id].name.to_camel_case()
@@ -1465,79 +1447,6 @@ impl Bindgen for FunctionBindgen<'_> {
14651447
self.push_str(");\n");
14661448
}
14671449

1468-
Instruction::CallWasmAsyncImport {
1469-
iface,
1470-
name,
1471-
params: wasm_params,
1472-
results: wasm_results,
1473-
} => {
1474-
// The first thing we do here is define the completion callback
1475-
// which the host will invoke when the asynchronous call
1476-
// actually finishes. This receives our own custom state
1477-
// parameter as the first parameter which is the `Sender`
1478-
// converted to a `usize`. Afterwards it receives all the
1479-
// results which we'll transfer ove the `sender`, the canonical
1480-
// ABI of the results.
1481-
self.push_str("unsafe extern \"C\" fn completion_callback(sender: usize");
1482-
for (i, result) in wasm_results.iter().enumerate() {
1483-
self.push_str(", ");
1484-
self.push_str(&format!("ret{}: ", i));
1485-
self.push_str(wasm_type(*result));
1486-
}
1487-
self.push_str(") {\n");
1488-
self.push_str("wit_bindgen_guest_rust::rt::Sender::from_usize(sender).send((");
1489-
for i in 0..wasm_results.len() {
1490-
self.push_str(&format!("ret{},", i));
1491-
}
1492-
self.push_str("));\n");
1493-
self.push_str("}\n");
1494-
1495-
// Next we create the future channel which will be used to track
1496-
// the state of this import. The "oneshot" here means that the
1497-
// sender (`tx`) will send something once over `rx`. The type of
1498-
// the `Oneshot` is the type of the `wasm_results` which is the
1499-
// canonical ABI of the results that this function produces.
1500-
self.push_str("let (rx, tx) = wit_bindgen_guest_rust::rt::Oneshot::<(");
1501-
for ty in *wasm_results {
1502-
self.push_str(wasm_type(*ty));
1503-
self.push_str(", ");
1504-
}
1505-
self.push_str(")>::new();\n");
1506-
1507-
// Then we can actually call the function now that we have
1508-
// all the parameters. The first parameters to the import are
1509-
// the canonical ABI `operands` we were provided, and the last
1510-
// two arguments are our completion callback and the context for
1511-
// the callback, our `tx` sender.
1512-
let func = self.declare_import(iface, name, wasm_params, &[]);
1513-
self.push_str(&func);
1514-
self.push_str("(");
1515-
for op in operands {
1516-
self.push_str(op);
1517-
self.push_str(", ");
1518-
}
1519-
self.push_str("completion_callback as i32, ");
1520-
self.push_str("tx.into_usize() as i32");
1521-
self.push_str(");\n");
1522-
1523-
// And finally we want to "appear synchronous" with an async
1524-
// function, so we immediately `.await` the results of the
1525-
// oneshot. This binds all the canonical ABI results to then get
1526-
// translated in further instructions to the result of this
1527-
// function call.
1528-
let tmp = self.tmp();
1529-
self.push_str("let (");
1530-
for i in 0..wasm_results.len() {
1531-
let name = format!("ret{}_{}", tmp, i);
1532-
self.push_str(&name);
1533-
self.push_str(",");
1534-
results.push(name);
1535-
}
1536-
self.push_str(") = rx.await;\n");
1537-
}
1538-
1539-
Instruction::CallWasmAsyncExport { .. } => unreachable!(),
1540-
15411450
Instruction::CallInterface { module, func } => {
15421451
self.push_str("let result = ");
15431452
results.push("result".to_string());
@@ -1573,9 +1482,6 @@ impl Bindgen for FunctionBindgen<'_> {
15731482
}
15741483
self.push_str(&operands.join(", "));
15751484
self.push_str(")");
1576-
if func.is_async {
1577-
self.push_str(".await");
1578-
}
15791485
self.push_str(";\n");
15801486
}
15811487

@@ -1595,15 +1501,6 @@ impl Bindgen for FunctionBindgen<'_> {
15951501
}
15961502
}
15971503

1598-
Instruction::ReturnAsyncExport { .. } => {
1599-
self.emit_cleanup();
1600-
self.push_str(&format!(
1601-
"wit_bindgen_guest_rust::rt::async_export_done({}, {});\n",
1602-
operands[0], operands[1]
1603-
));
1604-
}
1605-
Instruction::ReturnAsyncImport { .. } => unreachable!(),
1606-
16071504
Instruction::I32Load { offset } => {
16081505
results.push(format!("*(({} + {}) as *const i32)", operands[0], offset));
16091506
}

crates/gen-guest-spidermonkey-js/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,6 @@ impl Generator for SpiderMonkeyWasm<'_> {
10501050
}
10511051

10521052
fn import(&mut self, iface: &Interface, func: &Function) {
1053-
assert!(!func.is_async, "async not supported yet");
1054-
10551053
// Add the raw Wasm import.
10561054
let wasm_sig = iface.wasm_signature(AbiVariant::GuestImport, func);
10571055
let type_index = self.intern_type(wasm_sig.clone());
@@ -1087,8 +1085,6 @@ impl Generator for SpiderMonkeyWasm<'_> {
10871085
}
10881086

10891087
fn export(&mut self, iface: &Interface, func: &Function) {
1090-
assert!(!func.is_async, "async not supported yet");
1091-
10921088
let wasm_sig = iface.wasm_signature(AbiVariant::GuestExport, func);
10931089
let type_index = self.intern_type(wasm_sig.clone());
10941090
let export_fn_index = self.wit_export(self.exports.len());
@@ -2112,9 +2108,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
21122108
// []
21132109
}
21142110

2115-
abi::Instruction::CallWasmAsyncExport { .. } => todo!(),
2116-
abi::Instruction::CallWasmAsyncImport { .. } => todo!(),
2117-
21182111
abi::Instruction::Return { func, amt } => {
21192112
match self.lift_lower {
21202113
abi::LiftLower::LowerArgsLiftResults => {
@@ -2192,9 +2185,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
21922185
abi::Instruction::I32FromBool { .. } => todo!(),
21932186
abi::Instruction::BoolFromI32 { .. } => todo!(),
21942187

2195-
abi::Instruction::ReturnAsyncExport { .. } => todo!(),
2196-
abi::Instruction::ReturnAsyncImport { .. } => todo!(),
2197-
21982188
abi::Instruction::Malloc { .. } => todo!(),
21992189
abi::Instruction::Free { .. } => todo!(),
22002190
}

0 commit comments

Comments
 (0)