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