How is GHC.Prim.unpackInt8X64# meant to be used?

Ryan Scott ryan.gl.scott at gmail.com
Fri Sep 25 22:21:23 UTC 2020


GHC imposes an upper bound of 62 on the size of tuples one can use [1].
Currently, this upper bound applies to both boxed and unboxed tuples alike.
For example, if you try to create an unboxed tuple of arity 64, then GHC
will throw an error:

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

However, I discovered recently that there are places where GHC *does* use
unboxed tuples with arity greater than 62. For example, the
GHC.Prim.unpackInt8X64# [2] function returns an unboxed tuple of size 64. I
was confused for a while about how this was even possible, but I realized
later than GHC only enforces the tuple size limit in expressions and
patterns [3]. Simply having a type signature with a large unboxed tuple is
fine in and of itself, and since unpackInt8X64# is implemented as a primop,
no large unboxed tuples are ever used in the "body" of the function.
(Indeed, primops don't have function bodies in the conventional sense.)
Other functions in GHC.Prim that use unboxed tuples of arity 64 include
unpackWord8X64# [4], packInt8X64# [5], and packWord8X64# [6].

But this makes me wonder: how on earth is it even possible to *use*
unpackInt8X64#? The only thing that comes to mind is to pattern-match on
the unboxed tuple that it returns, but if you try to do that, you'll get a
"64-tuple is too large for GHC" error like shown above. What's more, I
can't find any test cases in the GHC test suite that show how
unpackInt8X64# or its cousins are supposed to be used. What am I missing?
The comments for these functions mention "Warning: this is only available
on LLVM", so perhaps someone familiar with the LLVM backend knows what the
answer is?

For some context, this came up in !4097, where I am attempting to extend
the "too large for GHC" error message to include types, in addition to
expressions and patterns [7]. However, doing so causes Haddock to error
when processing unpackInt8X64# et al.

Ryan S.
-----
[1]
https://gitlab.haskell.org/ghc/ghc/-/blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/compiler/GHC/Settings/Constants.hs#L13-15
[2]
https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:unpackInt8X64-35-
[3] https://gitlab.haskell.org/ghc/ghc/-/issues/18723
[4]
https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:unpackWord8X64-35-
[5]
https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:packInt8X64-35-
[6]
https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:packWord8X64-35-
[7] https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4097#note_301191
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200925/7ac6f4d8/attachment.html>


More information about the ghc-devs mailing list