[GHC] #10089: feature: warn about unused data definitions (with typeclass instances)

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.4 Component: Compiler | Operating System: Unknown/Multiple Keywords: | Type of failure: None/Unknown Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Let's consider an example: {{{#!hs -- M.hs: module M () where -- ghc knows about uselessness of those data D = D -- but doesn't about this: data E = E deriving (Show, Read) }}} '''ghc''' warns about useless '''D''', but not '''E''': {{{ $ ghc-7.8.4 -Wall -c M.hs -fforce-recomp M.hs:5:1: Warning: Defined but not used: type constructor or class āDā M.hs:5:10: Warning: Defined but not used: data constructor āDā }}} There is no way to refer to '''E''' type outside or call it's unstances, correct? I would expect no code should be generated for this module. '''ghc''' could also warn about defined, but not used instances for types, that are not exported. Some background on where those stray types come from: 1. programmer usually adds a set of data types into their program (say, 10-15 types to represent an AST) 2. then annotates them with 'deriving (Read, Show)' convenience instances 3. (months later) amends AST representation a bit and leaves leftover data types not used anywhere Does that make sense? Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 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): Good idea. It would take a little work to implement, though. A bit of background. Unused defintions are reported by `RnNames.reportUnusedNames`, which in turn consults the accumulated defs (definitions) and uses in the global `tcg_dus`. This in turn is set mainly by `RnSource.rnSrcDecls`. The defs/uses field is of type `NameSet.DefUses`, a type synonym for `[DefUse]`. However, ''the list is supposed to be in dependency order'', as you can see from `NameSet.findUses`. Instance declarations are currently treated as defining nothing, but having a bunch of uses. This is a `(Nothing, uses)` pair in the `DefUse` terminology. But that means that anything mentioned in an instance is unconditionally treated as "used", with the effect you observe. To do it right we'd really want to give the instance decl some "defs" too. Consider {{{ instance Show T where show = g }}} It could get a `DefUse` like this: `(Just {Show,T}, {g})`. This expresses the idea that if `Show` or `T` were referenced somewhere else (or exported) then the instance declaration (and all the things it refers to, namely `g`) would be treated as used. Actually you'd really want "and" rather than "or": if `Show` ''and'' `T` are both referenced somewhere else then the instance declarationis used. The trouble is that we can't then give the `[DefUse]` in dependency order: an instance declaration might mention a function, which refers to another type, which is in the head of another instance declaration. The obvious thing to do would be to give up on the dependency-order claim of `[DefUse]` and just take its transitive closure as a relation. Not too hard. So: * Treat `DefUses` as an un-ordered relation, and use transitive closure to find uses. * Give an instance decl `I` a `DefUse` like `(used in head of I, used elsewhere in I)`. * Provide "and" semantics as well as "or" semantics for `DefUse`. Not a big project, and worthwhile. Any volunteers? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * keywords: => newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: dfordivam Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by dfordivam): * owner: => dfordivam -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: dfordivam Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: 3221 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfordivam): * related: => 3221 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: dfordivam Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3221 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfordivam): * related: 3221 => #3221 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3221 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dfordivam): * owner: dfordivam => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #3221 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: newcomer => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10089: feature: warn about unused data definitions (with typeclass instances) -------------------------------------+------------------------------------- Reporter: slyfox | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Instances Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #3221 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => Instances -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10089#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC