114 points · by belter · 5y ago · 59 comments
2014-09. RFC 256 https://rust-lang.github.io/rfcs/0256-remove-refcounting-gc-...
« Remove the reference-counting based Gc<T> type from the standard library and its associated support infrastructure from rustc.
Doing so lays a cleaner foundation upon which to prototype a proper tracing GC »
Contemporary with that: https://news.ycombinator.com/item?id=8312327 nikomatsakis:
« I wouldn't be so quick to give up on GC support yet! "We have a plan!" But I don't think we'll have it in for Rust 1.0. »
2015-04:
https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.h...
"Memory safety without garbage collection." is now advertised as a "key value proposition" (this isn't quite the same as saying "we're not thinking of ever adding garbage collection", of course).
2016-08: https://manishearth.github.io/blog/2016/08/18/gc-support-in-...
« Recently we (Felix, Niko, and I) have been working on getting compiler-level GC support for Rust. The plan is to provide a base set of APIs and intrinsics on which GCs can be built, without including an actual GC itself. »
This is the "Unfinished design for a builtin Rust GC" described in TFA.
2018-10:
the introductory post for the shifgrethor library (described in TFA): https://boats.gitlab.io/blog/post/shifgrethor-i/
includes a bolded « I do not expect we will ever “add GC to Rust” ».
That way, you could have direct access to all the pointers in a program without jumping through the language's hoops. And other languages could benefit from it too.
I'm not sure if the GC integration is tied to JIT support or not. I think it's mostly related to insertion of safepoints which could be useful for Rust implementation
It's very fraught to try to "mitigate the waste" at the top of the pointer. Everybody involved is clear that what you're doing there is saving up pain for yourself because periodically more of those "wasted" bits become significant and each time that happens if you've been using them now you've incurred a maintenance burden.
The waste at the bottom of the pointer is a far more sensible place to hide information because it won't get taken away when somebody ships a new CPU, it was already there in 32-bit architectures.
LLVM itself makes use of the latter trick extensively as I understand it, but doesn't use the former. If they've got a 64-byte structure, they can align them, then steal six bits at the bottom of each pointer to those structures for bit flags, and when Intel ships a new CPU their code still works. Whereas if I steal ten bits at the top of the pointer, when Intel ships Ice Lake CPUs my compiler now crashes. Good luck debugging that!
That's not how it works. The x86-64 ISA requires these "top" bits to be properly sign extended when actually accessing addresses, so any binary code that's using this "trick" is forward compatible wrt. future CPU's that might enable a bigger virtual address space. The only concern wrt. compatibility is purely ABI related but that can be managed at the OS and system-software layer.
Is it still the case after Go 1.14 (February 2020) when asynchronous preemption was implemented? As far as I know, goroutines are now preempted using signals instead of inserting checks at every function call.
Go still uses the function call check. The runtime devs found a way to combine it with a check to see if the goroutine's stack needs to be resized, so it doesn't actually cost anything.
A good GC would make heavily concurrent apps much easier to build with Rust. And would have better performance than the typical Arc Mutex objects passed around right now
I would enjoy someone test a model where the type system guarantees (or at least lets you detect the situation) that you cannot store such non-memory objects behind a traced GC node (these would include plain memory objects that need to be registered/unregistered precisely).
It might be that it would be needlessly annoying to use just compared to just RC. Or maybe it would be best of both worlds?
You can even turn it into RAII proper, by turning into a compilation error not handling those interfaces properly.
Again with .NET, there are SafeHandles as well, alongside the MarshalInterop APIs.
This is nothing new actually, Mesa/Cedar for Xerox PARC used reference counting with a cycle collector, while other descendent languages down to Modula-3 and Active Oberon always combined value types, tracing GC and C++ like resource handling capabilities.
Oh Common Lisp also has similar capabilities, specially the ZetaLisp predecessor from Lisp Machines.
Then Eiffel not only had this, it was also probably the first Algol like language to support non nullable references.
Sadly they decided to ignore all of this in Java, and then its world domination kind of made everyone else ignore it as well.
Thankfully even Java is improving their story in this regard, while languages like D, Nim and yes .NET kind of show what was already available for several decades.
Seems to me it is impossible to have both automatic precise release of a resources and collection-based GC?
As I understand it, even the documentation for IDisposable in .NET says as much at https://docs.microsoft.com/en-us/dotnet/api/system.idisposab...:
> The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.
> Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed.
So this is the interface you can use to explicitly release a resource, because the GC gets around to it only later at some unspecified time.
About SafeHandle it says at https://docs.microsoft.com/en-us/dotnet/api/system.runtime.i...:
> The SafeHandle class provides critical finalization of handle resources, preventing handles from being reclaimed prematurely by garbage collection and from being recycled by Windows to reference unintended unmanaged objects.
Doesn't seem it's at all helpful for automatic precise release of resources.
There may be advantages if you can use it to add compaction, but I don't think you need a GC to do that necessarily.
https://github.com/ixy-languages/ixy-languages
No wonder that M1 has specific architecture optimizations that help streamline ARC boilerplate code, while Swift 5.5 will bring more aggressive optimizations (disabled by default, because application can crash if weak/owned references are annotated improperly => WWDC 2021 talk)
> No wonder that M1 has specific architecture optimizations that help streamline ARC boilerplate code
No it doesn't. I told you it didn't the last time you said this.