#5316: Orphan instances strike again: ghc rejects a program at first but will
accept it if you repeat the same compilation command
----------------------------------------+-----------------------------------
Reporter: jcpetruzza | Owner:
Type: bug | Status: new
Priority: low | Milestone: _|_
Component: Compiler | Version: 7.0.4
Resolution: | Keywords:
Testcase: | Blockedby:
Difficulty: | Os: Unknown/Multiple
Blocking: | Architecture: Unknown/Multiple
Failure: GHC rejects valid program |
----------------------------------------+-----------------------------------
Changes (by simonpj):
* priority: normal => low
* milestone: => _|_
Comment:
I believe I know what is happening here. Background:
* GHC maintains a session-global "database" of instances from imported
packages
* This database only grows; when GHC needs to use functions from a
module, it loads up that module and adds its instances to the database.
* When looking up an instance, GHC looks up in this database (and in a
similar data base for the package being compiled, but that's not an issue
in this example).
In this case:
* When you first say `ghc --make T1 T2`, GHC has to compile both modules.
* T1 depends on `Text.Show.Functions`, which has a Show instance for
`(->)`
* T2 depends on `System.Event.Manager`, which also has a Show instance
for `(->)`.
* So when it comes to T2, the second module is loaded, and the overlap is
reported.
* Without optimisation, `System.Event.Manager` isn't loaded at all, so
its instances don't conflict.
* When '''recompiling''' GHC starts with an empty database and, since T1
hasn't changed, it doesn't recompile it. So the database isn't as
populated as before, and there's no overlap.
It's not very cool, but that's why.
Orphan instaces are a major pain. It's hard to do the Right Thing without
being very inefficient, and I'm reluctant to penalise all compilations.
It's a kind of bizarre case, and I'm not sure it's worth a lot of effort.
So I'll make it low priority -- but if someone is finding it painful,
please yell.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5316#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs