On Wed, Aug 17, 2016 at 9:04 AM, Mike via Digitalmars-d-announce <
digitalmars-d-announce@puremagic.com> wrote:
> Or perhaps DIP1000 changes the current behavior of the `scope` storage
> class.
> My understanding is that the `scope` storage class currently allocates a
> class on the stack (though its usage for this purpose is deprecated in
> favor of std.typecons.scoped).

Correct. I believe the reason for the deprecation was that it was too easy
to use considering how easy it was to get it's usage wrong, and that a
library implementation would be just as good, which would also lessen the
number of reserved words D has, and make devs more likely to check the
documentation for its caveats.

>   If DIP1000 is implemented, it will change that behavior, so the
> allocation will instead be on the GC heap, but the compiler will do some
> flow-control analysis to prevent escaping references.  Is that right?
> Mike

Not correct, the class would still be on the stack so we can have reference
semantics during assignment etc, but the instance is on the stack so its
faster and the function the code is inside can optionally be nogc.

DIP1000 will just make the compiler check that a stack instance does not
escape its scope (though it doesn't cover all cases).

struct Astruct {} // - on stack by default
class Aclass  {} // - on heap by default
void main() {
    Astruct a = new Astruct; // override, now Astruct is on the heap
(because of "new")
    Aclass c = new Aclass; // on the heap as per-usual
    scope Aclass c1 = new Aclass; // override, now class is on the stack
(most obvious use: to make all references use the same instance)

Reply via email to