wasmtime/runtime/gc/disabled/
rooting.rs1use crate::prelude::*;
2use crate::runtime::vm::{GcStore, VMExternRef, VMGcRef};
3use crate::{
4 runtime::Uninhabited,
5 store::{AutoAssertNoGc, StoreOpaque},
6 AsContext, AsContextMut, GcRef, Result, RootedGcRef,
7};
8use core::any::Any;
9use core::ffi::c_void;
10use core::fmt::{self, Debug};
11use core::hash::{Hash, Hasher};
12use core::marker;
13use core::ops::Deref;
14
15mod sealed {
16 use super::*;
17 pub trait GcRefImpl {}
18 pub trait RootedGcRefImpl<T: GcRef> {
19 fn assert_unreachable<U>(&self) -> U;
20
21 fn get_gc_ref<'a>(&self, _store: &'a StoreOpaque) -> Option<&'a VMGcRef> {
22 self.assert_unreachable()
23 }
24
25 fn try_gc_ref<'a>(&self, _store: &'a StoreOpaque) -> Result<&'a VMGcRef> {
26 self.assert_unreachable()
27 }
28
29 fn clone_gc_ref(&self, _store: &mut AutoAssertNoGc<'_>) -> Option<VMGcRef> {
30 self.assert_unreachable()
31 }
32
33 fn try_clone_gc_ref(&self, _store: &mut AutoAssertNoGc<'_>) -> Result<VMGcRef> {
34 self.assert_unreachable()
35 }
36 }
37}
38pub(crate) use sealed::*;
39
40#[derive(Debug, Default)]
41pub(crate) struct RootSet {}
42
43impl RootSet {
44 pub(crate) fn enter_lifo_scope(&self) -> usize {
45 usize::MAX
46 }
47
48 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 }
56}
57
58pub struct Rooted<T: GcRef> {
61 pub(crate) inner: Uninhabited,
62 _phantom: marker::PhantomData<T>,
63}
64
65impl<T: GcRef> Clone for Rooted<T> {
66 fn clone(&self) -> Self {
67 match self.inner {}
68 }
69}
70
71impl<T: GcRef> Copy for Rooted<T> {}
72
73impl<T: GcRef> Debug for Rooted<T> {
74 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 match self.inner {}
76 }
77}
78
79impl<T: GcRef> PartialEq for Rooted<T> {
80 fn eq(&self, _other: &Self) -> bool {
81 match self.inner {}
82 }
83}
84
85impl<T: GcRef> Eq for Rooted<T> {}
86
87impl<T: GcRef> Hash for Rooted<T> {
88 fn hash<H: Hasher>(&self, _state: &mut H) {
89 match self.inner {}
90 }
91}
92
93impl<T: GcRef> RootedGcRefImpl<T> for Rooted<T> {
94 fn assert_unreachable<U>(&self) -> U {
95 match self.inner {}
96 }
97}
98
99impl<T: GcRef> Deref for Rooted<T> {
100 type Target = T;
101
102 fn deref(&self) -> &Self::Target {
103 match self.inner {}
104 }
105}
106
107impl<T: GcRef> Rooted<T> {
108 pub(crate) fn comes_from_same_store(&self, _store: &StoreOpaque) -> bool {
109 match self.inner {}
110 }
111
112 pub fn to_manually_rooted(&self, _store: impl AsContextMut) -> Result<ManuallyRooted<T>> {
113 match self.inner {}
114 }
115
116 pub fn rooted_eq(a: Self, _b: Self) -> bool {
117 match a.inner {}
118 }
119
120 pub fn ref_eq(
121 _store: impl AsContext,
122 a: &impl RootedGcRef<T>,
123 _b: &impl RootedGcRef<T>,
124 ) -> Result<bool> {
125 a.assert_unreachable()
126 }
127
128 pub(crate) fn unchecked_cast<U: GcRef>(self) -> Rooted<U> {
129 match self.inner {}
130 }
131}
132
133pub struct RootScope<C>
136where
137 C: AsContextMut,
138{
139 inner: Uninhabited,
140 _phantom: marker::PhantomData<C>,
141}
142
143impl<C> RootScope<C>
144where
145 C: AsContextMut,
146{
147 pub fn reserve(&mut self, _additional: usize) {
148 match self.inner {}
149 }
150}
151
152impl<T> AsContext for RootScope<T>
153where
154 T: AsContextMut,
155{
156 type Data = T::Data;
157
158 fn as_context(&self) -> crate::StoreContext<'_, Self::Data> {
159 match self.inner {}
160 }
161}
162
163impl<T> AsContextMut for RootScope<T>
164where
165 T: AsContextMut,
166{
167 fn as_context_mut(&mut self) -> crate::StoreContextMut<'_, Self::Data> {
168 match self.inner {}
169 }
170}
171
172pub struct ManuallyRooted<T>
175where
176 T: GcRef,
177{
178 pub(crate) inner: Uninhabited,
179 _phantom: marker::PhantomData<T>,
180}
181
182impl<T: GcRef> Debug for ManuallyRooted<T> {
183 fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
184 match self.inner {}
185 }
186}
187
188impl<T: GcRef> Deref for ManuallyRooted<T> {
189 type Target = T;
190
191 fn deref(&self) -> &Self::Target {
192 match self.inner {}
193 }
194}
195
196impl<T> ManuallyRooted<T>
197where
198 T: GcRef,
199{
200 pub(crate) fn comes_from_same_store(&self, _store: &StoreOpaque) -> bool {
201 match self.inner {}
202 }
203
204 pub fn clone(&self, _store: impl AsContextMut) -> Self {
205 match self.inner {}
206 }
207
208 pub fn unroot(self, _store: impl AsContextMut) {
209 match self.inner {}
210 }
211
212 pub fn to_rooted(&self, _context: impl AsContextMut) -> Rooted<T> {
213 match self.inner {}
214 }
215
216 pub fn into_rooted(self, _context: impl AsContextMut) -> Rooted<T> {
217 match self.inner {}
218 }
219
220 pub(crate) fn unchecked_cast<U: GcRef>(self) -> ManuallyRooted<U> {
221 match self.inner {}
222 }
223}
224
225impl<T: GcRef> RootedGcRefImpl<T> for ManuallyRooted<T> {
226 fn assert_unreachable<U>(&self) -> U {
227 match self.inner {}
228 }
229}