DIP 1017--Add Bottom Type--Final Review

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 17 20:15:20 UTC 2019


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

-- 
Those who've learned LaTeX swear by it. Those who are learning LaTeX swear at it. -- Pete Bleackley


More information about the Digitalmars-d mailing list