[Dlang-study] [lifetime] Initial thoughts on lifetime management

Andrei Alexandrescu andrei at erdani.com
Wed Oct 28 15:42:46 PDT 2015


On 10/28/2015 06:39 PM, Timon Gehr wrote:
> Actually, we do not need #references <= count.
> It's just (#references > 0) -> (count > 0).
> (The converse should also hold, but then #references has to include
> cyclic references.)

That's right. Interesting!

>> (There are other analyses that compute conservative bounds, such as our
>> well-known VRP or computing the stack frame size for a function.)
>> ...
>
> The analysis does not need to determine the maximal number of increments
> in the scope. They can in principle all be fused into one inc upon
> object creation and one dec upon exit (both multiplicity 1), with the
> obvious caveat that the reference may now live longer than before the
> transformation. Increments are then only necessary within the method
> body if there is a chance that the copied reference escapes.
>
>>> Anyway, the solution is indeed to make it the responsibility of the
>>> caller to keep the borrowed object alive. I.e. when passing a non-scope
>>> reference to a scope argument, the reference count must be increased for
>>> the duration of the call. The benefit is that scope references can be
>>> duplicated arbitrarily without updating the reference count.
>>> This applies to globals just as well as to other cases.
>>
>> Sounds interesting. So it looks like one additional hidden variable per
>> reference created in a scope may be necessary in order to avoid
>> complicated inc/dec for references.
>> ...
>
> IMHO it's not all that complicated even without the lowering.

Fantastic. That's why you're paid the big bucks! :o)


Andrei


More information about the Dlang-study mailing list