[GHC] #13187: Strange debug output printed: isPredTy Const Int (, ) Bool Char

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Poor/confusing Unknown/Multiple | error message Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I noticed this when debugging an issue in `th-desugar`. If you have this file: {{{#!hs {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TemplateHaskell #-} module Bug where type Const a b = b test36_expand = $([| let f :: Const Int (,) Bool Char -> Char f = snd in f |]) }}} 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` ([http://git.haskell.org/ghc.git/blob/3eebd1f5fd56689baa63fcc63b7f4bde0ae70d0b... here]): {{{#!hs 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 | ^^^^^^ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13187 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by RyanGlScott: @@ -6,1 +6,0 @@ - {-# LANGUAGE TemplateHaskell #-} @@ -10,3 +9,3 @@ - test36_expand = $([| let f :: Const Int (,) Bool Char -> Char - f = snd in - f |]) + + f :: Const Int (,) Bool Char -> Char + f = snd New description: I noticed this when debugging an issue in `th-desugar`. If you have this file: {{{#!hs {-# 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` ([http://git.haskell.org/ghc.git/blob/3eebd1f5fd56689baa63fcc63b7f4bde0ae70d0b... here]): {{{#!hs 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 | ^^^^^^ }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13187#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Yes, this use of `pprTrace` is poor. It should be changed to `WARNING`. I don't think it indicates a bug, though. The problem is that `Const` is over-saturated, in that it looks like it should take only two arguments but is given four. In this case, though, the over-saturation is just fine, as `Const` is polymorphic in its return kind, specialized to an arrow kind. It's conceivable that `isPredTy` will get it wrong, in this over-saturated case. But I don't see how to do better without zonking, etc., and so I vote to punt. It's only about pretty-printing anyway. If someone complains, we can re-examine. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13187#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3033 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3033 * milestone: => 8.2.1 Comment: I like the idea of turning it into a `WARN`. I've done so in Phab:D3033, and refactored that comment below it a bit. Does this look OK? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13187#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Compiler (Type | Version: 8.1
checker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Poor/confusing | Unknown/Multiple
error message | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3033
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#13187: Strange debug output printed: isPredTy Const Int (,) Bool Char -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.1 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3033 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13187#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC