Skip to content

Commit facc992

Browse files
authored
Enable warnings if async is disabled (bytecodealliance#10145)
* Enable warnings if `async` is disabled Continuation of work in bytecodealliance#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
1 parent 7ebb78a commit facc992

File tree

12 files changed

+806
-781
lines changed

12 files changed

+806
-781
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ jobs:
541541
os: ubuntu-latest
542542
test: >
543543
cargo check -p wasmtime --no-default-features --features runtime,component-model &&
544-
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model &&
544+
cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async &&
545545
cargo check -p cranelift-control --no-default-features &&
546546
cargo check -p pulley-interpreter --features encode,decode,disas,interp &&
547547
cargo check -p wasmtime-wasi-io --no-default-features
@@ -573,7 +573,7 @@ jobs:
573573
# A no_std target without 64-bit atomics
574574
- target: riscv32imac-unknown-none-elf
575575
os: ubuntu-latest
576-
test: cargo check -p wasmtime --no-default-features --features runtime,gc,component-model
576+
test: cargo check -p wasmtime --no-default-features --features runtime,gc,component-model,async
577577
env: ${{ matrix.env || fromJSON('{}') }}
578578
steps:
579579
- uses: actions/checkout@v4

crates/wasmtime/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@
285285
// here to get warnings in all configurations of Wasmtime.
286286
#![cfg_attr(
287287
any(
288-
not(feature = "async"),
289288
not(feature = "gc"),
290289
not(feature = "gc-drc"),
291290
not(feature = "gc-null"),

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::hash_map::HashMap;
99
use crate::prelude::*;
1010
use crate::{AsContextMut, Engine, Module, StoreContextMut};
1111
use alloc::sync::Arc;
12-
use core::future::Future;
1312
use core::marker;
14-
use core::pin::Pin;
13+
#[cfg(feature = "async")]
14+
use core::{future::Future, pin::Pin};
1515
use wasmtime_environ::component::{NameMap, NameMapIntern};
1616
use wasmtime_environ::PrimaryMap;
1717

@@ -433,8 +433,8 @@ impl<T> LinkerInstance<'_, T> {
433433
);
434434
let ff = move |mut store: StoreContextMut<'_, T>, params: Params| -> Result<Return> {
435435
let async_cx = store.as_context_mut().0.async_cx().expect("async cx");
436-
let mut future = Pin::from(f(store.as_context_mut(), params));
437-
unsafe { async_cx.block_on(future.as_mut()) }?
436+
let future = f(store.as_context_mut(), params);
437+
unsafe { async_cx.block_on(Pin::from(future)) }?
438438
};
439439
self.func_wrap(name, ff)
440440
}
@@ -604,8 +604,8 @@ impl<T> LinkerInstance<'_, T> {
604604
);
605605
let ff = move |mut store: StoreContextMut<'_, T>, params: &[Val], results: &mut [Val]| {
606606
let async_cx = store.as_context_mut().0.async_cx().expect("async cx");
607-
let mut future = Pin::from(f(store.as_context_mut(), params, results));
608-
unsafe { async_cx.block_on(future.as_mut()) }?
607+
let future = f(store.as_context_mut(), params, results);
608+
unsafe { async_cx.block_on(Pin::from(future)) }?
609609
};
610610
self.func_new(name, ff)
611611
}
@@ -676,8 +676,8 @@ impl<T> LinkerInstance<'_, T> {
676676
&self.engine,
677677
move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| {
678678
let async_cx = cx.as_context_mut().0.async_cx().expect("async cx");
679-
let mut future = Pin::from(dtor(cx.as_context_mut(), param));
680-
match unsafe { async_cx.block_on(future.as_mut()) } {
679+
let future = dtor(cx.as_context_mut(), param);
680+
match unsafe { async_cx.block_on(Pin::from(future)) } {
681681
Ok(Ok(())) => Ok(()),
682682
Ok(Err(trap)) | Err(trap) => Err(trap),
683683
}

crates/wasmtime/src/runtime/func.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use crate::{
1212
};
1313
use alloc::sync::Arc;
1414
use core::ffi::c_void;
15-
use core::future::Future;
1615
use core::mem::{self, MaybeUninit};
1716
use core::num::NonZeroUsize;
18-
use core::pin::Pin;
1917
use core::ptr::NonNull;
18+
#[cfg(feature = "async")]
19+
use core::{future::Future, pin::Pin};
2020
use wasmtime_environ::VMSharedTypeIndex;
2121

2222
/// A reference to the abstract `nofunc` heap value.
@@ -563,8 +563,8 @@ impl Func {
563563
.0
564564
.async_cx()
565565
.expect("Attempt to spawn new action on dying fiber");
566-
let mut future = Pin::from(func(caller, params, results));
567-
match unsafe { async_cx.block_on(future.as_mut()) } {
566+
let future = func(caller, params, results);
567+
match unsafe { async_cx.block_on(Pin::from(future)) } {
568568
Ok(Ok(())) => Ok(()),
569569
Ok(Err(trap)) | Err(trap) => Err(trap),
570570
}
@@ -838,6 +838,7 @@ impl Func {
838838
}
839839
}
840840

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

886-
match unsafe { async_cx.block_on(future.as_mut()) } {
887+
match unsafe { async_cx.block_on(Pin::from(future)) } {
887888
Ok(ret) => ret.into_fallible(),
888889
Err(e) => R::fallible_from_error(e),
889890
}

crates/wasmtime/src/runtime/linker.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ use crate::store::StoreOpaque;
55
use crate::{prelude::*, IntoFunc};
66
use crate::{
77
AsContext, AsContextMut, Caller, Engine, Extern, ExternType, Func, FuncType, ImportType,
8-
Instance, Module, StoreContextMut, Val, ValRaw, ValType, WasmTyList,
8+
Instance, Module, StoreContextMut, Val, ValRaw, ValType,
99
};
1010
use alloc::sync::Arc;
1111
use core::fmt;
12-
#[cfg(feature = "async")]
13-
use core::future::Future;
1412
use core::marker;
1513
#[cfg(feature = "async")]
16-
use core::pin::Pin;
14+
use core::{future::Future, pin::Pin};
1715
use log::warn;
1816

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

544542
/// Asynchronous analog of [`Linker::func_wrap`].
545543
#[cfg(feature = "async")]
546-
pub fn func_wrap_async<F, Params: WasmTyList, Args: crate::WasmRet>(
544+
pub fn func_wrap_async<F, Params: crate::WasmTyList, Args: crate::WasmRet>(
547545
&mut self,
548546
module: &str,
549547
name: &str,
@@ -568,8 +566,8 @@ impl<T> Linker<T> {
568566
.0
569567
.async_cx()
570568
.expect("Attempt to start async function on dying fiber");
571-
let mut future = Pin::from(func(caller, args));
572-
match unsafe { async_cx.block_on(future.as_mut()) } {
569+
let future = func(caller, args);
570+
match unsafe { async_cx.block_on(Pin::from(future)) } {
573571
Ok(ret) => ret.into_fallible(),
574572
Err(e) => Args::fallible_from_error(e),
575573
}

0 commit comments

Comments
 (0)