[GHC] #12920: Overzealous unused-top-binds
GHC
ghc-devs at haskell.org
Sat Dec 3 14:58:17 UTC 2016
#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
More information about the ghc-tickets
mailing list