Skip to content

Commit 87e7fb9

Browse files
committed
Rename Trace::visit to Trace::trace
Less likely to conflict with a user-defined trait method. Also rename the 'visit' option to 'trace_template' (in unsafe_gc_impl!). This is something I've wanted to do for a while.
1 parent d38fe19 commit 87e7fb9

File tree

18 files changed

+130
-140
lines changed

18 files changed

+130
-140
lines changed

libs/context/src/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,20 @@ unsafe impl<C: RawCollectorImpl> Trace for CollectorId<C> {
350350
const NEEDS_TRACE: bool = false;
351351
const NEEDS_DROP: bool = false;
352352
#[inline(always)]
353-
fn visit<V: GcVisitor>(&mut self, _visitor: &mut V) -> Result<(), V::Err> {
353+
fn trace<V: GcVisitor>(&mut self, _visitor: &mut V) -> Result<(), V::Err> {
354354
Ok(())
355355
}
356356

357357
#[inline]
358-
unsafe fn visit_inside_gc<'gc, V, Id>(gc: &mut Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err> where V: GcVisitor, Id: zerogc::CollectorId, Self: GcSafe<'gc, Id> {
358+
unsafe fn trace_inside_gc<'gc, V, Id>(gc: &mut Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err> where V: GcVisitor, Id: zerogc::CollectorId, Self: GcSafe<'gc, Id> {
359359
// Fine to stuff inside a pointer. We're a regular 'Sized' type
360-
visitor.visit_gc(gc)
360+
visitor.trace_gc(gc)
361361
}
362362
}
363363
unsafe impl<C: RawCollectorImpl> TrustedDrop for CollectorId<C> {}
364364
unsafe impl<C: RawCollectorImpl> TraceImmutable for CollectorId<C> {
365365
#[inline(always)]
366-
fn visit_immutable<V: GcVisitor>(&self, _visitor: &mut V) -> Result<(), <V as GcVisitor>::Err> {
366+
fn trace_immutable<V: GcVisitor>(&self, _visitor: &mut V) -> Result<(), <V as GcVisitor>::Err> {
367367
Ok(())
368368
}
369369
}

libs/context/src/handle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,21 @@ unsafe impl<T: GcSafe<'static, CollectorId<C>>, C: RawHandleImpl> Trace for GcHa
477477
const NEEDS_TRACE: bool = false;
478478
const NEEDS_DROP: bool = true;
479479
#[inline(always)]
480-
fn visit<V>(&mut self, _visitor: &mut V) -> Result<(), V::Err>
480+
fn trace<V>(&mut self, _visitor: &mut V) -> Result<(), V::Err>
481481
where V: zerogc::GcVisitor {
482482
Ok(())
483483
}
484484

485485
#[inline]
486-
unsafe fn visit_inside_gc<'gc, V, Id>(gc: &mut Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err>
486+
unsafe fn trace_inside_gc<'gc, V, Id>(gc: &mut Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err>
487487
where V: GcVisitor, Id: zerogc::CollectorId, Self: GcSafe<'gc, Id> {
488488
// Fine to stuff inside a pointer. We're a `Sized` type
489-
visitor.visit_gc(gc)
489+
visitor.trace_gc(gc)
490490
}
491491
}
492492
unsafe impl<T: GcSafe<'static, CollectorId<C>>, C: RawHandleImpl> TraceImmutable for GcHandle<T, C> {
493493
#[inline(always)]
494-
fn visit_immutable<V>(&self, _visitor: &mut V) -> Result<(), V::Err>
494+
fn trace_immutable<V>(&self, _visitor: &mut V) -> Result<(), V::Err>
495495
where V: GcVisitor {
496496
Ok(())
497497
}

libs/derive/src/derive.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ impl TraceField {
207207
parse_quote!(zerogc::Trace)
208208
};
209209
let method_name: Ident = if immutable {
210-
parse_quote!(visit_immutable)
210+
parse_quote!(trace_immutable)
211211
} else {
212-
parse_quote!(visit)
212+
parse_quote!(trace)
213213
};
214214
quote_spanned!(self.ty.span() => <#ty as #trait_name>::#method_name(#access, gc_visitor)?)
215215
}
@@ -284,7 +284,7 @@ struct SerdeTypeOpts {
284284
/// It is automatically inferred if you have any `Gc`, `GcArray`
285285
/// or `GcString` fields (ignoring fully qualified paths).
286286
#[darling(default)]
287-
require_simple_alloc: bool,
287+
require_simple_alloc: Option<bool>,
288288
}
289289

290290
#[derive(Debug, Clone, Default, FromMeta)]
@@ -502,7 +502,7 @@ impl TraceDeriveInput {
502502
return Err(Error::custom("The `zerogc/serde1` feature is disabled (please enable it)"));
503503
}
504504
let (gc_lifetime, generics) = self.generics_with_gc_lifetime(parse_quote!('gc));
505-
let should_require_simple_alloc = self.all_fields().iter().any(|field| {
505+
let default_should_require_simple_alloc = self.all_fields().iter().any(|field| {
506506
let is_gc_allocated = match field.ty {
507507
Type::Path(ref p) if p.path.segments.len() == 1 => {
508508
/*
@@ -522,7 +522,10 @@ impl TraceDeriveInput {
522522
}
523523
}
524524
is_gc_allocated
525-
}) || self.serde_opts.as_ref().map_or(false, |opts| opts.require_simple_alloc);
525+
});
526+
let should_require_simple_alloc = self.serde_opts.as_ref()
527+
.and_then(|opts| opts.require_simple_alloc)
528+
.unwrap_or(default_should_require_simple_alloc);
526529
let do_require_simple_alloc = |id: &dyn ToTokens| {
527530
quote!(<<#id as zerogc::CollectorId>::System as zerogc::GcSystem>::Context: zerogc::GcSimpleAlloc)
528531
};
@@ -859,9 +862,9 @@ impl TraceDeriveInput {
859862
parse_quote!(zerogc::Trace)
860863
};
861864
let method_name: Ident = if immutable {
862-
parse_quote!(visit_immutable)
865+
parse_quote!(trace_immutable)
863866
} else {
864-
parse_quote!(visit)
867+
parse_quote!(trace)
865868
};
866869
let mut generics = self.generics.original.clone();
867870
for regular in self.generics.regular_type_params() {
@@ -925,9 +928,9 @@ impl TraceDeriveInput {
925928
ActualId: zerogc::CollectorId, Self: zerogc::GcSafe<'actual_gc, ActualId> + 'actual_gc);
926929
Some(quote! {
927930
#[inline]
928-
unsafe fn visit_inside_gc<'actual_gc, Visitor, ActualId>(gc: &mut zerogc::Gc<'actual_gc, Self, ActualId>, visitor: &mut Visitor) -> Result<(), Visitor::Err>
931+
unsafe fn trace_inside_gc<'actual_gc, Visitor, ActualId>(gc: &mut zerogc::Gc<'actual_gc, Self, ActualId>, visitor: &mut Visitor) -> Result<(), Visitor::Err>
929932
#where_clause {
930-
visitor.visit_gc(gc)
933+
visitor.trace_gc(gc)
931934
}
932935
})
933936
} else { None };

libs/derive/src/macros.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,7 @@ pub struct MacroInput {
138138
/// This is necessary if the type is not `Sized`
139139
#[kwarg(optional)]
140140
visit_inside_gc: Option<VisitInsideGcClosure>,
141-
/*
142-
* The following three arguments are parsed
143-
* into a 'VisitImpl' via the 'parse_visitor' function.
144-
*
145-
* TODO: Make the name for this option 'visit_template'
146-
*
147-
* I feel like that's a more accurate description
148-
* of its function.....
149-
*/
150-
#[kwarg(optional, rename = "visit")]
141+
#[kwarg(optional, rename = "trace_template")]
151142
raw_visit_template: Option<VisitClosure>,
152143
#[kwarg(optional, rename = "trace_mut")]
153144
trace_mut_closure: Option<VisitClosure>,
@@ -263,7 +254,7 @@ impl MacroInput {
263254
let visit_impl = self.parse_visitor()?.expand_impl(mutable)?;
264255
let (impl_generics, _, where_clause) = generics.split_for_impl();
265256
let trait_name = if mutable { quote!(#zerogc_crate::Trace) } else { quote!(#zerogc_crate::TraceImmutable) };
266-
let visit_method_name = if mutable { quote!(visit) } else { quote!(visit_immutable) };
257+
let trace_method_name = if mutable { quote!(trace) } else { quote!(trace_immutable) };
267258
let needs_drop_const = if mutable {
268259
let expr = &self.needs_drop;
269260
Some(quote!(const NEEDS_DROP: bool = {
@@ -286,7 +277,7 @@ impl MacroInput {
286277
let visit_inside_gc = if mutable {
287278
let expr = match self.visit_inside_gc {
288279
Some(ref expr) => expr.0.body.clone(),
289-
None => quote!(visitor.visit_gc(gc))
280+
None => quote!(visitor.trace_gc(gc))
290281
};
291282
let where_clause = if let Some(ref clause) = self.bounds.visit_inside_gc {
292283
clause.clone()
@@ -295,7 +286,7 @@ impl MacroInput {
295286
};
296287
Some(quote! {
297288
#[inline]
298-
unsafe fn visit_inside_gc<'actual_gc, Visitor, ActualId>(gc: &mut #zerogc_crate::Gc<'actual_gc, Self, ActualId>, visitor: &mut Visitor) -> Result<(), Visitor::Err>
289+
unsafe fn trace_inside_gc<'actual_gc, Visitor, ActualId>(gc: &mut #zerogc_crate::Gc<'actual_gc, Self, ActualId>, visitor: &mut Visitor) -> Result<(), Visitor::Err>
299290
#where_clause {
300291
#expr
301292
}
@@ -313,7 +304,7 @@ impl MacroInput {
313304
#needs_trace_const
314305
#needs_drop_const
315306
#[inline] // TODO: Should this be unconditional?
316-
fn #visit_method_name<Visitor: #zerogc_crate::GcVisitor + ?Sized>(&#mutability self, visitor: &mut Visitor) -> Result<(), Visitor::Err> {
307+
fn #trace_method_name<Visitor: #zerogc_crate::GcVisitor + ?Sized>(&#mutability self, visitor: &mut Visitor) -> Result<(), Visitor::Err> {
317308
#visit_impl
318309
}
319310
#visit_inside_gc
@@ -791,7 +782,7 @@ pub enum VisitImpl {
791782
/// | #mutability | `` (empty) | `mut` |
792783
/// | #as_ref | `as_ref` | `as_mut` |
793784
/// | #iter | `iter` | `iter_mut` |
794-
/// | #visit_func | `visit` | `visit_immutable` |
785+
/// | #trace_func | `trace` | `trace_immutable` |
795786
/// | #b | `&` | `&mut` |
796787
/// | ## (escape) | `#` | `#` |
797788
///
@@ -816,7 +807,7 @@ enum MagicVarType {
816807
Mutability,
817808
AsRef,
818809
Iter,
819-
VisitFunc,
810+
TraceFunc,
820811
B
821812
}
822813
impl MagicVarType {
@@ -826,7 +817,7 @@ impl MagicVarType {
826817
"mutability" => MagicVarType::Mutability,
827818
"as_ref" => MagicVarType::AsRef,
828819
"iter" => MagicVarType::Iter,
829-
"visit_func" => MagicVarType::VisitFunc,
820+
"trace_func" => MagicVarType::TraceFunc,
830821
"b" => MagicVarType::B,
831822
_ => return Err(
832823
Error::new(ident.span(),
@@ -862,11 +853,11 @@ impl VisitImpl {
862853
quote!(iter)
863854
}
864855
}
865-
MagicVarType::VisitFunc => {
856+
MagicVarType::TraceFunc => {
866857
if mutable {
867-
quote!(visit)
858+
quote!(trace)
868859
} else {
869-
quote!(visit_immutable)
860+
quote!(trace_immutable)
870861
}
871862
}
872863
MagicVarType::B => {

libs/simple/src/layout.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ unsafe_gc_impl!(
191191
NEEDS_TRACE => true,
192192
NEEDS_DROP => true,
193193
null_trace => never,
194-
visit => |self, visitor| {
194+
trace_template => |self, visitor| {
195195
unreachable!()
196196
}
197197
);
@@ -330,7 +330,7 @@ unsafe_gc_impl!(
330330
unsafe {
331331
let start: *mut T = self.ptr() as *const T as *mut T;
332332
for i in 0..self.len() {
333-
visitor.visit(&mut *start.add(i))?;
333+
visitor.trace(&mut *start.add(i))?;
334334
}
335335
}
336336
Ok(())
@@ -340,7 +340,7 @@ unsafe_gc_impl!(
340340
unsafe {
341341
let start: *mut T = self.ptr() as *const T as *mut T;
342342
for i in 0..self.len() {
343-
visitor.visit_immutable(&*start.add(i))?;
343+
visitor.trace_immutable(&*start.add(i))?;
344344
}
345345
}
346346
Ok(())
@@ -503,7 +503,7 @@ impl<'gc, T: GcSafe<'gc, crate::CollectorId>> StaticVecType for T {
503503
val as *mut T,
504504
len
505505
);
506-
let Ok(()) = <[T] as Trace>::visit(slice, visitor);
506+
let Ok(()) = <[T] as Trace>::trace(slice, visitor);
507507
}
508508
visit::<T> as unsafe fn(*mut c_void, &mut MarkVisitor)
509509
})
@@ -544,7 +544,7 @@ impl<'gc, T: GcSafe<'gc, crate::CollectorId>> StaticGcType for [T] {
544544
val as *mut T,
545545
len
546546
);
547-
let Ok(()) = <[T] as Trace>::visit(slice, visitor);
547+
let Ok(()) = <[T] as Trace>::trace(slice, visitor);
548548
}
549549
visit::<T> as unsafe fn(*mut c_void, &mut MarkVisitor)
550550
})

libs/simple/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub unsafe trait DynTrace {
218218
}
219219
unsafe impl<T: Trace + ?Sized> DynTrace for T {
220220
fn trace(&mut self, visitor: &mut MarkVisitor) {
221-
let Ok(()) = self.visit(visitor);
221+
let Ok(()) = self.trace(visitor);
222222
}
223223
}
224224

@@ -816,7 +816,7 @@ impl RawSimpleCollector {
816816
as *const *mut SimpleVecRepr<()>
817817
as *const Gc<SimpleVecRepr<DynamicObj>>);
818818
// TODO: Assert not moving?
819-
let Ok(()) = visitor.visit_vec::<(), _>(&mut target_gc);
819+
let Ok(()) = visitor.trace_vec::<(), _>(&mut target_gc);
820820
}
821821
}
822822
}
@@ -944,7 +944,7 @@ unsafe impl GcVisitor for MarkVisitor<'_> {
944944
type Err = !;
945945

946946
#[inline]
947-
unsafe fn visit_gc<'gc, T, Id>(
947+
unsafe fn trace_gc<'gc, T, Id>(
948948
&mut self, gc: &mut ::zerogc::Gc<'gc, T, Id>
949949
) -> Result<(), Self::Err>
950950
where T: GcSafe<'gc, Id>, Id: ::zerogc::CollectorId {
@@ -972,7 +972,7 @@ unsafe impl GcVisitor for MarkVisitor<'_> {
972972
}
973973
}
974974

975-
unsafe fn visit_trait_object<'gc, T, Id>(&mut self, gc: &mut zerogc::Gc<'gc, T, Id>) -> Result<(), Self::Err>
975+
unsafe fn trace_trait_object<'gc, T, Id>(&mut self, gc: &mut zerogc::Gc<'gc, T, Id>) -> Result<(), Self::Err>
976976
where T: ?Sized + GcSafe<'gc, Id> + Pointee<Metadata=DynMetadata<T>> + zerogc::DynTrace<'gc, Id>, Id: zerogc::CollectorId {
977977
if TypeId::of::<Id>() == TypeId::of::<crate::CollectorId>() {
978978
/*
@@ -996,14 +996,14 @@ unsafe impl GcVisitor for MarkVisitor<'_> {
996996
}
997997

998998
#[inline]
999-
unsafe fn visit_vec<'gc, T, Id>(&mut self, raw: &mut ::zerogc::Gc<'gc, Id::RawVecRepr<'gc>, Id>) -> Result<(), Self::Err>
999+
unsafe fn trace_vec<'gc, T, Id>(&mut self, raw: &mut ::zerogc::Gc<'gc, Id::RawVecRepr<'gc>, Id>) -> Result<(), Self::Err>
10001000
where T: GcSafe<'gc, Id>, Id: ::zerogc::CollectorId {
10011001
// Just visit our innards as if they were a regular `Gc` reference
1002-
self.visit_gc(raw)
1002+
self.trace_gc(raw)
10031003
}
10041004

10051005
#[inline]
1006-
unsafe fn visit_array<'gc, T, Id>(&mut self, array: &mut ::zerogc::array::GcArray<'gc, T, Id>) -> Result<(), Self::Err>
1006+
unsafe fn trace_array<'gc, T, Id>(&mut self, array: &mut ::zerogc::array::GcArray<'gc, T, Id>) -> Result<(), Self::Err>
10071007
where T: GcSafe<'gc, Id>, Id: ::zerogc::CollectorId {
10081008
if TypeId::of::<Id>() == TypeId::of::<crate::CollectorId>() {
10091009
/*
@@ -1052,7 +1052,7 @@ impl MarkVisitor<'_> {
10521052
unsafe fn _visit_own_gc<'gc, T: Trace + ?Sized>(
10531053
&mut self, gc: &mut Gc<'gc, T>
10541054
) {
1055-
self._visit_own_gc_with(gc, |val, visitor| <T as Trace>::visit(val, visitor))
1055+
self._visit_own_gc_with(gc, |val, visitor| <T as Trace>::trace(val, visitor))
10561056
}
10571057
/// Visit a GC type whose [::zerogc::CollectorId] matches our own,
10581058
/// tracing it with the specified closure

src/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ unsafe_gc_impl!(
279279
NEEDS_TRACE => true,
280280
NEEDS_DROP => false,
281281
trace_mut => |self, visitor| {
282-
unsafe { visitor.visit_array(self) }
282+
unsafe { visitor.trace_array(self) }
283283
},
284284
collector_id => Id,
285285
visit_inside_gc => |gc, visitor| {
286-
visitor.visit_gc(gc)
286+
visitor.trace_gc(gc)
287287
}
288288
);

src/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ unsafe_gc_impl!(
9999
* In other words is possible to safely trace a `GcCell`
100100
* with a garbage collected type, as long as it is never mutated.
101101
*/
102-
visitor.visit(self.get_mut())
102+
visitor.trace(self.get_mut())
103103
},
104104
trace_immutable => |self, visitor| {
105105
/*
@@ -108,7 +108,7 @@ unsafe_gc_impl!(
108108
* We require `NullTrace` in order to `set` our internals.
109109
*/
110110
let mut value = self.get();
111-
visitor.visit(&mut value)?;
111+
visitor.trace(&mut value)?;
112112
self.set(value);
113113
Ok(())
114114
}

src/epsilon.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,17 @@ unsafe impl Trace for EpsilonCollectorId {
392392
const NEEDS_DROP: bool = false;
393393

394394
#[inline]
395-
fn visit<V: GcVisitor>(&mut self, _visitor: &mut V) -> Result<(), <V as GcVisitor>::Err> {
395+
fn trace<V: GcVisitor>(&mut self, _visitor: &mut V) -> Result<(), <V as GcVisitor>::Err> {
396396
Ok(())
397397
}
398398

399-
unsafe fn visit_inside_gc<'gc, V, Id>(gc: &mut crate::Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err> where V: GcVisitor, Id: CollectorId, Self: GcSafe<'gc, Id> + 'gc {
400-
visitor.visit_gc(gc)
399+
unsafe fn trace_inside_gc<'gc, V, Id>(gc: &mut crate::Gc<'gc, Self, Id>, visitor: &mut V) -> Result<(), V::Err> where V: GcVisitor, Id: CollectorId, Self: GcSafe<'gc, Id> + 'gc {
400+
visitor.trace_gc(gc)
401401
}
402402
}
403403
unsafe impl TraceImmutable for EpsilonCollectorId {
404404
#[inline]
405-
fn visit_immutable<V: GcVisitor>(&self, _visitor: &mut V) -> Result<(), V::Err> {
405+
fn trace_immutable<V: GcVisitor>(&self, _visitor: &mut V) -> Result<(), V::Err> {
406406
Ok(())
407407
}
408408
}

0 commit comments

Comments
 (0)