Skip to content

Commit

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

Continuation of work in #10131. This additionally handles turning off
`gc-null` and `gc-drc` and the various combinations within.

* Fix some more warnings

* Fix a feature combo build
  • Loading branch information
alexcrichton authored Jan 30, 2025
1 parent b9d1624 commit a727985
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 118 deletions.
1 change: 1 addition & 0 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,7 @@ impl Default for Collector {
}
}

#[cfg(feature = "gc")]
impl Collector {
fn not_auto(&self) -> Option<Collector> {
match self {
Expand Down
3 changes: 0 additions & 3 deletions crates/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@
// here to get warnings in all configurations of Wasmtime.
#![cfg_attr(
any(
not(feature = "gc"),
not(feature = "gc-drc"),
not(feature = "gc-null"),
not(feature = "cranelift"),
not(feature = "runtime"),
not(feature = "std"),
Expand Down
13 changes: 7 additions & 6 deletions crates/wasmtime/src/runtime/externals/global.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::prelude::*;
use crate::runtime::vm::{GcRootsList, SendSyncPtr};
use crate::{
store::{AutoAssertNoGc, StoreData, StoreOpaque, Stored},
trampoline::generate_global_export,
AnyRef, AsContext, AsContextMut, ExternRef, Func, GlobalType, HeapType, Mutability, Ref,
RootedGcRefImpl, Val, ValType,
};
use core::ptr;
use core::ptr::NonNull;
use wasmtime_environ::TypeTrace;

/// A WebAssembly `global` value which can be read and written to.
Expand Down Expand Up @@ -216,17 +214,20 @@ impl Global {
Ok(())
}

pub(crate) fn trace_root(&self, store: &mut StoreOpaque, gc_roots_list: &mut GcRootsList) {
#[cfg(feature = "gc")]
pub(crate) fn trace_root(
&self,
store: &mut StoreOpaque,
gc_roots_list: &mut crate::runtime::vm::GcRootsList,
) {
if let Some(ref_ty) = self._ty(store).content().as_ref() {
if !ref_ty.is_vmgcref_type_and_points_to_object() {
return;
}

if let Some(gc_ref) = unsafe { store[self.0].definition.as_ref().as_gc_ref() } {
let gc_ref = NonNull::from(gc_ref);
let gc_ref = SendSyncPtr::new(gc_ref);
unsafe {
gc_roots_list.add_root(gc_ref, "Wasm global");
gc_roots_list.add_root(gc_ref.into(), "Wasm global");
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions crates/wasmtime/src/runtime/externals/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::trampoline::generate_table_export;
use crate::vm::ExportTable;
use crate::{AnyRef, AsContext, AsContextMut, ExternRef, Func, HeapType, Ref, TableType};
use core::iter;
use core::ptr::NonNull;
use runtime::{GcRootsList, SendSyncPtr};
use wasmtime_environ::TypeTrace;

/// A WebAssembly `table`, or an array of values.
Expand Down Expand Up @@ -376,7 +374,12 @@ impl Table {
Ok(())
}

pub(crate) fn trace_roots(&self, store: &mut StoreOpaque, gc_roots_list: &mut GcRootsList) {
#[cfg(feature = "gc")]
pub(crate) fn trace_roots(
&self,
store: &mut StoreOpaque,
gc_roots_list: &mut crate::runtime::vm::GcRootsList,
) {
if !self
._ty(store)
.element()
Expand All @@ -388,10 +391,8 @@ impl Table {
let table = self.wasmtime_table(store, iter::empty());
for gc_ref in unsafe { (*table).gc_refs_mut() } {
if let Some(gc_ref) = gc_ref {
let gc_ref = NonNull::from(gc_ref);
let gc_ref = SendSyncPtr::new(gc_ref);
unsafe {
gc_roots_list.add_root(gc_ref, "Wasm table element");
gc_roots_list.add_root(gc_ref.into(), "Wasm table element");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
use alloc::sync::Arc;
use core::ffi::c_void;
use core::mem::{self, MaybeUninit};
use core::num::NonZeroUsize;
use core::ptr::NonNull;
#[cfg(feature = "async")]
use core::{future::Future, pin::Pin};
Expand Down Expand Up @@ -1211,7 +1210,7 @@ impl Func {
// already. If it is at capacity (unlikely) then we need to do a GC
// to free up space.
let num_gc_refs = ty.as_wasm_func_type().non_i31_gc_ref_params_count();
if let Some(num_gc_refs) = NonZeroUsize::new(num_gc_refs) {
if let Some(num_gc_refs) = core::num::NonZeroUsize::new(num_gc_refs) {
return Ok(opaque
.gc_store()?
.gc_heap
Expand Down Expand Up @@ -2444,6 +2443,7 @@ impl HostFunc {
}

/// Analog of [`Func::wrap_inner`]
#[cfg(any(feature = "component-model", feature = "async"))]
pub fn wrap_inner<F, T, Params, Results>(engine: &Engine, func: F) -> Self
where
F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static,
Expand Down
3 changes: 1 addition & 2 deletions crates/wasmtime/src/runtime/func/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
use core::ffi::c_void;
use core::marker;
use core::mem::{self, MaybeUninit};
use core::num::NonZeroUsize;
use core::ptr::{self, NonNull};
use wasmtime_environ::VMSharedTypeIndex;

Expand Down Expand Up @@ -155,7 +154,7 @@ where
{
// See the comment in `Func::call_impl_check_args`.
let num_gc_refs = _params.vmgcref_pointing_to_object_count();
if let Some(num_gc_refs) = NonZeroUsize::new(num_gc_refs) {
if let Some(num_gc_refs) = core::num::NonZeroUsize::new(num_gc_refs) {
return _store
.unwrap_gc_store()
.gc_heap
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<T> fmt::Display for GcHeapOutOfMemory<T> {
impl<T> core::error::Error for GcHeapOutOfMemory<T> {}

impl<T> GcHeapOutOfMemory<T> {
#[cfg(feature = "gc")]
pub(crate) fn new(inner: T) -> Self {
Self { inner }
}
Expand Down
12 changes: 2 additions & 10 deletions crates/wasmtime/src/runtime/gc/disabled/arrayref.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::runtime::vm::VMGcRef;
use crate::{
store::{AutoAssertNoGc, StoreContextMut, StoreOpaque},
ArrayType, AsContext, AsContextMut, GcRefImpl, Result, Rooted, Val, I31,
store::{StoreContextMut, StoreOpaque},
ArrayType, AsContext, AsContextMut, GcRefImpl, Result, Val,
};

/// Support for `ArrayRefPre` disabled at compile time because the `gc` cargo
Expand All @@ -15,13 +14,6 @@ pub enum ArrayRef {}
impl GcRefImpl for ArrayRef {}

impl ArrayRef {
pub(crate) fn from_cloned_gc_ref(
_store: &mut AutoAssertNoGc<'_>,
_gc_ref: VMGcRef,
) -> Rooted<Self> {
unreachable!()
}

pub fn ty(&self, _store: impl AsContext) -> Result<ArrayType> {
match *self {}
}
Expand Down
11 changes: 1 addition & 10 deletions crates/wasmtime/src/runtime/gc/disabled/eqref.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::runtime::vm::VMGcRef;
use crate::{
store::{AutoAssertNoGc, StoreOpaque},
ArrayRef, AsContext, AsContextMut, GcRefImpl, HeapType, ManuallyRooted, Result, Rooted,
store::StoreOpaque, ArrayRef, AsContext, GcRefImpl, HeapType, ManuallyRooted, Result, Rooted,
StructRef, I31,
};

Expand Down Expand Up @@ -40,13 +38,6 @@ impl From<ManuallyRooted<ArrayRef>> for ManuallyRooted<EqRef> {
impl GcRefImpl for EqRef {}

impl EqRef {
pub(crate) fn from_cloned_gc_ref(
_store: &mut AutoAssertNoGc<'_>,
_gc_ref: VMGcRef,
) -> Rooted<Self> {
unreachable!()
}

pub fn ty(&self, _store: impl AsContext) -> Result<HeapType> {
match *self {}
}
Expand Down
22 changes: 0 additions & 22 deletions crates/wasmtime/src/runtime/gc/disabled/rooting.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use crate::prelude::*;
use crate::runtime::vm::{GcStore, VMGcRef};
use crate::{
runtime::Uninhabited,
store::{AutoAssertNoGc, StoreOpaque},
AsContext, AsContextMut, GcRef, Result, RootedGcRef,
};
use core::any::Any;
use core::ffi::c_void;
use core::fmt::{self, Debug};
use core::hash::{Hash, Hasher};
use core::marker;
Expand Down Expand Up @@ -46,13 +43,6 @@ impl RootSet {
}

pub(crate) fn exit_lifo_scope(&mut self, _gc_store: Option<&mut GcStore>, _scope: usize) {}

pub(crate) fn with_lifo_scope<T>(
store: &mut StoreOpaque,
f: impl FnOnce(&mut StoreOpaque) -> T,
) -> T {
f(store)
}
}

/// This type is disabled because the `gc` cargo feature was not enabled at
Expand Down Expand Up @@ -124,10 +114,6 @@ impl<T: GcRef> Rooted<T> {
) -> Result<bool> {
a.assert_unreachable()
}

pub(crate) fn unchecked_cast<U: GcRef>(self) -> Rooted<U> {
match self.inner {}
}
}

/// This type has been disabled because the `gc` cargo feature was not enabled
Expand Down Expand Up @@ -197,10 +183,6 @@ impl<T> ManuallyRooted<T>
where
T: GcRef,
{
pub(crate) fn comes_from_same_store(&self, _store: &StoreOpaque) -> bool {
match self.inner {}
}

pub fn clone(&self, _store: impl AsContextMut) -> Self {
match self.inner {}
}
Expand All @@ -216,10 +198,6 @@ where
pub fn into_rooted(self, _context: impl AsContextMut) -> Rooted<T> {
match self.inner {}
}

pub(crate) fn unchecked_cast<U: GcRef>(self) -> ManuallyRooted<U> {
match self.inner {}
}
}

impl<T: GcRef> RootedGcRefImpl<T> for ManuallyRooted<T> {
Expand Down
12 changes: 2 additions & 10 deletions crates/wasmtime/src/runtime/gc/disabled/structref.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::runtime::vm::VMGcRef;
use crate::{
store::{AutoAssertNoGc, StoreContextMut, StoreOpaque},
AsContext, AsContextMut, GcRefImpl, Result, Rooted, StructType, Val, I31,
store::{StoreContextMut, StoreOpaque},
AsContext, AsContextMut, GcRefImpl, Result, StructType, Val,
};

/// Support for `StructRefPre` disabled at compile time because the `gc` cargo
Expand All @@ -15,13 +14,6 @@ pub enum StructRef {}
impl GcRefImpl for StructRef {}

impl StructRef {
pub(crate) fn from_cloned_gc_ref(
_store: &mut AutoAssertNoGc<'_>,
_gc_ref: VMGcRef,
) -> Rooted<Self> {
unreachable!()
}

pub fn ty(&self, _store: impl AsContext) -> Result<StructType> {
match *self {}
}
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ impl Module {
}

/// Lookup the stack map at a program counter value.
#[cfg(feature = "gc")]
pub(crate) fn lookup_stack_map(&self, pc: usize) -> Option<&wasmtime_environ::StackMap> {
let text_offset = pc - self.inner.module.text().as_ptr() as usize;
let (index, func_offset) = self.inner.module.func_by_text_offset(text_offset)?;
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/module/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl ModuleRegistry {
}

/// Fetches a registered module given a program counter value.
#[cfg(feature = "gc")]
pub fn lookup_module_by_pc(&self, pc: usize) -> Option<&Module> {
let (module, _) = self.module_and_offset(pc)?;
Some(module)
Expand Down
28 changes: 17 additions & 11 deletions crates/wasmtime/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@
//! contents of `StoreOpaque`. This is an invariant that we, as the authors of
//! `wasmtime`, must uphold for the public interface to be safe.
use crate::hash_set::HashSet;
use crate::instance::InstanceData;
use crate::linker::Definition;
use crate::module::RegisteredModuleId;
use crate::prelude::*;
use crate::runtime::vm::mpk::ProtectionKey;
#[cfg(feature = "gc")]
use crate::runtime::vm::GcRootsList;
use crate::runtime::vm::{
Backtrace, ExportGlobal, GcRootsList, GcStore, InstanceAllocationRequest, InstanceAllocator,
InstanceHandle, Interpreter, InterpreterRef, ModuleRuntimeInfo, OnDemandInstanceAllocator,
SignalHandler, StoreBox, StorePtr, Unwind, VMContext, VMFuncRef, VMGcRef, VMRuntimeLimits,
ExportGlobal, GcStore, InstanceAllocationRequest, InstanceAllocator, InstanceHandle,
Interpreter, InterpreterRef, ModuleRuntimeInfo, OnDemandInstanceAllocator, SignalHandler,
StoreBox, StorePtr, Unwind, VMContext, VMFuncRef, VMGcRef, VMRuntimeLimits,
};
use crate::trampoline::VMHostGlobalContext;
use crate::type_registry::RegisteredType;
use crate::RootSet;
use crate::{module::ModuleRegistry, Engine, Module, Trap, Val, ValRaw};
use crate::{Global, Instance, Memory, RootScope, Table, Uninhabited};
use crate::{Global, Instance, Memory, Table, Uninhabited};
use alloc::sync::Arc;
use core::fmt;
use core::marker;
Expand Down Expand Up @@ -317,9 +317,11 @@ pub struct StoreOpaque {
// GC-related fields.
gc_store: Option<GcStore>,
gc_roots: RootSet,
#[cfg(feature = "gc")]
gc_roots_list: GcRootsList,
// Types for which the embedder has created an allocator for.
gc_host_alloc_types: HashSet<RegisteredType>,
#[cfg(feature = "gc")]
gc_host_alloc_types: crate::hash_set::HashSet<crate::type_registry::RegisteredType>,

// Numbers of resources instantiated in this store, and their limits
instance_count: usize,
Expand Down Expand Up @@ -528,8 +530,10 @@ impl<T> Store<T> {
signal_handler: None,
gc_store: None,
gc_roots: RootSet::default(),
#[cfg(feature = "gc")]
gc_roots_list: GcRootsList::default(),
gc_host_alloc_types: HashSet::default(),
#[cfg(feature = "gc")]
gc_host_alloc_types: Default::default(),
modules: ModuleRegistry::default(),
func_refs: FuncRefs::default(),
host_globals: Vec::new(),
Expand Down Expand Up @@ -1478,6 +1482,7 @@ impl StoreOpaque {
}

#[inline]
#[cfg(feature = "gc")]
pub(crate) fn gc_roots_mut(&mut self) -> &mut RootSet {
&mut self.gc_roots
}
Expand Down Expand Up @@ -1536,7 +1541,7 @@ impl StoreOpaque {

#[cfg(feature = "gc")]
fn trace_wasm_stack_roots(&mut self, gc_roots_list: &mut GcRootsList) {
use crate::runtime::vm::SendSyncPtr;
use crate::runtime::vm::{Backtrace, SendSyncPtr};
use core::ptr::NonNull;

log::trace!("Begin trace GC roots :: Wasm stack");
Expand Down Expand Up @@ -1610,7 +1615,8 @@ impl StoreOpaque {
/// type in this store, and we don't have to worry about the type being
/// reclaimed (since it is possible that none of the Wasm modules in this
/// store are holding it alive).
pub(crate) fn insert_gc_host_alloc_type(&mut self, ty: RegisteredType) {
#[cfg(feature = "gc")]
pub(crate) fn insert_gc_host_alloc_type(&mut self, ty: crate::type_registry::RegisteredType) {
self.gc_host_alloc_types.insert(ty);
}

Expand Down Expand Up @@ -2028,7 +2034,7 @@ unsafe impl<T> crate::runtime::vm::VMStore for StoreInner<T> {

#[cfg(feature = "gc")]
fn maybe_async_gc(&mut self, root: Option<VMGcRef>) -> Result<Option<VMGcRef>> {
let mut scope = RootScope::new(self);
let mut scope = crate::RootScope::new(self);
let store = scope.as_context_mut().0;
let store_id = store.id();
let root = root.map(|r| store.gc_roots_mut().push_lifo_root(store_id, r));
Expand Down
3 changes: 1 addition & 2 deletions crates/wasmtime/src/runtime/store/async_.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use crate::runtime::vm::mpk::{self, ProtectionMask};
use crate::runtime::vm::GcRootsList;
use crate::store::{ResourceLimiterInner, StoreInner, StoreOpaque};
#[cfg(feature = "call-hook")]
use crate::CallHook;
Expand Down Expand Up @@ -251,7 +250,7 @@ impl StoreOpaque {
}

#[cfg(feature = "gc")]
async fn trace_roots_async(&mut self, gc_roots_list: &mut GcRootsList) {
async fn trace_roots_async(&mut self, gc_roots_list: &mut crate::runtime::vm::GcRootsList) {
use crate::runtime::vm::Yield;

log::trace!("Begin trace GC roots");
Expand Down
Loading

0 comments on commit a727985

Please sign in to comment.