DIP60: @nogc attribute

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 17 12:51:39 PDT 2014


On 4/17/2014 10:41 AM, Dicebot wrote:
> On Thursday, 17 April 2014 at 16:57:32 UTC, Walter Bright wrote:
>>> With current limitations @nogc is only useful to verify that embedded code which
>>> does not have GC at all does not use any GC-triggering language features before
>>> it comes to weird linker errors / rt-asserts. But that does not work good either
>>> because of next problem:
>>
>> Remember that @nogc will be inferred for template functions. That means that
>> whether it is @nogc or not will depend on its arguments being @nogc, which is
>> just what is needed.
>
> No, it looks like I have stated that very wrong because everyone understood it
> in completely opposite way. What I mean is that `put()` is NOT @nogc and it
> still should work. Same as weakly pure is kind of pure but allowed to mutate its
> arguments, proposed "weakly @nogc" can only call GC via functions directly
> accessible from its arguments.

I don't see value for this behavior.


>> I know that you bring up the array literal issue and gc a lot, but this is
>> simply not a major issue with @nogc. The @nogc will tell you if it will
>> allocate on the gc or not, on a case by case basis, and you can use easy
>> workarounds as necessary.
>
> Beg my pardon, I have overstated this one indeed but temptation was just too
> high :) On actual topic - what "case by case" basis do you have in mind? There
> are no cases mentioned in spec when literals are guaranteed to not allocated
> AFAIK. Probably compiler developers know them but definitely not me.

That's why the compiler will tell you if it will allocate or not.



More information about the Digitalmars-d mailing list