diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index 9ab3aca4dabf..68ac8f903c2b 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -2729,6 +2729,7 @@ impl Default for Collector { } } +#[cfg(feature = "gc")] impl Collector { fn not_auto(&self) -> Option { match self { diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rs index 4e058c7e94a8..8ba5599ae98e 100644 --- a/crates/wasmtime/src/lib.rs +++ b/crates/wasmtime/src/lib.rs @@ -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"), diff --git a/crates/wasmtime/src/runtime/externals/global.rs b/crates/wasmtime/src/runtime/externals/global.rs index 7c22b2b8ac8c..be7b3bcc683f 100644 --- a/crates/wasmtime/src/runtime/externals/global.rs +++ b/crates/wasmtime/src/runtime/externals/global.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use crate::runtime::vm::{GcRootsList, SendSyncPtr}; use crate::{ store::{AutoAssertNoGc, StoreData, StoreOpaque, Stored}, trampoline::generate_global_export, @@ -7,7 +6,6 @@ use crate::{ 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. @@ -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"); } } } diff --git a/crates/wasmtime/src/runtime/externals/table.rs b/crates/wasmtime/src/runtime/externals/table.rs index fd404859e7de..0af0c9605353 100644 --- a/crates/wasmtime/src/runtime/externals/table.rs +++ b/crates/wasmtime/src/runtime/externals/table.rs @@ -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. @@ -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() @@ -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"); } } } diff --git a/crates/wasmtime/src/runtime/func.rs b/crates/wasmtime/src/runtime/func.rs index 1082a248406e..a1a0807b7a58 100644 --- a/crates/wasmtime/src/runtime/func.rs +++ b/crates/wasmtime/src/runtime/func.rs @@ -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}; @@ -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 @@ -2444,6 +2443,7 @@ impl HostFunc { } /// Analog of [`Func::wrap_inner`] + #[cfg(any(feature = "component-model", feature = "async"))] pub fn wrap_inner(engine: &Engine, func: F) -> Self where F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static, diff --git a/crates/wasmtime/src/runtime/func/typed.rs b/crates/wasmtime/src/runtime/func/typed.rs index 241b34c2eeb7..0923249098ac 100644 --- a/crates/wasmtime/src/runtime/func/typed.rs +++ b/crates/wasmtime/src/runtime/func/typed.rs @@ -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; @@ -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 diff --git a/crates/wasmtime/src/runtime/gc.rs b/crates/wasmtime/src/runtime/gc.rs index 6c972e287c8d..4e49322610de 100644 --- a/crates/wasmtime/src/runtime/gc.rs +++ b/crates/wasmtime/src/runtime/gc.rs @@ -83,6 +83,7 @@ impl fmt::Display for GcHeapOutOfMemory { impl core::error::Error for GcHeapOutOfMemory {} impl GcHeapOutOfMemory { + #[cfg(feature = "gc")] pub(crate) fn new(inner: T) -> Self { Self { inner } } diff --git a/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs index 53679b8994cd..08b148a83587 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs @@ -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 @@ -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 { - unreachable!() - } - pub fn ty(&self, _store: impl AsContext) -> Result { match *self {} } diff --git a/crates/wasmtime/src/runtime/gc/disabled/eqref.rs b/crates/wasmtime/src/runtime/gc/disabled/eqref.rs index 460653402bbd..cd51a3c7bc04 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/eqref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/eqref.rs @@ -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, }; @@ -40,13 +38,6 @@ impl From> for ManuallyRooted { impl GcRefImpl for EqRef {} impl EqRef { - pub(crate) fn from_cloned_gc_ref( - _store: &mut AutoAssertNoGc<'_>, - _gc_ref: VMGcRef, - ) -> Rooted { - unreachable!() - } - pub fn ty(&self, _store: impl AsContext) -> Result { match *self {} } diff --git a/crates/wasmtime/src/runtime/gc/disabled/rooting.rs b/crates/wasmtime/src/runtime/gc/disabled/rooting.rs index 84ac4c6eba00..2c13204f7a28 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/rooting.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/rooting.rs @@ -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; @@ -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( - 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 @@ -124,10 +114,6 @@ impl Rooted { ) -> Result { a.assert_unreachable() } - - pub(crate) fn unchecked_cast(self) -> Rooted { - match self.inner {} - } } /// This type has been disabled because the `gc` cargo feature was not enabled @@ -197,10 +183,6 @@ impl ManuallyRooted 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 {} } @@ -216,10 +198,6 @@ where pub fn into_rooted(self, _context: impl AsContextMut) -> Rooted { match self.inner {} } - - pub(crate) fn unchecked_cast(self) -> ManuallyRooted { - match self.inner {} - } } impl RootedGcRefImpl for ManuallyRooted { diff --git a/crates/wasmtime/src/runtime/gc/disabled/structref.rs b/crates/wasmtime/src/runtime/gc/disabled/structref.rs index af47636f7ce9..6f5819d6c1bb 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/structref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/structref.rs @@ -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 @@ -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 { - unreachable!() - } - pub fn ty(&self, _store: impl AsContext) -> Result { match *self {} } diff --git a/crates/wasmtime/src/runtime/module.rs b/crates/wasmtime/src/runtime/module.rs index 9f2c99a540b9..44958485295a 100644 --- a/crates/wasmtime/src/runtime/module.rs +++ b/crates/wasmtime/src/runtime/module.rs @@ -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)?; diff --git a/crates/wasmtime/src/runtime/module/registry.rs b/crates/wasmtime/src/runtime/module/registry.rs index 909ebdab4f57..d2ceeb865824 100644 --- a/crates/wasmtime/src/runtime/module/registry.rs +++ b/crates/wasmtime/src/runtime/module/registry.rs @@ -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) diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs index a65743c66669..22d45c3b79a1 100644 --- a/crates/wasmtime/src/runtime/store.rs +++ b/crates/wasmtime/src/runtime/store.rs @@ -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; @@ -317,9 +317,11 @@ pub struct StoreOpaque { // GC-related fields. gc_store: Option, 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, + #[cfg(feature = "gc")] + gc_host_alloc_types: crate::hash_set::HashSet, // Numbers of resources instantiated in this store, and their limits instance_count: usize, @@ -528,8 +530,10 @@ impl Store { 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(), @@ -1478,6 +1482,7 @@ impl StoreOpaque { } #[inline] + #[cfg(feature = "gc")] pub(crate) fn gc_roots_mut(&mut self) -> &mut RootSet { &mut self.gc_roots } @@ -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"); @@ -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); } @@ -2028,7 +2034,7 @@ unsafe impl crate::runtime::vm::VMStore for StoreInner { #[cfg(feature = "gc")] fn maybe_async_gc(&mut self, root: Option) -> Result> { - 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)); diff --git a/crates/wasmtime/src/runtime/store/async_.rs b/crates/wasmtime/src/runtime/store/async_.rs index 77d13841c79e..d65f0c3f3c55 100644 --- a/crates/wasmtime/src/runtime/store/async_.rs +++ b/crates/wasmtime/src/runtime/store/async_.rs @@ -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; @@ -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"); diff --git a/crates/wasmtime/src/runtime/trampoline/memory.rs b/crates/wasmtime/src/runtime/trampoline/memory.rs index dd2f93f178bb..38bc7e3aa329 100644 --- a/crates/wasmtime/src/runtime/trampoline/memory.rs +++ b/crates/wasmtime/src/runtime/trampoline/memory.rs @@ -2,10 +2,9 @@ use crate::memory::{LinearMemory, MemoryCreator}; use crate::prelude::*; use crate::runtime::vm::mpk::ProtectionKey; use crate::runtime::vm::{ - CompiledModuleId, GcHeapAllocationIndex, Imports, InstanceAllocationRequest, InstanceAllocator, - InstanceAllocatorImpl, Memory, MemoryAllocationIndex, MemoryBase, ModuleRuntimeInfo, - OnDemandInstanceAllocator, RuntimeLinearMemory, RuntimeMemoryCreator, SharedMemory, StorePtr, - Table, TableAllocationIndex, + CompiledModuleId, Imports, InstanceAllocationRequest, InstanceAllocator, InstanceAllocatorImpl, + Memory, MemoryAllocationIndex, MemoryBase, ModuleRuntimeInfo, OnDemandInstanceAllocator, + RuntimeLinearMemory, RuntimeMemoryCreator, SharedMemory, StorePtr, Table, TableAllocationIndex, }; use crate::store::{InstanceId, StoreOpaque}; use crate::MemoryType; @@ -246,14 +245,17 @@ unsafe impl InstanceAllocatorImpl for SingleMemoryInstance<'_> { fn allocate_gc_heap( &self, _gc_runtime: &dyn crate::runtime::vm::GcRuntime, - ) -> Result<(GcHeapAllocationIndex, Box)> { + ) -> Result<( + crate::runtime::vm::GcHeapAllocationIndex, + Box, + )> { unreachable!() } #[cfg(feature = "gc")] fn deallocate_gc_heap( &self, - _allocation_index: GcHeapAllocationIndex, + _allocation_index: crate::runtime::vm::GcHeapAllocationIndex, _gc_heap: Box, ) { unreachable!() diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index 998142b27416..7a519273e129 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -392,6 +392,7 @@ impl RegisteredType { /// /// Only struct and array types have GC layouts; function types do not have /// layouts. + #[cfg(feature = "gc")] pub fn layout(&self) -> Option<&GcLayout> { self.layout.as_ref() } diff --git a/crates/wasmtime/src/runtime/types.rs b/crates/wasmtime/src/runtime/types.rs index 954df787969d..430da308bf4b 100644 --- a/crates/wasmtime/src/runtime/types.rs +++ b/crates/wasmtime/src/runtime/types.rs @@ -1401,6 +1401,7 @@ impl StorageType { /// https://webassembly.github.io/gc/core/syntax/types.html#bitwidth-fieldtype /// and /// https://webassembly.github.io/gc/core/syntax/types.html#bitwidth-valtype + #[cfg(feature = "gc")] pub(crate) fn data_byte_size(&self) -> Option { match self { StorageType::I8 => Some(1), @@ -1979,6 +1980,7 @@ impl ArrayType { Engine::same(self.registered_type.engine(), engine) } + #[cfg(feature = "gc")] pub(crate) fn registered_type(&self) -> &RegisteredType { &self.registered_type } @@ -2342,6 +2344,7 @@ impl FuncType { self.registered_type.index() } + #[cfg(feature = "gc")] pub(crate) fn as_wasm_func_type(&self) -> &WasmFuncType { self.registered_type.unwrap_func() } diff --git a/crates/wasmtime/src/runtime/vm.rs b/crates/wasmtime/src/runtime/vm.rs index 592cf9c6f334..b50cd129cb51 100644 --- a/crates/wasmtime/src/runtime/vm.rs +++ b/crates/wasmtime/src/runtime/vm.rs @@ -31,7 +31,6 @@ mod memory; mod mmap_vec; mod provenance; mod send_sync_ptr; -mod send_sync_unsafe_cell; mod store_box; mod sys; mod table; @@ -95,7 +94,6 @@ pub use crate::runtime::vm::vmcontext::{ VMOpaqueContext, VMRuntimeLimits, VMTableImport, VMWasmCallFunction, ValRaw, }; pub use send_sync_ptr::SendSyncPtr; -pub use send_sync_unsafe_cell::SendSyncUnsafeCell; mod module_id; pub use module_id::CompiledModuleId; @@ -114,6 +112,11 @@ mod async_yield; #[cfg(feature = "async")] pub use crate::runtime::vm::async_yield::*; +#[cfg(feature = "gc-null")] +mod send_sync_unsafe_cell; +#[cfg(feature = "gc-null")] +pub use send_sync_unsafe_cell::SendSyncUnsafeCell; + cfg_if::cfg_if! { if #[cfg(has_virtual_memory)] { pub use crate::runtime::vm::byte_count::*; diff --git a/crates/wasmtime/src/runtime/vm/const_expr.rs b/crates/wasmtime/src/runtime/vm/const_expr.rs index 64f78f818d15..86b886028c23 100644 --- a/crates/wasmtime/src/runtime/vm/const_expr.rs +++ b/crates/wasmtime/src/runtime/vm/const_expr.rs @@ -1,14 +1,15 @@ //! Evaluating const expressions. +use crate::prelude::*; use crate::runtime::vm::{Instance, VMGcRef, ValRaw, I31}; use crate::store::{AutoAssertNoGc, StoreOpaque}; -use crate::{ - prelude::*, ArrayRef, ArrayRefPre, ArrayType, StructRef, StructRefPre, StructType, Val, -}; +#[cfg(feature = "gc")] +use crate::{ArrayRef, ArrayRefPre, ArrayType, StructRef, StructRefPre, StructType, Val}; use smallvec::SmallVec; +use wasmtime_environ::{ConstExpr, ConstOp, FuncIndex, GlobalIndex}; +#[cfg(feature = "gc")] use wasmtime_environ::{ - ConstExpr, ConstOp, FuncIndex, GlobalIndex, ModuleInternedTypeIndex, WasmCompositeInnerType, - WasmCompositeType, WasmSubType, + ModuleInternedTypeIndex, WasmCompositeInnerType, WasmCompositeType, WasmSubType, }; /// An interpreter for const expressions. diff --git a/crates/wasmtime/src/runtime/vm/gc/disabled.rs b/crates/wasmtime/src/runtime/vm/gc/disabled.rs index d93eb60ddde7..ead2faa6c8e1 100644 --- a/crates/wasmtime/src/runtime/vm/gc/disabled.rs +++ b/crates/wasmtime/src/runtime/vm/gc/disabled.rs @@ -5,22 +5,14 @@ #![allow(missing_docs)] -use crate::prelude::*; -use crate::runtime::vm::{GcHeap, GcRuntime}; -use wasmtime_environ::{ - GcArrayLayout, GcStructLayout, GcTypeLayouts, WasmArrayType, WasmStructType, -}; - pub enum VMExternRef {} -pub enum VMEqRef {} - pub enum VMStructRef {} pub enum VMArrayRef {} pub struct VMGcObjectDataMut<'a> { - inner: VMStructRef, + _inner: VMStructRef, _phantom: core::marker::PhantomData<&'a mut ()>, } diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled.rs b/crates/wasmtime/src/runtime/vm/gc/enabled.rs index 87ad2816b9a2..f47e416184d3 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled.rs @@ -3,6 +3,7 @@ mod arrayref; mod data; mod externref; +#[cfg(feature = "gc-drc")] mod free_list; mod structref; @@ -21,15 +22,11 @@ mod null; #[cfg(feature = "gc-null")] pub use null::*; -use crate::runtime::vm::GcRuntime; - -/// The default GC heap capacity: 512KiB. -#[cfg(not(miri))] -const DEFAULT_GC_HEAP_CAPACITY: usize = 1 << 19; - -/// The default GC heap capacity for miri: 64KiB. -#[cfg(miri)] -const DEFAULT_GC_HEAP_CAPACITY: usize = 1 << 16; +/// The default GC heap capacity. +// +// Note that this is a bit smaller for miri to avoid overheads. +#[cfg(any(feature = "gc-drc", feature = "gc-null"))] +const DEFAULT_GC_HEAP_CAPACITY: usize = if cfg!(miri) { 1 << 16 } else { 1 << 19 }; // Explicit methods with `#[allow]` to clearly indicate that truncation is // desired when used. diff --git a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs index b62d9494c6ee..c76666fc9fff 100644 --- a/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs +++ b/crates/wasmtime/src/runtime/vm/gc/enabled/null.rs @@ -9,8 +9,8 @@ use crate::{ prelude::*, vm::{ mmap::AlignedLength, ExternRefHostDataId, ExternRefHostDataTable, GarbageCollection, - GcHeap, GcHeapObject, GcProgress, GcRootsIter, Mmap, SendSyncUnsafeCell, TypedGcRef, - VMGcHeader, VMGcRef, + GcHeap, GcHeapObject, GcProgress, GcRootsIter, GcRuntime, Mmap, SendSyncUnsafeCell, + TypedGcRef, VMGcHeader, VMGcRef, }, GcHeapOutOfMemory, }; diff --git a/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs b/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs index 46c11adffd73..95bfdeaaa940 100644 --- a/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs +++ b/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs @@ -37,6 +37,7 @@ pub unsafe trait GcRuntime: 'static + Send + Sync { fn layouts(&self) -> &dyn GcTypeLayouts; /// Construct a new GC heap. + #[cfg(feature = "gc")] fn new_gc_heap(&self) -> Result>; } @@ -524,11 +525,19 @@ pub struct GcRootsList(Vec); // contents of the roots list (when it is non-empty, during GCs) borrow from // the store, which creates self-references. #[derive(Clone, Copy, Debug)] +#[cfg_attr( + not(feature = "gc"), + expect( + dead_code, + reason = "not worth it at this time to #[cfg] away these variants", + ) +)] enum RawGcRoot { Stack(SendSyncPtr), NonStack(SendSyncPtr), } +#[cfg(feature = "gc")] impl GcRootsList { /// Add a GC root that is inside a Wasm stack frame to this list. #[inline] diff --git a/crates/wasmtime/src/runtime/vm/instance.rs b/crates/wasmtime/src/runtime/vm/instance.rs index 270bd863795d..581021f40af9 100644 --- a/crates/wasmtime/src/runtime/vm/instance.rs +++ b/crates/wasmtime/src/runtime/vm/instance.rs @@ -400,6 +400,7 @@ impl Instance { self.runtime_info.env_module() } + #[cfg(feature = "gc")] pub(crate) fn runtime_module(&self) -> Option<&crate::Module> { match &self.runtime_info { ModuleRuntimeInfo::Module(m) => Some(m), diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs index d17a853e0572..c8898bfa502f 100644 --- a/crates/wasmtime/src/runtime/vm/libcalls.rs +++ b/crates/wasmtime/src/runtime/vm/libcalls.rs @@ -57,7 +57,9 @@ use crate::prelude::*; use crate::runtime::vm::table::{Table, TableElementType}; use crate::runtime::vm::vmcontext::VMFuncRef; -use crate::runtime::vm::{HostResultHasUnwindSentinel, Instance, TrapReason, VMGcRef, VMStore}; +#[cfg(feature = "gc")] +use crate::runtime::vm::VMGcRef; +use crate::runtime::vm::{HostResultHasUnwindSentinel, Instance, TrapReason, VMStore}; use core::convert::Infallible; use core::ptr::NonNull; #[cfg(feature = "threads")] diff --git a/crates/wasmtime/src/runtime/vm/mpk/disabled.rs b/crates/wasmtime/src/runtime/vm/mpk/disabled.rs index 03befb374484..fbc129f16830 100644 --- a/crates/wasmtime/src/runtime/vm/mpk/disabled.rs +++ b/crates/wasmtime/src/runtime/vm/mpk/disabled.rs @@ -16,6 +16,7 @@ pub fn keys(_: usize) -> &'static [ProtectionKey] { &[] } +#[cfg(any(feature = "async", feature = "pooling-allocator"))] pub fn allow(_: ProtectionMask) {} #[cfg(feature = "async")] @@ -25,6 +26,7 @@ pub fn current_mask() -> ProtectionMask { #[derive(Clone, Copy, Debug)] pub enum ProtectionKey {} + impl ProtectionKey { #[cfg(feature = "pooling-allocator")] pub fn protect(&self, _: &mut [u8]) -> Result<()> { @@ -37,8 +39,12 @@ impl ProtectionKey { } #[derive(Clone, Copy, Debug)] +#[cfg(any(feature = "async", feature = "pooling-allocator"))] pub struct ProtectionMask; + +#[cfg(any(feature = "async", feature = "pooling-allocator"))] impl ProtectionMask { + #[cfg(any(feature = "async", feature = "pooling-allocator"))] pub fn all() -> Self { Self } diff --git a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs index 996fd6f22909..276f8cca04c8 100644 --- a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs +++ b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs @@ -37,6 +37,10 @@ pub struct Backtrace(Vec); #[derive(Debug)] pub struct Frame { pc: usize, + #[cfg_attr( + not(feature = "gc"), + expect(dead_code, reason = "not worth #[cfg] annotations to remove") + )] fp: usize, } @@ -47,6 +51,7 @@ impl Frame { } /// Get this frame's frame pointer. + #[cfg(feature = "gc")] pub fn fp(&self) -> usize { self.fp } @@ -88,6 +93,7 @@ impl Backtrace { } /// Walk the current Wasm stack, calling `f` for each frame we walk. + #[cfg(feature = "gc")] pub fn trace(store: &StoreOpaque, f: impl FnMut(Frame) -> ControlFlow<()>) { let limits = store.runtime_limits(); let unwind = store.unwinder();