Skip to content

Commit 89612da

Browse files
committed
Account for concurrent resource destructors
This fixes a minor merge conflict between bytecodealliance#11325 and bytecodealliance#11328 which isn't currently exercised by in-repo WASI bindings but will be soon once wasip3-prototyping is finished merging.
1 parent 53c99a3 commit 89612da

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

crates/wit-bindgen/src/config.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,7 @@ impl FunctionConfig {
102102
resource_name: &str,
103103
) -> FunctionFlags {
104104
let mut ret = FunctionFlags::empty();
105-
106105
self.add_function_flags(resolve, ns, &format!("[drop]{resource_name}"), &mut ret);
107-
108-
// FIXME: this currently isn't supported and fools the rest of the
109-
// bindings generation to thinking a `*WithStore` trait is needed when
110-
// it isn't, so forcibly remove it. This'll need updating after #11325.
111-
ret.remove(FunctionFlags::STORE);
112-
113106
ret
114107
}
115108

crates/wit-bindgen/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ impl Wasmtime {
15281528
move |caller: &{wt}::component::Accessor::<T>, rep| {{
15291529
{wt}::component::__internal::Box::pin(async move {{
15301530
let accessor = &caller.with_data(host_getter);
1531-
Host{camel}Concurrent::drop(accessor, {wt}::component::Resource::new_own(rep)).await
1531+
Host{camel}WithStore::drop(accessor, {wt}::component::Resource::new_own(rep)).await
15321532
}})
15331533
}},
15341534
)?;"
@@ -2892,6 +2892,7 @@ impl<'a> InterfaceGenerator<'a> {
28922892
);
28932893
ret.with_store_name = Some(format!("{trait_name}WithStore"));
28942894

2895+
let mut extra_with_store_function = false;
28952896
for extra in extra_functions {
28962897
match extra {
28972898
ExtraTraitMethod::ResourceDrop { name } => {
@@ -2907,6 +2908,7 @@ impl<'a> InterfaceGenerator<'a> {
29072908
self.src,
29082909
"fn drop<T: 'static>(accessor: &{wt}::component::Accessor<T, Self>, rep: {wt}::component::Resource<{camel}>) -> impl ::core::future::Future<Output = {wt}::Result<()>> + Send where Self: Sized;"
29092910
);
2911+
extra_with_store_function = true;
29102912
}
29112913
ExtraTraitMethod::ErrorConvert { .. } => {}
29122914
}
@@ -2920,7 +2922,7 @@ impl<'a> InterfaceGenerator<'a> {
29202922

29212923
// If `*WithStore` is empty, generate a blanket impl for the trait since
29222924
// it's otherwise not necessary to implement it manually.
2923-
if partition.with_store.is_empty() {
2925+
if partition.with_store.is_empty() && !extra_with_store_function {
29242926
uwriteln!(self.src, "impl<_T: ?Sized> {trait_name}WithStore for _T");
29252927
uwriteln!(
29262928
self.src,
@@ -2945,13 +2947,12 @@ impl<'a> InterfaceGenerator<'a> {
29452947
for extra in extra_functions {
29462948
match extra {
29472949
ExtraTraitMethod::ResourceDrop { name } => {
2948-
let camel = name.to_upper_camel_case();
2949-
29502950
let flags = self.import_resource_drop_flags(name);
29512951
ret.all_func_flags |= flags;
29522952
if flags.contains(FunctionFlags::STORE) {
29532953
continue;
29542954
}
2955+
let camel = name.to_upper_camel_case();
29552956
uwrite!(
29562957
self.src,
29572958
"fn drop(&mut self, rep: {wt}::component::Resource<{camel}>) -> "
@@ -3020,6 +3021,9 @@ fn convert_{snake}(&mut self, err: {root}{custom_name}) -> {wt}::Result<{camel}>
30203021
match extra {
30213022
ExtraTraitMethod::ResourceDrop { name } => {
30223023
let flags = self.import_resource_drop_flags(name);
3024+
if flags.contains(FunctionFlags::STORE) {
3025+
continue;
3026+
}
30233027
let camel = name.to_upper_camel_case();
30243028
let mut await_ = "";
30253029
if flags.contains(FunctionFlags::ASYNC) {

0 commit comments

Comments
 (0)