DIP60: @nogc attribute

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 16 13:28:57 PDT 2014


On Wednesday, 16 April 2014 at 19:44:19 UTC, Peter Alexander 
wrote:
> On Tuesday, 15 April 2014 at 17:01:38 UTC, Walter Bright wrote:
>> http://wiki.dlang.org/DIP60
>>
>> Start on implementation:
>>
>> https://github.com/D-Programming-Language/dmd/pull/3455
>
> Some initial thoughts:
>
> * Is it perhaps too early to introduce this? We don't have 
> allocators yet, so it can be quite hard to avoid the GC in some 
> situations.
>
> * Many Phobos functions use 'text' and 'format' in asserts. 
> What should be done about those?

As a rule of thumb, format and text should *already* be avoided 
altogether in (non-static) asserts, as they can throw exceptions, 
preventing a function from being @nothrow. For example, sort:
https://github.com/D-Programming-Language/phobos/pull/2075/files#diff-ff74a46362b5953e8c88120e2490f839R9344

That said, the issue remains relevant for @nogc. Not only the 
exception itself, but also for the ".msg" field. How do we 
allocate it? Who cleans it up? Does the catcher have to do it? 
Can the catcher know he has to do it?

> * Does @nogc => nothrow? If I'm not mistaken, throw must 
> through a GC-allocated Throwable.

Even then, what about asserts? Well, I guess it's OK if Errors 
leak, since you are supposed to terminate shortly afterwards.

> * If the above is true, does that mean exceptions cannot be 
> used at all in @nogc code?
>
> * I worry about the number of attributes being added. Where do 
> we draw the line? Are we going to add every attribute that 
> someone finds a use for? @logicalconst @nonrecursive 
> @nonreentrant @guaranteedtermination @neverreturns

I like the concept of having an "@everything" attribute. It 
"future proofs" code (in a way, if you are also fine with it 
potentially breaking). Also, it is often easier (I think) to not 
think in terms of "what guarantees does my function provide", but 
rather "what guarantees does my function *not* provide"? EG:

void myFun(int* p) @everyting impure;

My function is safe, nothrow, nogc etc... except pure.

BUT, I think this should be the subject of another thread. Let's 
focus on @nogc.


More information about the Digitalmars-d mailing list