[GHC] #12920: Overzealous unused-top-binds

#12920: Overzealous unused-top-binds -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2-rc1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | error/warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The following example produces three warnings: {{{ module Foo () where type A = Int type B = A foo :: IO () foo = print (bar 3 :: B) bar :: a -> a bar = id }}} `ghci Foo -Wall` produces {{{ GHCi, version 8.0.1.20161117: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Foo ( Foo.hs, interpreted ) Foo.hs:5:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘B’ Foo.hs:8:1: warning: [-Wunused-top-binds] Defined but not used: ‘foo’ Foo.hs:11:1: warning: [-Wunused-top-binds] Defined but not used: ‘bar’ Ok, modules loaded: Foo. }}} The three errors reported are inconsistent because GHC reports that `B` is unused, but somehow feels that `A` *is* used. It seems to me that two possibilities could work: 1. GHC reports 1 error: GHC should only report that `foo` is unused, since `A` is used in `B`, `B` is used in `foo`, and `bar` is used in `foo`. This seems like the best approach to me. 2. GHC reports 4 errors: One might choose to apply the definition of "unused" transitively so that, since `foo` is unused, everything used in `foo` is considered unused (unless "used" elsewhere). In this case, `A` should also be reported as unused, but it currently isn't. This definition would be exceedingly useful for removing dead code, but it also produces very noisy output when there is a lot of dead code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12920 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12920: Overzealous unused-top-binds -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Yes, that does look inconsistent; I'm not sure why.
This definition would be exceedingly useful for removing dead code, but it also produces very noisy output when there is a lot of dead code.
Yes, this is a tension, but I don't know how to resolve it. Until now we have done the transitive thing, but mostly I think that the non-transitive version might be better. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12920#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12920: Overzealous unused-top-binds -------------------------------------+------------------------------------- Reporter: crockeea | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I just ran into this issue in a somewhat different context: {{{#!hs {-# OPTIONS_GHC -Wunused-top-binds #-} module Bug () where type A = Int type B = A type C = B a, b, c :: Int a = 42 b = a c = b }}} {{{ GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug2.hs, interpreted ) Bug2.hs:6:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘C’ | 6 | type C = B | ^^^^^^^^^^ Bug2.hs:9:1: warning: [-Wunused-top-binds] Defined but not used: ‘a’ | 9 | a = 42 | ^ Bug2.hs:10:1: warning: [-Wunused-top-binds] Defined but not used: ‘b’ | 10 | b = a | ^ Bug2.hs:11:1: warning: [-Wunused-top-binds] Defined but not used: ‘c’ | 11 | c = b | ^ Ok, one module loaded. }}} It appears that `-Wunused-top-binds` has different transitivity behavior when it comes to functions vs. type synonyms: the former has transitive behavior, whereas the latter does not. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12920#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12920: Overzealous unused-top-binds -------------------------------------+------------------------------------- Reporter: crockeea | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by crockeea): @RyanGlScott I think that is *exactly* the behavior I was seeing in the original ticket. Thanks for clarifying the problem (and somehow finding this ancient ticket!) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12920#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC