DIP 1017--Add Bottom Type--Final Review

Johan Engelen j at j.nl
Tue Jan 15 10:59:40 UTC 2019


On Tuesday, 15 January 2019 at 08:59:07 UTC, Mike Parker wrote:
> DIP 1017, "Add Bottom Type", is now ready for Final Review.

I know we are no longer supposed to discuss the proposal's 
merits, but...

The proposal does not describe its merits. The only merit listed 
is being able to specify that a function does not return. The 
obvious choice is adding a function attribute for that, yet the 
proposal introduces a new magic type with a whole set of new 
problems of its own and only has a few lines of text on why an 
attribute would not cut it.

No rationale is given for:
1 - implicit conversion of Tbottom to other types
2 - being able to use a noreturn function in expressions `a || 
b`, `a && b`,  `a ? b : c`
3 - why a new _type_ is needed for describing a property of a 
function (that's what attributes are for)
4 - D already has a bottom type: `void`, why is a new type needed?


"A function that returns a Tbottom is covariant with a function 
that returns any type T if T is returned via the registers"
The word "register" has no meaning here. "Register" is 
(correctly) not defined in the spec and some targets don't have 
registers. One line down the proposal mentions that this is 
implementation-defined, so it acknowledges that this sentence has 
no clear meaning.


The proposal mentions the C std function `exit()`. With this 
proposal, we are still not able to directly call `exit()` and 
have the compiler understand that the function doesn't return. 
The declaration `extern(C) Tbottom exit();` won't mangle 
correctly, whereas `extern(C) void exit() @noreturn` would. In 
other words: interfacing with C needs to be described in the 
proposal.


In the discussion of the alternative `@noreturn`, it is claimed 
that "This has the awkward result of a function specifying it has 
a return type `T`, but never returns that type."  Such functions 
would simply return `void`, which I don't find awkward at all: 
`void` is a bottom type after all.
Then it is mentioned that with `@noreturn` "Other potential uses 
of a bottom type will not be expressible", but there is no 
rationale or full description of those other uses. How is the 
'bottomness' of `Tbottom` different from `void`?


I would have imagined this proposal to be completely different: 
describe why having a new bottom type is useful, and then in a 
small extra paragraph mentioning that this new bottom type can 
also be used to describe nonreturning functions. A big addition 
like this needs a big justification with a solution to a major 
shortcoming. Not being able to specify a function never returning 
is just a very minor shortcoming.

-Johan



More information about the Digitalmars-d mailing list