Escape Analysis on reddit

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Nov 1 08:51:37 PDT 2008


ore-sama wrote:
> Andrei Alexandrescu Wrote:
> 
>> In this case it's not even conservative, it's doing the correct
>> thing. To illustrate the effects of a conservative approach,
>> consider:
>> 
>> scope int *foo(scope int *p) { int x; auto r = &x; r = p; return r;
>>  }
>> 
>> This function won't compile if the compiler employs
>> flow-insensitive escape analysis (see e.g. 
>> http://en.wikipedia.org/wiki/Data_flow_analysis ) because r will be
>>  marked as escaping regardless of order of statements.
> 
> If compiler is able to mark data as escaping and compare escape marks
> of variables, isn't it able to derive parameters' marks rather than
> requesting them from programmers? Thus it can build function's
> precise signature and reading it from obj file (another
> long-announced feature) it can decide whether that function is
> callable from current context, but compiler should also check objs
> before linking to make sure that their metadata don't conflict.

Excellent point. The compiler can do that, but it would take a long time 
and would need access to the entire source code (the dreaded 
"interprocedural analysis"). This makes modular development difficult.

A solution is to have the programmer put information about the function 
in the function signature. There's a tradeoff to be made so as not to 
burden the programmer with writing too long signatures.


Andrei



More information about the Digitalmars-d mailing list