DIP60: @nogc attribute

Meta via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 15 20:26:23 PDT 2014


On Tuesday, 15 April 2014 at 21:42:51 UTC, Walter Bright wrote:
> On 4/15/2014 2:41 PM, Brad Anderson wrote:
>> Yes, please. Too few of the attributes have inverse attributes.
>
> That's a subject for another DIP.

This would go fairly well with Andrei's idea of passing true or 
false to an attribute to enable or disable it.

@gc(false) void fun() {}

Also, as was mentioned earlier in the thread, if @gc was actually 
implemented as a UDA just like any other, gc could simply be a 
struct that the compiler looks for, something along those lines.

struct gc
{
     bool enable;
     //...
}

Which naturally implements Andrei's proposed syntax. The same 
could be done for @property, @safe, etc. If we had DMD as a 
library, @gc probably wouldn't even need to be "special", i.e., 
compiler magic.

Finally, as MonarchDodra mentioned, the number of optional 
attributes to mark a function with can get to be a problem after 
awhile. I have two ideas on this. One is extending the concept of 
aliases to also alias attributes, like so:

//TypeTuple or just bare list?
alias everything = TypeTuple!(@safe, nothrow, pure, @gc(false));

or

alias everything(Attrs...) = Attrs;

I think that the Microsoft language with effect algebra 
(Bearophile has mentioned it before) does this. E.g., pure is 
actually:
alias pure: noeffects nothrow //... (I don't remember the actual 
syntax)

Secondly, this could just be a "higher level attribute". I don't 
know if this would require a language change or not...

struct Everything
{
     bool _pure;
     bool _nothrow;
     //...
}


More information about the Digitalmars-d mailing list