DIP74: Reference Counted Class Objects

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 26 16:09:59 PST 2015


On Thursday, 26 February 2015 at 21:50:56 UTC, Andrei 
Alexandrescu wrote:
> http://wiki.dlang.org/DIP74 got to reviewable form. Please 
> destroy and discuss.
>
> Thanks,
>
> Andrei

"The compiler detects automatically and treats specially all 
classes and interfaces that define the following two methods:"

Well, RefCounted could use compile time reflexion to do so. Even 
better, we could define a lvalue property for RefCounted to use a 
counter so we can do intrusive counting in both classes and 
structs.

"@safe code may not issue explicit calls to opAddRef/opRelease. "

I guess we could simply make them @system .

" RCOs objects are subject to additional limitations compared to 
their GC counterparts:

No conversion to Object or interfaces that are not reference 
counted "

No problem, I'm gonna duplicate all my code and as will every 
single library writer out there.

Missing:

All write of RCO reference to statics must be atomic and ordered 
as long as the language can't enforce thread locality (at least 
in @safe code).

Generally:
This DIP works around (announced) limitations of DIP25. As escape 
can only be checked properly for type with no indirections, and 
only solve the problem for classes/interfaces. Other type with 
indirection remains an unsolved problem.

If I were in charge, that would be a clear no, and the sign that 
DIP25 approach needs to be reworked, as wack-a-mole is not a good 
way to handle design.


More information about the Digitalmars-d mailing list