Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07bd52f
generalize async fiber abstraction
dicej Jun 17, 2025
66ce1cd
address review feedback
dicej Jun 24, 2025
ae227b6
fix miri-flagged stacked borrow violation
dicej Jun 24, 2025
8b8ecb1
remove unneeded `Send` bounds
dicej Jun 24, 2025
bd20d14
address more review feedback
dicej Jun 24, 2025
45859eb
address more review feedback
dicej Jun 24, 2025
77d0a80
update `impl Send For StoreFiber` comment
dicej Jun 24, 2025
8a8768e
Remove currently-extraneous `Result<()>` from fibers
alexcrichton Jun 25, 2025
b67b8b8
Use safe pointers instead of raw pointers
alexcrichton Jun 25, 2025
fee87ee
Fold more responsibility into `resume_fiber_raw`
alexcrichton Jun 25, 2025
3de8282
Remove channels from async fibers
alexcrichton Jun 25, 2025
dbc0b7d
Fold `on_fiber_raw` directly into `on_fiber`
alexcrichton Jun 25, 2025
7562905
Don't use `Option` in `FiberFuture`
alexcrichton Jun 25, 2025
b9926c6
Fold `suspend` functions together
alexcrichton Jun 25, 2025
44c96f8
Move stack limit management to `FiberResumeState`
alexcrichton Jun 25, 2025
97e6aef
add some doc comments to `fiber.rs`
dicej Jun 25, 2025
9d95bbb
update `fiber.rs` and friends to match CM async requirements
dicej Jun 25, 2025
8edeb24
fix non-component-model-async build warnings
dicej Jun 25, 2025
3806f68
make `resume_fiber` private in `fiber.rs`
dicej Jun 25, 2025
7afd823
Shrink `PollContext` state
alexcrichton Jun 25, 2025
057a923
Refactor `AsyncCx`, reduce `unsafe`
alexcrichton Jun 25, 2025
2942248
Adjust some lint attributes
alexcrichton Jun 26, 2025
3e92492
Make manipulation of `AsyncState` safe
alexcrichton Jun 26, 2025
f45ea3a
Fix dead code warning
alexcrichton Jun 26, 2025
37630c0
More dead code warnings
alexcrichton Jun 26, 2025
c28dfaa
Cut down on raw pointers in fiber.rs
alexcrichton Jun 26, 2025
8adfffb
Move executor save/restore to normal fiber state save/restore
alexcrichton Jun 26, 2025
141d70e
Bikeshed a method name
alexcrichton Jun 26, 2025
691e58f
update comment in make_fiber
dicej Jun 26, 2025
c3cb184
fix machports build
dicej Jun 26, 2025
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
7 changes: 4 additions & 3 deletions benches/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ fn bench_host_to_wasm<Params, Results>(
typed_params: Params,
typed_results: Results,
) where
Params: WasmParams + ToVals + Copy,
Results: WasmResults + ToVals + Copy + PartialEq + Debug,
Params: WasmParams + ToVals + Copy + Sync,
Results: WasmResults + ToVals + Copy + Sync + PartialEq + Debug + 'static,
{
// Benchmark the "typed" version, which should be faster than the versions
// below.
Expand Down Expand Up @@ -628,7 +628,8 @@ mod component {
+ PartialEq
+ Debug
+ Send
+ Sync,
+ Sync
+ 'static,
{
// Benchmark the "typed" version.
c.bench_function(&format!("component - host-to-wasm - typed - {name}"), |b| {
Expand Down
2 changes: 2 additions & 0 deletions crates/wasmtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub(crate) mod code_memory;
#[cfg(feature = "debug-builtins")]
pub(crate) mod debug;
pub(crate) mod externals;
#[cfg(feature = "async")]
pub(crate) mod fiber;
pub(crate) mod gc;
pub(crate) mod instance;
pub(crate) mod instantiate;
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl Func {
let mut store = store.as_context_mut();
assert!(
store.0.async_support(),
"cannot use `call_async` without enabling async support in the config"
"cannot use `post_return_async` without enabling async support in the config"
);
// Future optimization opportunity: conditionally use a fiber here since
// some func's post_return will not need the async context (i.e. end up
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/func/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ where
) -> Result<Return>
where
Params: Send + Sync,
Return: Send + Sync,
Return: Send + Sync + 'static,
{
let mut store = store.as_context_mut();
assert!(
Expand Down
22 changes: 7 additions & 15 deletions crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,8 @@ impl<T: 'static> LinkerInstance<'_, T> {
self.engine.config().async_support,
"cannot use `func_wrap_async` without enabling async support in the config"
);
let ff = move |mut store: StoreContextMut<'_, T>, params: Params| -> Result<Return> {
let async_cx = store.as_context_mut().0.async_cx().expect("async cx");
let future = f(store.as_context_mut(), params);
unsafe { async_cx.block_on(Pin::from(future)) }?
let ff = move |store: StoreContextMut<'_, T>, params: Params| -> Result<Return> {
store.block_on(|store| f(store, params).into())?
};
self.func_wrap(name, ff)
}
Expand Down Expand Up @@ -603,12 +601,10 @@ impl<T: 'static> LinkerInstance<'_, T> {
self.engine.config().async_support,
"cannot use `func_new_async` without enabling async support in the config"
);
let ff = move |mut store: StoreContextMut<'_, T>, params: &[Val], results: &mut [Val]| {
let async_cx = store.as_context_mut().0.async_cx().expect("async cx");
let future = f(store.as_context_mut(), params, results);
unsafe { async_cx.block_on(Pin::from(future)) }?
let ff = move |store: StoreContextMut<'_, T>, params: &[Val], results: &mut [Val]| {
store.with_blocking(|store, cx| cx.block_on(Pin::from(f(store, params, results)))?)
};
self.func_new(name, ff)
return self.func_new(name, ff);
}

/// Defines a [`Module`] within this instance.
Expand Down Expand Up @@ -676,12 +672,8 @@ impl<T: 'static> LinkerInstance<'_, T> {
let dtor = Arc::new(crate::func::HostFunc::wrap_inner(
&self.engine,
move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| {
let async_cx = cx.as_context_mut().0.async_cx().expect("async cx");
let future = dtor(cx.as_context_mut(), param);
match unsafe { async_cx.block_on(Pin::from(future)) } {
Ok(Ok(())) => Ok(()),
Ok(Err(trap)) | Err(trap) => Err(trap),
}
cx.as_context_mut()
.block_on(|store| dtor(store, param).into())?
},
));
self.insert(name, Definition::Resource(ty, dtor))?;
Expand Down
7 changes: 7 additions & 0 deletions crates/wasmtime/src/runtime/component/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ impl ComponentStoreData {
pub fn next_component_instance_id(&self) -> ComponentInstanceId {
self.instances.next_key()
}

#[cfg(feature = "component-model-async")]
pub(crate) fn drop_fibers(store: &mut StoreOpaque) {
_ = store;
// This function will actually do something when runtime support for
// `component-model-async` is merged.
}
}

impl StoreData {
Expand Down
Loading