Bottom Type--Type Theory

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 18 00:33:11 UTC 2019


On Fri, Jan 18, 2019 at 01:13:28AM +0100, Johannes Loher via Digitalmars-d wrote:
> Am 18.01.19 um 00:53 schrieb H. S. Teoh:
> > Another case to consider: what should .typeid of Tbottom return?
> > 
> Indeed an interesting question. Since `Tbottom` is a type like any
> other, it needs to return an instance of TypeInfo.

Right.


> The even more interesting question is what the methods should return.
> Take for example `TypeInfo.equals`. Because there are no values of
> type `Tbottom`, any two instances of type `Tbottom` are equal and the
> method should return true. On the other hand, by the same argument,
> any two instances of `Tbottom` are not equal and the method should
> return false.

Actually, since there can be no instances of Tbottom, that in theory
also means TypeInfo.equals should never get called.  Which means its
implementation should simply be `assert(0);`.


> From a more pragmatic point of view: It does not really matter what
> this method returns. It does take pointers to void which internally
> will be cast to `Tbottom*` (becasue we are actually comparing
> `Tbottom`s) and then dereferencing it will simply abort the program
> (`null` dereferencing).

This would be consistent with the implementation of .equal being
`assert(0);`.


> I think it is similar for the other methods. Some simply return some
> information about the type, e.g. `talign` should return 0.

Yeah, .compares should also be `assert(0);`, not sure about .tsize:
what's the size of something that doesn't exist?  I'm tempted to say
.tsize should abort, but then returning 0 doesn't seem amiss either (if
the instance doesn't exist, it also does not take up any space). It
would help generic code not abort needlessly if they're just querying
type information without actually trying to create an instance.

Certainly .swap should assert(0), .next should return null, and
.initializer should assert(0).

In fact, I wonder if making .initializer call assert(0) would be enough
to implement the "initializing Tbottom == assert(0)" rule -- maybe even
without the compiler specifically checking for this case!  (Though
compiler checking will probably still be necessary in order to emit sane
error messages at compile-time rather than seemingly-unexplained aborts
at runtime. But it could be enough for an MVP.)

Then .flags... 0 I suppose?  And .offTi: null; .destroy and .postblit:
assert(0).  .talign... dunno, I suppose 0 is as good a value as any
other?

No idea what .argTypes is supposed to do.

.rtInfo should probably return some generic no-op information. Or should
it assert(0)? Since I'd expect someone calling .rtInfo implies that
they've somehow created an instance of Tbottom, which is impossible.
Though it's hard to say if the GC may pre-initialize buffers or what-not
based on traversing all TypeInfo's.  Don't know.


T

-- 
If you think you are too small to make a difference, try sleeping in a closed room with a mosquito. -- Jan van Steenbergen


More information about the Digitalmars-d mailing list