Future of SafeRefCounted
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Tue Feb 25 00:17:19 UTC 2025
On Saturday, February 22, 2025 12:05:49 PM MST Dukc via Digitalmars-d wrote:
> What are your thoughts?
Personally, I'm very much hoping that DIP 1000 gets killed off. There are
some niche cases where it's useful, but in general, it's just too
disruptive. In order to support it in general, code that doesn't care at all
about it has to be marked with scope in order for the code that does care
about it to be able to use that code. And the reason that the current plan
is for Phobos v3 to not do anything with DIP 1000 is because a number of us
feel that way. Atila is looking to see if he can come up with a way to make
it work without being so disruptive, but I question that that's going to
work, whereas others like Rikki are looking to do something else entirely
which will theoretically cover more than DIP 1000 does. So, I don't know
what we're going to end up with, but realistically, if a type requires DIP
1000 in order to be @safe, then it's likely not going to be @safe in Phobos
v3.
As for RefCounted specifically, I haven't looked at its implementation
recently, so I don't know why it can't be @safe, but off the top of my head,
I don't see why it can't be possible to create something like RefCounted
that is @safe. Maybe some part of what the current design does would have to
be disallowed, but it sure seems like it should be possible to have
reference counting work with @safe so long as you don't allow references to
the internals to escape. And if for some reason, it can't be, well, then
either the code using it will need to wrap it in a way that allows for
@safe, or it can't be @safe.
And for the vast majority of code, nothing like RefCounted is needed. The GC
largely solves the problem with regards to memory management, and the cases
where you want or need to do something else will probably want a solution
that's tied to whatever allocators are being used rather than a more general
ref-counting solution (assuming that reference counting is wanted at all).
It's mostly just system resources that need to be deterministically freed /
destroyed where reference counting becomes necessary. So, IMHO, we do need a
solution for reference counting in Phobos v3, but it's also niche enough
that I don't think that it's the end of the world if some @trusted is
required for it - much as I agree that it would ideally be @safe. But again,
I'd have to sit down and work through the problem to say for sure whether it
can be @safe without DIP 1000. Either way, as things stand, DIP 1000 is not
going to be a solution for making anything in Phobos v3 @safe.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list