[project @ 2000-11-20 16:07:12 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnIfaces.lhs
index d4a6f32..7311439 100644 (file)
@@ -244,8 +244,8 @@ slurpSourceRefs source_binders source_fvs
 
     go_outer decls fvs all_gates refs  -- refs are not necessarily slurped yet
        = traceRn (text "go_outer" <+> ppr refs)                `thenRn_`
-         getImportedInstDecls all_gates                        `thenRn` \ inst_decls ->
          foldlRn go_inner (decls, fvs, emptyFVs) refs          `thenRn` \ (decls1, fvs1, gates1) ->
+         getImportedInstDecls (all_gates `plusFV` gates1)      `thenRn` \ inst_decls ->
          rnIfaceInstDecls decls1 fvs1 gates1 inst_decls        `thenRn` \ (decls2, fvs2, gates2) ->
          go_outer decls2 fvs2 (all_gates `plusFV` gates2)
                               (nameSetToList (gates2 `minusNameSet` all_gates))
@@ -344,12 +344,9 @@ recordSlurp ifaces@(Ifaces { iDecls = (decls_map, n_slurped),
     new_vslurp | isModuleInThisPackage mod = (imp_mods, addOneToNameSet imp_names main_name)
               | otherwise                 = (extendModuleSet imp_mods mod, imp_names)
 
-recordLocalSlurps local_avails
+recordLocalSlurps new_names
   = getIfacesRn        `thenRn` \ ifaces ->
-    let
-       new_slurped_names = foldl addAvailToNameSet (iSlurp ifaces) local_avails
-    in
-    setIfacesRn (ifaces { iSlurp  = new_slurped_names })
+    setIfacesRn (ifaces { iSlurp  = iSlurp ifaces `unionNameSets` new_names })
 \end{code}
 
 
@@ -603,19 +600,13 @@ data ImportDeclResult
   | HereItIs (Module, RdrNameTyClDecl)
 
 importDecl name
-  =    -- STEP 1: Check if it was loaded before beginning this module
-    if isLocalName name then
-       traceRn (text "Already (local)" <+> ppr name) `thenRn_`
-       returnRn AlreadySlurped
-    else
-
-       -- STEP 2: Check if we've slurped it in while compiling this module
+  =    -- STEP 1: Check if we've slurped it in while compiling this module
     getIfacesRn                                `thenRn` \ ifaces ->
     if name `elemNameSet` iSlurp ifaces then   
        returnRn AlreadySlurped 
     else
 
-       -- STEP 3: Check if it's already in the type environment
+       -- STEP 2: Check if it's already in the type environment
     getTypeEnvRn                       `thenRn` \ lookup ->
     case lookup name of {
        Just ty_thing | name `elemNameEnv` wiredInThingEnv
@@ -629,13 +620,13 @@ importDecl name
 
        Nothing -> 
 
-       -- STEP 4: OK, we have to slurp it in from an interface file
+       -- STEP 3: OK, we have to slurp it in from an interface file
        --         First load the interface file
     traceRn nd_doc                     `thenRn_`
     loadHomeInterface nd_doc name      `thenRn_`
     getIfacesRn                                `thenRn` \ ifaces ->
 
-       -- STEP 5: Get the declaration out
+       -- STEP 4: Get the declaration out
     let
        (decls_map, _) = iDecls ifaces
     in
@@ -710,8 +701,21 @@ checkModUsage (mod_name, _, _, NothingAtAll)
        -- In this case we don't even want to open Foo's interface.
   = up_to_date (ptext SLIT("Nothing used from:") <+> ppr mod_name)
 
-checkModUsage (mod_name, _, _, whats_imported)
-  = tryLoadInterface doc_str mod_name ImportBySystem   `thenRn` \ (iface, maybe_err) ->
+checkModUsage (mod_name, _, is_boot, whats_imported)
+  =    -- Load the imported interface is possible
+       -- We use tryLoadInterface, because failure is not an error
+       -- (might just be that the old .hi file for this module is out of date)
+       -- We use ImportByUser/ImportByUserSource as the 'from' flag, 
+       --      a) because we need to know whether to load the .hi-boot file
+       --      b) because loadInterface things matters are amiss if we 
+       --         ImportBySystem an interface it knows nothing about
+    let
+       doc_str = sep [ptext SLIT("need version info for"), ppr mod_name]
+       from    | is_boot   = ImportByUserSource
+               | otherwise = ImportByUser
+    in
+    tryLoadInterface doc_str mod_name from     `thenRn` \ (iface, maybe_err) ->
+
     case maybe_err of {
        Just err -> out_of_date (sep [ptext SLIT("Can't find version number for module"), 
                                      ppr mod_name]) ;
@@ -758,8 +762,6 @@ checkModUsage (mod_name, _, _, whats_imported)
        up_to_date (ptext SLIT("...but the bits I use haven't."))
 
     }}
-  where
-    doc_str = sep [ptext SLIT("need version info for"), ppr mod_name]
 
 ------------------------
 checkModuleVersion old_mod_vers new_vers