- load mod = loadInterface (pprModuleName mod <+> ptext SLIT("is a orphan-instance module")) mod ImportBySystem
-
-loadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (Module, Ifaces)
-loadInterface doc_str mod_name from
- = getIfacesRn `thenRn` \ ifaces ->
- let
- mod_map = iImpModInfo ifaces
- mod_info = lookupFM mod_map mod_name
- in_map = maybeToBool mod_info
- in
-
- -- Issue a warning for a redundant {- SOURCE -} import
- -- It's redundant if the moduld is in the iImpModInfo at all,
- -- because we arrange to read all the ordinary imports before
- -- any of the {- SOURCE -} imports
- warnCheckRn (not (in_map && case from of {ImportByUserSource -> True; other -> False}))
- (warnRedundantSourceImport mod_name) `thenRn_`
-
- -- CHECK WHETHER WE HAVE IT ALREADY
- case mod_info of {
- Just (_, _, Just (load_mod, _, _))
- -> -- We're read it already so don't re-read it
- returnRn (load_mod, ifaces) ;
-
- mod_map_result ->
-
- -- READ THE MODULE IN
- findAndReadIface doc_str mod_name from in_map
- `thenRn` \ (hi_boot_read, read_result) ->
- case read_result of {
- Nothing -> -- Not found, so add an empty export env to the Ifaces map
- -- so that we don't look again
- let
- mod = mkVanillaModule mod_name
- new_mod_map = addToFM mod_map mod_name (0, False, Just (mod, False, []))
- new_ifaces = ifaces { iImpModInfo = new_mod_map }
- in
- setIfacesRn new_ifaces `thenRn_`
- failWithRn (mod, new_ifaces) (noIfaceErr mod hi_boot_read) ;
-
- -- Found and parsed!
- Just (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)
-
- getModuleRn `thenRn` \ this_mod_nm ->
- let
- rd_decls = pi_decls iface
- in
- foldlRn (loadDecl mod) (iDecls ifaces) rd_decls `thenRn` \ new_decls ->
- foldlRn (loadInstDecl mod) (iInsts ifaces) (pi_insts iface) `thenRn` \ new_insts ->
- (if (opt_IgnoreIfacePragmas)
- then returnRn emptyBag
- else foldlRn (loadRule mod) (iRules ifaces) (pi_rules iface)) `thenRn` \ new_rules ->
- foldlRn (loadFixDecl mod_name) (iFixes ifaces) rd_decls `thenRn` \ new_fixities ->
- mapRn (loadExport this_mod_nm) (pi_exports iface) `thenRn` \ avails_s ->
- let
- -- 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 mod_map (pi_usages iface)
- other -> mod_map
-
- -- Now add info about this module
- mod_map2 = addToFM mod_map1 mod_name mod_details
- mod_details = (pi_mod iface, pi_orphan iface, Just (mod, hi_boot_read, concat avails_s))
-
- new_ifaces = ifaces { iImpModInfo = mod_map2,
- iDecls = new_decls,
- iFixes = new_fixities,
- iRules = new_rules,
- iInsts = new_insts }
- in
- setIfacesRn new_ifaces `thenRn_`
- returnRn (mod, new_ifaces)
- }}