GC Support in Rust

We’ve been discussing adding hooks to Rust to make it easy to implement or integrate with GCs.

I’ve written a post illustrating the design we have so far.

Feedback welcome! We’d especially love to see some discussion about solutions for the unresolved problems mentioned in the post.

8 Likes

Please, make sure that the design will support compacting and ideally multithreaded GCs.

Since you already have stackmaps (and register maps) in your design, compaction will just involve patching these locations/registers.

Multithreading is an order of magnitude more complex if objects can be accessed from multiple threads, though. It will require stopping threads that access GC objects at safepoints.

Compacting should be doable, either by using double-pointers, or by doing the patching you mention. Will be tricky, but I don’t think it will be impossible.

Yes, you need some form of safepoint mechanism (which the implementor can add) for multithreaded gcs.

Double-pointers will require more compiler support. Patching is easier (and still safe).

Safepoints are another issue, there are three major ways to implement them: memory protection games, code patching and polling. The first two can be implemented with zero overhead but are not available on all systems (e.g. XBox or iPhone). And polling requires runtime overhead, sometimes significant.

Then there’s a question of write barrier for card marking if a generational GC is needed.

Double pointers require zero compiler support. When I say double pointers I just mean that Rust-side GC values are handles.

The safety of patching is questionable, because of noalias and the general safety issues around mutation. It can be implemented safely, but it’s not that straightforward.

Do you need a Pinnable trait?

No, you just need to use UnsafeCell properly.

Simple double pointers will indeed help for single-threaded GC.

Why noalias is a problem? Stackmap should identify all the possible aliased locations (barring unsafe code).

&-pointers aren’t put into the stack map. Though this could be a mode you switch on, I guess.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.