Skip to content

Unboxed tuple size limit is incorrectly checked

This:

{-# LANGUAGE UnboxedTuples #-}
module Hi where
f = (#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#)
g = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)

gives

Tuple.hs:4:5: error:
    A 64-tuple is too large for GHC
      (max size is 62)
      Workaround: use nested tuples or define a data type
  |
4 | f = (#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Tuple.hs:5:5: error:
    A 63-tuple is too large for GHC
      (max size is 62)
      Workaround: use nested tuples or define a data type
  |
5 | g = (,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Less commas but the unboxed tuple is larger. Probably we're counting RuntimeReps when checking the size limit for an unboxed tuple. Looking at the code

boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
boxedTupleArr   = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Boxed   i | i <- [0..mAX_TUPLE_SIZE]]
unboxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Unboxed i | i <- [0..mAX_TUPLE_SIZE]]

we shouldn't: the constant mAX_TUPLE_SIZE corresponds to the number of fields.

The limit is checked correctly for type T = (#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#).

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