1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
use crate::prelude::*;
use crate::runtime::vm::{GcStore, VMExternRef, 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;
use core::ops::Deref;

mod sealed {
    use super::*;
    pub trait GcRefImpl {}
    pub trait RootedGcRefImpl<T: GcRef> {
        fn assert_unreachable<U>(&self) -> U;

        fn get_gc_ref<'a>(&self, _store: &'a StoreOpaque) -> Option<&'a VMGcRef> {
            self.assert_unreachable()
        }

        fn try_gc_ref<'a>(&self, _store: &'a StoreOpaque) -> Result<&'a VMGcRef> {
            self.assert_unreachable()
        }

        fn clone_gc_ref(&self, _store: &mut AutoAssertNoGc<'_>) -> Option<VMGcRef> {
            self.assert_unreachable()
        }

        fn try_clone_gc_ref(&self, _store: &mut AutoAssertNoGc<'_>) -> Result<VMGcRef> {
            self.assert_unreachable()
        }
    }
}
pub(crate) use sealed::*;

#[derive(Debug, Default)]
pub(crate) struct RootSet {}

impl RootSet {
    pub(crate) fn enter_lifo_scope(&self) -> usize {
        usize::MAX
    }

    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
/// compile time.
pub struct Rooted<T: GcRef> {
    pub(crate) inner: Uninhabited,
    _phantom: marker::PhantomData<T>,
}

impl<T: GcRef> Clone for Rooted<T> {
    fn clone(&self) -> Self {
        match self.inner {}
    }
}

impl<T: GcRef> Copy for Rooted<T> {}

impl<T: GcRef> Debug for Rooted<T> {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self.inner {}
    }
}

impl<T: GcRef> PartialEq for Rooted<T> {
    fn eq(&self, _other: &Self) -> bool {
        match self.inner {}
    }
}

impl<T: GcRef> Eq for Rooted<T> {}

impl<T: GcRef> Hash for Rooted<T> {
    fn hash<H: Hasher>(&self, _state: &mut H) {
        match self.inner {}
    }
}

impl<T: GcRef> RootedGcRefImpl<T> for Rooted<T> {
    fn assert_unreachable<U>(&self) -> U {
        match self.inner {}
    }
}

impl<T: GcRef> Deref for Rooted<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        match self.inner {}
    }
}

impl<T: GcRef> Rooted<T> {
    pub(crate) fn comes_from_same_store(&self, _store: &StoreOpaque) -> bool {
        match self.inner {}
    }

    pub fn to_manually_rooted(&self, _store: impl AsContextMut) -> Result<ManuallyRooted<T>> {
        match self.inner {}
    }

    pub fn rooted_eq(a: Self, _b: Self) -> bool {
        match a.inner {}
    }

    pub fn ref_eq(
        _store: impl AsContext,
        a: &impl RootedGcRef<T>,
        _b: &impl RootedGcRef<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
/// at compile time.
pub struct RootScope<C>
where
    C: AsContextMut,
{
    inner: Uninhabited,
    _phantom: marker::PhantomData<C>,
}

impl<C> RootScope<C>
where
    C: AsContextMut,
{
    pub fn reserve(&mut self, _additional: usize) {
        match self.inner {}
    }
}

impl<T> AsContext for RootScope<T>
where
    T: AsContextMut,
{
    type Data = T::Data;

    fn as_context(&self) -> crate::StoreContext<'_, Self::Data> {
        match self.inner {}
    }
}

impl<T> AsContextMut for RootScope<T>
where
    T: AsContextMut,
{
    fn as_context_mut(&mut self) -> crate::StoreContextMut<'_, Self::Data> {
        match self.inner {}
    }
}

/// This type has been disabled because the `gc` cargo feature was not enabled
/// at compile time.
pub struct ManuallyRooted<T>
where
    T: GcRef,
{
    pub(crate) inner: Uninhabited,
    _phantom: marker::PhantomData<T>,
}

impl<T: GcRef> Debug for ManuallyRooted<T> {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self.inner {}
    }
}

impl<T: GcRef> Deref for ManuallyRooted<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        match self.inner {}
    }
}

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 {}
    }

    pub fn unroot(self, _store: impl AsContextMut) {
        match self.inner {}
    }

    pub fn to_rooted(&self, _context: impl AsContextMut) -> Rooted<T> {
        match self.inner {}
    }

    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> {
    fn assert_unreachable<U>(&self) -> U {
        match self.inner {}
    }
}