From: simonpj@microsoft.com Date: Fri, 6 Oct 2006 14:01:02 +0000 (+0000) Subject: Avoid repeatedly loading GHC.Prim X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=c305b14a2481b4e367a5b70981a0b8b667a95e61 Avoid repeatedly loading GHC.Prim This patch changes HscTypes.lookupIfaceByModule. The problem was that when compiling the 'base' package, we'd repeatedly reload GHC.Prim. This is easily fixed by looking in the PIT too. A comment with lookupIfaceByModule explains --- diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs index 34f6555..8b126e6 100644 --- a/compiler/main/HscTypes.lhs +++ b/compiler/main/HscTypes.lhs @@ -109,7 +109,7 @@ import FastString ( FastString ) import DATA_IOREF ( IORef, readIORef ) import StringBuffer ( StringBuffer ) -import Maybe ( catMaybes ) +import Maybes ( catMaybes, seqMaybe ) import Time ( ClockTime ) \end{code} @@ -247,12 +247,21 @@ lookupIfaceByModule -> Module -> Maybe ModIface lookupIfaceByModule dflags hpt pit mod - -- in one-shot, we don't use the HPT - | not (isOneShot (ghcMode dflags)) && modulePackageId mod == this_pkg - = fmap hm_iface (lookupUFM hpt (moduleName mod)) - | otherwise - = lookupModuleEnv pit mod - where this_pkg = thisPackage dflags + | modulePackageId mod == thisPackage dflags + = -- The module comes from the home package, so look first + -- in the HPT. If it's not from the home package it's wrong to look + -- in the HPT, because the HPT is indexed by *ModuleName* not Module + fmap hm_iface (lookupUFM hpt (moduleName mod)) + `seqMaybe` lookupModuleEnv pit mod + + | otherwise = lookupModuleEnv pit mod -- Look in PIT only + +-- If the module does come from the home package, why do we look in the PIT as well? +-- (a) In OneShot mode, even home-package modules accumulate in the PIT +-- (b) Even in Batch (--make) mode, there is *one* case where a home-package +-- module is in the PIT, namely GHC.Prim when compiling the base package. +-- We could eliminate (b) if we wanted, by making GHC.Prim belong to a packake +-- of its own, but it doesn't seem worth the bother. \end{code}