DIP60: @nogc attribute

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 26 03:11:16 PDT 2014


Walter Bright:

> The @nogc logic is entirely contained in the front end, and is 
> not affected by back end logic.

Thank you for your answer and sorry for me being sometimes too 
much nervous.
So the problem I was alarmed about doesn't exists.

Some time ago I have filed this ER:
https://issues.dlang.org/show_bug.cgi?id=12642

That shows this rejected code that I thought could be accepted:

__gshared int[1] data1;
int[1] bar() @nogc {
     int x;
     return [x];
}
void main() @nogc {
     int x;
     data1 = [x];
     int[1] data2;
     data2 = [x];
}


So that's an example of what you are talking about. DMD is 
already performing some stack allocation of array literals that 
the @nogc is not seeing and rejecting.

Kenji Hara has commented:

> If you remove @nogc annotation, all array literals will be
> allocated on stack. So this is pure front-end issue,
> and may be fixed easily.

So the ER 12642 should be a wontfix, or a front-end rule should 
be added to be added so all D compilers allocate those cases on 
the stack.

If I am not missing some more point, what is the best solution?

Bye,
bearophile


More information about the Digitalmars-d mailing list