[GHC] #14179: "Conflicting family instance" error pretty prints data family instances poorly

#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 (Type checker) | Keywords: TypeFamilies | 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: -------------------------------------+------------------------------------- This can be observed on GHC 8.0.1 or later: {{{#!hs {-# LANGUAGE TypeFamilies #-} module Bug where data family Fam a data instance Fam Int data instance Fam Int }}} {{{ $ /opt/ghc/8.2.1/bin/ghci Bug.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:5:15: error: Conflicting family instance declarations: Fam Int = -- Defined at Bug.hs:5:15 Fam Int = -- Defined at Bug.hs:6:15 | 5 | data instance Fam Int | ^^^ }}} Notice how GHC attempts to pretty-print the RHS by using a `=` symbol, but there is no RHS! This gets even more confusing with this program, which requires GHC HEAD: {{{#!hs {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeFamilies #-} module Bug where data family Fam :: k -> * data instance Fam :: * -> * data instance Fam :: * -> * }}} {{{ $ ghc5/inplace/bin/ghc-stage2 --interactive Bug.hs GHCi, version 8.3.20170818: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:6:15: error: Conflicting family instance declarations: Fam = -- Defined at Bug.hs:6:15 Fam = -- Defined at Bug.hs:7:15 | 6 | data instance Fam :: * -> * | ^^^ }}} Not only is there no RHS, but the kind signatures of each instance aren't printed either. This is an issue, since the entire reason why the two instances conflict are because of their kinds! We should rethink how data family instances are pretty printer here to avoid this issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.1 checker) | Resolution: | Keywords: TypeFamilies 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 RyanGlScott): Indeed, the particular pretty printer that's being used in this error message is really broken. If you give GHC these conflicting instances: {{{#!hs module Bug where data family Fam a data instance Fam [a] where Fam1 :: Fam [Int] Fam2 :: Fam [Bool] data instance Fam [a] where Fam3 :: Fam [a] Fam4 :: Fam [Char] }}} Then the error message will print out information that's just plain wrong: {{{ $ ghci Bug.hs GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:6:15: error: Conflicting family instance declarations: Fam [a] = Fam1 | Fam2 -- Defined at Bug.hs:6:15 Fam [a] = Fam3 | Fam4 -- Defined at Bug.hs:9:15 | 6 | data instance Fam [a] where | ^^^ }}} I use the word "particular" above since the general-purpose data family instance pretty printer actually does the right thing: {{{ λ> :i Fam data family Fam a -- Defined at Bug.hs:5:1 data instance Fam [a] where Fam3 :: Fam [a] Fam4 :: Fam [Char] -- Defined at Bug.hs:11:15 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.1 checker) | Resolution: | Keywords: TypeFamilies 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 RyanGlScott): This is an interesting one. I think that the solution here might be to pretty-print conflicting data family instances slightly differently than conflicting data family instances, for two reasons: 1. Type family instances are unique in that you have can have duplicate instances (see #14440). Thus, the pretty-printer //must// show their right-hand sides, because otherwise a user wouldn't know why they were conflicting. Data family instances, on the other hand, do not permit duplicates. These conflict, for instance: {{{#!hs data family Foo a data instance Foo a data instance Foo a }}} 2. The right-hand side of a data family instance can be quite large if there are many constructors. We could address this with `pprDeeperList`, but it's of questionable utility, since a. We might be suppressing the constructors in which two data family instance differ, and b. Part 1. brings into question whether it's worth going through this trouble in the first place, since the constructors themselves aren't the thing which causes data family instances to conflict. In light of this, I would propose simply pretty-printing the data family instances without any constructors at all. In other words, for the programs in the original description, I would propose having these be the respective error messages: {{{ Bug.hs:5:15: error: Conflicting family instance declarations: Fam Int -- Defined at Bug.hs:5:15 Fam Int -- Defined at Bug.hs:6:15 | 5 | data instance Fam Int | ^^^ }}} {{{ Bug.hs:6:15: error: Conflicting family instance declarations: Fam :: * -> * -- Defined at Bug.hs:6:15 Fam :: * -> * -- Defined at Bug.hs:7:15 | 6 | data instance Fam :: * -> * | ^^^ }}} And for the program in comment:1: {{{ Bug.hs:6:15: error: Conflicting family instance declarations: Fam [a] -- Defined at Bug.hs:6:15 Fam [a] -- Defined at Bug.hs:9:15 | 6 | data instance Fam [a] where | ^^^ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.1 checker) | Resolution: | Keywords: TypeFamilies 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 simonpj): comment:2 sounds plausible to me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

PS: The first sentence of comment:2 doesn't make sense though: "pretty-
#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (Type | Version: 8.2.1 checker) | Resolution: | Keywords: TypeFamilies 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:D4711 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4711 Comment: Replying to [comment:3 simonpj]: print conflicting data family instances slightly differently than conflicting data family instances". Maybe needs an edit. Good catch. Fixed. Alas, I wasn't able to do much about the kind signature thing, since by the time we call this error message, we've completely lost track of whether the original data family instance declaration was written with an explicit kind signature or not. Nevertheless, I've implemented the other suggestions in this thread in Phab:D4711, which substantially cleans up the error message (and will at the very least give results that make sense in //some// context). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14179: "Conflicting family instance" error pretty prints data family instances
poorly
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.2.1
checker) |
Resolution: | Keywords: TypeFamilies
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:D4711
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#14179: "Conflicting family instance" error pretty prints data family instances poorly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler (Type | Version: 8.2.1 checker) | Resolution: fixed | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: indexed- error message | types/should_fail/T14179 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4711 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * testcase: => indexed-types/should_fail/T14179 * resolution: => fixed * milestone: => 8.6.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14179#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14179: "Conflicting family instance" error pretty prints data family instances
poorly
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.6.1
Component: Compiler (Type | Version: 8.2.1
checker) |
Resolution: fixed | Keywords: TypeFamilies
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Poor/confusing | Test Case: indexed-
error message | types/should_fail/T14179
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4711
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott
participants (1)
-
GHC