-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename unsafe_ignore_trace
and unsafe_empty_trace
#52
Comments
One can cause the collector to panic with inappropriate use of use gc::{Finalize, Gc, Trace};
#[derive(Finalize, Trace)]
struct S(#[unsafe_ignore_trace] Gc<()>);
fn main() {
Gc::new(S(Gc::new(())));
}
|
Using Gc for memo_table was degrading the runtime execution of some algorithms due to the garbage collector tracing the memoization table. Replacing Gc with Rc to prevent a panic caused by the macro. see: Manishearth/rust-gc#52
I'm trying to understand what the panic message from #52 (comment) is about. It seems to me like the two In other words, I'm thinking that having I guess, based on the error message the issue somehow stems from the fact that Gc needs to Finalize and not Drop? But I must say I'm not sure I understand what exactly Finalize is used for, so I don't get the issue. In other words, I currently think this panic is a bug in (For some context, I'm coming from my first blog post and this is something I would not be able to guarantee, if it must assert that no |
@Ekleog The inner In the particular case of the destructor of a rooted |
Ordinarily, objects dropped during collections would only contain unrooted Gc pointers. But with `#[unsafe_ignore_trace]` it’s possible to smuggle a rooted Gc pointer into the heap. When we collect a rooted Gc pointer, we need to dereference it in order to unroot its contents. This should be safe because the associated allocation cannot have been collected while the Gc is rooted. Fixes an “assertion failed: finalizer_safe()” panic in the included test case (refs Manishearth#52). Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Ordinarily, objects dropped during collections would only contain unrooted Gc pointers. But with `#[unsafe_ignore_trace]` it’s possible to smuggle a rooted Gc pointer into the heap. When we collect a rooted Gc pointer, we need to dereference it in order to unroot its contents. This should be safe because the associated allocation cannot have been collected while the Gc is rooted. Fixes an “assertion failed: finalizer_safe()” panic in the included test case (refs Manishearth#52). Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Hmm… do you know of a place where I could read about what |
Omitting fields from all of the trace methods is actually safe, due to the design of this garbage collector. It just means that any
Gc<T>
s which are hidden by these impls will not ever be unrooted, and thus will not be collected if they participate in a cycle.As leaking is safe, these should be renamed from
unsafe_ignore_trace
to justignore_trace
andunsafe_empty_trace
to justempty_trace
.The text was updated successfully, but these errors were encountered: