[GHC] #15167: DerivClause list is not populated for (TyConI (DataD ...))

#15167: DerivClause list is not populated for (TyConI (DataD ...)) -------------------------------------+------------------------------------- Reporter: 0xd34df00d | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Template | Version: 8.4.2 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!haskell % cat Test.hs {-# LANGUAGE LambdaCase #-} module Test where import Language.Haskell.TH test :: Name -> Q [Dec] test name = reify name >>= \case TyConI dec -> do runIO $ print dec pure [] _ -> pure [] % cat Run.hs {-# LANGUAGE TemplateHaskell #-} import Test data Foo = Foo deriving (Eq, Ord, Show) test ''Foo % ghc Run.hs [2 of 2] Compiling Main ( Run.hs, Run.o ) DataD [] Main.Foo [] Nothing [NormalC Main.Foo []] [] }}} One might expect the `DataD` to mention `Eq, Ord, Show` in the `DerivClause` list, but it doesn't. This behavior manifests with every ghc version I tried: 8.0.2, 8.2.2, 8.4.2. I also asked a question whether it's intended behaviour on #haskell, and I've been advised to open a bug report, so here it is. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15167 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15167: DerivClause list is not populated for (TyConI (DataD ...)) -------------------------------------+------------------------------------- Reporter: 0xd34df00d | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.4.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: newcomer (added) Comment: Indeed, this is expected. Reified data declarations never have derived instances attached to them, as they're only used when splicing a TH- constructed data type into source code. (If you want to know a data type's instances via TH, you should use `reifyInstances`.) The Haddocks in `template-haskell` currently don't state that reified data types lack derived instance information, however, so it would be good to update the documentation to reflect this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15167#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15167: DerivClause list is not populated for (TyConI (DataD ...)) -------------------------------------+------------------------------------- Reporter: 0xd34df00d | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.4.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by 0xd34df00d): Thanks for getting to my report! Seems like `reifyInstances`'s documentation could also be slightly improved: it's not entirely obvious from it right now that it can/should be used to get the list of instances for a data type. Indeed, for the above example, how does one use it to get something about `Eq, Ord, Show` without knowing a priori that those are the classes that `Foo` implements? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15167#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15167: DerivClause list is not populated for (TyConI (DataD ...)) -------------------------------------+------------------------------------- Reporter: 0xd34df00d | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Template Haskell | Version: 8.4.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Unfortunately I don't think we currently have a good way to get this information. When we are asked to reify the tycon the original Haskell AST (which would contain the `deriving` information) that we typechecked to produce the type is gone. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15167#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15167: DerivClause list is not populated for (TyConI (DataD ...))
-------------------------------------+-------------------------------------
Reporter: 0xd34df00d | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.8.1
Component: Template Haskell | Version: 8.4.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott
participants (1)
-
GHC