-loadRule :: Module -> Bag GatedDecl
- -> RdrNameRuleDecl -> RnM d (Bag GatedDecl)
--- "Gate" the rule simply by whether the rule variable is
--- needed. We can refine this later.
-loadRule mod rules decl@(IfaceRuleDecl var body src_loc)
- = setModuleRn (moduleName mod) $
- mkImportedGlobalFromRdrName var `thenRn` \ var_name ->
- returnRn ((unitNameSet var_name, (mod, RuleD decl)) `consBag` rules)
-
--- SUP: TEMPORARY HACK, ignoring module deprecations for now
-loadDeprec :: Module -> DeprecationEnv -> RdrNameDeprecation -> RnM d DeprecationEnv
-loadDeprec mod deprec_env (Deprecation (IEModuleContents _) txt)
- = traceRn (text "module deprecation not yet implemented:" <+> ppr mod <> colon <+> ppr txt) `thenRn_`
- returnRn deprec_env
-loadDeprec mod deprec_env (Deprecation ie txt)
- = setModuleRn (moduleName mod) $
- mapRn mkImportedGlobalFromRdrName (namesFromIE ie) `thenRn` \ names ->
- traceRn (text "loaded deprecation(s) for" <+> hcat (punctuate comma (map ppr names)) <> colon <+> ppr txt) `thenRn_`
- returnRn (extendNameEnv deprec_env (zip names (repeat txt)))
-
-namesFromIE :: IE a -> [a]
-namesFromIE (IEVar n ) = [n]
-namesFromIE (IEThingAbs n ) = [n]
-namesFromIE (IEThingAll n ) = [n]
-namesFromIE (IEThingWith n ns) = n:ns
-namesFromIE (IEModuleContents _ ) = []
-\end{code}
-
-
-%********************************************************
-%* *
-\subsection{Loading usage information}
-%* *
-%********************************************************
-
-\begin{code}
-checkUpToDate :: ModuleName -> RnMG Bool -- True <=> no need to recompile
-checkUpToDate mod_name
- = getIfacesRn `thenRn` \ ifaces ->
- findAndReadIface doc_str mod_name
- ImportByUser
- (error "checkUpToDate") `thenRn` \ (_, read_result) ->
-
- -- CHECK WHETHER WE HAVE IT ALREADY
- case read_result of
- Nothing -> -- Old interface file not found, so we'd better bail out
- traceRn (sep [ptext SLIT("Didnt find old iface"),
- pprModuleName mod_name]) `thenRn_`
- returnRn False
-
- Just (_, iface)
- -> -- Found it, so now check it
- checkModUsage (pi_usages iface)
- where
- -- Only look in current directory, with suffix .hi
- doc_str = sep [ptext SLIT("need usage info from"), pprModuleName mod_name]
-
-checkModUsage [] = returnRn True -- Yes! Everything is up to date!
-
-checkModUsage ((mod_name, old_mod_vers, _, _, Specifically []) : rest)
- -- If CurrentModule.hi contains
- -- import Foo :: ;
- -- then that simply records that Foo lies below CurrentModule in the
- -- hierarchy, but CurrentModule doesn't depend in any way on Foo.
- -- In this case we don't even want to open Foo's interface.
- = traceRn (ptext SLIT("Nothing used from:") <+> ppr mod_name) `thenRn_`
- checkModUsage rest -- This one's ok, so check the rest
-
-checkModUsage ((mod_name, old_mod_vers, _, _, whats_imported) : rest)
- = loadInterface doc_str mod_name ImportBySystem `thenRn` \ (mod, ifaces) ->
- let
- maybe_mod_vers = case lookupFM (iImpModInfo ifaces) mod_name of
- Just (version, _, _, Just (_, _)) -> Just version
- other -> Nothing
- in
- case maybe_mod_vers of {
- Nothing -> -- If we can't find a version number for the old module then
- -- bail out saying things aren't up to date
- traceRn (sep [ptext SLIT("Can't find version number for module"),
- pprModuleName mod_name])
- `thenRn_` returnRn False ;
-
- Just new_mod_vers ->
-
- -- If the module version hasn't changed, just move on
- if new_mod_vers == old_mod_vers then
- traceRn (sep [ptext SLIT("Module version unchanged:"), pprModuleName mod_name])
- `thenRn_` checkModUsage rest
- else
- traceRn (sep [ptext SLIT("Module version has changed:"), pprModuleName mod_name])
- `thenRn_`
- -- Module version changed, so check entities inside
-
- -- If the usage info wants to say "I imported everything from this module"
- -- it does so by making whats_imported equal to Everything
- -- In that case, we must recompile
- case whats_imported of {
- Everything -> traceRn (ptext SLIT("...and I needed the whole module")) `thenRn_`
- returnRn False; -- Bale out
-
- Specifically old_local_vers ->
-
- -- Non-empty usage list, so check item by item
- checkEntityUsage mod_name (iDecls ifaces) old_local_vers `thenRn` \ up_to_date ->
- if up_to_date then
- traceRn (ptext SLIT("...but the bits I use haven't.")) `thenRn_`
- checkModUsage rest -- This one's ok, so check the rest
- else
- returnRn False -- This one failed, so just bail out now
- }}
- where
- doc_str = sep [ptext SLIT("need version info for"), pprModuleName mod_name]
-
-
-checkEntityUsage mod decls []
- = returnRn True -- Yes! All up to date!
-
-checkEntityUsage mod decls ((occ_name,old_vers) : rest)
- = mkImportedGlobalName mod occ_name `thenRn` \ name ->
- case lookupNameEnv decls name of
-
- Nothing -> -- We used it before, but it ain't there now
- traceRn (sep [ptext SLIT("No longer exported:"), ppr name])
- `thenRn_` returnRn False