Skip to content

Commit

Permalink
fix: re-export async_support in rt
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Jan 21, 2025
1 parent 629ced7 commit 2a14d1f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
3 changes: 3 additions & 0 deletions crates/guest-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,5 +877,8 @@ pub mod rt {
#[cfg(all(feature = "realloc", not(target_env = "p2")))]
pub use wit_bindgen_rt::cabi_realloc;

#[cfg(feature = "async")]
pub use wit_bindgen_rt::async_support;

pub use crate::pre_wit_bindgen_0_20_0::*;
}
12 changes: 6 additions & 6 deletions crates/rust/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}

Instruction::FutureLift { payload, .. } => {
let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
let op = &operands[0];
let name = payload
.as_ref()
Expand All @@ -504,7 +504,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}

Instruction::StreamLift { payload, .. } => {
let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
let op = &operands[0];
let name = self
.gen
Expand All @@ -523,7 +523,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}

Instruction::ErrorContextLift { .. } => {
let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
let op = &operands[0];
results.push(format!(
"{async_support}::ErrorContext::from_handle({op} as u32)"
Expand Down Expand Up @@ -869,7 +869,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Instruction::AsyncCallWasm { name, size, align } => {
let func = self.declare_import(name, &[WasmType::Pointer; 2], &[WasmType::I32]);

let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
let tmp = self.tmp();
let layout = format!("layout{tmp}");
let alloc = self.gen.path_to_std_alloc_module();
Expand Down Expand Up @@ -906,7 +906,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
.unwrap()
.to_upper_camel_case();
let call = if self.async_ {
let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
format!("{async_support}::futures::FutureExt::map(T::new")
} else {
format!("{ty}::new(T::new",)
Expand Down Expand Up @@ -975,7 +975,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
} else {
params
};
let async_support = self.gen.path_to_async_support();
let async_support = self.gen.path_to_async_module();
// TODO: This relies on `abi::Generator` emitting
// `AsyncCallReturn` immediately after this instruction to
// complete the incomplete expression we generate here. We
Expand Down
20 changes: 10 additions & 10 deletions crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ macro_rules! {macro_name} {{
.unwrap_or_else(|| "$root".into())
);
let func_name = &func.name;
let async_support = self.path_to_async_support();
let async_support = self.path_to_async_module();

match &self.resolve.types[ty].kind {
TypeDefKind::Future(payload_type) => {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ pub mod vtable{ordinal} {{
self.src.push_str("}\n");

if async_ {
let async_support = self.path_to_async_support();
let async_support = self.path_to_async_module();
uwrite!(
self.src,
"\
Expand Down Expand Up @@ -2513,8 +2513,8 @@ pub mod vtable{ordinal} {{
self.path_from_runtime_module(RuntimeItem::StdAllocModule, "alloc")
}

pub fn path_to_async_support(&mut self) -> String {
"::wit_bindgen_rt::async_support".into()
pub fn path_to_async_module(&mut self) -> String {
self.path_from_runtime_module(RuntimeItem::AsyncModule, "async_support")
}

fn path_from_runtime_module(
Expand Down Expand Up @@ -2837,7 +2837,7 @@ impl<'a> {camel}Borrow<'a>{{
}

fn type_future(&mut self, _id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
let async_support = self.path_to_async_support();
let async_support = self.path_to_async_module();
let mode = TypeMode {
style: TypeOwnershipStyle::Owned,
lists_borrowed: false,
Expand All @@ -2854,7 +2854,7 @@ impl<'a> {camel}Borrow<'a>{{
}

fn type_stream(&mut self, _id: TypeId, name: &str, ty: &Type, docs: &Docs) {
let async_support = self.path_to_async_support();
let async_support = self.path_to_async_module();
let mode = TypeMode {
style: TypeOwnershipStyle::Owned,
lists_borrowed: false,
Expand All @@ -2871,7 +2871,7 @@ impl<'a> {camel}Borrow<'a>{{
}

fn type_error_context(&mut self, _id: TypeId, name: &str, docs: &Docs) {
let async_support = self.path_to_async_support();
let async_support = self.path_to_async_module();
self.rustdoc(docs);
self.push_str(&format!("pub type {} = ", name.to_upper_camel_case()));
self.push_str(&format!("{async_support}::ErrorContext"));
Expand Down Expand Up @@ -2967,7 +2967,7 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator<
}

fn anonymous_type_future(&mut self, _id: TypeId, ty: &Option<Type>, _docs: &Docs) {
let async_support = self.interface.path_to_async_support();
let async_support = self.interface.path_to_async_module();
let mode = TypeMode {
style: TypeOwnershipStyle::Owned,
lists_borrowed: false,
Expand All @@ -2980,7 +2980,7 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator<
}

fn anonymous_type_stream(&mut self, _id: TypeId, ty: &Type, _docs: &Docs) {
let async_support = self.interface.path_to_async_support();
let async_support = self.interface.path_to_async_module();
let mode = TypeMode {
style: TypeOwnershipStyle::Owned,
lists_borrowed: false,
Expand All @@ -2993,7 +2993,7 @@ impl<'a, 'b> wit_bindgen_core::AnonymousTypeGenerator<'a> for AnonTypeGenerator<
}

fn anonymous_type_error_context(&mut self) {
let async_support = self.interface.path_to_async_support();
let async_support = self.interface.path_to_async_module();
self.interface
.push_str(&format!("{async_support}::ErrorContext"));
}
Expand Down
26 changes: 14 additions & 12 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum RuntimeItem {
AsF64,
ResourceType,
BoxType,
AsyncModule,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -463,7 +464,7 @@ pub mod wit_future {
#[doc(hidden)]
pub trait FuturePayload: Unpin + Sized + 'static {
fn new() -> (u32, &'static ::wit_bindgen_rt::async_support::FutureVtable<Self>);
fn new() -> (u32, &'static super::async_support::FutureVtable<Self>);
}",
);
for code in self.future_payloads.values() {
Expand All @@ -472,17 +473,17 @@ pub mod wit_future {
self.src.push_str(
"\
/// Creates a new Component Model `future` with the specified payload type.
pub fn new<T: FuturePayload>() -> (::wit_bindgen_rt::async_support::FutureWriter<T>, ::wit_bindgen_rt::async_support::FutureReader<T>) {
pub fn new<T: FuturePayload>() -> (super::async_support::FutureWriter<T>, super::async_support::FutureReader<T>) {
let (handle, vtable) = T::new();
::wit_bindgen_rt::async_support::with_entry(handle, |entry| match entry {
super::async_support::with_entry(handle, |entry| match entry {
::std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(::wit_bindgen_rt::async_support::Handle::LocalOpen);
entry.insert(super::async_support::Handle::LocalOpen);
}
::std::collections::hash_map::Entry::Occupied(_) => unreachable!(),
});
(
::wit_bindgen_rt::async_support::FutureWriter::new(handle, vtable),
::wit_bindgen_rt::async_support::FutureReader::new(handle, vtable),
super::async_support::FutureWriter::new(handle, vtable),
super::async_support::FutureReader::new(handle, vtable),
)
}
}
Expand All @@ -497,7 +498,7 @@ pub mod wit_stream {
#![allow(dead_code, unused_variables, clippy::all)]
pub trait StreamPayload: Unpin + Sized + 'static {
fn new() -> (u32, &'static ::wit_bindgen_rt::async_support::StreamVtable<Self>);
fn new() -> (u32, &'static super::async_support::StreamVtable<Self>);
}",
);
for code in self.stream_payloads.values() {
Expand All @@ -506,17 +507,17 @@ pub mod wit_stream {
self.src.push_str(
"\
/// Creates a new Component Model `stream` with the specified payload type.
pub fn new<T: StreamPayload>() -> (::wit_bindgen_rt::async_support::StreamWriter<T>, ::wit_bindgen_rt::async_support::StreamReader<T>) {
pub fn new<T: StreamPayload>() -> (super::async_support::StreamWriter<T>, super::async_support::StreamReader<T>) {
let (handle, vtable) = T::new();
::wit_bindgen_rt::async_support::with_entry(handle, |entry| match entry {
super::async_support::with_entry(handle, |entry| match entry {
::std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(::wit_bindgen_rt::async_support::Handle::LocalOpen);
entry.insert(super::async_support::Handle::LocalOpen);
}
::std::collections::hash_map::Entry::Occupied(_) => unreachable!(),
});
(
::wit_bindgen_rt::async_support::StreamWriter::new(handle, vtable),
::wit_bindgen_rt::async_support::StreamReader::new(handle, vtable),
super::async_support::StreamWriter::new(handle, vtable),
super::async_support::StreamReader::new(handle, vtable),
)
}
}
Expand Down Expand Up @@ -754,6 +755,7 @@ impl<T: WasmResource> Drop for Resource<T> {
"#,
);
}
RuntimeItem::AsyncModule => {}
}
}

Expand Down

0 comments on commit 2a14d1f

Please sign in to comment.