Skip to content

Commit

Permalink
Merge pull request #106 from HalidOdat/feature/trace-rc
Browse files Browse the repository at this point in the history
Added `Trace` for `Rc`
  • Loading branch information
Manishearth authored Jun 16, 2020
2 parents c5408d2 + 33dd4ec commit 9b05709
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::num::{
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32,
AtomicU64, AtomicU8, AtomicUsize,
Expand Down Expand Up @@ -141,6 +142,7 @@ simple_empty_finalize_trace![
char,
String,
Box<str>,
Rc<str>,
Path,
PathBuf,
NonZeroIsize,
Expand Down Expand Up @@ -256,6 +258,13 @@ type_arg_tuple_based_finalized_trace_impls![
(A, B, C, D, E, F, G, H, I, J, K, L);
];

impl<T: Trace + ?Sized> Finalize for Rc<T> {}
unsafe impl<T: Trace + ?Sized> Trace for Rc<T> {
custom_trace!(this, {
mark(&**this);
});
}

impl<T: Trace + ?Sized> Finalize for Box<T> {}
unsafe impl<T: Trace + ?Sized> Trace for Box<T> {
custom_trace!(this, {
Expand Down
16 changes: 16 additions & 0 deletions gc/tests/trace_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use gc_derive::{Finalize, Trace};
use std::cell::RefCell;
use std::rc::Rc;

thread_local!(static X: RefCell<u8> = RefCell::new(0));

Expand Down Expand Up @@ -37,6 +38,21 @@ struct InnerBoxStr {
inner: Box<str>,
}

#[derive(Trace, Clone, Finalize)]
struct InnerRcSlice {
inner: Box<[u32]>,
}

#[derive(Trace, Clone, Finalize)]
struct InnerRcStr {
inner: Rc<str>,
}

#[derive(Trace, Clone, Finalize)]
struct InnerRcStruct {
inner: Rc<Bar>,
}

#[derive(Trace, Finalize)]
struct Baz {
a: Bar,
Expand Down

0 comments on commit 9b05709

Please sign in to comment.