[GHC] #10890: Incorrect redundant import warning for type classes

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Given the three files below, the import marked with (!!!) is reported as redundant. Upon deleting it, GHC reports that "has" is not a visible class method of BClass. This came up in the context of the MFP (#10751), with the correspondences Base<->Control.Monad, Extends<->Control.Monad.Fail. We would like to have Control.Monad re-export Control.Monad.Fail.MonadFail without its (clashing) member "fail" for the time being. For future compatibility, some modules should implement MonadFail right now, requiring us to import Control.Monad.Fail explicitly in order to write an instance. Said procedure leads to the described import warning, which breaks the validation script for example. {{{#!hs -- Base.hs module Base (AClass(..), BClass()) where import Extends (BClass()) class AClass a where has :: a }}} {{{#!hs -- Extends.hs module Extends where class BClass b where has :: b }}} {{{#!hs -- UseSite.hs module UseSite where import Base import Extends -- (!!!) data Bar = Bar instance AClass Bar where has = Bar instance BClass Bar where has = Bar }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by quchen): * cc: hvr (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Description changed by quchen: Old description:
Given the three files below, the import marked with (!!!) is reported as redundant. Upon deleting it, GHC reports that "has" is not a visible class method of BClass.
This came up in the context of the MFP (#10751), with the correspondences Base<->Control.Monad, Extends<->Control.Monad.Fail. We would like to have Control.Monad re-export Control.Monad.Fail.MonadFail without its (clashing) member "fail" for the time being. For future compatibility, some modules should implement MonadFail right now, requiring us to import Control.Monad.Fail explicitly in order to write an instance. Said procedure leads to the described import warning, which breaks the validation script for example.
{{{#!hs -- Base.hs module Base (AClass(..), BClass()) where
import Extends (BClass())
class AClass a where has :: a }}}
{{{#!hs -- Extends.hs module Extends where
class BClass b where has :: b }}}
{{{#!hs -- UseSite.hs module UseSite where
import Base import Extends -- (!!!)
data Bar = Bar
instance AClass Bar where has = Bar
instance BClass Bar where has = Bar }}}
New description: Given the three files below, the import marked with (!!!) is reported as redundant. Upon deleting it, GHC reports that "has" is not a visible class method of BClass. This came up in the context of the MFP (#10751), with the correspondences Base<->Control.Monad, Extends<->Control.Monad.Fail. We would like to have Control.Monad re-export Control.Monad.Fail.MonadFail without its (clashing) member "fail" for the time being. For future compatibility, some modules should implement MonadFail right now, requiring us to import Control.Monad.Fail explicitly in order to write an instance. Said procedure leads to the described import warning, which breaks the validation script for example. {{{#!hs -- Base.hs module Base (AClass(..), BClass()) where import Extends (BClass()) class AClass a where has :: a }}} {{{#!hs -- Extends.hs module Extends where class BClass b where has :: b }}} {{{#!hs -- UseSite.hs module UseSite where import Base import Extends -- (!!!) data Bar = Bar instance AClass Bar where has = Bar instance BClass Bar where has = Bar }}} We either get {{{ UseSite.hs:12:5: error: ‘has’ is not a (visible) method of class ‘BClass’ }}} or {{{ UseSite.hs:4:1: warning: The import of ‘Extends’ is redundant except perhaps to import instances from ‘Extends’ To import instances alone, use: import Extends() }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by osa1): * cc: osa1 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by osa1): Not sure how much this helps with debugging this, but I found out that when compiling this slightly modified program: {{{#!haskell module Main where import Base (AClass (has)) import Extends (BClass (has)) data Bar = Bar instance AClass Bar where has = Bar instance BClass Bar where has = Bar }}} GHC prints this: {{{ Main.hs:3:1: warning: The import of ‘Base.has’ from module ‘Base’ is redundant Main.hs:4:1: warning: The import of ‘Extends.has’ from module ‘Extends’ is redundant Linking Main ... }}} This is a test case I generated while trying to figure out if GHC thinks both `has` are coming from the same module. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by osa1): This is awesome, just re-order imports like this: {{{#!haskell import Extends import Base }}} and GHC doesn't print the warning anymore :) I'm about to solve this case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by osa1): Here's more stuff: GHC actually doesn't even consider `has` as an used symbol(i.e. internally it doesn't add it to the set of symbols used in a module, `tcg_used_rdrnames` of `TcGblEnv`), so in this case it only considers importing `AClass` and `BClass`. (that why in my second example it prints warnings about both `has`) `BClass` is exported by both `Base` and `Extends`. Now let's say we have this: {{{#!haskell import Base import Extends }}} Which one should be used for importing `BClass`? GHC makes the choice based on their locations in the source file. That is, it imports it from `Base` and not from `Extends`. But if I change imports like this: {{{#!haskell import Extends import Base }}} Now GHC imports `BClass` from `Extends` because it comes first in the source code, so no warnings here. Long story short, I think the problem is that GHC doesn't consider `has` a used symbol. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by osa1): Not sure how to proceed here but I have an experimental patch https://github.com/osa1/ghc/commit/d8647e1ae28be98554b4976ab1c4bc275b3c280b. Does anyone have any ideas? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by quchen): * cc: quchen (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by osa1): I started to think like my experimental patch doesn't make things any worse, but fixes some of the cases. I'll test it a little bit more and probably open a Phab ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: D1257 -------------------------------------+------------------------------------- Changes (by osa1): * status: new => patch * differential: => D1257 Comment: Thanks to @quchen for realizing that my patch reduces to previous version if there's only one imported `RdrName` with same name. I created a patch for this and I'll be adding tests soon. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D1257 -------------------------------------+------------------------------------- Changes (by thomie): * differential: D1257 => Phab:D1257 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes
-------------------------------------+-------------------------------------
Reporter: quchen | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1257
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#10890: Incorrect redundant import warning for type classes -------------------------------------+------------------------------------- Reporter: quchen | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1257 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => closed * resolution: => fixed Comment: Thanks Ömer! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10890#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10890: Incorrect redundant import warning for type classes
-------------------------------------+-------------------------------------
Reporter: quchen | Owner:
Type: bug | Status: closed
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1257
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#10890: Incorrect redundant import warning for type classes
-------------------------------------+-------------------------------------
Reporter: quchen | Owner:
Type: bug | Status: closed
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 7.10.2
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| warnings/should_compile/T10890,
| T10890_1, T10890_2
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1257
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by simonpj):
* testcase: => warnings/should_compile/T10890, T10890_1, T10890_2
Comment:
I followed up with this
{{{
commit 3e94842d4d1258fbd6a1202bf74d41ce1d01c753
Author: Simon Peyton Jones
participants (1)
-
GHC