[GHC] #12067: warn-unused-imports does not detect coersions
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When using `coerce`, GHC can erroneously warn that imports are unnecessary. For example: Foo.hs {{{ module Foo (MT(..), M) where import Control.Monad.Identity newtype MT m b = MT (m b) type M b = MT Identity b }}} Main.hs {{{ import Control.Monad.Identity import Data.Coerce import Foo foo :: M [a] -> MT [] a foo = coerce }}} GHC (with `-fwarn-unused-imports`) warns {{{ Main.hs:1:1: Warning: The import of ‘Control.Monad.Identity’ is redundant except perhaps to import instances from ‘Control.Monad.Identity’ To import instances alone, use: import Control.Monad.Identity() }}} But this is incorrect: we need the constructor `Identity` to be in scope in order for the coercion to succeed. Thus the import is not redundant, nor is it needed to import instances. In particular, the two implied suggestions 1. remove the import altogether 2. change the import to `import Control.Monad.Identity` both (correctly) result in compile errors. At a minimum, the warning message should be updated to include this possibility, but it would be even better if GHC could detect this and not throw a warning at all. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #10347 Comment: Also happens with 8.0. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by crockeea: @@ -34,2 +34,2 @@ - nor is it needed to import instances. In particular, the two implied - suggestions + nor is it needed to (only) import instances. In particular, the two + implied suggestions @@ -37,2 +37,2 @@ - 1. remove the import altogether - 2. change the import to `import Control.Monad.Identity` + 1. remove the import in Main.hs altogether + 2. change the import in Main.hs to `import Control.Monad.Identity ()` New description: When using `coerce`, GHC can erroneously warn that imports are unnecessary. For example: Foo.hs {{{ module Foo (MT(..), M) where import Control.Monad.Identity newtype MT m b = MT (m b) type M b = MT Identity b }}} Main.hs {{{ import Control.Monad.Identity import Data.Coerce import Foo foo :: M [a] -> MT [] a foo = coerce }}} GHC (with `-fwarn-unused-imports`) warns {{{ Main.hs:1:1: Warning: The import of ‘Control.Monad.Identity’ is redundant except perhaps to import instances from ‘Control.Monad.Identity’ To import instances alone, use: import Control.Monad.Identity() }}} But this is incorrect: we need the constructor `Identity` to be in scope in order for the coercion to succeed. Thus the import is not redundant, nor is it needed to (only) import instances. In particular, the two implied suggestions 1. remove the import in Main.hs altogether 2. change the import in Main.hs to `import Control.Monad.Identity ()` both (correctly) result in compile errors. At a minimum, the warning message should be updated to include this possibility, but it would be even better if GHC could detect this and not throw a warning at all. -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"23b80ac41cc945cea0fc6ff9ade6b4be8aa81b7f/ghc" 23b80ac/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="23b80ac41cc945cea0fc6ff9ade6b4be8aa81b7f" Deal correctly with unused imports for 'coerce' We only do newtype unwrapping for Coercible constraints if the newtype's data constructor is in scope. We were trying to record the fact that the data constructor was thereby 'used', so that an import statement would not be flagged as unnecsssary (by -Wunused-imports). But the code was simply wrong. It was wrong because it assumed that only one level of unwrapping happened, whereas tcTopNormaliseNewTypeTF_maybe actually unwraps multiple layers. So we need to return a /list/ of data constructors that are used. This entailed a bit of refactoring, as usual. Fixes Trac #12067 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: warning at compile-time | typecheck/should_compile/T12067 Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * testcase: => typecheck/should_compile/T12067 * status: new => merge * milestone: => 8.0.2 Comment: Thank you for the bug report! Ben/Austin: merge if convenient, but I don't think it's a show-stopper. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coersions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: warning at compile-time | typecheck/should_compile/T12067 Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"6c28f24aa8202f79db49b85b815011703d647fd9/ghc" 6c28f24/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="6c28f24aa8202f79db49b85b815011703d647fd9" Deal correctly with unused imports for 'coerce' We only do newtype unwrapping for Coercible constraints if the newtype's data constructor is in scope. We were trying to record the fact that the data constructor was thereby 'used', so that an import statement would not be flagged as unnecsssary (by -Wunused-imports). But the code was simply wrong. It was wrong because it assumed that only one level of unwrapping happened, whereas tcTopNormaliseNewTypeTF_maybe actually unwraps multiple layers. So we need to return a /list/ of data constructors that are used. This entailed a bit of refactoring, as usual. Fixes Trac #12067 (cherry picked from commit 23b80ac41cc945cea0fc6ff9ade6b4be8aa81b7f) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12067: warn-unused-imports does not detect coercions -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: warning at compile-time | typecheck/should_compile/T12067 Blocked By: | Blocking: Related Tickets: #10347 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC