Skip to content

Commit a727985

Browse files
authored
Enable warnings if gc is disabled (bytecodealliance#10149)
* Enable warnings if `gc` is disabled Continuation of work in bytecodealliance#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
1 parent b9d1624 commit a727985

File tree

28 files changed

+101
-118
lines changed

28 files changed

+101
-118
lines changed

crates/wasmtime/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,7 @@ impl Default for Collector {
27292729
}
27302730
}
27312731

2732+
#[cfg(feature = "gc")]
27322733
impl Collector {
27332734
fn not_auto(&self) -> Option<Collector> {
27342735
match self {

crates/wasmtime/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@
285285
// here to get warnings in all configurations of Wasmtime.
286286
#![cfg_attr(
287287
any(
288-
not(feature = "gc"),
289-
not(feature = "gc-drc"),
290-
not(feature = "gc-null"),
291288
not(feature = "cranelift"),
292289
not(feature = "runtime"),
293290
not(feature = "std"),

crates/wasmtime/src/runtime/externals/global.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use crate::prelude::*;
2-
use crate::runtime::vm::{GcRootsList, SendSyncPtr};
32
use crate::{
43
store::{AutoAssertNoGc, StoreData, StoreOpaque, Stored},
54
trampoline::generate_global_export,
65
AnyRef, AsContext, AsContextMut, ExternRef, Func, GlobalType, HeapType, Mutability, Ref,
76
RootedGcRefImpl, Val, ValType,
87
};
98
use core::ptr;
10-
use core::ptr::NonNull;
119
use wasmtime_environ::TypeTrace;
1210

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

219-
pub(crate) fn trace_root(&self, store: &mut StoreOpaque, gc_roots_list: &mut GcRootsList) {
217+
#[cfg(feature = "gc")]
218+
pub(crate) fn trace_root(
219+
&self,
220+
store: &mut StoreOpaque,
221+
gc_roots_list: &mut crate::runtime::vm::GcRootsList,
222+
) {
220223
if let Some(ref_ty) = self._ty(store).content().as_ref() {
221224
if !ref_ty.is_vmgcref_type_and_points_to_object() {
222225
return;
223226
}
224227

225228
if let Some(gc_ref) = unsafe { store[self.0].definition.as_ref().as_gc_ref() } {
226-
let gc_ref = NonNull::from(gc_ref);
227-
let gc_ref = SendSyncPtr::new(gc_ref);
228229
unsafe {
229-
gc_roots_list.add_root(gc_ref, "Wasm global");
230+
gc_roots_list.add_root(gc_ref.into(), "Wasm global");
230231
}
231232
}
232233
}

crates/wasmtime/src/runtime/externals/table.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use crate::trampoline::generate_table_export;
55
use crate::vm::ExportTable;
66
use crate::{AnyRef, AsContext, AsContextMut, ExternRef, Func, HeapType, Ref, TableType};
77
use core::iter;
8-
use core::ptr::NonNull;
9-
use runtime::{GcRootsList, SendSyncPtr};
108
use wasmtime_environ::TypeTrace;
119

1210
/// A WebAssembly `table`, or an array of values.
@@ -376,7 +374,12 @@ impl Table {
376374
Ok(())
377375
}
378376

379-
pub(crate) fn trace_roots(&self, store: &mut StoreOpaque, gc_roots_list: &mut GcRootsList) {
377+
#[cfg(feature = "gc")]
378+
pub(crate) fn trace_roots(
379+
&self,
380+
store: &mut StoreOpaque,
381+
gc_roots_list: &mut crate::runtime::vm::GcRootsList,
382+
) {
380383
if !self
381384
._ty(store)
382385
.element()
@@ -388,10 +391,8 @@ impl Table {
388391
let table = self.wasmtime_table(store, iter::empty());
389392
for gc_ref in unsafe { (*table).gc_refs_mut() } {
390393
if let Some(gc_ref) = gc_ref {
391-
let gc_ref = NonNull::from(gc_ref);
392-
let gc_ref = SendSyncPtr::new(gc_ref);
393394
unsafe {
394-
gc_roots_list.add_root(gc_ref, "Wasm table element");
395+
gc_roots_list.add_root(gc_ref.into(), "Wasm table element");
395396
}
396397
}
397398
}

crates/wasmtime/src/runtime/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{
1313
use alloc::sync::Arc;
1414
use core::ffi::c_void;
1515
use core::mem::{self, MaybeUninit};
16-
use core::num::NonZeroUsize;
1716
use core::ptr::NonNull;
1817
#[cfg(feature = "async")]
1918
use core::{future::Future, pin::Pin};
@@ -1211,7 +1210,7 @@ impl Func {
12111210
// already. If it is at capacity (unlikely) then we need to do a GC
12121211
// to free up space.
12131212
let num_gc_refs = ty.as_wasm_func_type().non_i31_gc_ref_params_count();
1214-
if let Some(num_gc_refs) = NonZeroUsize::new(num_gc_refs) {
1213+
if let Some(num_gc_refs) = core::num::NonZeroUsize::new(num_gc_refs) {
12151214
return Ok(opaque
12161215
.gc_store()?
12171216
.gc_heap
@@ -2444,6 +2443,7 @@ impl HostFunc {
24442443
}
24452444

24462445
/// Analog of [`Func::wrap_inner`]
2446+
#[cfg(any(feature = "component-model", feature = "async"))]
24472447
pub fn wrap_inner<F, T, Params, Results>(engine: &Engine, func: F) -> Self
24482448
where
24492449
F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static,

crates/wasmtime/src/runtime/func/typed.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
use core::ffi::c_void;
1010
use core::marker;
1111
use core::mem::{self, MaybeUninit};
12-
use core::num::NonZeroUsize;
1312
use core::ptr::{self, NonNull};
1413
use wasmtime_environ::VMSharedTypeIndex;
1514

@@ -155,7 +154,7 @@ where
155154
{
156155
// See the comment in `Func::call_impl_check_args`.
157156
let num_gc_refs = _params.vmgcref_pointing_to_object_count();
158-
if let Some(num_gc_refs) = NonZeroUsize::new(num_gc_refs) {
157+
if let Some(num_gc_refs) = core::num::NonZeroUsize::new(num_gc_refs) {
159158
return _store
160159
.unwrap_gc_store()
161160
.gc_heap

crates/wasmtime/src/runtime/gc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl<T> fmt::Display for GcHeapOutOfMemory<T> {
8383
impl<T> core::error::Error for GcHeapOutOfMemory<T> {}
8484

8585
impl<T> GcHeapOutOfMemory<T> {
86+
#[cfg(feature = "gc")]
8687
pub(crate) fn new(inner: T) -> Self {
8788
Self { inner }
8889
}

crates/wasmtime/src/runtime/gc/disabled/arrayref.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::runtime::vm::VMGcRef;
21
use crate::{
3-
store::{AutoAssertNoGc, StoreContextMut, StoreOpaque},
4-
ArrayType, AsContext, AsContextMut, GcRefImpl, Result, Rooted, Val, I31,
2+
store::{StoreContextMut, StoreOpaque},
3+
ArrayType, AsContext, AsContextMut, GcRefImpl, Result, Val,
54
};
65

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

1716
impl ArrayRef {
18-
pub(crate) fn from_cloned_gc_ref(
19-
_store: &mut AutoAssertNoGc<'_>,
20-
_gc_ref: VMGcRef,
21-
) -> Rooted<Self> {
22-
unreachable!()
23-
}
24-
2517
pub fn ty(&self, _store: impl AsContext) -> Result<ArrayType> {
2618
match *self {}
2719
}

crates/wasmtime/src/runtime/gc/disabled/eqref.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::runtime::vm::VMGcRef;
21
use crate::{
3-
store::{AutoAssertNoGc, StoreOpaque},
4-
ArrayRef, AsContext, AsContextMut, GcRefImpl, HeapType, ManuallyRooted, Result, Rooted,
2+
store::StoreOpaque, ArrayRef, AsContext, GcRefImpl, HeapType, ManuallyRooted, Result, Rooted,
53
StructRef, I31,
64
};
75

@@ -40,13 +38,6 @@ impl From<ManuallyRooted<ArrayRef>> for ManuallyRooted<EqRef> {
4038
impl GcRefImpl for EqRef {}
4139

4240
impl EqRef {
43-
pub(crate) fn from_cloned_gc_ref(
44-
_store: &mut AutoAssertNoGc<'_>,
45-
_gc_ref: VMGcRef,
46-
) -> Rooted<Self> {
47-
unreachable!()
48-
}
49-
5041
pub fn ty(&self, _store: impl AsContext) -> Result<HeapType> {
5142
match *self {}
5243
}

crates/wasmtime/src/runtime/gc/disabled/rooting.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use crate::prelude::*;
21
use crate::runtime::vm::{GcStore, VMGcRef};
32
use crate::{
43
runtime::Uninhabited,
54
store::{AutoAssertNoGc, StoreOpaque},
65
AsContext, AsContextMut, GcRef, Result, RootedGcRef,
76
};
8-
use core::any::Any;
9-
use core::ffi::c_void;
107
use core::fmt::{self, Debug};
118
use core::hash::{Hash, Hasher};
129
use core::marker;
@@ -46,13 +43,6 @@ impl RootSet {
4643
}
4744

4845
pub(crate) fn exit_lifo_scope(&mut self, _gc_store: Option<&mut GcStore>, _scope: usize) {}
49-
50-
pub(crate) fn with_lifo_scope<T>(
51-
store: &mut StoreOpaque,
52-
f: impl FnOnce(&mut StoreOpaque) -> T,
53-
) -> T {
54-
f(store)
55-
}
5646
}
5747

5848
/// This type is disabled because the `gc` cargo feature was not enabled at
@@ -124,10 +114,6 @@ impl<T: GcRef> Rooted<T> {
124114
) -> Result<bool> {
125115
a.assert_unreachable()
126116
}
127-
128-
pub(crate) fn unchecked_cast<U: GcRef>(self) -> Rooted<U> {
129-
match self.inner {}
130-
}
131117
}
132118

133119
/// This type has been disabled because the `gc` cargo feature was not enabled
@@ -197,10 +183,6 @@ impl<T> ManuallyRooted<T>
197183
where
198184
T: GcRef,
199185
{
200-
pub(crate) fn comes_from_same_store(&self, _store: &StoreOpaque) -> bool {
201-
match self.inner {}
202-
}
203-
204186
pub fn clone(&self, _store: impl AsContextMut) -> Self {
205187
match self.inner {}
206188
}
@@ -216,10 +198,6 @@ where
216198
pub fn into_rooted(self, _context: impl AsContextMut) -> Rooted<T> {
217199
match self.inner {}
218200
}
219-
220-
pub(crate) fn unchecked_cast<U: GcRef>(self) -> ManuallyRooted<U> {
221-
match self.inner {}
222-
}
223201
}
224202

225203
impl<T: GcRef> RootedGcRefImpl<T> for ManuallyRooted<T> {

0 commit comments

Comments
 (0)