[GHC] #10487: Unhelpful error from instance Generic

#10487: Unhelpful error from instance Generic -------------------------------------+------------------------------------- Reporter: | Owner: andreas.abel | Status: new Type: bug | Milestone: Priority: normal | Version: 7.10.1 Component: Compiler | Operating System: Unknown/Multiple Keywords: | Type of failure: None/Unknown Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- That's the error you like too see, or rather not. ;( {{{ [180 of 289] Compiling Agda.TypeChecking.Serialise ( src/full/Agda/TypeChecking/Serialise.hs, dist-2.4.2.4/build/Agda/TypeChecking/Serialise.o ) src/full/Agda/TypeChecking/Serialise.hs:1:1: Duplicate instance declarations: instance GHC.Generics.Datatype Agda.TypeChecking.Serialise.D1Name -- Defined at src/full/Agda/TypeChecking/Serialise.hs:1:1 instance GHC.Generics.Datatype Agda.TypeChecking.Serialise.D1Name -- Defined at src/full/Agda/TypeChecking/Serialise.hs:1:1 src/full/Agda/TypeChecking/Serialise.hs:1:1: Duplicate instance declarations: instance GHC.Generics.Constructor Agda.TypeChecking.Serialise.C1_0Name -- Defined at src/full/Agda/TypeChecking/Serialise.hs:1:1 instance GHC.Generics.Constructor Agda.TypeChecking.Serialise.C1_0Name -- Defined at src/full/Agda/TypeChecking/Serialise.hs:1:1 }}} Problems: * no position in file * system generated names D1Name, C1_0Name * obvious bogus (same instance cannot be defined twice at same location) * leads me to suspect bug in Generics rather than in my code Reproduce: * git clone agda/agda from github, * checkout this commit https://github.com/agda/agda/commit/46823536559276807639488eae151a0e855fdb95 * and try to compile with {{{ make install-bin }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: Unhelpful error from instance Generic -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by andreas.abel): It is also a proper bug. {{{#!hs module M where data Name = Name }}} {{{#!hs {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE StandaloneDeriving #-} module N where import GHC.Generics import qualified M data Name = Name deriving instance Generic M.Name deriving instance Generic Name }}} Error: {{{ [1 of 2] Compiling M ( M.hs, interpreted ) [2 of 2] Compiling N ( /home/abel/play/haskell/bugs/Generics/N.hs, interpreted ) /home/abel/play/haskell/bugs/Generics/N.hs:1:1: Duplicate instance declarations: instance Datatype N.D1Name -- Defined at /home/abel/play/haskell/bugs/Generics/N.hs:1:1 instance Datatype N.D1Name -- Defined at /home/abel/play/haskell/bugs/Generics/N.hs:1:1 /home/abel/play/haskell/bugs/Generics/N.hs:1:1: Duplicate instance declarations: instance Constructor N.C1_0Name -- Defined at /home/abel/play/haskell/bugs/Generics/N.hs:1:1 instance Constructor N.C1_0Name -- Defined at /home/abel/play/haskell/bugs/Generics/N.hs:1:1 Failed, modules loaded: M. }}} Qualified names are not handled properly by DeriveGeneric. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by dreixel): I'm afraid this is due to the simplistic way in which the names for the helper datatypes of the representation are generated. Should be easy to fix, though. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: dreixel Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * owner: => dreixel * priority: normal => highest * milestone: => 7.12.1 Comment: Thanks Pedro -- was that an offer? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: dreixel Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): dreixel, do you intend on putting together a patch to fix this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: dreixel Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Andres Loh has offered to take over `Generic` and `DeriveAnyClass`, but only at the end of the summer. I'm not sure what his Trac alias is. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: dreixel Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: D1081 -------------------------------------+------------------------------------- Changes (by osa1): * cc: omeragacan@… (added) * differential: => D1081 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: D1081 -------------------------------------+------------------------------------- Changes (by osa1): * owner: dreixel => osa1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: D1081 -------------------------------------+------------------------------------- Changes (by hvr): * cc: kosmikus (added) Comment: Replying to [comment:6 simonpj]:
Andres Loh has offered to take over `Generic` and `DeriveAnyClass`, but only at the end of the summer.
I'm not sure what his Trac alias is.
It's `kosmikus` -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Changes (by thomie): * differential: D1081 => Phab:D1081 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by osa1): Simon asked for a concrete example and some explanations on Phabricator thread so here it is: (I'm just learning this stuff so there may be mistakes) When we ask GHC to derive a Generic instance, it generates some instances other than Generic, and it also generates new data types for constructors of the type(and I think also for fields of constructors). Let's say I have this: {{{ module N where import GHC.Generics data Name = N1 String | N2 Int deriving instance Generic Name }}} GHC generates these instances: {{{ instance GHC.Generics.Generic N.Name where GHC.Generics.from (N.N1 g1_a17z) = ... GHC.Generics.from (N.N2 g1_a17A) = ... GHC.Generics.to (...) = ... GHC.Generics.to (...) = ... instance GHC.Generics.Datatype N.D1Name where GHC.Generics.datatypeName _ = "Name" GHC.Generics.moduleName _ = "N" instance GHC.Generics.Constructor N.C1_0Name where GHC.Generics.conName _ = "N1" instance GHC.Generics.Constructor N.C1_1Name where GHC.Generics.conName _ = "N2" }}} and these new data types: {{{ N.D1Name N.C1_0Name N.C1_1Name N.S1_0_0Name N.S1_1_0Name }}} Now the problem is, if I have something like this: {{{ module N where import GHC.Generics import qualified M as Blah data Name = Name deriving instance Generic Blah.Name deriving instance Generic Name --- module M where data Name = Name }}} It generates same data types and instances(including head parts, because generated data types are same so instance heads have to refer to same names) for both Names. This leads to duplicate data type and instance declarations. What I did for D1081 so far was to add module names as prefix to generated data types. It worked fine(currently validates), but if we use package imports it should break. So we thought maybe we should use qualified names of modules as a prefix. In our case, that would mean generating `Blah_` prefixed types for `Name` in module `M`, and non-prefixed types for `Name` in current module. With package imports the user need to give modules different names so this should work. But it turns out to be hard to implement, because at the point we're generating instance code, we don't have any knowledge about qualified imports. `RdrName`s are eliminated during renaming. With some experiments I realized `Outputable.PrintUnqualified` doesn't give this info etc. That's where I got stuck. We thought of some solutions: - Add `RdrName` as a field to `Name`. `Name` is a pretty central data type and we may not want to change it. Also, this probably means changing a lot of other code. - Pass `RdrName`s through type checker. No changes in any data types, but we still need to change a lot of other code, functions etc. just to pass this argument through. - (We had the idea of using `Outputable.PrintUnqualified` data but that won't work) I must mention, I don't have an example with package imports. Maybe GHC is already giving modules different names when package imports is used? That would solve everything. I'll try to build a broken(with my patch) example today. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by simonpj): Are the newly declared data types supposed to be user-visible, with predictable names (they don't look very user-friendly!) or is it just an internal matter. If it's just a question of generating fresh names that are distinct, you could use the same approach as for dictionary-functions. Look at `TcEnv.newDFunName`. This reminds me (Andres) that there is an outstanding task to clean up this generics stuff using `DataKinds`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by osa1): I don't think they're user visible, because for example if I load the file in GHCi I can't see those types there(although I must say I don't know how this is possible to implement, I'd expect everything in that module to be visible). I'll have a look at `TcEnv.newDFunName`, it sounds like a great idea. Is there a ticket for the clean up task? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by simonpj):
Is there a ticket for the clean up task?
I don't think so -- there should be -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by dreixel): The generated datatypes do not have to be user-visible. As for using DataKinds in generics, I wouldn't really call it a clean up task, as I think there's some bit of design left to do. Anyway, it's mostly described in here: https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving#Ki... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: new Priority: highest | Milestone: 7.12.1 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Comment (by osa1): I fixed name generation and the patch is ready for reviews. Only missing thing is a test for package imports. Does anyone know if it's possible to add a test with packages without modifying test driver? (`driver/runtests.py`) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules
-------------------------------------+-------------------------------------
Reporter: andreas.abel | Owner: osa1
Type: bug | Status: new
Priority: highest | Milestone: 8.0.1
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions: Phab:D1081
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => fixed Comment: Pushed. I assume we aren't backporting to 7.10? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: T10487 Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1081 -------------------------------------+------------------------------------- Changes (by osa1): * testcase: => T10487 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10487: DeriveGeneric breaks when the same data name is used in different modules -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: osa1 Type: bug | Status: closed Priority: highest | Milestone: 8.0.1 Component: Compiler | Version: 7.10.1 Resolution: fixed | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: T10487 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1081 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => Generics -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10487#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC