DIP60: @nogc attribute

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 21 15:52:42 PDT 2014


On Sunday, 20 April 2014 at 18:48:49 UTC, John Colvin wrote:
>> The way I understood your idea, was that a template could be 
>> marked @nogc, and yet still allow template arguments that 
>> themselves may gc.
>>
>> This can be accomplished by creating a unit test that passes 
>> non-allocating template parameters, and then verifying the 
>> instantiation is @nogc.
>
> The only way that works is if the unittest has coverage of all 
> possible currently non-GC-using instantiations of all templates 
> all the way down the call-tree.*
>
> Imagine the case where some function deep down the call-tree 
> has a `static if(T == NastyType) doGCStuff();`.
>
> In order to protect against this, you have to check the 
> internals of the entire call-tree in order to write the 
> required unittest, and verify manually that you haven't missed 
> a case every time anything changes.
>
> *alright, technically only those that can be instantiated by 
> the function your testing, but this still blows up pretty fast.

Looks like John has similar thinking pattern for this specific 
case :P

Also you proposal does not add any hygiene checks to non-template 
functions _and_ requires to create a boilerplate output range 
mocks (for all possible duck types) and extra static asserts for 
all functions that you may want to mark as weak @nogc. I don't 
see it as clean solution that can actually be used in a library.

The very marketing value of @nogc is not to show that something 
like it is possible (it already is) but to show "hey, look how 
easy and clean it is!"


More information about the Digitalmars-d mailing list