Why is 'scope' so weak?
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Tue Dec 7 10:58:58 PST 2010
On 24/11/2010 17:08, Lars T. Kyllingstad wrote:
> On Wed, 24 Nov 2010 10:34:10 -0600, Andrei Alexandrescu wrote:
>
>> 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
>>>> <public at kyllingen.nospamnet> 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?
>
>
> http://d.puremagic.com/issues/show_bug.cgi?id=5270
>
> I'm curious to see what the solution to this will be.
>
> -Lars
Indeed, is the bug that one cannot use scope delegates in @safe code?
--
Bruno Medeiros - Software Engineer
More information about the Digitalmars-d
mailing list