DIP 1029---Add throw as Function Attribute---Community Review Round 1

Dukc ajieskola at gmail.com
Wed Jan 15 12:29:43 UTC 2020


On Tuesday, 14 January 2020 at 22:30:40 UTC, Walter Bright wrote:
> On 1/14/2020 8:44 AM, Dukc wrote:
>> This would be a step forward, of course. But would not it be 
>> better to kill the one-way attribute problem in one go 
>> -meaning, making an antiattribute for `pure` and `@nogc` too?
>
> Because for the anti-nothrow we already have a trivial solution 
> staring us in the face, we just have to pick it up. I have no 
> explanation for not seeing the obvious before.

Good.

>
>
>> In addition, I suggest that there should be a way to use 
>> [`pure:`/`nothrow:`/`@nogc:`/`@safe:`/their antiattributes] so 
>> that they only apply when attributes are not inferred - not 
>> for templated functions. This would also remove a big obstacle 
>> from front of DIP1028, as one could just mark the whole module 
>> `@system` with one statement without killing template `@safe` 
>> or `@live` inference.
>
> It turns out that there's another "attribute" under the covers 
> - the default. Only when an attribute is the default does 
> inference come into play. Hence, when "nothrow" becomes the 
> default, there will be actually three states - throw, nothrow, 
> and default.

Yes, correct. But what is worth mentioning ew are actually 
discussing about FOUR attributes: `throw`, `nothrow`, present 
default and the `nothrow` default. If the latest someday becomes 
the default, we suddently lose our ability to use the current 
default.

What I was saying that it would be worthwhile to make all those 
"default" attributes accessible so that is the scope already is, 
say `throw`, you can change it to the (current or likely-future) 
default behaviour. This will make the transition to 
nothrow-default much easier, as people can set their whole 
modules to the old default to keep legacy code running, or set 
the whole module to the new default so that the checks are done 
even before the transition.

>
> It works out rather nicely. It's in play for 
> safe/trusted/system already, and has been since the beginning.

Setting the default this way should also be possible for 
`@system/`@safe/`@live` too (in theory, for `@trusted` too, but 
why in the world would anyone want to default to it?). And for 
other inferred attributes, if they get their antiattributes.




More information about the Digitalmars-d mailing list