DIP 1017--Add Bottom Type--Final Review

Neia Neutuladh neia at ikeran.org
Wed Jan 16 07:23:56 UTC 2019


On Wed, 16 Jan 2019 04:24:34 +0000, aliak wrote:
> On Wednesday, 16 January 2019 at 01:14:58 UTC, Nicholas Wilson wrote:
>> Those can all be done by an attribute. So it comes down to a cost
>> benefit analysis: the benefits they provide are the same,
>> except the implementation of bottom is going to be much more costly.
> 
> Is it "much" more costly?
> 
> What about the benefit of not being able to write code like:
> 
> @noreturn int f() { ... } // wat?

That's a downside. Consider a binding processor for a scripting language. 
It accepts functions of the form:

    int fn(State* state);

where the return value indicates the number of return values pushed onto 
the stack. You want this processor to handle an `abort` function. You must 
declare it as:

    int abort(State* state);

You also want these functions to be able to call each other, and you want 
the `abort` function to have proper flow analysis when you do so. 
Therefore you must declare it as:

    noreturn abort(State* state);

This is obviously a problem. You either need two different functions with 
different names (and since both do the same thing, they'll be similar 
names, easy to confuse), or to forego the flow analysis benefits of 
noreturn.

It's a disincentive to use noreturn.

This might not be enough of a reason to use an attribute instead of a 
type, but it's *a* reason, and that kind of code has its place.


More information about the Digitalmars-d mailing list