diff --git a/README.md b/README.md index 4f6725d..2467349 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ impl Finalize for Foo { // Clean up resources for Foo, because we think it will be destroyed. // Foo may not be destroyed after a call to finalize, as another // finalizer may create a reference to it due to reference cycles. + // Recursive calls of Finalize::finalize on fields are not required here + // because this is handled by Trace::finalize_glue already. } } ``` diff --git a/gc/src/trace.rs b/gc/src/trace.rs index 0a97993..a68e72f 100644 --- a/gc/src/trace.rs +++ b/gc/src/trace.rs @@ -172,13 +172,7 @@ simple_empty_finalize_trace![ RandomState ]; -impl Finalize for [T; N] { - fn finalize(&self) { - for v in self { - v.finalize(); - } - } -} +impl Finalize for [T; N] {} unsafe impl Trace for [T; N] { custom_trace!(this, { for v in this { @@ -213,13 +207,7 @@ macro_rules! fn_finalize_trace_group { macro_rules! tuple_finalize_trace { () => {}; // This case is handled above, by simple_finalize_empty_trace!(). ($($args:ident),*) => { - impl<$($args: $crate::Finalize),*> Finalize for ($($args,)*) { - fn finalize(&self) { - #[allow(non_snake_case)] - let &($(ref $args,)*) = self; - $(($args).finalize();)* - } - } + impl<$($args),*> Finalize for ($($args,)*) {} unsafe impl<$($args: $crate::Trace),*> Trace for ($($args,)*) { custom_trace!(this, { #[allow(non_snake_case)] @@ -255,24 +243,14 @@ type_arg_tuple_based_finalize_trace_impls![ (A, B, C, D, E, F, G, H, I, J, K, L); ]; -impl Finalize for Box { - fn finalize(&self) { - (**self).finalize(); - } -} +impl Finalize for Box {} unsafe impl Trace for Box { custom_trace!(this, { mark(&**this); }); } -impl Finalize for [T] { - fn finalize(&self) { - for e in self { - e.finalize(); - } - } -} +impl Finalize for [T] {} unsafe impl Trace for [T] { custom_trace!(this, { for e in this { @@ -281,13 +259,7 @@ unsafe impl Trace for [T] { }); } -impl Finalize for Vec { - fn finalize(&self) { - for e in self { - e.finalize(); - } - } -} +impl Finalize for Vec {} unsafe impl Trace for Vec { custom_trace!(this, { for e in this { @@ -296,13 +268,7 @@ unsafe impl Trace for Vec { }); } -impl Finalize for Option { - fn finalize(&self) { - if let Some(v) = self { - v.finalize(); - } - } -} +impl Finalize for Option {} unsafe impl Trace for Option { custom_trace!(this, { if let Some(v) = this { @@ -311,14 +277,7 @@ unsafe impl Trace for Option { }); } -impl Finalize for Result { - fn finalize(&self) { - match self { - Ok(v) => v.finalize(), - Err(v) => v.finalize(), - } - } -} +impl Finalize for Result {} unsafe impl Trace for Result { custom_trace!(this, { match this { @@ -328,13 +287,7 @@ unsafe impl Trace for Result { }); } -impl Finalize for BinaryHeap { - fn finalize(&self) { - for v in self { - v.finalize(); - } - } -} +impl Finalize for BinaryHeap {} unsafe impl Trace for BinaryHeap { custom_trace!(this, { for v in this { @@ -343,14 +296,7 @@ unsafe impl Trace for BinaryHeap { }); } -impl Finalize for BTreeMap { - fn finalize(&self) { - for (k, v) in self { - k.finalize(); - v.finalize(); - } - } -} +impl Finalize for BTreeMap {} unsafe impl Trace for BTreeMap { custom_trace!(this, { for (k, v) in this { @@ -360,13 +306,7 @@ unsafe impl Trace for BTreeMap { }); } -impl Finalize for BTreeSet { - fn finalize(&self) { - for v in self { - v.finalize(); - } - } -} +impl Finalize for BTreeSet {} unsafe impl Trace for BTreeSet { custom_trace!(this, { for v in this { @@ -375,15 +315,7 @@ unsafe impl Trace for BTreeSet { }); } -impl Finalize for HashMap { - fn finalize(&self) { - self.hasher().finalize(); - for (k, v) in self { - k.finalize(); - v.finalize(); - } - } -} +impl Finalize for HashMap {} unsafe impl Trace for HashMap { custom_trace!(this, { mark(this.hasher()); @@ -394,14 +326,7 @@ unsafe impl Trace for HashMap { }); } -impl Finalize for HashSet { - fn finalize(&self) { - self.hasher().finalize(); - for v in self { - v.finalize(); - } - } -} +impl Finalize for HashSet {} unsafe impl Trace for HashSet { custom_trace!(this, { mark(this.hasher()); @@ -411,13 +336,7 @@ unsafe impl Trace for HashSet { }); } -impl Finalize for LinkedList { - fn finalize(&self) { - for v in self { - v.finalize(); - } - } -} +impl Finalize for LinkedList {} unsafe impl Trace for LinkedList { custom_trace!(this, { for v in this.iter() { @@ -431,13 +350,7 @@ unsafe impl Trace for PhantomData { unsafe_empty_trace!(); } -impl Finalize for VecDeque { - fn finalize(&self) { - for v in self { - v.finalize(); - } - } -} +impl Finalize for VecDeque {} unsafe impl Trace for VecDeque { custom_trace!(this, { for v in this { @@ -446,16 +359,7 @@ unsafe impl Trace for VecDeque { }); } -impl<'a, T: ToOwned + ?Sized> Finalize for Cow<'a, T> -where - T::Owned: Finalize, -{ - fn finalize(&self) { - if let Cow::Owned(ref v) = self { - v.finalize(); - } - } -} +impl<'a, T: ToOwned + ?Sized> Finalize for Cow<'a, T>{} unsafe impl<'a, T: ToOwned + ?Sized> Trace for Cow<'a, T> where T::Owned: Trace,