Escape analysis

Sean Kelly sean at invisibleduck.org
Tue Oct 28 15:23:16 PDT 2008


Walter Bright wrote:
> Sean Kelly wrote:
>> I do think, however, that 'scope' should be the default behavior, for 
>> two reasons.  It's backwards-compatible, which is handy.  But more 
>> importantly, I'd say that probably 95% of the current uses of 
>> delegates are scoped, and that isn't likely to shift all the way to 
>> 50% even if D moved to a much more functional style of programming.  
>> Algorithms, for example, all use scoped delegates, which I'd say is 
>> far and away their most common current use.
> 
> The counter to that is that when there is an inadvertent escape of a 
> reference, the error is often undetectable even while it silently 
> corrupts data and behaves erratically.
> 
> In other words (as Andrei pointed out to me) the cost of those errors, 
> even though rare, is very high. This makes it highly desirable to 
> prevent them automatically, rather than relying on the skill and 
> attention to detail of the programmer.

I think the cost/benefit of this could probably be argued either way. 
I've never encountered a bug related to this, for example, so to me the 
benefit is entirely theoretical while the cost is immediate.

> The 'scope' storage class also has a future in that it is possible using 
> data flow analysis to statically verify it.

This is the real benefit in my mind.  From a "features I want in a 
systems programming language" standpoint I absolutely do not want 
default dynamic closures (today at any rate).  However, just like 
'const' I very much appreciate that this approach allows for static 
verification.  So as much as I hate to say so I think that default 
dynamic closures would be the best long-term option for D.  The cost of 
DMA will continue to come down anyway, and once a codebase is converted 
it probably won't be too difficult to maintain going forward.


Sean



More information about the Digitalmars-d mailing list