Skip to content
Merged
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/gen-guest-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ impl Generator for C {
}

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

Expand Down Expand Up @@ -1053,7 +1052,6 @@ impl Generator for C {
}

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

Expand Down
103 changes: 0 additions & 103 deletions crates/gen-guest-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ impl Generator for RustWasm {
fn import(&mut self, iface: &Interface, func: &Function) {
let mut sig = FnSig::default();
let param_mode = TypeMode::AllBorrowed("'_");
sig.async_ = func.is_async;
match &func.kind {
FunctionKind::Freestanding => {}
FunctionKind::Static { resource, .. } | FunctionKind::Method { resource, .. } => {
Expand Down Expand Up @@ -579,10 +578,6 @@ impl Generator for RustWasm {
self.src.push_str("::*;\n");
}

if func.is_async {
self.src.push_str("let future = async move {\n");
}

let mut f = FunctionBindgen::new(self, params);
iface.call(
AbiVariant::GuestExport,
Expand All @@ -597,18 +592,12 @@ impl Generator for RustWasm {
} = f;
assert!(!needs_cleanup_list);
self.src.push_str(&String::from(src));
if func.is_async {
self.src.push_str("};\n");
self.src
.push_str("wit_bindgen_guest_rust::rt::execute(Box::pin(future));\n");
}
self.src.push_str("}\n");

let prev = mem::take(&mut self.src);
self.in_trait = true;
let mut sig = FnSig::default();
sig.private = true;
sig.async_ = func.is_async;
match &func.kind {
FunctionKind::Freestanding => {}
FunctionKind::Static { .. } => sig.use_item_name = true,
Expand Down Expand Up @@ -659,11 +648,7 @@ impl Generator for RustWasm {
fn finish_one(&mut self, iface: &Interface, files: &mut Files) {
let mut src = mem::take(&mut self.src);

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

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

Instruction::CallWasmAsyncImport {
iface,
name,
params: wasm_params,
results: wasm_results,
} => {
// The first thing we do here is define the completion callback
// which the host will invoke when the asynchronous call
// actually finishes. This receives our own custom state
// parameter as the first parameter which is the `Sender`
// converted to a `usize`. Afterwards it receives all the
// results which we'll transfer ove the `sender`, the canonical
// ABI of the results.
self.push_str("unsafe extern \"C\" fn completion_callback(sender: usize");
for (i, result) in wasm_results.iter().enumerate() {
self.push_str(", ");
self.push_str(&format!("ret{}: ", i));
self.push_str(wasm_type(*result));
}
self.push_str(") {\n");
self.push_str("wit_bindgen_guest_rust::rt::Sender::from_usize(sender).send((");
for i in 0..wasm_results.len() {
self.push_str(&format!("ret{},", i));
}
self.push_str("));\n");
self.push_str("}\n");

// Next we create the future channel which will be used to track
// the state of this import. The "oneshot" here means that the
// sender (`tx`) will send something once over `rx`. The type of
// the `Oneshot` is the type of the `wasm_results` which is the
// canonical ABI of the results that this function produces.
self.push_str("let (rx, tx) = wit_bindgen_guest_rust::rt::Oneshot::<(");
for ty in *wasm_results {
self.push_str(wasm_type(*ty));
self.push_str(", ");
}
self.push_str(")>::new();\n");

// Then we can actually call the function now that we have
// all the parameters. The first parameters to the import are
// the canonical ABI `operands` we were provided, and the last
// two arguments are our completion callback and the context for
// the callback, our `tx` sender.
let func = self.declare_import(iface, name, wasm_params, &[]);
self.push_str(&func);
self.push_str("(");
for op in operands {
self.push_str(op);
self.push_str(", ");
}
self.push_str("completion_callback as i32, ");
self.push_str("tx.into_usize() as i32");
self.push_str(");\n");

// And finally we want to "appear synchronous" with an async
// function, so we immediately `.await` the results of the
// oneshot. This binds all the canonical ABI results to then get
// translated in further instructions to the result of this
// function call.
let tmp = self.tmp();
self.push_str("let (");
for i in 0..wasm_results.len() {
let name = format!("ret{}_{}", tmp, i);
self.push_str(&name);
self.push_str(",");
results.push(name);
}
self.push_str(") = rx.await;\n");
}

Instruction::CallWasmAsyncExport { .. } => unreachable!(),

Instruction::CallInterface { module, func } => {
self.push_str("let result = ");
results.push("result".to_string());
Expand Down Expand Up @@ -1573,9 +1482,6 @@ impl Bindgen for FunctionBindgen<'_> {
}
self.push_str(&operands.join(", "));
self.push_str(")");
if func.is_async {
self.push_str(".await");
}
self.push_str(";\n");
}

Expand All @@ -1595,15 +1501,6 @@ impl Bindgen for FunctionBindgen<'_> {
}
}

Instruction::ReturnAsyncExport { .. } => {
self.emit_cleanup();
self.push_str(&format!(
"wit_bindgen_guest_rust::rt::async_export_done({}, {});\n",
operands[0], operands[1]
));
}
Instruction::ReturnAsyncImport { .. } => unreachable!(),

Instruction::I32Load { offset } => {
results.push(format!("*(({} + {}) as *const i32)", operands[0], offset));
}
Expand Down
10 changes: 0 additions & 10 deletions crates/gen-guest-spidermonkey-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,6 @@ impl Generator for SpiderMonkeyWasm<'_> {
}

fn import(&mut self, iface: &Interface, func: &Function) {
assert!(!func.is_async, "async not supported yet");

// Add the raw Wasm import.
let wasm_sig = iface.wasm_signature(AbiVariant::GuestImport, func);
let type_index = self.intern_type(wasm_sig.clone());
Expand Down Expand Up @@ -1087,8 +1085,6 @@ impl Generator for SpiderMonkeyWasm<'_> {
}

fn export(&mut self, iface: &Interface, func: &Function) {
assert!(!func.is_async, "async not supported yet");

let wasm_sig = iface.wasm_signature(AbiVariant::GuestExport, func);
let type_index = self.intern_type(wasm_sig.clone());
let export_fn_index = self.wit_export(self.exports.len());
Expand Down Expand Up @@ -2112,9 +2108,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
// []
}

abi::Instruction::CallWasmAsyncExport { .. } => todo!(),
abi::Instruction::CallWasmAsyncImport { .. } => todo!(),

abi::Instruction::Return { func, amt } => {
match self.lift_lower {
abi::LiftLower::LowerArgsLiftResults => {
Expand Down Expand Up @@ -2192,9 +2185,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
abi::Instruction::I32FromBool { .. } => todo!(),
abi::Instruction::BoolFromI32 { .. } => todo!(),

abi::Instruction::ReturnAsyncExport { .. } => todo!(),
abi::Instruction::ReturnAsyncImport { .. } => todo!(),

abi::Instruction::Malloc { .. } => todo!(),
abi::Instruction::Free { .. } => todo!(),
}
Expand Down
Loading