[project @ 2000-10-24 15:55:35 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnIfaces.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnIfaces]{Cacheing and Renaming of Interfaces}
5
6 \begin{code}
7 module RnIfaces
8        (
9         getInterfaceExports,
10         getImportedInstDecls, getImportedRules,
11         lookupFixityRn, 
12         importDecl, ImportDeclResult(..), recordLocalSlurps, 
13         mkImportInfo, getSlurped,
14
15         RecompileRequired, outOfDate, upToDate, recompileRequired
16        )
17 where
18
19 #include "HsVersions.h"
20
21 import CmdLineOpts      ( DynFlags, opt_NoPruneDecls, opt_NoPruneTyDecls, opt_IgnoreIfacePragmas )
22 import HscTypes
23 import HsSyn            ( HsDecl(..), InstDecl(..),  HsType(..) )
24 import HsImpExp         ( ImportDecl(..) )
25 import BasicTypes       ( Version, defaultFixity )
26 import RdrHsSyn         ( RdrNameHsDecl, RdrNameTyClDecl, RdrNameInstDecl )
27 import RnHiFiles        ( tryLoadInterface, loadHomeInterface, loadInterface, 
28                           loadOrphanModules
29                         )
30 import RnEnv
31 import RnMonad
32 import Name             ( Name {-instance NamedThing-}, nameOccName,
33                           nameModule, isLocallyDefined, 
34                           NamedThing(..),
35                           elemNameEnv
36                          )
37 import Module           ( Module, ModuleEnv,
38                           moduleName, isModuleInThisPackage,
39                           ModuleName, WhereFrom(..),
40                           emptyModuleEnv, lookupModuleEnvByName,
41                           extendModuleEnv_C, lookupWithDefaultModuleEnv
42                         )
43 import NameSet
44 import PrelInfo         ( wiredInThingEnv )
45 import Maybes           ( orElse )
46 import FiniteMap
47 import Outputable
48 import Bag
49
50 import List             ( nub )
51 \end{code}
52
53
54 %*********************************************************
55 %*                                                      *
56 \subsection{Getting what a module exports}
57 %*                                                      *
58 %*********************************************************
59
60 @getInterfaceExports@ is called only for directly-imported modules.
61
62 \begin{code}
63 getInterfaceExports :: ModuleName -> WhereFrom -> RnMG (Module, Avails)
64 getInterfaceExports mod_name from
65   = getHomeIfaceTableRn                 `thenRn` \ hit ->
66     case lookupModuleEnvByName hit mod_name of {
67         Just mi -> returnRn (mi_module mi, mi_exports mi) ;
68         Nothing  -> 
69
70     loadInterface doc_str mod_name from `thenRn` \ ifaces ->
71     case lookupModuleEnvByName (iPIT ifaces) mod_name of
72         Just mi -> returnRn (mi_module mi, mi_exports mi) ;
73                 -- loadInterface always puts something in the map
74                 -- even if it's a fake
75         Nothing -> pprPanic "getInterfaceExports" (ppr mod_name)
76     }
77     where
78       doc_str = sep [ppr mod_name, ptext SLIT("is directly imported")]
79 \end{code}
80
81
82 %*********************************************************
83 %*                                                      *
84 \subsection{Instance declarations are handled specially}
85 %*                                                      *
86 %*********************************************************
87
88 This has to be in RnIfaces (or RnHiFiles) because it calls loadHomeInterface
89
90 \begin{code}
91 lookupFixityRn :: Name -> RnMS Fixity
92 lookupFixityRn name
93   | isLocallyDefined name
94   = getFixityEnv                        `thenRn` \ local_fix_env ->
95     returnRn (lookupLocalFixity local_fix_env name)
96
97   | otherwise   -- Imported
98       -- For imported names, we have to get their fixities by doing a loadHomeInterface,
99       -- and consulting the Ifaces that comes back from that, because the interface
100       -- file for the Name might not have been loaded yet.  Why not?  Suppose you import module A,
101       -- which exports a function 'f', which is defined in module B.  Then B isn't loaded
102       -- right away (after all, it's possible that nothing from B will be used).
103       -- When we come across a use of 'f', we need to know its fixity, and it's then,
104       -- and only then, that we load B.hi.  That is what's happening here.
105   = getHomeIfaceTableRn                 `thenRn` \ hit ->
106     loadHomeInterface doc name          `thenRn` \ ifaces ->
107     case lookupTable hit (iPIT ifaces) name of
108         Just iface -> returnRn (lookupNameEnv (mi_fixities iface) name `orElse` defaultFixity)
109         Nothing    -> returnRn defaultFixity
110   where
111     doc = ptext SLIT("Checking fixity for") <+> ppr name
112 \end{code}
113
114
115 %*********************************************************
116 %*                                                      *
117 \subsection{Instance declarations are handled specially}
118 %*                                                      *
119 %*********************************************************
120
121 \begin{code}
122 getImportedInstDecls :: NameSet -> RnMG [(Module,RdrNameHsDecl)]
123 getImportedInstDecls gates
124   =     -- First, load any orphan-instance modules that aren't aready loaded
125         -- Orphan-instance modules are recorded in the module dependecnies
126     getIfacesRn                                         `thenRn` \ ifaces ->
127     let
128         orphan_mods =
129           [mod | (mod, (True, _, False)) <- fmToList (iImpModInfo ifaces)]
130     in
131     loadOrphanModules orphan_mods                       `thenRn_` 
132
133         -- Now we're ready to grab the instance declarations
134         -- Find the un-gated ones and return them, 
135         -- removing them from the bag kept in Ifaces
136     getIfacesRn                                         `thenRn` \ ifaces ->
137     let
138         (decls, new_insts) = selectGated gates (iInsts ifaces)
139     in
140     setIfacesRn (ifaces { iInsts = new_insts })         `thenRn_`
141
142     traceRn (sep [text "getImportedInstDecls:", 
143                   nest 4 (fsep (map ppr gate_list)),
144                   text "Slurped" <+> int (length decls) <+> text "instance declarations",
145                   nest 4 (vcat (map ppr_brief_inst_decl decls))])       `thenRn_`
146     returnRn decls
147   where
148     gate_list      = nameSetToList gates
149
150 ppr_brief_inst_decl (mod, InstD (InstDecl inst_ty _ _ _ _))
151   = case inst_ty of
152         HsForAllTy _ _ tau -> ppr tau
153         other              -> ppr inst_ty
154
155 getImportedRules :: RnMG [(Module,RdrNameHsDecl)]
156 getImportedRules 
157   | opt_IgnoreIfacePragmas = returnRn []
158   | otherwise
159   = getIfacesRn         `thenRn` \ ifaces ->
160     let
161         gates              = iSlurp ifaces      -- Anything at all that's been slurped
162         rules              = iRules ifaces
163         (decls, new_rules) = selectGated gates rules
164     in
165     if null decls then
166         returnRn []
167     else
168     setIfacesRn (ifaces { iRules = new_rules })              `thenRn_`
169     traceRn (sep [text "getImportedRules:", 
170                   text "Slurped" <+> int (length decls) <+> text "rules"])   `thenRn_`
171     returnRn decls
172
173 selectGated gates decl_bag
174         -- Select only those decls whose gates are *all* in 'gates'
175 #ifdef DEBUG
176   | opt_NoPruneDecls    -- Just to try the effect of not gating at all
177   = (foldrBag (\ (_,d) ds -> d:ds) [] decl_bag, emptyBag)       -- Grab them all
178
179   | otherwise
180 #endif
181   = foldrBag select ([], emptyBag) decl_bag
182   where
183     select (reqd, decl) (yes, no)
184         | isEmptyNameSet (reqd `minusNameSet` gates) = (decl:yes, no)
185         | otherwise                                  = (yes,      (reqd,decl) `consBag` no)
186 \end{code}
187
188
189 %*********************************************************
190 %*                                                      *
191 \subsection{Keeping track of what we've slurped, and version numbers}
192 %*                                                      *
193 %*********************************************************
194
195 getImportVersions figures out what the ``usage information'' for this
196 moudule is; that is, what it must record in its interface file as the
197 things it uses.  It records:
198
199 \begin{itemize}
200 \item   (a) anything reachable from its body code
201 \item   (b) any module exported with a @module Foo@
202 \item   (c) anything reachable from an exported item
203 \end{itemize}
204
205 Why (b)?  Because if @Foo@ changes then this module's export list
206 will change, so we must recompile this module at least as far as
207 making a new interface file --- but in practice that means complete
208 recompilation.
209
210 Why (c)?  Consider this:
211 \begin{verbatim}
212         module A( f, g ) where  |       module B( f ) where
213           import B( f )         |         f = h 3
214           g = ...               |         h = ...
215 \end{verbatim}
216
217 Here, @B.f@ isn't used in A.  Should we nevertheless record @B.f@ in
218 @A@'s usages?  Our idea is that we aren't going to touch A.hi if it is
219 *identical* to what it was before.  If anything about @B.f@ changes
220 than anyone who imports @A@ should be recompiled in case they use
221 @B.f@ (they'll get an early exit if they don't).  So, if anything
222 about @B.f@ changes we'd better make sure that something in A.hi
223 changes, and the convenient way to do that is to record the version
224 number @B.f@ in A.hi in the usage list.  If B.f changes that'll force a
225 complete recompiation of A, which is overkill but it's the only way to 
226 write a new, slightly different, A.hi.
227
228 But the example is tricker.  Even if @B.f@ doesn't change at all,
229 @B.h@ may do so, and this change may not be reflected in @f@'s version
230 number.  But with -O, a module that imports A must be recompiled if
231 @B.h@ changes!  So A must record a dependency on @B.h@.  So we treat
232 the occurrence of @B.f@ in the export list *just as if* it were in the
233 code of A, and thereby haul in all the stuff reachable from it.
234
235 [NB: If B was compiled with -O, but A isn't, we should really *still*
236 haul in all the unfoldings for B, in case the module that imports A *is*
237 compiled with -O.  I think this is the case.]
238
239 Even if B is used at all we get a usage line for B
240         import B <n> :: ... ;
241 in A.hi, to record the fact that A does import B.  This is used to decide
242 to look to look for B.hi rather than B.hi-boot when compiling a module that
243 imports A.  This line says that A imports B, but uses nothing in it.
244 So we'll get an early bale-out when compiling A if B's version changes.
245
246 \begin{code}
247 mkImportInfo :: ModuleName                      -- Name of this module
248              -> [ImportDecl n]                  -- The import decls
249              -> RnMG [ImportVersion Name]
250
251 mkImportInfo this_mod imports
252   = getIfacesRn                                 `thenRn` \ ifaces ->
253     getHomeIfaceTableRn                         `thenRn` \ hit -> 
254     let
255         import_all_mods :: [ModuleName]
256                 -- Modules where we imported all the names
257                 -- (apart from hiding some, perhaps)
258         import_all_mods = nub [ m | ImportDecl m _ _ _ imp_list _ <- imports,
259                                     import_all imp_list ]
260
261         import_all (Just (False, _)) = False    -- Imports are specified explicitly
262         import_all other             = True     -- Everything is imported
263
264         mod_map   = iImpModInfo ifaces
265         imp_names = iVSlurp     ifaces
266         pit       = iPIT        ifaces
267
268         -- mv_map groups together all the things imported from a particular module.
269         mv_map :: ModuleEnv [Name]
270         mv_map = foldr add_mv emptyModuleEnv imp_names
271
272         add_mv name mv_map = addItem mv_map (nameModule name) name
273
274         -- Build the result list by adding info for each module.
275         -- For (a) a library module, we don't record it at all unless it contains orphans
276         --         (We must never lose track of orphans.)
277         -- 
278         --     (b) a source-imported module, don't record the dependency at all
279         --      
280         -- (b) may seem a bit strange.  The idea is that the usages in a .hi file records
281         -- *all* the module's dependencies other than the loop-breakers.  We use
282         -- this info in findAndReadInterface to decide whether to look for a .hi file or
283         -- a .hi-boot file.  
284         --
285         -- This means we won't track version changes, or orphans, from .hi-boot files.
286         -- The former is potentially rather bad news.  It could be fixed by recording
287         -- whether something is a boot file along with the usage info for it, but 
288         -- I can't be bothered just now.
289
290         mk_imp_info mod_name (has_orphans, is_boot, opened) so_far
291            | mod_name == this_mod       -- Check if M appears in the set of modules 'below' M
292                                         -- This seems like a convenient place to check
293            = WARN( not is_boot, ptext SLIT("Wierd:") <+> ppr this_mod <+> 
294                                 ptext SLIT("imports itself (perhaps indirectly)") )
295              so_far
296  
297            | not opened                 -- We didn't even open the interface
298            =            -- This happens when a module, Foo, that we explicitly imported has 
299                         -- 'import Baz' in its interface file, recording that Baz is below
300                         -- Foo in the module dependency hierarchy.  We want to propagate this
301                         -- information.  The Nothing says that we didn't even open the interface
302                         -- file but we must still propagate the dependency info.
303                         -- The module in question must be a local module (in the same package)
304              go_for_it NothingAtAll
305
306
307            | is_lib_module && not has_orphans
308            = so_far             
309            
310            | is_lib_module                      -- Record the module version only
311            = go_for_it (Everything module_vers)
312
313            | otherwise
314            = go_for_it whats_imported
315
316              where
317                 go_for_it exports = (mod_name, has_orphans, is_boot, exports) : so_far
318                 mod_iface         = lookupTableByModName hit pit mod_name `orElse` panic "mkImportInfo"
319                 mod               = mi_module mod_iface
320                 is_lib_module     = not (isModuleInThisPackage mod)
321                 version_info      = mi_version mod_iface
322                 version_env       = vers_decls version_info
323                 module_vers       = vers_module version_info
324
325                 whats_imported = Specifically module_vers
326                                               export_vers import_items 
327                                               (vers_rules version_info)
328
329                 import_items = [(n,v) | n <- lookupWithDefaultModuleEnv mv_map [] mod,
330                                         let v = lookupNameEnv version_env n `orElse` 
331                                                 pprPanic "mk_whats_imported" (ppr n)
332                                ]
333                 export_vers | moduleName mod `elem` import_all_mods 
334                             = Just (vers_exports version_info)
335                             | otherwise
336                             = Nothing
337         
338         import_info = foldFM mk_imp_info [] mod_map
339     in
340     traceRn (text "Modules in Ifaces: " <+> fsep (map ppr (keysFM mod_map)))    `thenRn_`
341     returnRn import_info
342
343
344 addItem :: ModuleEnv [a] -> Module -> a -> ModuleEnv [a]
345 addItem fm mod x = extendModuleEnv_C add_item fm mod [x]
346                  where
347                    add_item xs _ = x:xs
348 \end{code}
349
350 \begin{code}
351 getSlurped
352   = getIfacesRn         `thenRn` \ ifaces ->
353     returnRn (iSlurp ifaces)
354
355 recordSlurp ifaces@(Ifaces { iSlurp = slurped_names, iVSlurp = imp_names })
356             avail
357   = let
358         new_slurped_names = addAvailToNameSet slurped_names avail
359         new_imp_names     = availName avail : imp_names
360     in
361     ifaces { iSlurp  = new_slurped_names, iVSlurp = new_imp_names }
362
363 recordLocalSlurps local_avails
364   = getIfacesRn         `thenRn` \ ifaces ->
365     let
366         new_slurped_names = foldl addAvailToNameSet (iSlurp ifaces) local_avails
367     in
368     setIfacesRn (ifaces { iSlurp  = new_slurped_names })
369 \end{code}
370
371
372 %*********************************************************
373 %*                                                      *
374 \subsection{Getting in a declaration}
375 %*                                                      *
376 %*********************************************************
377
378 \begin{code}
379 importDecl :: Name -> RnMG ImportDeclResult
380
381 data ImportDeclResult
382   = AlreadySlurped
383   | WiredIn     
384   | Deferred
385   | HereItIs (Module, RdrNameTyClDecl)
386
387 importDecl name
388   =     -- Check if it was loaded before beginning this module
389     checkAlreadyAvailable name          `thenRn` \ done ->
390     if done then
391         returnRn AlreadySlurped
392     else
393
394         -- Check if we slurped it in while compiling this module
395     getIfacesRn                         `thenRn` \ ifaces ->
396     if name `elemNameSet` iSlurp ifaces then    
397         returnRn AlreadySlurped 
398     else 
399
400         -- Don't slurp in decls from this module's own interface file
401         -- (Indeed, this shouldn't happen.)
402     if isLocallyDefined name then
403         addWarnRn (importDeclWarn name) `thenRn_`
404         returnRn AlreadySlurped
405     else
406
407         -- When we find a wired-in name we must load its home
408         -- module so that we find any instance decls lurking therein
409     if name `elemNameEnv` wiredInThingEnv then
410         loadHomeInterface doc name      `thenRn_`
411         returnRn WiredIn
412
413     else getNonWiredInDecl name
414   where
415     doc = ptext SLIT("need home module for wired in thing") <+> ppr name
416
417 getNonWiredInDecl :: Name -> RnMG ImportDeclResult
418 getNonWiredInDecl needed_name 
419   = traceRn doc_str                             `thenRn_`
420     loadHomeInterface doc_str needed_name       `thenRn` \ ifaces ->
421     case lookupNameEnv (iDecls ifaces) needed_name of
422
423 {-              OMIT DEFERRED STUFF FOR NOW, TILL GHCI WORKS
424       Just (version, avail, is_tycon_name, decl@(_, TyClD (TyData DataType _ _ _ _ ncons _ _ _ _)))
425         -- This case deals with deferred import of algebraic data types
426
427         |  not opt_NoPruneTyDecls
428
429         && (opt_IgnoreIfacePragmas || ncons > 1)
430                 -- We only defer if imported interface pragmas are ingored
431                 -- or if it's not a product type.
432                 -- Sole reason: The wrapper for a strict function may need to look
433                 -- inside its arg, and hence need to see its arg type's constructors.
434
435         && not (getUnique tycon_name `elem` cCallishTyKeys)
436                 -- Never defer ccall types; we have to unbox them, 
437                 -- and importing them does no harm
438
439
440         ->      -- OK, so we're importing a deferrable data type
441             if needed_name == tycon_name
442                 -- The needed_name is the TyCon of a data type decl
443                 -- Record that it's slurped, put it in the deferred set
444                 -- and don't return a declaration at all
445                 setIfacesRn (recordSlurp (ifaces {iDeferred = iDeferred ifaces 
446                                                               `addOneToNameSet` tycon_name})
447                                          version (AvailTC needed_name [needed_name]))   `thenRn_`
448                 returnRn Deferred
449
450             else
451                 -- The needed name is a constructor of a data type decl,
452                 -- getting a constructor, so remove the TyCon from the deferred set
453                 -- (if it's there) and return the full declaration
454                 setIfacesRn (recordSlurp (ifaces {iDeferred = iDeferred ifaces 
455                                                                `delFromNameSet` tycon_name})
456                                     version avail)      `thenRn_`
457                 returnRn (HereItIs decl)
458         where
459            tycon_name = availName avail
460 -}
461
462       Just (avail,_,decl)
463         -> setIfacesRn (recordSlurp ifaces avail)       `thenRn_`
464            returnRn (HereItIs decl)
465
466       Nothing 
467         -> addErrRn (getDeclErr needed_name)    `thenRn_` 
468            returnRn AlreadySlurped
469   where
470      doc_str = ptext SLIT("need decl for") <+> ppr needed_name
471
472 {-              OMIT FOR NOW
473 getDeferredDecls :: RnMG [(Module, RdrNameHsDecl)]
474 getDeferredDecls 
475   = getIfacesRn         `thenRn` \ ifaces ->
476     let
477         decls_map           = iDecls ifaces
478         deferred_names      = nameSetToList (iDeferred ifaces)
479         get_abstract_decl n = case lookupNameEnv decls_map n of
480                                  Just (_, _, _, decl) -> decl
481     in
482     traceRn (sep [text "getDeferredDecls", nest 4 (fsep (map ppr deferred_names))])     `thenRn_`
483     returnRn (map get_abstract_decl deferred_names)
484 -}
485 \end{code}
486
487 @getWiredInDecl@ maps a wired-in @Name@ to what it makes available.
488 It behaves exactly as if the wired in decl were actually in an interface file.
489 Specifically,
490 \begin{itemize}
491 \item   if the wired-in name is a data type constructor or a data constructor, 
492         it brings in the type constructor and all the data constructors; and
493         marks as ``occurrences'' any free vars of the data con.
494
495 \item   similarly for synonum type constructor
496
497 \item   if the wired-in name is another wired-in Id, it marks as ``occurrences''
498         the free vars of the Id's type.
499
500 \item   it loads the interface file for the wired-in thing for the
501         sole purpose of making sure that its instance declarations are available
502 \end{itemize}
503 All this is necessary so that we know all types that are ``in play'', so
504 that we know just what instances to bring into scope.
505         
506
507 %********************************************************
508 %*                                                      *
509 \subsection{Checking usage information}
510 %*                                                      *
511 %********************************************************
512
513 @recompileRequired@ is called from the HscMain.   It checks whether
514 a recompilation is required.  It needs access to the persistent state,
515 finder, etc, because it may have to load lots of interface files to
516 check their versions.
517
518 \begin{code}
519 type RecompileRequired = Bool
520 upToDate  = False       -- Recompile not required
521 outOfDate = True        -- Recompile required
522
523 recompileRequired :: Module 
524                   -> Bool               -- Source unchanged
525                   -> Maybe ModIface     -- Old interface, if any
526                   -> RnMG RecompileRequired
527 recompileRequired mod source_unchanged maybe_iface
528   = traceRn (text "Considering whether compilation is required for" <+> ppr mod <> colon)       `thenRn_`
529
530         -- CHECK WHETHER THE SOURCE HAS CHANGED
531     if not source_unchanged then
532         traceRn (nest 4 (text "Source file changed or recompilation check turned off")) `thenRn_` 
533         returnRn outOfDate
534     else
535
536         -- CHECK WHETHER WE HAVE AN OLD IFACE
537     case maybe_iface of 
538         Nothing -> traceRn (nest 4 (ptext SLIT("No old interface file")))       `thenRn_`
539                    returnRn outOfDate ;
540
541         Just iface  ->          -- Source code unchanged and no errors yet... carry on 
542                         checkList [checkModUsage u | u <- mi_usages iface]
543
544 checkList :: [RnMG RecompileRequired] -> RnMG RecompileRequired
545 checkList []             = returnRn upToDate
546 checkList (check:checks) = check        `thenRn` \ recompile ->
547                            if recompile then 
548                                 returnRn outOfDate
549                            else
550                                 checkList checks
551 \end{code}
552         
553 \begin{code}
554 checkModUsage :: ImportVersion Name -> RnMG RecompileRequired
555 -- Given the usage information extracted from the old
556 -- M.hi file for the module being compiled, figure out
557 -- whether M needs to be recompiled.
558
559 checkModUsage (mod_name, _, _, NothingAtAll)
560         -- If CurrentModule.hi contains 
561         --      import Foo :: ;
562         -- then that simply records that Foo lies below CurrentModule in the
563         -- hierarchy, but CurrentModule doesn't depend in any way on Foo.
564         -- In this case we don't even want to open Foo's interface.
565   = up_to_date (ptext SLIT("Nothing used from:") <+> ppr mod_name)
566
567 checkModUsage (mod_name, _, _, whats_imported)
568   = tryLoadInterface doc_str mod_name ImportBySystem    `thenRn` \ (ifaces, maybe_err) ->
569     case maybe_err of {
570         Just err -> out_of_date (sep [ptext SLIT("Can't find version number for module"), 
571                                       ppr mod_name]) ;
572                 -- Couldn't find or parse a module mentioned in the
573                 -- old interface file.  Don't complain -- it might just be that
574                 -- the current module doesn't need that import and it's been deleted
575
576         Nothing -> 
577
578     getHomeIfaceTableRn                                 `thenRn` \ hit ->
579     let
580         mod_details   = lookupTableByModName hit (iPIT ifaces) mod_name
581                         `orElse` panic "checkModUsage"
582         new_vers      = mi_version mod_details
583         new_decl_vers = vers_decls new_vers
584     in
585     case whats_imported of {    -- NothingAtAll dealt with earlier
586
587       Everything old_mod_vers -> checkModuleVersion old_mod_vers new_vers       `thenRn` \ recompile ->
588                                  if recompile then
589                                         out_of_date (ptext SLIT("...and I needed the whole module"))
590                                  else
591                                         returnRn upToDate ;
592
593       Specifically old_mod_vers maybe_old_export_vers old_decl_vers old_rule_vers ->
594
595         -- CHECK MODULE
596     checkModuleVersion old_mod_vers new_vers    `thenRn` \ recompile ->
597     if not recompile then
598         returnRn upToDate
599     else
600                                  
601         -- CHECK EXPORT LIST
602     if checkExportList maybe_old_export_vers new_vers then
603         out_of_date (ptext SLIT("Export list changed"))
604     else
605
606         -- CHECK RULES
607     if old_rule_vers /= vers_rules new_vers then
608         out_of_date (ptext SLIT("Rules changed"))
609     else
610
611         -- CHECK ITEMS ONE BY ONE
612     checkList [checkEntityUsage new_decl_vers u | u <- old_decl_vers]   `thenRn` \ recompile ->
613     if recompile then
614         returnRn outOfDate      -- This one failed, so just bail out now
615     else
616         up_to_date (ptext SLIT("...but the bits I use haven't."))
617
618     }}
619   where
620     doc_str = sep [ptext SLIT("need version info for"), ppr mod_name]
621
622 ------------------------
623 checkModuleVersion old_mod_vers new_vers
624   | vers_module new_vers == old_mod_vers
625   = up_to_date (ptext SLIT("Module version unchanged"))
626
627   | otherwise
628   = out_of_date (ptext SLIT("Module version has changed"))
629
630 ------------------------
631 checkExportList Nothing  new_vers = upToDate
632 checkExportList (Just v) new_vers = v /= vers_exports new_vers
633
634 ------------------------
635 checkEntityUsage new_vers (name,old_vers)
636   = case lookupNameEnv new_vers name of
637
638         Nothing       ->        -- We used it before, but it ain't there now
639                           out_of_date (sep [ptext SLIT("No longer exported:"), ppr name])
640
641         Just new_vers   -- It's there, but is it up to date?
642           | new_vers == old_vers -> returnRn upToDate
643           | otherwise            -> out_of_date (sep [ptext SLIT("Out of date:"), ppr name])
644
645 up_to_date  msg = traceRn msg `thenRn_` returnRn upToDate
646 out_of_date msg = traceRn msg `thenRn_` returnRn outOfDate
647 \end{code}
648
649
650 %*********************************************************
651 %*                                                       *
652 \subsection{Errors}
653 %*                                                       *
654 %*********************************************************
655
656 \begin{code}
657 getDeclErr name
658   = vcat [ptext SLIT("Failed to find interface decl for") <+> quotes (ppr name),
659           ptext SLIT("from module") <+> quotes (ppr (nameModule name))
660          ]
661
662 importDeclWarn name
663   = sep [ptext SLIT(
664     "Compiler tried to import decl from interface file with same name as module."), 
665          ptext SLIT(
666     "(possible cause: module name clashes with interface file already in scope.)")
667         ] $$
668     hsep [ptext SLIT("name:"), quotes (ppr name)]
669 \end{code}