4 ms·
All the GC implementations I've seen in Rust use unsafe code, and I really wanted to avoid it. I struggled a bit with some of the RefCell stuff, but the folks
by groovy2shoes 11y ago
All the GC implementations I've seen in Rust use unsafe code, and I really wanted to avoid it. I struggled a bit with some of the RefCell stuff, but the folks on #rust were really helpful. I'm still not sure that a practical GC can be implemented without unsafe, given that RefCells can't be recursively borrowed (so as soon as you have mutable recursive data structures, you have to find some way to work around the RefCell limitation that the contents can only be mutably borrowed once). I wonder if it wouldn't be nice to have something similar to a RefCell that allows multiple mutable borrows, which I think would be safe (only) if the application is single-threaded. Or perhaps a variant that mutably borrows only non-RefCell bits of the contents, leaving the nested RefCell free to be mutably borrowed.
Thanks for your feedback :) I'd had it sitting there for a while with no idea if it was any good or not.
- steveklabnik 11y ago> I think would be safe (only) if the application is single-threaded. Unfortunately, it's not that easy: http://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/ http://manishearth.github.io/blog/2015/05/17/the-problem-wit...
- groovy2shoes 11y agoGood to know. Thanks.
- Manishearth 11y agoIn fact, RefCell can't even be shared between threads, it _has_ to be used in a single threaded context. RefCell and the "no mutable aliasing" isn't something to be "worked around", it's something to embrace, because safety and many other things come from it.