Skip to content

Commit

Permalink
more safety comment futzing
Browse files Browse the repository at this point in the history
  • Loading branch information
kyren committed May 13, 2023
1 parent d7f9c55 commit 09e1598
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/gc-arena/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,23 @@ impl<R: for<'a> Rootable<'a> + ?Sized> Arena<R> {

// SAFETY: The Arena is Send if the projected Root type is Send. This is safe because Gc pointers
// are Send *only* when their branding lifetime is known to be 'static. Because an Arena only allows
// access to the internal pointers and the gc context through a generative 'gc lifetime that is
// access to the internal pointers and the GC context through a generative 'gc lifetime that is
// not known to be 'static within the bounds of the callback, Gc pointers are *not* Send within the
// callback, only "at rest" when viewed from outside the arena. Because `Context` is !Sync and !
// Send, and `Gc<'gc, T>` is unconditionally !Sync and !Send if we don't know what 'gc is, we can't
// really get in any trouble when inside the arena callbacks, neither Gc pointers nor pointers to
// the Context can escape the the running thread or the mutate callback.
// callback, only "at rest" when viewed from outside the arena. Because `Context` is !Sync and
// !Send, and `Gc<'gc, T>` is unconditionally !Sync and !Send when we don't know what 'gc is, we
// can't really get in any trouble when inside the arena callbacks, neither Gc pointers nor pointers
// to the Context can escape the the running thread or the mutate callback.
//
// Effectively, this means that you can get a Send-able arena if every type "other than
// Gc<'gc, T>" is Send, because outside of the arena mutate call, we can know that Gc<'gc, T> is
// *really* `Gc<'static, T>` and thus can be Send.
//
// The `'gc` lifetime generated by Arena callbacks is, effectively "'static and in an arena". You
// could use the `'gc` lifetime in a different type, other than `Gc` or other `gc_arena` types,
// that implements Send iff 'gc == 'static, and in doing so, the projection of those types would be
// 'static and thus also possibly Send. This must be correct though, because in order for a type
// to be 'gc without unsafety, any 'gc types it contains must have come from `gc-arena` methods and
// actually be "'static and in an arena".
// can use the `'gc` lifetime in different types, other than `Gc` or other `gc_arena` types, and
// in doing so, the projection of those types would be 'static and thus also possibly Send. This
// must be correct though, because in order for a type to be 'gc without unsafety, any 'gc types it
// contains must have come from `gc-arena` methods and actually be "'static and in an arena", and
// thus safe to be Send.
unsafe impl<R: for<'a> Rootable<'a> + ?Sized> Send for Arena<R> where Root<'static, R>: Send {}

/// Create a temporary arena without a root object and perform the given operation on it. No garbage
Expand Down

0 comments on commit 09e1598

Please sign in to comment.