Skip to content

Strange debug output printed: isPredTy Const Int (,) Bool Char

I noticed this when debugging an issue in th-desugar. If you have this file:

{-# LANGUAGE PolyKinds #-}
module Bug where

type Const a b = b

f :: Const Int (,) Bool Char -> Char
f = snd

And compile it on GHC HEAD with -ddump-tc-trace enabled, even if you redirect the output of -ddump-tc-trace to a file with -ddump-to-file, GHC will still print what appears to be debugging messages!

$ ~/Software/ghc3/inplace/bin/ghc-stage2 Bug.hs -ddump-to-file -fforce-recomp -ddump-tc-trace
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
isPredTy Const Int (,) Bool Char

The source of that isPredTy message is in Type (here):

go_k :: Kind -> [KindOrType] -> Bool
-- True <=> ('k' applied to 'kts') = Constraint
go_k k [] = isConstraintKind k
go_k k (arg:args) = case piResultTy_maybe k arg of
                      Just k' -> go_k k' args
                      Nothing -> pprTrace "isPredTy" (ppr ty)
                                 False
   -- This last case should not happen; but it does if we
   -- we call isPredTy during kind checking, especially if
   -- there is actually a kind error.  Example that showed
   -- this up: polykinds/T11399

Several things stand out here:

  1. Should we be using pprTrace this way?
  2. Given that the comment says that "This last case should not happen", is this program indicative of a bug? Or perhaps this code really can be legitimately reached, and the comment should be updated to reflect this?

FWIW, polykinds/T11399 exhibits the same issue:

$ ~/Software/ghc3/inplace/bin/ghc-stage2 Bug2.hs -ddump-to-file -fforce-recomp -ddump-tc-trace
[1 of 1] Compiling T11399           ( Bug2.hs, Bug2.o )
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *
isPredTy a_aCn[sk:1] *

Bug2.hs:10:32: error:
    • Couldn't match kind ‘*’ with ‘GHC.Types.RuntimeRep’
      When matching kinds
        a :: * -> *
        TYPE :: GHC.Types.RuntimeRep -> *
      Expected kind ‘* -> *’, but ‘UhOh a’ has kind ‘a * -> *’
    • In the first argument of ‘Functor’, namely ‘(UhOh a)’
      In the instance declaration for ‘Functor (UhOh a)’
   |
10 | instance Functor a => Functor (UhOh a) where
   |                                ^^^^^^
Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information