+ -- No errors renaming source so rename the interfaces ...
+ -- _scc_ "preRnIfaces"
+ let
+ -- split up all names that occurred in the source; between
+ -- those that are defined therein and those merely mentioned.
+ -- We also divide by tycon/class and value names (as usual).
+
+ occ_rns = [ rn | (rn,_) <- eltsUFM occ_fm ]
+ -- all occurrence names, from this module and imported
+
+ (defined_here, defined_elsewhere)
+ = partition isLocallyDefined occ_rns
+
+ (_, imports_used)
+ = partition isRnWired defined_elsewhere
+
+ (def_tcs, def_vals) = partition isRnTyConOrClass defined_here
+ (occ_tcs, occ_vals) = partition isRnTyConOrClass occ_rns
+ -- the occ stuff includes *all* occurrences,
+ -- including those for which we have definitions
+
+ (orig_def_env, orig_def_dups)
+ = extendGlobalRnEnv emptyRnEnv (map pairify_rn def_vals)
+ (map pairify_rn def_tcs)
+ (orig_occ_env, orig_occ_dups)
+ = extendGlobalRnEnv emptyRnEnv (map pairify_rn occ_vals)
+ (map pairify_rn occ_tcs)
+
+ -- This stuff is pretty dodgy right now: I think original
+ -- names and occurrence names may be getting entangled
+ -- when they shouldn't be... WDP 96/06
+
+ pairify_rn rn -- ToDo: move to Name?
+ = let
+ name = getName rn
+ in
+ (if isLocalName name
+ then Unqual (getLocalName name)
+ else case (origName "pairify_rn" name) of { OrigName m n ->
+ Qual m n }
+ , rn)
+ in
+-- ASSERT (isEmptyBag orig_occ_dups)
+-- (if (isEmptyBag orig_occ_dups) then \x->x
+-- else pprTrace "orig_occ_dups:" (ppAboves [ ppCat [ppr PprDebug m, ppr PprDebug n, ppr PprDebug o] | (m,n,o) <- bagToList orig_occ_dups])) $
+ ASSERT (isEmptyBag orig_def_dups)
+
+ -- _scc_ "rnIfaces"
+ rnIfaces iface_cache imp_mods us3 orig_def_env orig_occ_env
+ rn_module (initMustHaves ++ imports_used) >>=
+ \ (rn_module_with_imports, final_env,
+ (implicit_val_fm, implicit_tc_fm),
+ usage_stuff,
+ (iface_errs, iface_warns)) ->
+
+ return (rn_module_with_imports,
+ final_env,
+ imp_mods,
+ export_stuff,
+ usage_stuff,
+ errs_so_far `unionBags` iface_errs,
+ warns_so_far `unionBags` iface_warns)
+ where
+ rn_panic = panic "renameModule: aborted with errors"
+
+ (us1, us') = splitUniqSupply us
+ (us2, us3) = splitUniqSupply us'
+
+initMustHaves :: [RnName]
+ -- things we *must* find declarations for, because the
+ -- compiler may eventually make reference to them (e.g.,
+ -- class Eq)
+initMustHaves
+ | opt_NoImplicitPrelude
+ = [{-no Prelude.hi, no point looking-}]
+ | otherwise
+ = [ name_fn (mkWiredInName u orig ExportAll)
+ | (orig@(OrigName mod str), (u, name_fn)) <- fmToList builtinKeysMap ]
+\end{code}
+
+\begin{code}
+makeHiMap :: Maybe String -> IO (FiniteMap Module FilePath)
+
+makeHiMap Nothing = error "Rename.makeHiMap:no .hi map given by the GHC driver (?)"
+makeHiMap (Just f)
+ = readFile f >>= \ cts ->
+ return (snag_mod emptyFM cts [])
+ where
+ -- we alternate between "snag"ging mod(ule names) and path(names),
+ -- accumulating names (reversed) and the final resulting map
+ -- as we move along.
+
+ snag_mod map [] [] = map
+ snag_mod map (' ':cs) rmod = snag_path map (_PK_ (reverse rmod)) cs []
+ snag_mod map (c:cs) rmod = snag_mod map cs (c:rmod)
+
+ snag_path map mod [] rpath = addToFM map mod (reverse rpath)
+ snag_path map mod ('\n':cs) rpath = snag_mod (addToFM map mod (reverse rpath)) cs []
+ snag_path map mod (c:cs) rpath = snag_path map mod cs (c:rpath)