DIP 1017--Add Bottom Type--Final Review

Jonathan Marler johnnymarler at gmail.com
Thu Jan 17 18:51:13 UTC 2019


On Thursday, 17 January 2019 at 17:17:45 UTC, Tim 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.
>
> An advantage of the bottom type over an attribute is, that it 
> is part of the function type. A library allowing to set a 
> custom error handler could specify that the error handler must 
> not return:
> alias ErrorHandler = TBottom function(string msg);
>

Great example, let's include this in the DIP.

> Here is another example for TBottom* == typeof(null): If a 
> library type allows custom user data with a template and you 
> don't need, you could specify TBottom.
> struct LibraryType(UserData)
> {
>     // ...
>     UserData* userData;
> }
> Since the compiler knows, that userData is always null, it 
> could eliminate dead code. Note that it would not be possible 
> to specify typeof(null) as the template parameter of 
> LibraryType, because then userData would be of type 
> typeof(null)*.

This is another good example. I'd like to point out that the Unit 
type would allow you to do the same thing for a struct like:

struct AnotherLibraryType(UserData)
{
     UserData userData;
}

But in your example the template uses a pointer to UserData.  In 
this case the only way to express that you don't want any user 
data is to pass the Bottom type.

To summarize, the bottom type allows you to declare a special 
pointer with no storage!

     TBottom*.sizeof == 0

This is also something that should be in the DIP and Walter 
should chime in with whether or not he thinks these semantics can 
actually be implemented.



More information about the Digitalmars-d mailing list