[project @ 2005-03-17 10:16:32 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / HscTypes.lhs
index 97df435..5119a78 100644 (file)
@@ -11,7 +11,7 @@ module HscTypes (
        ModDetails(..), 
        ModGuts(..), ModImports(..), ForeignStubs(..),
 
-       ModSummary(..), showModMsg,
+       ModSummary(..), showModMsg, isBootSummary,
        msHsFilePath, msHiFilePath, msObjFilePath, 
 
        HscSource(..), isHsBoot, hscSourceString,       -- Re-exported from DriverPhases
@@ -169,8 +169,6 @@ emptyPackageIfaceTable = emptyModuleEnv
 
 data HomeModInfo 
   = HomeModInfo { hm_iface    :: ModIface,
-                 hm_globals  :: Maybe GlobalRdrEnv,    -- Its top level environment
-                                                       -- Nothing <-> compiled module
                  hm_details  :: ModDetails,
                  hm_linkable :: Linkable }
 \end{code}
@@ -195,29 +193,16 @@ lookupIfaceByModule hpt pit mod
 
 
 \begin{code}
-hptInstances :: HscEnv -> [(Module, IsBootInterface)] -> [DFunId]
+hptInstances :: HscEnv -> (Module -> Bool) -> [DFunId]
 -- Find all the instance declarations that are in modules imported 
 -- by this one, directly or indirectly, and are in the Home Package Table
 -- This ensures that we don't see instances from modules --make compiled 
 -- before this one, but which are not below this one
-hptInstances hsc_env deps
-  | isOneShot (hsc_mode hsc_env) = []  -- In one-shot mode, the HPT is empty
-  | otherwise
-  = let 
-       hpt = hsc_HPT hsc_env
-    in
-    [ dfun 
-    |  -- Find each non-hi-boot module below me
-      (mod, False) <- deps
-
-       -- Look it up in the HPT
-    , let mod_info = ASSERT2( mod `elemModuleEnv` hpt, ppr mod $$ vcat (map ppr_hm (moduleEnvElts hpt)))
-                    fromJust (lookupModuleEnv hpt mod)
-
-       -- And get its dfuns
+hptInstances hsc_env want_this_module
+  = [ dfun 
+    | mod_info <- moduleEnvElts (hsc_HPT hsc_env)
+    , want_this_module (mi_module (hm_iface mod_info))
     , dfun <- md_insts (hm_details mod_info) ]
-  where
-   ppr_hm hm = ppr (mi_module (hm_iface hm))
 
 hptRules :: HscEnv -> [(Module, IsBootInterface)] -> [IdCoreRule]
 -- Get rules from modules "below" this one (in the dependency sense)
@@ -297,6 +282,11 @@ data ModIface
                -- the version of the parent class/tycon changes
        mi_decls :: [(Version,IfaceDecl)],      -- Sorted
 
+        mi_globals  :: !(Maybe GlobalRdrEnv),
+               -- Its top level environment or Nothing if we read this
+               -- interface from an interface file.  (We need the source
+               -- file to figure out the top-level environment.)
+
                -- Instance declarations and rules
        mi_insts     :: [IfaceInst],    -- Sorted
        mi_rules     :: [IfaceRule],    -- Sorted
@@ -412,6 +402,7 @@ emptyModIface pkg mod
               mi_insts = [],
               mi_rules = [],
               mi_decls = [],
+              mi_globals  = Nothing,
               mi_rule_vers = initialVersion,
               mi_dep_fn = emptyIfaceDepCache,
               mi_fix_fn = emptyIfaceFixCache,
@@ -916,6 +907,8 @@ msHsFilePath  ms = expectJust "msHsFilePath" (ml_hs_file  (ms_location ms))
 msHiFilePath  ms = ml_hi_file  (ms_location ms)
 msObjFilePath ms = ml_obj_file (ms_location ms)
 
+isBootSummary :: ModSummary -> Bool
+isBootSummary ms = isHsBoot (ms_hsc_src ms)
 
 instance Outputable ModSummary where
    ppr ms