Reference counting with fat pointers

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 26 05:43:27 PDT 2014


On Saturday, 26 July 2014 at 10:49:25 UTC, Marc Schütz wrote:
> Interesting proposal. It seems that you want to change the 
> default for pointers in D, but Walter will probably not like 
> that ;-). But I wonder how much language support this actually 
> needs, much of it seems implementable with templates, which is 
> probably much more acceptable.

What language interface should be provided for RC is up to 
debate. Getting it working at the binary level is problematic 
enough, so I focused on it.

> Some random comments:
>
>> Scoped: "The reference count is incremented when escaped or 
>> copied to a fat pointer."
>
> Could you explain that? A scoped pointer can by definition 
> never be escaped; therefore there should be no need to pass the 
> reference counter along.

Disallowing escaping of scoped parameters implies strict scoping 
can work. I was trying to get escaping working. It's easy to deny 
it if the need be.

>> Function parameters: "Caller doesn't increment the counter 
>> when passing a pointer as a function argument."
>
> There are some corner cases here. For example when an r-value 
> is moved into a function as an argument. The callee will not 
> decrement the RC of its parameters, with the consequence that 
> the RC never goes to 0. There might be other problems, in 
> particular in the presence of optimizations.

Ouch, probably there is the same problem with tail call 
optimization. As of now, I was trying to get sharing and casting 
work, protocol for function parameters needs more work, will 
think about conservative counting here.

> See also my writeup on borrowing, will add more examples there:
> http://wiki.dlang.org/User:Schuetzm/scope

Hmm, if you got strict scoping work, that will be interesting.


More information about the Digitalmars-d mailing list