Module header tidyup, phase 1
[ghc-hetmet.git] / compiler / iface / LoadIface.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 %
5
6 Loading interface files
7
8 \begin{code}
9 module LoadIface (
10         loadInterface, loadInterfaceForName, loadWiredInHomeIface, 
11         loadSrcInterface, loadSysInterface, loadOrphanModules, 
12         findAndReadIface, readIface,    -- Used when reading the module's old interface
13         loadDecls,      -- Should move to TcIface and be renamed
14         initExternalPackageState,
15
16         ifaceStats, pprModIface, showIface
17    ) where
18
19 #include "HsVersions.h"
20
21 import {-# SOURCE #-}   TcIface( tcIfaceDecl, tcIfaceRules, tcIfaceInst, 
22                                  tcIfaceFamInst )
23
24 import DynFlags
25 import IfaceSyn
26 import IfaceEnv
27 import HscTypes
28
29 import BasicTypes hiding (SuccessFlag(..))
30 import TcRnMonad
31 import Type
32
33 import PrelNames
34 import PrelInfo
35 import PrelRules
36 import Rules
37 import InstEnv
38 import FamInstEnv
39 import Name
40 import NameEnv
41 import MkId
42 import Module
43 import OccName
44 import SrcLoc
45 import Maybes
46 import ErrUtils
47 import Finder
48 import UniqFM
49 import StaticFlags
50 import Outputable
51 import BinIface
52 import Panic
53
54 import Data.List
55 import Data.Maybe
56 import Data.IORef
57 \end{code}
58
59
60 %************************************************************************
61 %*                                                                      *
62         loadSrcInterface, loadOrphanModules, loadHomeInterface
63
64                 These three are called from TcM-land    
65 %*                                                                      *
66 %************************************************************************
67
68 \begin{code}
69 -- | Load the interface corresponding to an @import@ directive in 
70 -- source code.  On a failure, fail in the monad with an error message.
71 loadSrcInterface :: SDoc -> ModuleName -> IsBootInterface -> RnM ModIface
72 loadSrcInterface doc mod want_boot  = do        
73   -- We must first find which Module this import refers to.  This involves
74   -- calling the Finder, which as a side effect will search the filesystem
75   -- and create a ModLocation.  If successful, loadIface will read the
76   -- interface; it will call the Finder again, but the ModLocation will be
77   -- cached from the first search.
78   hsc_env <- getTopEnv
79   res <- ioToIOEnv $ findImportedModule hsc_env mod Nothing
80   case res of
81     Found _ mod -> do
82       mb_iface <- initIfaceTcRn $ loadInterface doc mod (ImportByUser want_boot)
83       case mb_iface of
84         Failed err      -> failWithTc err
85         Succeeded iface -> return iface
86     err ->
87         let dflags = hsc_dflags hsc_env in
88         failWithTc (cannotFindInterface dflags mod err)
89
90 -- | Load interfaces for a collection of orphan modules.
91 loadOrphanModules :: [Module] -> TcM ()
92 loadOrphanModules mods
93   | null mods = returnM ()
94   | otherwise = initIfaceTcRn $
95                 do { traceIf (text "Loading orphan modules:" <+> 
96                                  fsep (map ppr mods))
97                    ; mappM_ load mods
98                    ; returnM () }
99   where
100     load mod   = loadSysInterface (mk_doc mod) mod
101     mk_doc mod = ppr mod <+> ptext SLIT("is a orphan-instance module")
102
103 -- | Loads the interface for a given Name.
104 loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
105 loadInterfaceForName doc name
106   = do  { 
107 #ifdef DEBUG
108                 -- Should not be called with a name from the module being compiled
109           this_mod <- getModule
110         ; ASSERT2( not (nameIsLocalOrFrom this_mod name), ppr name <+> parens doc )
111 #endif
112           initIfaceTcRn $ loadSysInterface doc (nameModule name)
113     }
114
115 -- | An 'IfM' function to load the home interface for a wired-in thing,
116 -- so that we're sure that we see its instance declarations and rules
117 loadWiredInHomeIface :: Name -> IfM lcl ()
118 loadWiredInHomeIface name
119   = ASSERT( isWiredInName name )
120     do loadSysInterface doc (nameModule name); return ()
121   where
122     doc = ptext SLIT("Need home interface for wired-in thing") <+> ppr name
123
124 -- | A wrapper for 'loadInterface' that throws an exception if it fails
125 loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
126 loadSysInterface doc mod_name
127   = do  { mb_iface <- loadInterface doc mod_name ImportBySystem
128         ; case mb_iface of 
129             Failed err      -> ghcError (ProgramError (showSDoc err))
130             Succeeded iface -> return iface }
131 \end{code}
132
133
134 %*********************************************************
135 %*                                                      *
136                 loadInterface
137
138         The main function to load an interface
139         for an imported module, and put it in
140         the External Package State
141 %*                                                      *
142 %*********************************************************
143
144 \begin{code}
145 loadInterface :: SDoc -> Module -> WhereFrom
146               -> IfM lcl (MaybeErr Message ModIface)
147
148 -- loadInterface looks in both the HPT and PIT for the required interface
149 -- If not found, it loads it, and puts it in the PIT (always). 
150
151 -- If it can't find a suitable interface file, we
152 --      a) modify the PackageIfaceTable to have an empty entry
153 --              (to avoid repeated complaints)
154 --      b) return (Left message)
155 --
156 -- It's not necessarily an error for there not to be an interface
157 -- file -- perhaps the module has changed, and that interface 
158 -- is no longer used
159
160 loadInterface doc_str mod from
161   = do  {       -- Read the state
162           (eps,hpt) <- getEpsAndHpt
163
164         ; traceIf (text "Considering whether to load" <+> ppr mod <+> ppr from)
165
166                 -- Check whether we have the interface already
167         ; dflags <- getDOpts
168         ; case lookupIfaceByModule dflags hpt (eps_PIT eps) mod of {
169             Just iface 
170                 -> returnM (Succeeded iface) ;  -- Already loaded
171                         -- The (src_imp == mi_boot iface) test checks that the already-loaded
172                         -- interface isn't a boot iface.  This can conceivably happen,
173                         -- if an earlier import had a before we got to real imports.   I think.
174             other -> do
175
176         { let { hi_boot_file = case from of
177                                 ImportByUser usr_boot -> usr_boot
178                                 ImportBySystem        -> sys_boot
179
180               ; mb_dep   = lookupUFM (eps_is_boot eps) (moduleName mod)
181               ; sys_boot = case mb_dep of
182                                 Just (_, is_boot) -> is_boot
183                                 Nothing           -> False
184                         -- The boot-ness of the requested interface, 
185               }         -- based on the dependencies in directly-imported modules
186
187         -- READ THE MODULE IN
188         ; read_result <- findAndReadIface doc_str mod hi_boot_file
189         ; case read_result of {
190             Failed err -> do
191                 { let fake_iface = emptyModIface mod
192
193                 ; updateEps_ $ \eps ->
194                         eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
195                         -- Not found, so add an empty iface to 
196                         -- the EPS map so that we don't look again
197                                 
198                 ; returnM (Failed err) } ;
199
200         -- Found and parsed!
201             Succeeded (iface, file_path)        -- Sanity check:
202                 | ImportBySystem <- from,       --   system-importing...
203                   modulePackageId (mi_module iface) == thisPackage dflags,
204                                                 --   a home-package module...
205                   Nothing <- mb_dep             --   that we know nothing about
206                 -> returnM (Failed (badDepMsg mod))
207
208                 | otherwise ->
209
210         let 
211             loc_doc = text file_path
212         in 
213         initIfaceLcl mod loc_doc $ do
214
215         --      Load the new ModIface into the External Package State
216         -- Even home-package interfaces loaded by loadInterface 
217         --      (which only happens in OneShot mode; in Batch/Interactive 
218         --      mode, home-package modules are loaded one by one into the HPT)
219         -- are put in the EPS.
220         --
221         -- The main thing is to add the ModIface to the PIT, but
222         -- we also take the
223         --      IfaceDecls, IfaceInst, IfaceRules
224         -- out of the ModIface and put them into the big EPS pools
225
226         -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
227         ---    names is done correctly (notably, whether this is an .hi file or .hi-boot file).
228         --     If we do loadExport first the wrong info gets into the cache (unless we
229         --      explicitly tag each export which seems a bit of a bore)
230
231         ; ignore_prags      <- doptM Opt_IgnoreInterfacePragmas
232         ; new_eps_decls     <- loadDecls ignore_prags (mi_decls iface)
233         ; new_eps_insts     <- mapM tcIfaceInst (mi_insts iface)
234         ; new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
235         ; new_eps_rules     <- tcIfaceRules ignore_prags (mi_rules iface)
236
237         ; let { final_iface = iface {   mi_decls = panic "No mi_decls in PIT",
238                                         mi_insts = panic "No mi_insts in PIT",
239                                         mi_rules = panic "No mi_rules in PIT" } }
240
241         ; updateEps_  $ \ eps -> 
242             eps { 
243               eps_PIT          = extendModuleEnv (eps_PIT eps) mod final_iface,
244               eps_PTE          = addDeclsToPTE   (eps_PTE eps) new_eps_decls,
245               eps_rule_base    = extendRuleBaseList (eps_rule_base eps) 
246                                                     new_eps_rules,
247               eps_inst_env     = extendInstEnvList (eps_inst_env eps)  
248                                                    new_eps_insts,
249               eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
250                                                       new_eps_fam_insts,
251               eps_stats        = addEpsInStats (eps_stats eps) 
252                                                (length new_eps_decls)
253               (length new_eps_insts) (length new_eps_rules) }
254
255         ; return (Succeeded final_iface)
256     }}}}
257
258 badDepMsg mod 
259   = hang (ptext SLIT("Interface file inconsistency:"))
260        2 (sep [ptext SLIT("home-package module") <+> quotes (ppr mod) <+> ptext SLIT("is mentioned is needed,"), 
261                ptext SLIT("but is not among the dependencies of interfaces directly imported by the module being compiled")])
262
263 -----------------------------------------------------
264 --      Loading type/class/value decls
265 -- We pass the full Module name here, replete with
266 -- its package info, so that we can build a Name for
267 -- each binder with the right package info in it
268 -- All subsequent lookups, including crucially lookups during typechecking
269 -- the declaration itself, will find the fully-glorious Name
270 --
271 -- We handle ATs specially.  They are not main declarations, but also not
272 -- implict things (in particular, adding them to `implicitTyThings' would mess
273 -- things up in the renaming/type checking of source programs).
274 -----------------------------------------------------
275
276 addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
277 addDeclsToPTE pte things = extendNameEnvList pte things
278
279 loadDecls :: Bool
280           -> [(Version, IfaceDecl)]
281           -> IfL [(Name,TyThing)]
282 loadDecls ignore_prags ver_decls
283    = do { mod <- getIfModule
284         ; thingss <- mapM (loadDecl ignore_prags mod) ver_decls
285         ; return (concat thingss)
286         }
287
288 loadDecl :: Bool                    -- Don't load pragmas into the decl pool
289          -> Module
290           -> (Version, IfaceDecl)
291           -> IfL [(Name,TyThing)]   -- The list can be poked eagerly, but the
292                                     -- TyThings are forkM'd thunks
293 loadDecl ignore_prags mod (_version, decl)
294   = do  {       -- Populate the name cache with final versions of all 
295                 -- the names associated with the decl
296           main_name      <- mk_new_bndr mod (ifName decl)
297         ; traceIf (text "Loading decl for " <> ppr main_name)
298         ; implicit_names <- mapM (mk_new_bndr mod) (ifaceDeclSubBndrs decl)
299
300         -- Typecheck the thing, lazily
301         -- NB. Firstly, the laziness is there in case we never need the
302         -- declaration (in one-shot mode), and secondly it is there so that 
303         -- we don't look up the occurrence of a name before calling mk_new_bndr
304         -- on the binder.  This is important because we must get the right name
305         -- which includes its nameParent.
306
307         ; thing <- forkM doc $ do { bumpDeclStats main_name
308                                   ; tcIfaceDecl ignore_prags decl }
309
310         -- Populate the type environment with the implicitTyThings too
311         ; let mini_env = mkOccEnv [(getOccName t, t) | t <- implicitTyThings thing]
312               lookup n = case lookupOccEnv mini_env (getOccName n) of
313                            Just thing -> thing
314                            Nothing    -> 
315                              pprPanic "loadDecl" (ppr main_name <+> ppr n $$ ppr (decl))
316
317         ; returnM $ (main_name, thing) :  [(n, lookup n) | n <- implicit_names]
318         }
319                 -- We build a list from the *known* names, with (lookup n) thunks
320                 -- as the TyThings.  That way we can extend the PTE without poking the
321                 -- thunks
322   where
323         -- mk_new_bndr allocates in the name cache the final canonical
324         -- name for the thing, with the correct 
325         --      * parent
326         --      * location
327         -- imported name, to fix the module correctly in the cache
328     mk_new_bndr mod occ 
329         = newGlobalBinder mod occ 
330                           (importedSrcLoc (showSDoc (ppr (moduleName mod))))
331                         -- ToDo: qualify with the package name if necessary
332
333     doc = ptext SLIT("Declaration for") <+> ppr (ifName decl)
334
335 bumpDeclStats :: Name -> IfL ()         -- Record that one more declaration has actually been used
336 bumpDeclStats name
337   = do  { traceIf (text "Loading decl for" <+> ppr name)
338         ; updateEps_ (\eps -> let stats = eps_stats eps
339                               in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
340         }
341 \end{code}
342
343
344 %*********************************************************
345 %*                                                      *
346 \subsection{Reading an interface file}
347 %*                                                      *
348 %*********************************************************
349
350 \begin{code}
351 findAndReadIface :: SDoc -> Module
352                  -> IsBootInterface     -- True  <=> Look for a .hi-boot file
353                                         -- False <=> Look for .hi file
354                  -> TcRnIf gbl lcl (MaybeErr Message (ModIface, FilePath))
355         -- Nothing <=> file not found, or unreadable, or illegible
356         -- Just x  <=> successfully found and parsed 
357
358         -- It *doesn't* add an error to the monad, because 
359         -- sometimes it's ok to fail... see notes with loadInterface
360
361 findAndReadIface doc_str mod hi_boot_file
362   = do  { traceIf (sep [hsep [ptext SLIT("Reading"), 
363                               if hi_boot_file 
364                                 then ptext SLIT("[boot]") 
365                                 else empty,
366                               ptext SLIT("interface for"), 
367                               ppr mod <> semi],
368                         nest 4 (ptext SLIT("reason:") <+> doc_str)])
369
370         -- Check for GHC.Prim, and return its static interface
371         ; dflags <- getDOpts
372         ; if mod == gHC_PRIM
373           then returnM (Succeeded (ghcPrimIface, 
374                                    "<built in interface for GHC.Prim>"))
375           else do
376
377         -- Look for the file
378         ; hsc_env <- getTopEnv
379         ; mb_found <- ioToIOEnv (findHiFile hsc_env mod hi_boot_file)
380         ; case mb_found of {
381               Failed err -> do
382                 { traceIf (ptext SLIT("...not found"))
383                 ; dflags <- getDOpts
384                 ; returnM (Failed (cannotFindInterface dflags 
385                                         (moduleName mod) err)) } ;
386
387               Succeeded file_path -> do 
388
389         -- Found file, so read it
390         { traceIf (ptext SLIT("readIFace") <+> text file_path)
391         ; read_result <- readIface mod file_path hi_boot_file
392         ; case read_result of
393             Failed err -> returnM (Failed (badIfaceFile file_path err))
394             Succeeded iface 
395                 | mi_module iface /= mod ->
396                   return (Failed (wrongIfaceModErr iface mod file_path))
397                 | otherwise ->
398                   returnM (Succeeded (iface, file_path))
399                         -- Don't forget to fill in the package name...
400         }}}
401
402 findHiFile :: HscEnv -> Module -> IsBootInterface
403            -> IO (MaybeErr FindResult FilePath)
404 findHiFile hsc_env mod hi_boot_file
405   = do
406       maybe_found <- findExactModule hsc_env mod
407       case maybe_found of
408         Found loc mod -> return (Succeeded path)
409                 where
410                    path = addBootSuffix_maybe hi_boot_file (ml_hi_file loc)
411         err -> return (Failed err)
412 \end{code}
413
414 @readIface@ tries just the one file.
415
416 \begin{code}
417 readIface :: Module -> FilePath -> IsBootInterface 
418           -> TcRnIf gbl lcl (MaybeErr Message ModIface)
419         -- Failed err    <=> file not found, or unreadable, or illegible
420         -- Succeeded iface <=> successfully found and parsed 
421
422 readIface wanted_mod file_path is_hi_boot_file
423   = do  { dflags <- getDOpts
424         ; res <- tryMostM $ readBinIface file_path
425         ; case res of
426             Right iface 
427                 | wanted_mod == actual_mod -> return (Succeeded iface)
428                 | otherwise                -> return (Failed err)
429                 where
430                   actual_mod = mi_module iface
431                   err = hiModuleNameMismatchWarn wanted_mod actual_mod
432
433             Left exn    -> return (Failed (text (showException exn)))
434     }
435 \end{code}
436
437
438 %*********************************************************
439 %*                                                       *
440         Wired-in interface for GHC.Prim
441 %*                                                       *
442 %*********************************************************
443
444 \begin{code}
445 initExternalPackageState :: ExternalPackageState
446 initExternalPackageState
447   = EPS { 
448       eps_is_boot      = emptyUFM,
449       eps_PIT          = emptyPackageIfaceTable,
450       eps_PTE          = emptyTypeEnv,
451       eps_inst_env     = emptyInstEnv,
452       eps_fam_inst_env = emptyFamInstEnv,
453       eps_rule_base    = mkRuleBase builtinRules,
454         -- Initialise the EPS rule pool with the built-in rules
455       eps_stats = EpsStats { n_ifaces_in = 0, n_decls_in = 0, n_decls_out = 0
456                            , n_insts_in = 0, n_insts_out = 0
457                            , n_rules_in = length builtinRules, n_rules_out = 0 }
458     }
459 \end{code}
460
461
462 %*********************************************************
463 %*                                                       *
464         Wired-in interface for GHC.Prim
465 %*                                                       *
466 %*********************************************************
467
468 \begin{code}
469 ghcPrimIface :: ModIface
470 ghcPrimIface
471   = (emptyModIface gHC_PRIM) {
472         mi_exports  = [(gHC_PRIM, ghcPrimExports)],
473         mi_decls    = [],
474         mi_fixities = fixities,
475         mi_fix_fn  = mkIfaceFixCache fixities
476     }           
477   where
478     fixities = [(getOccName seqId, Fixity 0 InfixR)]
479                         -- seq is infixr 0
480 \end{code}
481
482 %*********************************************************
483 %*                                                      *
484 \subsection{Statistics}
485 %*                                                      *
486 %*********************************************************
487
488 \begin{code}
489 ifaceStats :: ExternalPackageState -> SDoc
490 ifaceStats eps 
491   = hcat [text "Renamer stats: ", msg]
492   where
493     stats = eps_stats eps
494     msg = vcat 
495         [int (n_ifaces_in stats) <+> text "interfaces read",
496          hsep [ int (n_decls_out stats), text "type/class/variable imported, out of", 
497                 int (n_decls_in stats), text "read"],
498          hsep [ int (n_insts_out stats), text "instance decls imported, out of",  
499                 int (n_insts_in stats), text "read"],
500          hsep [ int (n_rules_out stats), text "rule decls imported, out of",  
501                 int (n_rules_in stats), text "read"]
502         ]
503 \end{code}    
504
505
506 %************************************************************************
507 %*                                                                      *
508                 Printing interfaces
509 %*                                                                      *
510 %************************************************************************
511
512 \begin{code}
513 -- | Read binary interface, and print it out
514 showIface :: HscEnv -> FilePath -> IO ()
515 showIface hsc_env filename = do
516    -- skip the version check; we don't want to worry about profiled vs.
517    -- non-profiled interfaces, for example.
518    writeIORef v_IgnoreHiWay True
519    iface <- initTcRnIf 's' hsc_env () () $ readBinIface  filename
520    printDump (pprModIface iface)
521 \end{code}
522
523 \begin{code}
524 pprModIface :: ModIface -> SDoc
525 -- Show a ModIface
526 pprModIface iface
527  = vcat [ ptext SLIT("interface")
528                 <+> ppr (mi_module iface) <+> pp_boot 
529                 <+> ppr (mi_mod_vers iface) <+> pp_sub_vers
530                 <+> (if mi_orphan iface then ptext SLIT("[orphan module]") else empty)
531                 <+> int opt_HiVersion
532                 <+> ptext SLIT("where")
533         , vcat (map pprExport (mi_exports iface))
534         , pprDeps (mi_deps iface)
535         , vcat (map pprUsage (mi_usages iface))
536         , pprFixities (mi_fixities iface)
537         , vcat (map pprIfaceDecl (mi_decls iface))
538         , vcat (map ppr (mi_insts iface))
539         , vcat (map ppr (mi_rules iface))
540         , pprDeprecs (mi_deprecs iface)
541         ]
542   where
543     pp_boot | mi_boot iface = ptext SLIT("[boot]")
544             | otherwise     = empty
545
546     exp_vers  = mi_exp_vers iface
547     rule_vers = mi_rule_vers iface
548
549     pp_sub_vers | exp_vers == initialVersion && rule_vers == initialVersion = empty
550                 | otherwise = brackets (ppr exp_vers <+> ppr rule_vers)
551 \end{code}
552
553 When printing export lists, we print like this:
554         Avail   f               f
555         AvailTC C [C, x, y]     C(x,y)
556         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
557
558 \begin{code}
559 pprExport :: IfaceExport -> SDoc
560 pprExport (mod, items)
561  = hsep [ ptext SLIT("export"), ppr mod, hsep (map pp_avail items) ]
562   where
563     pp_avail :: GenAvailInfo OccName -> SDoc
564     pp_avail (Avail occ)    = ppr occ
565     pp_avail (AvailTC _ []) = empty
566     pp_avail (AvailTC n (n':ns)) 
567         | n==n'     = ppr n <> pp_export ns
568         | otherwise = ppr n <> char '|' <> pp_export (n':ns)
569     
570     pp_export []    = empty
571     pp_export names = braces (hsep (map ppr names))
572
573 pprUsage :: Usage -> SDoc
574 pprUsage usage
575   = hsep [ptext SLIT("import"), ppr (usg_name usage), 
576           int (usg_mod usage), 
577           pp_export_version (usg_exports usage),
578           int (usg_rules usage),
579           pp_versions (usg_entities usage) ]
580   where
581     pp_versions nvs = hsep [ ppr n <+> int v | (n,v) <- nvs ]
582     pp_export_version Nothing  = empty
583     pp_export_version (Just v) = int v
584
585 pprDeps :: Dependencies -> SDoc
586 pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs})
587   = vcat [ptext SLIT("module dependencies:") <+> fsep (map ppr_mod mods),
588           ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs), 
589           ptext SLIT("orphans:") <+> fsep (map ppr orphs)
590         ]
591   where
592     ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
593     ppr_boot True  = text "[boot]"
594     ppr_boot False = empty
595
596 pprIfaceDecl :: (Version, IfaceDecl) -> SDoc
597 pprIfaceDecl (ver, decl)
598   = ppr_vers ver <+> ppr decl
599   where
600         -- Print the version for the decl
601     ppr_vers v | v == initialVersion = empty
602                | otherwise           = int v
603
604 pprFixities :: [(OccName, Fixity)] -> SDoc
605 pprFixities []    = empty
606 pprFixities fixes = ptext SLIT("fixities") <+> pprWithCommas pprFix fixes
607                   where
608                     pprFix (occ,fix) = ppr fix <+> ppr occ 
609
610 pprDeprecs NoDeprecs        = empty
611 pprDeprecs (DeprecAll txt)  = ptext SLIT("Deprecate all") <+> doubleQuotes (ftext txt)
612 pprDeprecs (DeprecSome prs) = ptext SLIT("Deprecate") <+> vcat (map pprDeprec prs)
613                             where
614                               pprDeprec (name, txt) = ppr name <+> doubleQuotes (ftext txt)
615 \end{code}
616
617
618 %*********************************************************
619 %*                                                       *
620 \subsection{Errors}
621 %*                                                       *
622 %*********************************************************
623
624 \begin{code}
625 badIfaceFile file err
626   = vcat [ptext SLIT("Bad interface file:") <+> text file, 
627           nest 4 err]
628
629 hiModuleNameMismatchWarn :: Module -> Module -> Message
630 hiModuleNameMismatchWarn requested_mod read_mod = 
631   withPprStyle defaultUserStyle $
632     -- we want the Modules below to be qualified with package names,
633     -- so reset the PrintUnqualified setting.
634     hsep [ ptext SLIT("Something is amiss; requested module ")
635          , ppr requested_mod
636          , ptext SLIT("differs from name found in the interface file")
637          , ppr read_mod
638          ]
639
640 wrongIfaceModErr iface mod_name file_path 
641   = sep [ptext SLIT("Interface file") <+> iface_file,
642          ptext SLIT("contains module") <+> quotes (ppr (mi_module iface)) <> comma,
643          ptext SLIT("but we were expecting module") <+> quotes (ppr mod_name),
644          sep [ptext SLIT("Probable cause: the source code which generated"),
645              nest 2 iface_file,
646              ptext SLIT("has an incompatible module name")
647             ]
648         ]
649   where iface_file = doubleQuotes (text file_path)
650 \end{code}
651