Short list with things to finish for D2

Walter Bright newshound1 at digitalmars.com
Sat Nov 21 01:56:52 PST 2009


Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Andrei Alexandrescu wrote:
>>> If we use @safe and @trusted to indicate unequivocally "no escape", 
>>> then there is no analysis to be done - the hard part of the analysis 
>>> has already been done manually by the user.
>>
>> The problem then becomes:
>>
>> T[] foo(T[] t) { return t; }
>>
>> T[] bar()
>> {
>>    T[3] a;
>>    return foo(a);
>> }
> 
> The "no escape" rule only applies to pointers, not arrays. Translating 
> your example to pointers:
> 
> T* foo(T* t) { return t; }
> 
> T* bar() {
>     T[] a;
>     return foo(a.ptr);
> }
> 
> Steve Schweighoffer has pointed out a while ago that the compiler cannot 
> assume a scope of a returned value to be any larger than the scopes of 
> its parameters. Your example and the example above are canonical and the 
> most complicated analysis I know of in SafeD. It is admittedly a huge 
> complication, but just something that you'll need to pay attention to 
> when implementing.

What if foo were a safe concat, like:

T[] foo(T[] t, T[] s) { return t ~ s; }

T[] bar(T[] s)
{  T[3] a;
    return foo(a, s);
}

That's perfectly safe, but how is the compiler not to give an error on that?



More information about the Digitalmars-d mailing list