DIP 1017--Add Bottom Type--Final Review

Johannes Loher johannesloher at fg4f.de
Thu Jan 17 21:06:37 UTC 2019


Am 17.01.19 um 21:15 schrieb H. S. Teoh:
> On Thu, Jan 17, 2019 at 06:51:13PM +0000, Jonathan Marler via Digitalmars-d wrote:
> [...]
>> 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.
> 
> This would introduce an asymmetry with the rest of the pointer types in
> the language which all have equal sizes, and this asymmetry will
> percolate down to other language constructs, causing special cases and
> inconsistencies everywhere.  I don't recommend doing this.
> 
> A better approach might be to make TBottom* always equal to null --
> i.e., it's always illegal to dereference it because no instances of
> TBottom can exist.
> 
> (Of course, TBottom.sizeof would have to be either 0 or some kind of
> non-existent value, because instances of TBottom cannot actually exist.
> Based on the principle of symmetry, I'd think it should be 0, because
> making it an error would imply specialcasing generic code that may
> unknowingly be handed TBottom as a template type argument, and making it
> return some other value like -1 or size_t.min may cause problems in
> other generic code that might, for example, wish to allocate storage of
> the given size.  OTOH, maybe a negative .sizeof might be just the ticket
> to prevent generic code from trying to instantiate TBottom.  Either way,
> it would have to be treated specially -- which also means there's a
> price to be paid for adding TBottom to the language: there is no free
> lunch.)
> 
> 
> T
> 
+1 for making Tbottom* have the single value `null` (this totally makes
sense, it is a type which holds `null` or the address of a value of type
`Tbottom`, but no such address can exist, so it can only hold `null`).

`sizeof(Tbottom*) == 0` is then a logical consequence, even if it is
inconsistent with the size of other pointer types.


More information about the Digitalmars-d mailing list