Skip to content

Commit

Permalink
Enable warnings if async is disabled (#10145)
Browse files Browse the repository at this point in the history
* Enable warnings if `async` is disabled

Continuation of work in #10131.

This required a number of organizational changes to help cut down on
`#[cfg]`, notably lots of async-related pieces from `store.rs` have
moved to `store/async_.rs` to avoid having lots of conditional imports.
Additionally this removes all of the `#[cfg]` annotations on those
methods already.

Additionally the signature of `AsyncCx::block_on` was updated to be a
bit more general to ideally remove the need for `Pin` but it ended up
not panning out quite just yet. In the future it should be possible to
remove the need for `Pin` at callsites though.

* Rebase conflicts
  • Loading branch information
alexcrichton authored Jan 29, 2025
1 parent 7ebb78a commit facc992
Show file tree
Hide file tree
Showing 12 changed files with 806 additions and 781 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ jobs:
os: ubuntu-latest
test: >
cargo check -p wasmtime --no-default-features --features runtime,component-model &&
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model &&
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async &&
cargo check -p cranelift-control --no-default-features &&
cargo check -p pulley-interpreter --features encode,decode,disas,interp &&
cargo check -p wasmtime-wasi-io --no-default-features
Expand Down Expand Up @@ -573,7 +573,7 @@ jobs:
# A no_std target without 64-bit atomics
- target: riscv32imac-unknown-none-elf
os: ubuntu-latest
test: cargo check -p wasmtime --no-default-features --features runtime,gc,component-model
test: cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async
env: ${{ matrix.env || fromJSON('{}') }}
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion crates/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@
// here to get warnings in all configurations of Wasmtime.
#![cfg_attr(
any(
not(feature = "async"),
not(feature = "gc"),
not(feature = "gc-drc"),
not(feature = "gc-null"),
Expand Down
16 changes: 8 additions & 8 deletions crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::hash_map::HashMap;
use crate::prelude::*;
use crate::{AsContextMut, Engine, Module, StoreContextMut};
use alloc::sync::Arc;
use core::future::Future;
use core::marker;
use core::pin::Pin;
#[cfg(feature = "async")]
use core::{future::Future, pin::Pin};
use wasmtime_environ::component::{NameMap, NameMapIntern};
use wasmtime_environ::PrimaryMap;

Expand Down Expand Up @@ -433,8 +433,8 @@ impl<T> LinkerInstance<'_, T> {
);
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 mut future = Pin::from(f(store.as_context_mut(), params));
unsafe { async_cx.block_on(future.as_mut()) }?
let future = f(store.as_context_mut(), params);
unsafe { async_cx.block_on(Pin::from(future)) }?
};
self.func_wrap(name, ff)
}
Expand Down Expand Up @@ -604,8 +604,8 @@ impl<T> LinkerInstance<'_, T> {
);
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 mut future = Pin::from(f(store.as_context_mut(), params, results));
unsafe { async_cx.block_on(future.as_mut()) }?
let future = f(store.as_context_mut(), params, results);
unsafe { async_cx.block_on(Pin::from(future)) }?
};
self.func_new(name, ff)
}
Expand Down Expand Up @@ -676,8 +676,8 @@ impl<T> LinkerInstance<'_, T> {
&self.engine,
move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| {
let async_cx = cx.as_context_mut().0.async_cx().expect("async cx");
let mut future = Pin::from(dtor(cx.as_context_mut(), param));
match unsafe { async_cx.block_on(future.as_mut()) } {
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),
}
Expand Down
13 changes: 7 additions & 6 deletions crates/wasmtime/src/runtime/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::{
};
use alloc::sync::Arc;
use core::ffi::c_void;
use core::future::Future;
use core::mem::{self, MaybeUninit};
use core::num::NonZeroUsize;
use core::pin::Pin;
use core::ptr::NonNull;
#[cfg(feature = "async")]
use core::{future::Future, pin::Pin};
use wasmtime_environ::VMSharedTypeIndex;

/// A reference to the abstract `nofunc` heap value.
Expand Down Expand Up @@ -563,8 +563,8 @@ impl Func {
.0
.async_cx()
.expect("Attempt to spawn new action on dying fiber");
let mut future = Pin::from(func(caller, params, results));
match unsafe { async_cx.block_on(future.as_mut()) } {
let future = func(caller, params, results);
match unsafe { async_cx.block_on(Pin::from(future)) } {
Ok(Ok(())) => Ok(()),
Ok(Err(trap)) | Err(trap) => Err(trap),
}
Expand Down Expand Up @@ -838,6 +838,7 @@ impl Func {
}
}

#[cfg(feature = "async")]
fn wrap_inner<F, T, Params, Results>(mut store: impl AsContextMut<Data = T>, func: F) -> Func
where
F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static,
Expand Down Expand Up @@ -881,9 +882,9 @@ impl Func {
.0
.async_cx()
.expect("Attempt to start async function on dying fiber");
let mut future = Pin::from(func(caller, args));
let future = func(caller, args);

match unsafe { async_cx.block_on(future.as_mut()) } {
match unsafe { async_cx.block_on(Pin::from(future)) } {
Ok(ret) => ret.into_fallible(),
Err(e) => R::fallible_from_error(e),
}
Expand Down
16 changes: 7 additions & 9 deletions crates/wasmtime/src/runtime/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use crate::store::StoreOpaque;
use crate::{prelude::*, IntoFunc};
use crate::{
AsContext, AsContextMut, Caller, Engine, Extern, ExternType, Func, FuncType, ImportType,
Instance, Module, StoreContextMut, Val, ValRaw, ValType, WasmTyList,
Instance, Module, StoreContextMut, Val, ValRaw, ValType,
};
use alloc::sync::Arc;
use core::fmt;
#[cfg(feature = "async")]
use core::future::Future;
use core::marker;
#[cfg(feature = "async")]
use core::pin::Pin;
use core::{future::Future, pin::Pin};
use log::warn;

/// Structure used to link wasm modules/instances together.
Expand Down Expand Up @@ -465,8 +463,8 @@ impl<T> Linker<T> {
.0
.async_cx()
.expect("Attempt to spawn new function on dying fiber");
let mut future = Pin::from(func(caller, params, results));
match unsafe { async_cx.block_on(future.as_mut()) } {
let future = func(caller, params, results);
match unsafe { async_cx.block_on(Pin::from(future)) } {
Ok(Ok(())) => Ok(()),
Ok(Err(trap)) | Err(trap) => Err(trap),
}
Expand Down Expand Up @@ -543,7 +541,7 @@ impl<T> Linker<T> {

/// Asynchronous analog of [`Linker::func_wrap`].
#[cfg(feature = "async")]
pub fn func_wrap_async<F, Params: WasmTyList, Args: crate::WasmRet>(
pub fn func_wrap_async<F, Params: crate::WasmTyList, Args: crate::WasmRet>(
&mut self,
module: &str,
name: &str,
Expand All @@ -568,8 +566,8 @@ impl<T> Linker<T> {
.0
.async_cx()
.expect("Attempt to start async function on dying fiber");
let mut future = Pin::from(func(caller, args));
match unsafe { async_cx.block_on(future.as_mut()) } {
let future = func(caller, args);
match unsafe { async_cx.block_on(Pin::from(future)) } {
Ok(ret) => ret.into_fallible(),
Err(e) => Args::fallible_from_error(e),
}
Expand Down
Loading

0 comments on commit facc992

Please sign in to comment.