Idea #1 on integrating RC with GC

Timon Gehr timon.gehr at gmx.ch
Sat Feb 8 06:35:49 PST 2014


On 02/06/2014 12:16 AM, Adam D. Ruppe wrote:
> On Wednesday, 5 February 2014 at 22:32:52 UTC, Andrei Alexandrescu wrote:
>> ...
>> I should also add that imparting useful semantics to scope is much
>> more difficult than it might seem.
>
> I'm not so sure about that*, but the fact is scope would be enormously
> useful if it was implemented.
>
> * Let's say it meant "assigning to any higher scope is prohibited".

Then the type system should track scope depth (i.e. regions) in order to 
support abstraction properly. (This is Walter's usual identity function 
test, and it won't get less of a problem unless D gets a sane 
polymorphic type system.)

> That
> should be trivially easy to check and ensures that variable itself
> doesn't escape.

How would you express that a slice of a static stack array of 
GC-allocated references (and those may be escaped) shouldn't be escaped?

> The tricky part would be preventing:
>
> int[] global;
> void foo(scope int[] a) {
>     int[] b = a;
>     global = b;
> }

Well, to some extent this is a solved problem. Just decide which escape 
analysis strategy to use and maybe extend its precision with type 
information.


More information about the Digitalmars-d mailing list