diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-10-13 18:17:13 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2022-10-19 10:06:10 -0400 |
commit | 6148bd126c4602d011e7dd458288c02db1c16dc6 (patch) | |
tree | 0cebae532fef06af2374485530549273cee14bac /compiler/GHC/Cmm | |
parent | 1ef412dde750d4ffd01a332e555ed4503d4eda85 (diff) | |
download | haskell-wip/T22291.tar.gz |
codeGen: Allow levity-polymorphic primop resultswip/T22291
Consider a program such as:
```haskell
foo :: forall (lev :: Levity) (a :: TYPE (BoxedRep lev)). Addr# -> (# a #)
foo x = addrToAny# x
```
While this program is accepted by the type-checker, the code generator would previously
choke on it due the levity polymorphism of `foo`'s result. Specifically,
`boxedRepDataCon` would fail as it was unable to determine the result's `PrimRep`
while trying to identify its Cmm type:
```
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.5.20220906:
boxedRepDataCon
[lev_ayH]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:188:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Builtin/Types.hs:1629:9 in ghc:GHC.Builtin.Types
prim_rep_fun, called at compiler/GHC/Builtin/Types.hs:1618:44 in ghc:GHC.Builtin.Types
fun, called at compiler/GHC/Types/RepType.hs:615:5 in ghc:GHC.Types.RepType
runtimeRepPrimRep, called at compiler/GHC/Builtin/Types.hs:1660:20 in ghc:GHC.Builtin.Types
prim_rep_fun, called at compiler/GHC/Builtin/Types.hs:1655:64 in ghc:GHC.Builtin.Types
fun, called at compiler/GHC/Types/RepType.hs:615:5 in ghc:GHC.Types.RepType
runtimeRepPrimRep, called at compiler/GHC/Types/RepType.hs:585:5 in ghc:GHC.Types.RepType
kindPrimRep, called at compiler/GHC/Types/RepType.hs:537:18 in ghc:GHC.Types.RepType
typePrimRep, called at compiler/GHC/StgToCmm/Utils.hs:305:58 in ghc:GHC.StgToCmm.Utils
newUnboxedTupleRegs, called at compiler/GHC/StgToCmm/Prim.hs:1701:33 in ghc:GHC.StgToCmm.Prim
```
Here we fix this by modifying `PrimRep` to reflect the fact that we may
know that a value is boxed without knowing its particular levity:
```haskell
data PrimRep = BoxedRep Levity | IntRep | ...
```
This allows `kindPrimRep (TYPE (BoxedRep lev))` to return
`BoxedRep _|_`, which is enough information for the code generator to
compile `foo`.
Fixes #22291.
Diffstat (limited to 'compiler/GHC/Cmm')
-rw-r--r-- | compiler/GHC/Cmm/Utils.hs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/compiler/GHC/Cmm/Utils.hs b/compiler/GHC/Cmm/Utils.hs index 3671366d07..c657a287df 100644 --- a/compiler/GHC/Cmm/Utils.hs +++ b/compiler/GHC/Cmm/Utils.hs @@ -98,8 +98,7 @@ import GHC.Cmm.Dataflow.Collections primRepCmmType :: Platform -> PrimRep -> CmmType primRepCmmType platform = \case VoidRep -> panic "primRepCmmType:VoidRep" - LiftedRep -> gcWord platform - UnliftedRep -> gcWord platform + BoxedRep _ -> gcWord platform IntRep -> bWord platform WordRep -> bWord platform Int8Rep -> b8 @@ -141,8 +140,7 @@ typeCmmType platform ty = primRepCmmType platform (typePrimRep1 ty) primRepForeignHint :: PrimRep -> ForeignHint primRepForeignHint VoidRep = panic "primRepForeignHint:VoidRep" -primRepForeignHint LiftedRep = AddrHint -primRepForeignHint UnliftedRep = AddrHint +primRepForeignHint (BoxedRep _) = AddrHint primRepForeignHint IntRep = SignedHint primRepForeignHint Int8Rep = SignedHint primRepForeignHint Int16Rep = SignedHint |