RFC: Change what assert does on error

Dennis dkorpel at gmail.com
Tue Jul 8 14:34:04 UTC 2025


On Tuesday, 8 July 2025 at 10:47:52 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> I've found where the compiler is implementing this, verified it.
>
> Its not nothrow specific.

Whether a function is nothrow affects whether a call expression 
'can throw'

https://github.com/dlang/dmd/blob/9610da2443ec4ed3aeed060783e07f76287ae397/compiler/src/dmd/canthrow.d#L131-L139

Which affects whether a statement 'can throw'

https://github.com/dlang/dmd/blob/9610da2443ec4ed3aeed060783e07f76287ae397/compiler/src/dmd/blockexit.d#L101C23-L101C31

And when a 'try' statement can only fall through or halt, then a 
(try A; finally B) gets transformed into (A; B). When the try 
statement 'can throw' this doesn't happen.

https://github.com/dlang/dmd/blob/9610da2443ec4ed3aeed060783e07f76287ae397/compiler/src/dmd/statementsem.d#L3421-L3432

Through that path, nothrow produceds better generated code, which 
you can easily verify by looking at assembler output of:

```D
void f();
void testA() {try {f();} finally {f();}}

void g() nothrow;
void testB() {try {g();} finally {g();}}
```

> Its Exception specific, not nothrow. Its subtle, but very 
> distinct difference.

I have no idea what this distinction is supposed to say, but 
"there is no nothrow specific optimizations taking place" is 
either false or pedantic about words.


More information about the Digitalmars-d mailing list