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

Simon Peyton Jones simonpj at microsoft.com
Mon Sep 28 09:02:53 UTC 2020


Hmm.   It’s not clear to me why we have *any* limitation on the size of unboxed tuples.

For boxed tuples I know: we need an info table, code etc. But not so for unboxed.

Why do we need a limit at all?

Simon

From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Ryan Scott
Sent: 25 September 2020 23:21
To: GHC developers <ghc-devs at haskell.org>
Subject: How is GHC.Prim.unpackInt8X64# meant to be used?

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<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fblob%2Fa1f34d37b47826e86343e368a5c00f1a4b1f2bce%2Fcompiler%2FGHC%2FSettings%2FConstants.hs%23L13-15&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218050286&sdata=LAb06t4YCkyQgSfp3si07unb0sEW3vE7pEHRbzUxKZU%3D&reserved=0>
[2] https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:unpackInt8X64-35-<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fghc-prim-0.6.1%2Fdocs%2FGHC-Prim.html%23v%3AunpackInt8X64-35-&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218060277&sdata=eC52wb5dTfzVVAgJLMc428av%2FDgY9NyqyMCROfkD6ro%3D&reserved=0>
[3] https://gitlab.haskell.org/ghc/ghc/-/issues/18723<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fissues%2F18723&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218070276&sdata=VRucYwSTbGD1iD9KhJst2ZTmsuZ%2BQdwKTyivnTqKBm4%3D&reserved=0>
[4] https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:unpackWord8X64-35-<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fghc-prim-0.6.1%2Fdocs%2FGHC-Prim.html%23v%3AunpackWord8X64-35-&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218070276&sdata=3naSYWb5y2SpznOO0y4ip9Pd3hzzmbSuBWViCPbM%2FAU%3D&reserved=0>
[5] https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:packInt8X64-35-<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fghc-prim-0.6.1%2Fdocs%2FGHC-Prim.html%23v%3ApackInt8X64-35-&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218080272&sdata=QpdcjMe1gN91NJAPzTjdksFFXR3sibl5bZqhd23f6Hc%3D&reserved=0>
[6] https://hackage.haskell.org/package/ghc-prim-0.6.1/docs/GHC-Prim.html#v:packWord8X64-35-<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fghc-prim-0.6.1%2Fdocs%2FGHC-Prim.html%23v%3ApackWord8X64-35-&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218090268&sdata=x9%2FqCgRRALtH4%2B7wTK9hqxk%2FrhIqSs%2BPwIk%2BjQlljsY%3D&reserved=0>
[7] https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4097#note_301191<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.haskell.org%2Fghc%2Fghc%2F-%2Fmerge_requests%2F4097%23note_301191&data=02%7C01%7Csimonpj%40microsoft.com%7Ca2fa232c729f4943412a08d861a170e0%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637366699218090268&sdata=oGUSsN7bwBLV9p7MchpSfQH4dtjWm6apaumIM1IGg2Q%3D&reserved=0>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200928/47f6124c/attachment.html>


More information about the ghc-devs mailing list