[GHC] #8363: Order matters for unused import warnings when reexporting identifiers

#8363: Order matters for unused import warnings when reexporting identifiers ------------------------------------+------------------------------------- Reporter: bergmark | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Import order seem to change whether unused import warnings trigger when a module re-exports an identifier, with another module importing it and another module exporting the same identifier. Reproduction: {{{ module Foo ( (<$>) , g ) where import Control.Applicative g :: Int g = 1 }}} {{{ module Main where import Control.Applicative import Foo main :: IO () main = print =<< ((+2) <$> return g) }}} {{{ $ ghc -fwarn-unused-imports Main.hs [1 of 2] Compiling Foo ( Foo.hs, Foo.o ) [2 of 2] Compiling Main ( Main.hs, Main.o ) Linking Main ... }}} If Main is not using `g` then this gives a warning that the import of `Foo` is redundant. If we switch the order of the imports we do get the warning: {{{ module Main where import Foo import Control.Applicative main :: IO () main = print =<< ((+2) <$> return g) }}} {{{
ghc -fwarn-unused-imports Main.hs [1 of 2] Compiling Foo ( Foo.hs, Foo.o ) [2 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:4:1: Warning: The import of `Control.Applicative' is redundant except perhaps to import instances from `Control.Applicative' To import instances alone, use: import Control.Applicative() Linking Main ... }}} I expected both versions of Main to produce the same warning. Tested on GHC 7.7.20130824 and 7.4.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8363 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8363: Order matters for unused import warnings when reexporting identifiers -------------------------------------+------------------------------------ Reporter: bergmark | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Yes, you're right. In general it's a hard problem to find the minimal set of imports that are required. (It's a kind of set-covering problem.) GHC uses a cheap and cheerful heuristic that usually does reasonably well. The code is very localised, in `RnNames.warnUnusedImportDecls`. If anyone can do better, go for it! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8363#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8363: Order matters for unused import warnings when reexporting identifiers -------------------------------------+------------------------------------- Reporter: bergmark | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 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/8363#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8363: Order matters for unused import warnings when reexporting identifiers -------------------------------------+------------------------------------- Reporter: bergmark | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Be aware though that it has become somewhat popular to exploit this bug(?) to avoid writing CPP to manage the changes in Prelude's exports in 7.10. {{{ module Main where import Control.Applicative -- needed in 7.8, and not a warning in 7.10 -- because it comes before the Prelude import, -- though it actually is redundant in 7.10 import Prelude -- has the effect of canceling the implicit -- import of Prelude ... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8363#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8363: Order matters for unused import warnings when reexporting identifiers -------------------------------------+------------------------------------- Reporter: bergmark | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 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 thomie): * keywords: newcomer => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8363#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC