Skip to content

Commit 6ec0a5f

Browse files
committed
Try to get the rebase passing tests, not working
1 parent 24938f4 commit 6ec0a5f

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

crates/wasmtime/src/runtime/component/func.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,22 @@ impl Func {
290290
store.0.async_support(),
291291
"cannot use `call_async` without enabling async support in the config"
292292
);
293-
store
294-
.on_fiber(|store| self.call_impl(store, params, results))
295-
.await?
293+
#[cfg(feature = "component-model-async")]
294+
{
295+
let future = self.call_concurrent(store.as_context_mut(), params.to_vec());
296+
let run_results = self.instance.run(store, future).await??;
297+
assert_eq!(run_results.len(), results.len());
298+
for (result, slot) in run_results.into_iter().zip(results) {
299+
*slot = result;
300+
}
301+
Ok(())
302+
}
303+
#[cfg(not(feature = "component-model-async"))]
304+
{
305+
store
306+
.on_fiber(|store| self.call_impl(store, params, results))
307+
.await?
308+
}
296309
}
297310

298311
#[cfg(feature = "component-model-async")]

crates/wasmtime/src/runtime/component/func/typed.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,28 @@ where
180180
&self,
181181
mut store: impl AsContextMut<Data: Send>,
182182
params: Params,
183-
) -> Result<Return> {
183+
) -> Result<Return>
184+
where
185+
Params: 'static,
186+
Return: 'static,
187+
{
184188
let mut store = store.as_context_mut();
185189
assert!(
186190
store.0.async_support(),
187191
"cannot use `call_async` when async support is not enabled on the config"
188192
);
189-
store
190-
.on_fiber(|store| self.call_impl(store, params))
191-
.await?
193+
#[cfg(feature = "component-model-async")]
194+
{
195+
let prepared = self.prepare_call(store.as_context_mut(), params)?;
196+
let call = concurrent::queue_call(store.as_context_mut(), prepared)?;
197+
self.func.instance.run(store, call).await?
198+
}
199+
#[cfg(not(feature = "component-model-async"))]
200+
{
201+
store
202+
.on_fiber(|store| self.call_impl(store, params))
203+
.await?
204+
}
192205
}
193206

194207
/// Start a concurrent call to this function.

crates/wit-bindgen/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,10 +2745,10 @@ impl<'a> InterfaceGenerator<'a> {
27452745
func.item_name().to_snake_case(),
27462746
);
27472747

2748-
let param_mode = if let CallStyle::Concurrent = &style {
2749-
TypeMode::Owned
2750-
} else {
2748+
let param_mode = if let CallStyle::Sync = &style {
27512749
TypeMode::AllBorrowed("'_")
2750+
} else {
2751+
TypeMode::Owned
27522752
};
27532753

27542754
for (i, param) in func.params.iter().enumerate() {

examples/resource-component/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ async fn main() -> Result<()> {
138138
let component = Component::from_file(&engine, "target/wasm32-wasip2/debug/guest_kvdb.wasm")?;
139139
let bindings = KvDatabase::instantiate_async(&mut store, &component, &linker).await?;
140140
let result = bindings
141-
.call_replace_value(&mut store, "hello", "world")
141+
.call_replace_value(&mut store, "hello".to_string(), "world".to_string())
142142
.await?;
143143
assert_eq!(result, None);
144144
let result = bindings
145-
.call_replace_value(&mut store, "hello", "wasmtime")
145+
.call_replace_value(&mut store, "hello".to_string(), "wasmtime".to_string())
146146
.await?;
147147
assert_eq!(result, Some("world".to_string()));
148148
Ok(())

0 commit comments

Comments
 (0)