simonpj at microsoft.com
Wed Aug 13 09:51:33 EDT 2008
| I still don't understand why ghc will become "slower" with orphaned
| modules. Where is "wasted work" or which "instances are useless"?
| Doesn't ghc just read all interface files of modules in the import chain
| (i.e. all modules "below")? Or is that the "disaster in practice, so GHC
| tries to be clever"? In what way is GHC clever? Are only interface files
| of directly imported modules (plus orphaned modules mentioned in there)
| read in?
In the *absence* of orphan modules, GHC reads as few interface files as possible. It must read the interface of every *directly-imported* module. After that, it's by-need only. For example
module Foo where
x = ()
GHC must read Prelude.hi, but needs read nothing else to compile the module.
Now suppose it's like this instead
module Foo where
x = map
module Prelude( map, filter ) where
import GHC.Map( map )
import GHC.Filter( filter )
Now when compiling Foo, GHC reads Prelude.hi, and sees that GHC.Map.map is brought into scope. Since that function is *used* in Foo, GHC also reads GHC.Map.hi to find GHC.Map.map's type, unfolding, arity, strictness etc etc. But it doesn't read GHC.Filter.
In the *presence* of orphan modules, perhaps somewhere in the transitive closure of modules imported by Prelude, GHC must read those interface files too. We store a list of all orphan modules transitively below Prelude inside Prelude.hi, precisely so GHC knows which ones to read.
Does that help? (If so, and you find it helpful, would you like to add some advice or information to the GHC wiki? So that those not reading this thread right now might be illuminated later.)
More information about the Libraries