Pointer-or-Int 63-bit representations for Integer

Spiwack, Arnaud arnaud.spiwack at tweag.io
Mon Mar 8 17:41:43 UTC 2021

For what it's worth, Ocaml uses the fact that pointers are word-aligned
(hence even numbers) to let the gc distinguish between unboxed values and
pointers: 63-bit integers are made odd by representing n as (2n+1).

But GHC also makes use of the word-alignment of pointers: it is used for
pointer tagging [
]. The tag is, for a closure that has been forced, a representation of its
constructor (only the 7 first constructors can be so tagged, if I
understand correctly). This is an optimisation for pattern matching: you
don't have to run the closure's entry code every time you pattern-match.

The bottom-line is that it can't be true, in GHC, that odd values are
unboxed and even values are pointers, since odd pointers already exist. Not
sure whether the optimisation can be recovered.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20210308/4b1950b9/attachment.html>

More information about the ghc-devs mailing list