[project @ 2005-03-22 17:13:12 by simonmar]
[ghc-hetmet.git] / ghc / compiler / iface / LoadIface.lhs
index e5e7a5a..ab11421 100644 (file)
@@ -17,22 +17,20 @@ module LoadIface (
 import {-# SOURCE #-}  TcIface( tcIfaceDecl )
 
 import Packages                ( PackageState(..), PackageIdH(..), isHomePackage )
-import DriverState     ( v_GhcMode, isCompManagerMode )
-import CmdLineOpts     ( DynFlags(..), DynFlag( Opt_IgnoreInterfacePragmas ) )
+import DynFlags                ( DynFlags(..), DynFlag( Opt_IgnoreInterfacePragmas ),
+                         isOneShot )
 import IfaceSyn                ( IfaceDecl(..), IfaceConDecl(..), IfaceClassOp(..),
                          IfaceConDecls(..), IfaceInst(..), IfaceRule(..),
                          IfaceExpr(..), IfaceTyCon(..), IfaceIdInfo(..), 
                          IfaceType(..), IfacePredType(..), IfaceExtName,
                          mkIfaceExtName )
-import IfaceEnv                ( newGlobalBinder, lookupIfaceExt, lookupIfaceTc,
-                         lookupOrig )
+import IfaceEnv                ( newGlobalBinder, lookupIfaceExt, lookupIfaceTc, lookupAvail )
 import HscTypes                ( ModIface(..), TyThing, emptyModIface, EpsStats(..),
                          addEpsInStats, ExternalPackageState(..),
-                         PackageTypeEnv, emptyTypeEnv,  
+                         PackageTypeEnv, emptyTypeEnv,  HscEnv(..),
                          lookupIfaceByModule, emptyPackageIfaceTable,
                          IsBootInterface, mkIfaceFixCache, Gated,
-                         implicitTyThings, addRulesToPool, addInstsToPool,
-                         availNames
+                         implicitTyThings, addRulesToPool, addInstsToPool
                         )
 
 import BasicTypes      ( Version, Fixity(..), FixityDirection(..),
@@ -120,9 +118,10 @@ loadHiBootInterface
 
     do {       -- Load it (into the PTE), and return the exported names
          iface <- loadSrcInterface (mk_doc mod_nm) mod_nm True
-       ; sequenceM [ lookupOrig mod_nm occ
-                   | (mod,avails) <- mi_exports iface, 
-                     avail <- avails, occ <- availNames avail]
+       ; ns_s <-  sequenceM [ lookupAvail mod_nm avail
+                            | (mod,avails) <- mi_exports iface, 
+                              avail <- avails ]
+       ; return (concat ns_s)
     }}}
   where
     mk_doc mod = ptext SLIT("Need the hi-boot interface for") <+> ppr mod
@@ -577,7 +576,8 @@ findAndReadIface explicit doc_str mod_name hi_boot_file
          else do
 
        -- Look for the file
-       ; mb_found <- ioToIOEnv (findHiFile dflags explicit mod_name hi_boot_file)
+       ; hsc_env <- getTopEnv
+       ; mb_found <- ioToIOEnv (findHiFile hsc_env explicit mod_name hi_boot_file)
        ; case mb_found of {
              Failed err -> do
                { traceIf (ptext SLIT("...not found"))
@@ -599,20 +599,19 @@ findAndReadIface explicit doc_str mod_name hi_boot_file
                        -- Don't forget to fill in the package name...
        }}}
 
-findHiFile :: DynFlags -> Bool -> Module -> IsBootInterface
+findHiFile :: HscEnv -> Bool -> Module -> IsBootInterface
           -> IO (MaybeErr FindResult (FilePath, PackageIdH))
-findHiFile dflags explicit mod_name hi_boot_file
+findHiFile hsc_env explicit mod_name hi_boot_file
  = do { 
        -- In interactive or --make mode, we are *not allowed* to demand-load
        -- a home package .hi file.  So don't even look for them.
        -- This helps in the case where you are sitting in eg. ghc/lib/std
        -- and start up GHCi - it won't complain that all the modules it tries
        -- to load are found in the home location.
-       ghci_mode <- readIORef v_GhcMode ;
-       let { home_allowed = not (isCompManagerMode ghci_mode) } ;
+       let { home_allowed = isOneShot (ghcMode (hsc_dflags hsc_env)) } ;
        maybe_found <-  if home_allowed 
-                       then findModule        dflags mod_name explicit
-                       else findPackageModule dflags mod_name explicit;
+                       then findModule        hsc_env mod_name explicit
+                       else findPackageModule hsc_env mod_name explicit;
 
        case maybe_found of
          Found loc pkg -> return (Succeeded (path, pkg))