DIP 1017--Add Bottom Type--Final Review

Jonathan Marler johnnymarler at gmail.com
Tue Jan 15 20:07:52 UTC 2019


On Tuesday, 15 January 2019 at 16:01:13 UTC, Jonathan Marler 
wrote:
> On Tuesday, 15 January 2019 at 08:59:07 UTC, Mike Parker wrote:
>> DIP 1017, "Add Bottom Type", is now ready for Final Review. 
>> This is the last chance for community feedback before the DIP 
>> is handed off to Walter and Andrei for the Formal Assessment. 
>> Please read the procedures document for details on what is 
>> expected in this review stage:
>>
>> https://github.com/dlang/DIPs/blob/master/PROCEDURE.md#final-review
>>
>> The current revision of the DIP for this review is located 
>> here:
>>
>> https://github.com/dlang/DIPs/blob/4716033a8cbc2ee024bfad8942b2ff6b63521f63/DIPs/DIP1017.md
>>
>> In it you'll find a link to and summary of the previous review 
>> round. This round of review will continue until 11:59 pm ET on 
>> January 30 unless I call it off before then.
>>
>> Thanks in advance for your participation.
>
>
> I'd like to point out that this proposal is introducing 2 new 
> semantic features that are related but actually orthogonal.
>
> 1. Allow a functions to be marked as "no return"
> 2. Introduce a "bottom" type defined as typeof(assert(0)).  Any 
> function that returns this type will be marked as "no return".
>
> Other reviewers have asked for why using a "bottom" type is 
> preferable to a function attribute or a special out contract. 
> In regards to the first feature (allow functions to be marked 
> as "no return") they are all "semantically equivalent".  They 
> all provide a way for the control-flow analyzer to know when a 
> function doesn't return and optimize the code surrounding it.
>
> The second feature goes another step further by introducing the 
> "bottom type" into the language.  This introduces new semantics 
> that define how non-returning functions interact with the type 
> system.  Consider the following:
>
> int main(string[] args)
> {
>     return (args.length > 1) || assert(0);
> }
>
> This currently doesn't compile but will with the new "bottom" 
> type.  Note that this example is another demonstration for why 
> these 2 features are orthogonal.
>
> So the question of whether we should use a type/function 
> attribute/contract to mark functions as "no return" is a 
> different question than whether we should be introducing a new 
> bottom type.  The 2 are conflated because if we do introduce a 
> new "bottom" type, then it means we will already have a way to 
> mark a function as "no return".
>
> I would first try to answer whether or not we want the "bottom" 
> type.  If the answer is yes, then we now have a way to mark 
> functions as "no return".  If the answer is no, then we can use 
> a function attribute or special out contract.

To clarify a bit more.

The rationale of the DIP only applies to the first feature which 
is to come up with some way of marking a functions as "no 
return". I haven't seen any rationale for the second orthogonal 
feature which is adding a bottom type to the language.

 From what I understand, adding a bottom type to the language 
allows us to call no-return functions inside expressions.

return a || assert(0);

instead of

if (a)
     return a;
assert(0);

Though I can't come up with a practical use case for this.

What else does the new bottom type give us?  And be sure to 
distinguish between things that only require "no-return" 
functions and things that require a bottom type.  If they only 
require "no-return" functions, then they are not rationale for 
adding a bottom type.



More information about the Digitalmars-d mailing list