Description
Currently, force_bits
is a total operation in the sense that it will never go wrong in Miri (it can fail in CTFE though), but force_ptr
can fail. That is very annoying, it means that we have to call force_ptr
at just the right spot or we'll either causes errors in well-behaved code by converting too early, or re-do the conversion all the time because we do it too late. (See rust-lang/rust#62441 for some very careful force_ptr
placement.)
I think it might be a good idea to make force_ptr
never fail. The way this could be done is by designating a particular AllocId
as representing the "integer allocation" and having base address 0, so that a pointer with offset o
is equal to the integer o
. This would mean that every pointer-sized value has two equivalent representations (returned by force_bits
and force_ptr
, respectively) -- which is maybe suboptimal, but IMO it is better than the current situation where only some pointer-sized values have two representations.
Potentially, that would also let us use Pointer
instead of Scalar
in MemPlace
, simplifying (I think) lots of code. However, that would mean even CTFE has two different representations for the same value. But given that the engine will have to handle that anyway, I am not sure if it is a problem.
@oli-obk will recognize this as basically bringing back the "ZST allocation" or whatever it used to be called. It was a mess back then, but I think removing it only helped because it meant we had a canonical representation for every value -- a property we already lost with intptrcast.
What do you think?
Current proposal: #841 (comment)