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
use crate::{
Trace, TraceImmutable, GcVisitor, NullTrace, CollectorId,
GcSafe, GcSystem, GcContext,
};
use std::ptr::NonNull;
pub fn gc<'gc, T: GcSafe + 'static>(ptr: &'static T) -> Gc<'gc, T> {
unsafe {
Gc::from_raw(
DummyCollectorId { _priv: () },
NonNull::from(ptr)
)
}
}
pub fn leaked<'gc, T: GcSafe + 'static>(value: T) -> Gc<'gc, T> {
gc(Box::leak(Box::new(value)))
}
pub type Gc<'gc, T> = crate::Gc<'gc, T, DummyCollectorId>;
pub struct DummyContext {
_priv: ()
}
unsafe impl GcContext for DummyContext {
type System = DummySystem;
type Id = DummyCollectorId;
unsafe fn basic_safepoint<T: Trace>(&mut self, _value: &mut &mut T) {
}
unsafe fn freeze(&mut self) {
unimplemented!()
}
unsafe fn unfreeze(&mut self) {
unimplemented!()
}
unsafe fn recurse_context<T, F, R>(&self, value: &mut &mut T, func: F) -> R
where T: Trace, F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R {
let mut child = DummyContext { _priv: () };
func(&mut child, &mut *value)
}
}
#[derive(Default)]
pub struct DummySystem {
_priv: ()
}
impl DummySystem {
pub fn new() -> Self {
DummySystem::default()
}
pub fn new_context(&self) -> DummyContext {
DummyContext {
_priv: ()
}
}
}
unsafe impl GcSystem for DummySystem {
type Id = DummyCollectorId;
type Context = DummyContext;
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct DummyCollectorId {
_priv: ()
}
unsafe impl Trace for DummyCollectorId {
const NEEDS_TRACE: bool = false;
fn visit<V: GcVisitor>(&mut self, _visitor: &mut V) -> Result<(), <V as GcVisitor>::Err> {
Ok(())
}
}
unsafe impl TraceImmutable for DummyCollectorId {
fn visit_immutable<V: GcVisitor>(&self, _visitor: &mut V) -> Result<(), V::Err> {
Ok(())
}
}
unsafe impl NullTrace for DummyCollectorId {}
unsafe impl CollectorId for DummyCollectorId {
type System = DummySystem;
unsafe fn gc_write_barrier<'gc, T, V>(
_owner: &Gc<'gc, T>,
_value: &Gc<'gc, V>,
_field_offset: usize
) where T: GcSafe + ?Sized + 'gc, V: GcSafe + ?Sized + 'gc {}
unsafe fn assume_valid_system(&self) -> &Self::System {
unimplemented!()
}
}