[GHC] #13064: Incorrect redudant imports warning

GHC ghc-devs at haskell.org
Mon Aug 20 23:28:29 UTC 2018


#13064: Incorrect redudant imports warning
-------------------------------------+-------------------------------------
        Reporter:  phadej            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  low               |            Milestone:  8.8.1
       Component:  Compiler          |              Version:  8.0.1
      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:  #15393            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * cc: core-libraries-committee@… (added)
 * milestone:   => 8.8.1


Comment:

 I admit I'm a bit nervous about merging this. The fact that the new scheme
 results in so many warnings even in GHC's core libraries is deeply
 concerning. I suspect that this new scheme may break the guidance that the
 Core Libraries Committee (or, at very least, Ed Kmett) has long offered
 for dealing with additions to `Prelude`: adding a (seemingly redundant)
 import of `Prelude`.

 For instance, consider the case of the Semigroup/Monoid proposal (SMP),
 where `(<>)` was added to `Prelude`. Imagine that before SMP a user had a
 module with,
 {{{#!hs
 import Data.Semigroup (Semigroup, (<>))

 squash :: Semigroup a => a -> a -> a
 squash = (<>)
 }}}
 However, post-SMP the import of `Data.Semigroup` is redundant, leading to
 a warning which would cause failures with `-Wall`. Of course, the user
 could drop the `import`, but only at the expense of compatibility with
 earlier GHC releases.

 One way around this is to guard the import with CPP,
 {{{#!hs
 #if MIN_VERSION_base(4,11,0)
 import Data.Semigroup (Semigroup, (<>))
 #endif

 squash :: Semigroup a => a -> a -> a
 squash = (<>)
 }}}
 However, requiring this sort of refactoring stands in violation of the
 CLC's [[https://prime.haskell.org/wiki/Libraries/3-Release-Policy|Three
 Release Policy]] which states that no library change will cause `-Wall`
 failures that are avoidable only with CPP.

 This is why the CLC has instead recommended this solution instead:
 {{{#!hs
 import Data.Semigroup (Semigroup, (<>))
 import Prelude

 squash :: Semigroup a => a -> a -> a
 squash = (<>)
 }}}
 Under the current redundancy check this throws no warnings (assuming
 something is used from `Prelude`). However, under the new scheme GHC deems
 the `Data.Semigroup` to be redundant. Moreover, under the new semantics I
 don't see any way to recover the previous level of compatibility short of
 CPP guards.

 Note that I'm not saying that either behavior is more correct; rather, I'm
 merely saying that a truly massive amount of code may be relying on the
 status quo and we should be very careful before making changes here.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13064#comment:22>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list