On 11/24/10 5:06 AM, Lars T. Kyllingstad wrote:
On Tue, 23 Nov 2010 23:26:54 -0500, Robert Jacques wrote:
On Tue, 23 Nov 2010 07:59:27 -0500, Lars T. Kyllingstad
<[email protected]> wrote:
If I've understood things correctly, by marking a delegate parameter
with 'scope' you tell the compiler not to create a true closure for the
delegate. Effectively you're saying "I promise not to escape this
delegate, so you don't need to copy its context to the heap".
In brief, my question is: Why doesn't the compiler enforce this
promise? In particular, why is 'scope' not a type constructor?
For scope to be a type constructor, D requires some form of
ownership-types& local escape analysis. Just like mutable and immutable
data needs const, I think stack/thread-local/shared data needs scope.
(There is an old proposal on the wiki about the technical
implementation, though it's badly worded) But my understanding is that
all things ownership related are relegated to D3.
Well, I think something needs to be done about it in D2 as well, because
right now 'scope' allows memory corruption to happen even in safe mode,
as demonstrated by this slightly modified example:
[snip]
This is a bug. Could you please file it as major?
Andrei