kyren / gc-arena

Incremental garbage collection from safe Rust
Creative Commons Zero v1.0 Universal
436 stars 36 forks source link

Modify names and lifetime signatures for ergonomics. #65

Closed kyren closed 1 year ago

kyren commented 1 year ago

Renames CollectionContext -> Collection and MutationContext -> Mutation.

Gets rid of the explicit extra 'a lifetime on Mutation in favor of an easier to deal with &Mutation<'gc>, and the same change to Collection, the Collection parameter becomes &Collection.

Mutation and Collection are now #[repr(transparent)] newtypes of the Context, and they are produced through transmute.

The methods on Arena require a callback that accepts &'gc MutationContext<'gc>. This does not give any extra powers per se and is not dangerous, but it does enable wrapper types around &'gc MutationContext<'gc> to have one less lifetime in play.

As a related fix, also changes Arena::mutate like methods to again forbid returning internal root object references, as it can be used to place Gc pointers from Box::leak'ed arenas into other arenas. This is currently sound by sheer luck, but it is incredibly sketchy and should be disallowed.