Skip to content

Combine `RuntimeRep` and `PrimRep`

While reviewing !4612 (merged), I read Note [RuntimeRep and PrimRep]:

...

data PrimRep
  = VoidRep
  | LiftedRep     -- ^ Lifted pointer
  | UnliftedRep   -- ^ Unlifted pointer
  | Int8Rep       -- ^ Signed, 8-bit value
  | Int16Rep      -- ^ Signed, 16-bit value
  ...etc...
  | VecRep Int PrimElemRep  -- ^ SIMD fixed-width vector

...

data RuntimeRep = VecRep VecCount VecElem   -- ^ a SIMD vector type
                | TupleRep [RuntimeRep]     -- ^ An unboxed tuple of the given reps
                | SumRep [RuntimeRep]       -- ^ An unboxed sum of the given reps
                | LiftedRep       -- ^ lifted; represented by a pointer
                | UnliftedRep     -- ^ unlifted; represented by a pointer
                | BoxedRep Levity -- ^ boxed; represented by a pointer
                | IntRep          -- ^ signed, word-sized value
                ...etc...
data Levity     = Lifted
                | Unlifted

...

It's all in 1-1 correspondence with PrimRep except for TupleRep and SumRep,
which describe unboxed products and sums respectively.

Then why don't we just define

data PrimRep
  = VoidRep
  | BoxedRep Levity
  | Int8Rep       -- ^ Signed, 8-bit value
  | Int16Rep      -- ^ Signed, 16-bit value
  ...etc...
  | VecRep Int PrimElemRep  -- ^ SIMD fixed-width vector
data Levity     = Lifted
                | Unlifted

data RuntimeRep = TupleRep [RuntimeRep]     -- ^ An unboxed tuple of the given reps
                | SumRep [RuntimeRep]       -- ^ An unboxed sum of the given reps
                | Prim PrimRep

Seems far better. I don't even think that this is user-facing (just a manner of the parsing function of RuntimeReps), so maybe we get by without a GHC proposal?

CC @andrewthad @AndreasK @bgamari @rae @simonpj

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information