-\begin{code}
-loadHomeInterface :: SDoc -> Name -> RnM d Ifaces
-loadHomeInterface doc_str name
- = loadInterface doc_str (moduleName (nameModule name)) ImportBySystem
-
-loadOrphanModules :: [ModuleName] -> RnM d ()
-loadOrphanModules mods
- | null mods = returnRn ()
- | otherwise = traceRn (text "Loading orphan modules:" <+>
- fsep (map mods)) `thenRn_`
- mapRn_ load mods `thenRn_`
- returnRn ()
- where
- load mod = loadInterface (mk_doc mod) mod ImportBySystem
- mk_doc mod = ppr mod <+> ptext SLIT("is a orphan-instance module")
-
-
-loadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d Ifaces
-loadInterface doc mod from
- = tryLoadInterface doc mod from `thenRn` \ (ifaces, maybe_err) ->
- case maybe_err of
- Nothing -> returnRn ifaces
- Just err -> failWithRn ifaces err
-
-tryLoadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (Ifaces, Maybe Message)
- -- Returns (Just err) if an error happened
- -- Guarantees to return with iImpModInfo m --> (... Just cts)
- -- (If the load fails, we plug in a vanilla placeholder
-tryLoadInterface doc_str mod_name from
- = getIfacesRn `thenRn` \ ifaces ->
- let
- mod_map = iImpModInfo ifaces
- mod_info = lookupFM mod_map mod_name
-
- hi_boot_file
- = case (from, mod_info) of
- (ImportByUser, _) -> False -- Not hi-boot
- (ImportByUserSource, _) -> True -- hi-boot
- (ImportBySystem, Just (_, is_boot, _)) -> is_boot --
- (ImportBySystem, Nothing) -> False
- -- We're importing a module we know absolutely
- -- nothing about, so we assume it's from
- -- another package, where we aren't doing
- -- dependency tracking. So it won't be a hi-boot file.
-
- redundant_source_import
- = case (from, mod_info) of
- (ImportByUserSource, Just (_,False,_)) -> True
- other -> False
- in
- -- CHECK WHETHER WE HAVE IT ALREADY
- case mod_info of {
- Just (_, _, True)
- -> -- We're read it already so don't re-read it
- returnRn (ifaces, Nothing) ;
-
- _ ->
-
- -- Issue a warning for a redundant {- SOURCE -} import
- -- NB that we arrange to read all the ordinary imports before
- -- any of the {- SOURCE -} imports
- warnCheckRn (not redundant_source_import)
- (warnRedundantSourceImport mod_name) `thenRn_`
-
- -- READ THE MODULE IN
- findAndReadIface doc_str mod_name hi_boot_file `thenRn` \ read_resultb ->
- case read_result of {
- Left err -> -- Not found, so add an empty export env to the Ifaces map
- -- so that we don't look again
- let
- new_mod_map = addToFM mod_map mod_name (False, False, True)
- new_ifaces = ifaces { iImpModInfo = new_mod_map }
- in
- setIfacesRn new_ifaces `thenRn_`
- returnRn (new_ifaces, Just err) ;
-
- -- Found and parsed!
- Right (mod, iface) ->
-
- -- LOAD IT INTO Ifaces
-
- -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
- --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
- -- If we do loadExport first the wrong info gets into the cache (unless we
- -- explicitly tag each export which seems a bit of a bore)
-
-
- -- Sanity check. If we're system-importing a module we know nothing at all
- -- about, it should be from a different package to this one
- WARN( not (maybeToBool mod_info) &&
- case from of { ImportBySystem -> True; other -> False } &&
- isModuleInThisPackage mod,
- ppr mod )
-
- loadDecls mod (iDecls ifaces) (pi_decls iface) `thenRn` \ (decls_vers, new_decls) ->
- loadRules mod (iRules ifaces) (pi_rules iface) `thenRn` \ (rule_vers, new_rules) ->
- loadFixDecls mod_name (pi_fixity iface) `thenRn` \ (fix_vers, fix_env) ->
- foldlRn (loadDeprec mod) emptyDeprecEnv (pi_deprecs iface) `thenRn` \ deprec_env ->
- foldlRn (loadInstDecl mod) (iInsts ifaces) (pi_insts iface) `thenRn` \ new_insts ->
- loadExports (pi_exports iface) `thenRn` \ avails ->
- let
- version = VersionInfo { modVers = pi_vers iface,
- fixVers = fix_vers,
- ruleVers = rule_vers,
- declVers = decl_vers }
-
- -- For an explicit user import, add to mod_map info about
- -- the things the imported module depends on, extracted
- -- from its usage info.
- mod_map1 = case from of
- ImportByUser -> addModDeps mod (pi_usages iface) mod_map
- other -> mod_map
- mod_map2 = addToFM mod_map1 mod_name (pi_orphan iface, hi_boot_file, True)
-
- -- Now add info about this module to the PST
- new_pit = extendModuleEnv pit mod mod_iface
- mod_iface = ModIface { mdModule = mod, mvVersion = version,
- mdExports = avails,
- mdFixEnv = fix_env, mdDeprecEnv = deprec_env }
-
- new_ifaces = ifaces { iPIT = new_pit,
- iDecls = new_decls,
- iInsts = new_insts,
- iRules = new_rules,
- iImpModInfo = mod_map2 }
- in
- setIfacesRn new_ifaces `thenRn_`
- returnRn (new_ifaces, Nothing)
- }}