Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable warnings if async is disabled #10145

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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