Escape analysis (full scope analysis proposal)

Christopher Wright dhasenan at gmail.com
Sun Nov 9 05:59:18 PST 2008


Michel Fortin wrote:
> On 2008-11-06 23:36:55 -0500, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> Well how about this:
>>
>> int * p;
>> float * q;
>> if (condition) {
>>      int x; p = &x;
>> } else {
>>      float y; q = &y;
>> }
>>
>> Houston, we have a problem.
> 
> I don't see a problem at all. The compiler would expand the lifetime of 
> x to the outer scope, and do the same for y. Basically, the compiler 
> would make it this way in the compiled code:
> 
>     int * p;
>     float * q;
>     int x;
>     float y;
>     if (condition) {
>         p = &x;
>     } else {
>         q = &y;
>     }

In point of fact, it's expensive to extend the stack, so any compiler 
would do that, even without escape analysis.

On the other hand, what about nested functions? I don't think they'd 
cause any trouble, but I'm not certain.



More information about the Digitalmars-d mailing list