Garbage collection in Rust got a little better
52 points by polywolf
52 points by polywolf
I really wish there was a function to force the GC to go named “fire”
I’ve been working in this space for a long time for the garbage collector of my embedded scheme implementation scheme-rs, which has gone through many iterations. The solution I had for Trace was to instead make the visitor function itself a visitor: &mut dyn FnMut(OpaqueGcPtr). This is acceptable to me since I need to type-erase these functions anyway
For instance, I want to see if I can get niche-optimization for zero-overhead Option<Gc> and, of course, I always want to crank out extra performance.
From briefly reading the source code, it seems like this is blocked because null is used to indicate a dead pointer (see Gc::is_dead). Would it be possible to switch to a different sentinel value? E.g. -1.
My gut tells me this is fine on all(?) hardware. But I don't know if that runs afoul with some undefined behavior or Rust safety rules.
This isn’t the only blocking issue; otherwise I would use an unaligned pointer or a the maxed address and call it a day. The other problem is that UnsafeCell is exempt from niche optimization, so using a nonzero type internal still won’t allow Option<Gc> to be niche-optimized.