Skip to content

Desugarer panic with a constraint and representation polymorphism

The following program causes an isUnliftedType panic during desugaring:

{-# LANGUAGE TypeFamilies, PartialTypeSignatures #-}
module M where

import GHC.Stack
import GHC.Exts

type family T :: RuntimeRep

f :: forall (a :: TYPE T). (HasCallStack, _) => a
f = f

To see what's happening, let's replace a :: TYPE T with a :: TYPE LiftedRep and look at -ddump-ds-preopt:

f :: forall a. HasCallStack => a
[LclIdX]
f = \ (@a_ayI) ($dIP_aMo :: HasCallStack) ->
      let {
        $dIP_aLM :: HasCallStack
        [LclId]
        $dIP_aLM = ... } in
      let {
        $dIP_aLL :: HasCallStack
        [LclId]
        $dIP_aLL = ... } in
      letrec {
        f_aLH :: a_ayI
        [LclId]
        f_aLH = f_aLH; } in
      f_aLH

To define a function HasCallStack => a, we bind the HasCallStack evidence and define f_aLH :: a_ayI. This works, but if a :: TYPE T then f_aLH :: a_ayI is binding a variable whose type doesn't have a fixed rep.

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