Escape analysis

Hxal Hxal at freenode.irc
Mon Oct 27 13:28:46 PDT 2008


Walter Bright Wrote:
> The first step is, are function parameters considered to be escaping by 
> default or not by default? I.e.:
> 
> void bar(noscope int* p);    // p escapes
> void bar(scope int* p);      // p does not escape
> void bar(int* p);            // what should be the default?
> 
> What should be the default? The functional programmer would probably 
> choose scope as the default, and the OOP programmer noscope.

While requiring parameters by default to not escape the function
would be a great, because it'd cause less spam (I think they don't escape
in most cases) and potentially make programmers think around and
refactor their code - it'd also be quite a breaking change.

Defaulting to no escape checking being done and providing a scope parameter
class seems therefore the more obvious choice. It keeps existing code intact
and allows correctness checking and optimization on demand.

My only fear is that the feature will cause much frustration when we can reason
that a reference doesn't escape, but the compiler can't know that. For example
putting one scope parameter into another's field, or referencing a scope
parameter from a complex return value.

Anyway, if escape analysis is implemented, I'd suggest using a more high level
terminology like temporary and permanent objects. Might make more sense to
beginners.



More information about the Digitalmars-d mailing list