Ticket #2182 (new bug)

Opened 5 years ago

Last modified 5 years ago

ghc sessions (--make, --interactive, ghc api) erroneously retain instances

Reported by: claus Owned by:
Priority: low Milestone: _|_
Component: GHCi Version: 6.9
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

$ compiler/stage2/ghc-inplace --interactive
GHCi, version 6.9.20080317: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :i Functor
class Functor f where fmap :: (a -> b) -> f a -> f b
        -- Defined in GHC.Base
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.IOBase
Prelude> fmap not (True,True)

<interactive>:1:0:
    No instance for (Functor ((,) Bool))
      arising from a use of `fmap' at <interactive>:1:0-19
    Possible fix: add an instance declaration for (Functor ((,) Bool))
    In the expression: fmap not (True, True)
    In the definition of `it': it = fmap not (True, True)
Prelude> :m +Data.Array
Prelude Data.Array> :i Functor
class Functor f where fmap :: (a -> b) -> f a -> f b
        -- Defined in GHC.Base
instance (Ix i) => Functor (Array i) -- Defined in GHC.Arr
instance Functor ((->) r) -- Defined in Control.Monad.Instances
instance Functor ((,) a) -- Defined in Control.Monad.Instances
instance Functor (Either a) -- Defined in Control.Monad.Instances
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.IOBase
Prelude Data.Array> fmap not (True,True)
(True,False)
Prelude Data.Array> :m -Data.Array
Prelude> :i Functor
class Functor f where fmap :: (a -> b) -> f a -> f b
        -- Defined in GHC.Base
instance Functor ((->) r) -- Defined in Control.Monad.Instances
instance Functor ((,) a) -- Defined in Control.Monad.Instances
instance Functor (Either a) -- Defined in Control.Monad.Instances
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.IOBase
Prelude> fmap not (True,True)
(True,False)

Change History

Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10 branch

Thans for the report. #333 claims to have fixed this, but if so then it looks like it broke again.

Changed 5 years ago by simonmar

  • priority changed from normal to low
  • milestone changed from 6.10 branch to _|_

In fact this is a known bug mentioned in the User's Guide: http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html#bugs-ghc (see the final bullet point).

We don't have a ticket open for it as far as I can tell, though, so I'll leave this one open.

Changed 5 years ago by igloo

See also #2404

Changed 5 years ago by claus

  • summary changed from ghci session retains instances after :m -Module to ghc sessions (--make, --interactive, ghc api) erroneously retain instances

(changed ticket title to reflect broader scope)

This bug affects all ghc sessions, not just ghci. In particular:

- Cabal uses ghc --make, which can fail because of this bug

- Haddock 2 uses the ghc api, which can fail because of this bug

In both cases, the workaround is to repeat the command, so that it continues with a fresh ghc session, but that will not at all be obvious to users.

Example:

$ darcs get http://www.cs.kent.ac.uk/~cr3/toolbox/haskell/syb-utils
Finished getting.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.3

$ cd syb-utils/

$ runhaskell.exe Setup.hs configure
Configuring syb-utils-0.0.2008.8.19...
Warning: No license-file field.

$ runhaskell.exe Setup.hs build
Preprocessing library syb-utils-0.0.2008.8.19...
Building syb-utils-0.0.2008.8.19...
[1 of 6] Compiling Data.Generics.Instances.Dubious ( Data/Generics/Instances/Dubious.hs, dist\build/
Data/Generics/Instances/Dubious.o )
[2 of 6] Compiling Data.Generics.Utils ( Data/Generics/Utils.hs, dist\build/Data/Generics/Utils.o )
[3 of 6] Compiling Data.Generics.NoInstances ( Data/Generics/NoInstances.hs, dist\build/Data/Generic
s/NoInstances.o )
[4 of 6] Compiling Data.Generics.GPS ( Data/Generics/GPS.hs, dist\build/Data/Generics/GPS.o )
[5 of 6] Compiling Data.Generics.Instances.Standard ( Data/Generics/Instances/Standard.hs, dist\buil
d/Data/Generics/Instances/Standard.o )

Data/Generics/Instances/Standard.hs:61:0:
    Duplicate instance declarations:
      instance Data Bool
        -- Defined at Data/Generics/Instances/Standard.hs:(61,0)-(68,28)
      instance Data Bool -- Defined in Data.Generics.Instances
..

$ runhaskell.exe Setup.hs build
Preprocessing library syb-utils-0.0.2008.8.19...
Building syb-utils-0.0.2008.8.19...
[5 of 6] Compiling Data.Generics.Instances.Standard ( Data/Generics/Instances/Standard.hs, dist\buil
d/Data/Generics/Instances/Standard.o )
[6 of 6] Compiling Data.Generics.Alt ( Data/Generics/Alt.hs, dist\build/Data/Generics/Alt.o )
c:\ghc\ghc-6.8.3\bin\ar.exe: creating dist\build\libHSsyb-utils-0.0.2008.8.19.a

Confusingly, the behaviour is compiler-version and tool dependent:

$ runhaskell.exe Setup.hs clean
cleaning...

$ /cygdrive/c//fptools/ghc/ghc/stage2-inplace/ghc.exe --version
The Glorious Glasgow Haskell Compilation System, version 6.9.20080816

$ runhaskell Setup configure --with-compiler=c:/fptools/ghc/ghc/stage2-inplace/ghc.exe --with-hc-pk
g=c:/fptools/ghc/utils/ghc-pkg/install-inplace/bin/ghc-pkg.exe --with-haddock=c:/Program\ Files/Has
kell/bin/haddock.exe -fGhcApi
Configuring syb-utils-0.0.2008.8.19...
Warning: No license-file field.

cr3@cr3-lt ~/tst/ghc-session-bug/syb-utils
$ runhaskell.exe Setup.hs build
Preprocessing library syb-utils-0.0.2008.8.19...
Building syb-utils-0.0.2008.8.19...
[1 of 9] Compiling Data.Generics.Instances.Dubious ( Data\Generics\Instances\Dubious.hs, dist\build\
Data\Generics\Instances\Dubious.o )
[2 of 9] Compiling Data.Generics.Instances.Standard ( Data\Generics\Instances\Standard.hs, dist\buil
d\Data\Generics\Instances\Standard.o )
[3 of 9] Compiling Data.Generics.Utils ( Data\Generics\Utils.hs, dist\build\Data\Generics\Utils.o )
[4 of 9] Compiling Data.Generics.NoInstances ( Data\Generics\NoInstances.hs, dist\build\Data\Generic
s\NoInstances.o )
[5 of 9] Compiling Data.Generics.GPS ( Data\Generics\GPS.hs, dist\build\Data\Generics\GPS.o )
[6 of 9] Compiling Data.Generics.Alt ( Data\Generics\Alt.hs, dist\build\Data\Generics\Alt.o )
[7 of 9] Compiling GHC.Syb.Instances0 ( GHC\Syb\Instances0.hs, dist\build\GHC\Syb\Instances0.o )
[8 of 9] Compiling GHC.Syb.Instances ( GHC\Syb\Instances.hs, dist\build\GHC\Syb\Instances.o )
[9 of 9] Compiling GHC.Syb.Utils    ( GHC\Syb\Utils.hs, dist\build\GHC\Syb\Utils.o )
c:\ghc\ghc-6.8.3\bin\ar.exe: creating dist\build\libHSsyb-utils-0.0.2008.8.19.a

Note that ghc head and ghc 6.8.3 process the dependencies in a different order, which probably explains why the bug isn't triggered in head: Data.Generics.Instances.Dubious and Data.Generics.Instances.Standard represent two halves of base's Data.Generics.Instances; the latter isn't explicitly imported here, but Data.Generics.GPS uses Data.IntMap, which inadvertedly re-exports the instances from Data.Generics.Instances.

If Data.Generics.Instances.* are compiled first, ghc doesn't complain about alternative instances being present, but if either of Data.Generics.Instances.* is compiled after Data.Generics.GPS, the erroneously retained instances conflict with the newly defined ones.

We can confirm the bug is still there by trying to haddock2 the package with a fresh darcs haddock, freshly compiled with the same ghc head:

$ runhaskell.exe Setup.hs clean
cleaning...

$ /cygdrive/c/Program\ Files/Haskell/bin/haddock.exe --version
Haddock version 2.2.2, (c) Simon Marlow 2006
Ported to use the GHC API by David Waern 2006-2008

$ /cygdrive/c/Program\ Files/Haskell/bin/haddock.exe +RTS --info
 [("GHC RTS", "Yes")
 ,("GHC version", "6.9.20080816")
 ,("RTS way", "rts")
 ,("Host platform", "i386-unknown-mingw32")
 ,("Build platform", "i386-unknown-mingw32")
 ,("Target platform", "i386-unknown-mingw32")
 ,("Compiler unregisterised", "NO")
 ,("Tables next to code", "YES")
 ]

$ runhaskell Setup configure --with-compiler=c:/fptools/ghc/ghc/stage2-inplace/ghc.exe --with-hc-pk
g=c:/fptools/ghc/utils/ghc-pkg/install-inplace/bin/ghc-pkg.exe --with-haddock=c:/Program\ Files/Haskell/bin/haddock.exe -fGhcApi
Configuring syb-utils-0.0.2008.8.19...
Warning: No license-file field.

cr3@cr3-lt ~/tst/ghc-session-bug/syb-utils
$ runhaskell.exe Setup.hs haddock
Preprocessing library syb-utils-0.0.2008.8.19...
Running Haddock for syb-utils-0.0.2008.8.19...
Preprocessing library syb-utils-0.0.2008.8.19...
Warning: Cannot read c:\fptools\ghc\compiler\dist-stage2\doc\html\ghc\ghc.haddock:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\compiler\\dist-stage2\\doc\\html\\ghc\\ghc.haddock"
Skipping this interface.
Warning: Cannot read c:\fptools\ghc\libraries\base\dist\doc\html\base\base.haddock:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\libraries\\base\\dist\\doc\\html\\base\\base.haddock"
Skipping this interface.
Warning: Cannot read c:\fptools\ghc\libraries\containers\dist\doc\html\containers\containers.haddock
:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\libraries\\containers\\dist\\doc\\html\\containers\\containers.haddock"
Skipping this interface.

Data\Generics\Instances\Dubious.hs:59:9:
    Duplicate instance declarations:
      instance (Data a, Integral a) => Data (Ratio a)
        -- Defined at Data\Generics\Instances\Dubious.hs:59:9-46
      instance (Data a, Integral a) => Data (Ratio a)
        -- Defined in Data.Generics.Instances
..

$ runhaskell.exe Setup.hs haddock
Preprocessing library syb-utils-0.0.2008.8.19...
Running Haddock for syb-utils-0.0.2008.8.19...
Preprocessing library syb-utils-0.0.2008.8.19...
Warning: Cannot read c:\fptools\ghc\compiler\dist-stage2\doc\html\ghc\ghc.haddock:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\compiler\\dist-stage2\\doc\\html\\ghc\\ghc.haddock"
Skipping this interface.
Warning: Cannot read c:\fptools\ghc\libraries\base\dist\doc\html\base\base.haddock:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\libraries\\base\\dist\\doc\\html\\base\\base.haddock"
Skipping this interface.
Warning: Cannot read c:\fptools\ghc\libraries\containers\dist\doc\html\containers\containers.haddock
:
   "Magic number mismatch: couldn't load interface file: c:\\fptools\\ghc\\libraries\\containers\\dist\\doc\\html\\containers\\containers.haddock"
Skipping this interface.
Warning: in export list of "Data.Generics.NoInstances": module not found: "Data.Generics.Basics"
Warning: in export list of "Data.Generics.NoInstances": module not found: "Data.Generics.Aliases"
Warning: in export list of "Data.Generics.NoInstances": module not found: "Data.Generics.Schemes"
Warning: in export list of "Data.Generics.NoInstances": module not found: "Data.Generics.Text"
Warning: in export list of "Data.Generics.NoInstances": module not found: "Data.Generics.Twins"
Warning: in export list of "Data.Generics.Alt": module not found: "Data.Generics.Basics"
Warning: in export list of "Data.Generics.Alt": module not found: "Data.Generics.Aliases"
Warning: in export list of "Data.Generics.Alt": module not found: "Data.Generics.Schemes"
Warning: in export list of "Data.Generics.Alt": module not found: "Data.Generics.Text"
Warning: in export list of "Data.Generics.Alt": module not found: "Data.Generics.Twins"
Warning: syb-utils-0.0.2008.8.19:GHC.Syb.Instances: could not find link destinations for:
    Data.Typeable.TyCon
Warning: syb-utils-0.0.2008.8.19:GHC.Syb.Instances0: could not find link destinations for:
    Data.Typeable.TyCon
Warning: syb-utils-0.0.2008.8.19:GHC.Syb.Utils: could not find link destinations for:
    GHC.Classes.Eq GHC.Classes.Ord GHC.Show.Show Data.Generics.Basics.Data GHC.Types.Int GHC.Base.St
ring Data.Generics.Aliases.GenericQ GHC.Bool.Bool
Warning: syb-utils-0.0.2008.8.19:Data.Generics.GPS: could not find link destinations for:
    Data.Generics.Basics.Data Data.Generics.Aliases.GenericQ Data.Typeable.Typeable Data.Typeable.Typeable1 Data.Maybe.Maybe Data.IntMap.IntMap Data.IntSet.IntSet GHC.Types.Int Data.Generics.Aliases.GenericT
Warning: syb-utils-0.0.2008.8.19:Data.Generics.Utils: could not find link destinations for:
    Control.Applicative.Applicative Data.Typeable.Typeable1 Data.Typeable.Typeable Data.Generics.Basics.Data Data.Generics.Utils.X
Warning: syb-utils-0.0.2008.8.19:Data.Generics.Instances.Standard: could not find link destinations
for:
    Data.Typeable.TyCon
Documentation created: dist\doc\html\syb-utils\index.html

What are the chances of getting this fixed?

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.