Safe reference counting cannot be implemented as a library
sclytrack via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 31 11:53:03 PDT 2015
On Thursday, 29 October 2015 at 20:31:49 UTC, Zach the Mystic
wrote:
> On Tuesday, 27 October 2015 at 18:10:18 UTC, deadalnix wrote:
>> I've made the claim that we should implement reference
>> counting as a library many time, so I think I should explicit
>> my position. Indeed, RC require some level a compiler support
>> to be safe. That being said, the support does not need to be
>> specific to RC. On fact, my position is that the language
>> should provide some basic mechanism on top of which safe RC
>> can be implemented, as a library.
>>
>> The problem at hand here is escape analysis. The compiler must
>> be able to ensure that a reference doesn't escape the RC
>> mechanism in an uncontrolled manner. I'd like to add such
>> mechanism to the language rather than bake in reference
>> counting, as it can be used to solve other problem we are
>> facing today (@nogc exception for instance).
>
> Here's a link to the reference safety system I proposed some
> months ago:
>
> http://forum.dlang.org/post/offurllmuxjewizxedab@forum.dlang.org
>
> I'm very far from having the expertise needed to know whether
> it would be worth its weight in practice, but it was better to
> write it out than to keep it bottled up in my head. I hope it
> will be of some use.
1) Assignment to RCObject
-------------------------
{
RCObject obj = new RCObject()
Item item1 = obj.items[x];
_temp1 = obj;
obj = new RCObject();
_temp2 = obj;
obj = new RCObject();
}
2) Entering a subscope
----------------------
With this I mean entering a subscope that assigns to the RCObject.
{
RCObject obj2 = new RCObject()
RCObject obj = new RCObject()
_temp1 = obj; //(2) Entering a subscope
{
_temp2 = obj; //(1) Assignment to RCObject
obj = new RCObject();
}
}
3) Leaving a scope.
-------------------
The Item is not reference counted.
{
Item item1;
{
RCObject obj = new RCObject();
//item1 = obj.items[x]; //(3) Leaving subscope
}
}
{
RCObject obj = new RCObject();
Item item1;
_temp1 = obj; //(2) Entering subscope
{
_temp2 = obj; //(1) Assignement to RCObject
obj = new RCObject();
//item1 = obj.items[x]; //(3) Leaving subscope
_temp3 = obj; //(1) Assignement to RCObject
obj = new RCObject();
}
}
4) RCObject joins a scope
-------------------------
{
_temp1 = obj.field.rcobject; //(4) RCObject joins current scope.
Item item1 = obj.field.rcobject.a.items[0];
//_temp1; //(2) Entering subscope
{
_temp3 = obj.field.rcobject; //(1) Assignment to RCObject
obj.field.rcobject = new RCObject();
}
_temp4 = obj.field.rcobject; //(4) RCObject joins current scope.
item1 = obj.field.rcobject.a.items[2];
}
More information about the Digitalmars-d
mailing list