GHC Panic deriving unbox vector (StrictData/unbox-strict-fields interaction)
The attached program
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Lib where
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Deriving
data V a = V {-# UNPACK #-} !a {-# UNPACK #-} !a
deriving (Show)
derivingUnbox "V"
[t| forall a. V.Unbox a => V a -> (a, a) |]
[| \(V a b) -> (a, b) |]
[| \(a, b) -> V a b |]
fails to compile with the following error:
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.3 for x86_64-unknown-linux):
mkNewTyConRhs
MV_V [Int#, MVector s_a7WC[sk:1] a_a7WA[sk:1],
MVector s_a7WC[sk:1] a_a7WA[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/iface/BuildTyCl.hs:65:27 in ghc:BuildTyCl
Removing either of the -funbox-strict-fields or StrictData pragma allow the code to compile correctly, but you do need to compile with -O to get the incorrect behaviour -ghci is fine loading the module.
Although I wouldn't expect them to interact here as I don't get the same behaviour if I explicitly write out what would be implied by the flag and pragma:
data V a = V {-# UNPACK #-} !a {-# UNPACK #-} !a
deriving (Show)
just warnings about the unused UNPACKs.