0d9feb4f8dd463355dddd29e88f57e1052f61a2a
[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 {   
242                                 mi_decls     = panic "No mi_decls in PIT",
243                                 mi_insts     = panic "No mi_insts in PIT",
244                                 mi_fam_insts = panic "No mi_fam_insts in PIT",
245                                 mi_rules     = panic "No mi_rules in PIT"
246                               } }
247
248         ; updateEps_  $ \ eps -> 
249             eps { 
250               eps_PIT          = extendModuleEnv (eps_PIT eps) mod final_iface,
251               eps_PTE          = addDeclsToPTE   (eps_PTE eps) new_eps_decls,
252               eps_rule_base    = extendRuleBaseList (eps_rule_base eps) 
253                                                     new_eps_rules,
254               eps_inst_env     = extendInstEnvList (eps_inst_env eps)  
255                                                    new_eps_insts,
256               eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
257                                                       new_eps_fam_insts,
258               eps_mod_fam_inst_env
259                                = let
260                                    fam_inst_env = 
261                                      extendFamInstEnvList emptyFamInstEnv
262                                                           new_eps_fam_insts
263                                  in
264                                  extendModuleEnv (eps_mod_fam_inst_env eps)
265                                                  mod
266                                                  fam_inst_env,
267               eps_stats        = addEpsInStats (eps_stats eps) 
268                                                (length new_eps_decls)
269               (length new_eps_insts) (length new_eps_rules) }
270
271         ; return (Succeeded final_iface)
272     }}}}
273
274 badDepMsg mod 
275   = hang (ptext SLIT("Interface file inconsistency:"))
276        2 (sep [ptext SLIT("home-package module") <+> quotes (ppr mod) <+> ptext SLIT("is mentioned is needed,"), 
277                ptext SLIT("but is not among the dependencies of interfaces directly imported by the module being compiled")])
278
279 -----------------------------------------------------
280 --      Loading type/class/value decls
281 -- We pass the full Module name here, replete with
282 -- its package info, so that we can build a Name for
283 -- each binder with the right package info in it
284 -- All subsequent lookups, including crucially lookups during typechecking
285 -- the declaration itself, will find the fully-glorious Name
286 --
287 -- We handle ATs specially.  They are not main declarations, but also not
288 -- implict things (in particular, adding them to `implicitTyThings' would mess
289 -- things up in the renaming/type checking of source programs).
290 -----------------------------------------------------
291
292 addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
293 addDeclsToPTE pte things = extendNameEnvList pte things
294
295 loadDecls :: Bool
296           -> [(Version, IfaceDecl)]
297           -> IfL [(Name,TyThing)]
298 loadDecls ignore_prags ver_decls
299    = do { mod <- getIfModule
300         ; thingss <- mapM (loadDecl ignore_prags mod) ver_decls
301         ; return (concat thingss)
302         }
303
304 loadDecl :: Bool                    -- Don't load pragmas into the decl pool
305          -> Module
306           -> (Version, IfaceDecl)
307           -> IfL [(Name,TyThing)]   -- The list can be poked eagerly, but the
308                                     -- TyThings are forkM'd thunks
309 loadDecl ignore_prags mod (_version, decl)
310   = do  {       -- Populate the name cache with final versions of all 
311                 -- the names associated with the decl
312           main_name      <- mk_new_bndr mod (ifName decl)
313         ; traceIf (text "Loading decl for " <> ppr main_name)
314         ; implicit_names <- mapM (mk_new_bndr mod) (ifaceDeclSubBndrs decl)
315
316         -- Typecheck the thing, lazily
317         -- NB. Firstly, the laziness is there in case we never need the
318         -- declaration (in one-shot mode), and secondly it is there so that 
319         -- we don't look up the occurrence of a name before calling mk_new_bndr
320         -- on the binder.  This is important because we must get the right name
321         -- which includes its nameParent.
322
323         ; thing <- forkM doc $ do { bumpDeclStats main_name
324                                   ; tcIfaceDecl ignore_prags decl }
325
326         -- Populate the type environment with the implicitTyThings too
327         ; let mini_env = mkOccEnv [(getOccName t, t) | t <- implicitTyThings thing]
328               lookup n = case lookupOccEnv mini_env (getOccName n) of
329                            Just thing -> thing
330                            Nothing    -> 
331                              pprPanic "loadDecl" (ppr main_name <+> ppr n $$ ppr (decl))
332
333         ; returnM $ (main_name, thing) :  [(n, lookup n) | n <- implicit_names]
334         }
335                 -- We build a list from the *known* names, with (lookup n) thunks
336                 -- as the TyThings.  That way we can extend the PTE without poking the
337                 -- thunks
338   where
339         -- mk_new_bndr allocates in the name cache the final canonical
340         -- name for the thing, with the correct 
341         --      * parent
342         --      * location
343         -- imported name, to fix the module correctly in the cache
344     mk_new_bndr mod occ 
345         = newGlobalBinder mod occ 
346                           (importedSrcLoc (showSDoc (ppr (moduleName mod))))
347                         -- ToDo: qualify with the package name if necessary
348
349     doc = ptext SLIT("Declaration for") <+> ppr (ifName decl)
350
351 bumpDeclStats :: Name -> IfL ()         -- Record that one more declaration has actually been used
352 bumpDeclStats name
353   = do  { traceIf (text "Loading decl for" <+> ppr name)
354         ; updateEps_ (\eps -> let stats = eps_stats eps
355                               in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
356         }
357 \end{code}
358
359
360 %*********************************************************
361 %*                                                      *
362 \subsection{Reading an interface file}
363 %*                                                      *
364 %*********************************************************
365
366 \begin{code}
367 findAndReadIface :: SDoc -> Module
368                  -> IsBootInterface     -- True  <=> Look for a .hi-boot file
369                                         -- False <=> Look for .hi file
370                  -> TcRnIf gbl lcl (MaybeErr Message (ModIface, FilePath))
371         -- Nothing <=> file not found, or unreadable, or illegible
372         -- Just x  <=> successfully found and parsed 
373
374         -- It *doesn't* add an error to the monad, because 
375         -- sometimes it's ok to fail... see notes with loadInterface
376
377 findAndReadIface doc_str mod hi_boot_file
378   = do  { traceIf (sep [hsep [ptext SLIT("Reading"), 
379                               if hi_boot_file 
380                                 then ptext SLIT("[boot]") 
381                                 else empty,
382                               ptext SLIT("interface for"), 
383                               ppr mod <> semi],
384                         nest 4 (ptext SLIT("reason:") <+> doc_str)])
385
386         -- Check for GHC.Prim, and return its static interface
387         ; dflags <- getDOpts
388         ; if mod == gHC_PRIM
389           then returnM (Succeeded (ghcPrimIface, 
390                                    "<built in interface for GHC.Prim>"))
391           else do
392
393         -- Look for the file
394         ; hsc_env <- getTopEnv
395         ; mb_found <- ioToIOEnv (findHiFile hsc_env mod hi_boot_file)
396         ; case mb_found of {
397               Failed err -> do
398                 { traceIf (ptext SLIT("...not found"))
399                 ; dflags <- getDOpts
400                 ; returnM (Failed (cannotFindInterface dflags 
401                                         (moduleName mod) err)) } ;
402
403               Succeeded file_path -> do 
404
405         -- Found file, so read it
406         { traceIf (ptext SLIT("readIFace") <+> text file_path)
407         ; read_result <- readIface mod file_path hi_boot_file
408         ; case read_result of
409             Failed err -> returnM (Failed (badIfaceFile file_path err))
410             Succeeded iface 
411                 | mi_module iface /= mod ->
412                   return (Failed (wrongIfaceModErr iface mod file_path))
413                 | otherwise ->
414                   returnM (Succeeded (iface, file_path))
415                         -- Don't forget to fill in the package name...
416         }}}
417
418 findHiFile :: HscEnv -> Module -> IsBootInterface
419            -> IO (MaybeErr FindResult FilePath)
420 findHiFile hsc_env mod hi_boot_file
421   = do
422       maybe_found <- findExactModule hsc_env mod
423       case maybe_found of
424         Found loc mod -> return (Succeeded path)
425                 where
426                    path = addBootSuffix_maybe hi_boot_file (ml_hi_file loc)
427         err -> return (Failed err)
428 \end{code}
429
430 @readIface@ tries just the one file.
431
432 \begin{code}
433 readIface :: Module -> FilePath -> IsBootInterface 
434           -> TcRnIf gbl lcl (MaybeErr Message ModIface)
435         -- Failed err    <=> file not found, or unreadable, or illegible
436         -- Succeeded iface <=> successfully found and parsed 
437
438 readIface wanted_mod file_path is_hi_boot_file
439   = do  { dflags <- getDOpts
440         ; res <- tryMostM $ readBinIface file_path
441         ; case res of
442             Right iface 
443                 | wanted_mod == actual_mod -> return (Succeeded iface)
444                 | otherwise                -> return (Failed err)
445                 where
446                   actual_mod = mi_module iface
447                   err = hiModuleNameMismatchWarn wanted_mod actual_mod
448
449             Left exn    -> return (Failed (text (showException exn)))
450     }
451 \end{code}
452
453
454 %*********************************************************
455 %*                                                       *
456         Wired-in interface for GHC.Prim
457 %*                                                       *
458 %*********************************************************
459
460 \begin{code}
461 initExternalPackageState :: ExternalPackageState
462 initExternalPackageState
463   = EPS { 
464       eps_is_boot      = emptyUFM,
465       eps_PIT          = emptyPackageIfaceTable,
466       eps_PTE          = emptyTypeEnv,
467       eps_inst_env     = emptyInstEnv,
468       eps_fam_inst_env = emptyFamInstEnv,
469       eps_rule_base    = mkRuleBase builtinRules,
470         -- Initialise the EPS rule pool with the built-in rules
471       eps_mod_fam_inst_env
472                        = emptyModuleEnv,
473       eps_stats = EpsStats { n_ifaces_in = 0, n_decls_in = 0, n_decls_out = 0
474                            , n_insts_in = 0, n_insts_out = 0
475                            , n_rules_in = length builtinRules, n_rules_out = 0 }
476     }
477 \end{code}
478
479
480 %*********************************************************
481 %*                                                       *
482         Wired-in interface for GHC.Prim
483 %*                                                       *
484 %*********************************************************
485
486 \begin{code}
487 ghcPrimIface :: ModIface
488 ghcPrimIface
489   = (emptyModIface gHC_PRIM) {
490         mi_exports  = [(gHC_PRIM, ghcPrimExports)],
491         mi_decls    = [],
492         mi_fixities = fixities,
493         mi_fix_fn  = mkIfaceFixCache fixities
494     }           
495   where
496     fixities = [(getOccName seqId, Fixity 0 InfixR)]
497                         -- seq is infixr 0
498 \end{code}
499
500 %*********************************************************
501 %*                                                      *
502 \subsection{Statistics}
503 %*                                                      *
504 %*********************************************************
505
506 \begin{code}
507 ifaceStats :: ExternalPackageState -> SDoc
508 ifaceStats eps 
509   = hcat [text "Renamer stats: ", msg]
510   where
511     stats = eps_stats eps
512     msg = vcat 
513         [int (n_ifaces_in stats) <+> text "interfaces read",
514          hsep [ int (n_decls_out stats), text "type/class/variable imported, out of", 
515                 int (n_decls_in stats), text "read"],
516          hsep [ int (n_insts_out stats), text "instance decls imported, out of",  
517                 int (n_insts_in stats), text "read"],
518          hsep [ int (n_rules_out stats), text "rule decls imported, out of",  
519                 int (n_rules_in stats), text "read"]
520         ]
521 \end{code}    
522
523
524 %************************************************************************
525 %*                                                                      *
526                 Printing interfaces
527 %*                                                                      *
528 %************************************************************************
529
530 \begin{code}
531 -- | Read binary interface, and print it out
532 showIface :: HscEnv -> FilePath -> IO ()
533 showIface hsc_env filename = do
534    -- skip the version check; we don't want to worry about profiled vs.
535    -- non-profiled interfaces, for example.
536    writeIORef v_IgnoreHiWay True
537    iface <- initTcRnIf 's' hsc_env () () $ readBinIface  filename
538    printDump (pprModIface iface)
539 \end{code}
540
541 \begin{code}
542 pprModIface :: ModIface -> SDoc
543 -- Show a ModIface
544 pprModIface iface
545  = vcat [ ptext SLIT("interface")
546                 <+> ppr (mi_module iface) <+> pp_boot 
547                 <+> ppr (mi_mod_vers iface) <+> pp_sub_vers
548                 <+> (if mi_orphan iface then ptext SLIT("[orphan module]") else empty)
549                 <+> (if mi_finsts iface then ptext SLIT("[family instance module]") else empty)
550                 <+> int opt_HiVersion
551                 <+> ptext SLIT("where")
552         , vcat (map pprExport (mi_exports iface))
553         , pprDeps (mi_deps iface)
554         , vcat (map pprUsage (mi_usages iface))
555         , pprFixities (mi_fixities iface)
556         , vcat (map pprIfaceDecl (mi_decls iface))
557         , vcat (map ppr (mi_insts iface))
558         , vcat (map ppr (mi_rules iface))
559         , pprDeprecs (mi_deprecs iface)
560         ]
561   where
562     pp_boot | mi_boot iface = ptext SLIT("[boot]")
563             | otherwise     = empty
564
565     exp_vers  = mi_exp_vers iface
566     rule_vers = mi_rule_vers iface
567
568     pp_sub_vers | exp_vers == initialVersion && rule_vers == initialVersion = empty
569                 | otherwise = brackets (ppr exp_vers <+> ppr rule_vers)
570 \end{code}
571
572 When printing export lists, we print like this:
573         Avail   f               f
574         AvailTC C [C, x, y]     C(x,y)
575         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
576
577 \begin{code}
578 pprExport :: IfaceExport -> SDoc
579 pprExport (mod, items)
580  = hsep [ ptext SLIT("export"), ppr mod, hsep (map pp_avail items) ]
581   where
582     pp_avail :: GenAvailInfo OccName -> SDoc
583     pp_avail (Avail occ)    = ppr occ
584     pp_avail (AvailTC _ []) = empty
585     pp_avail (AvailTC n (n':ns)) 
586         | n==n'     = ppr n <> pp_export ns
587         | otherwise = ppr n <> char '|' <> pp_export (n':ns)
588     
589     pp_export []    = empty
590     pp_export names = braces (hsep (map ppr names))
591
592 pprUsage :: Usage -> SDoc
593 pprUsage usage
594   = hsep [ptext SLIT("import"), ppr (usg_name usage), 
595           int (usg_mod usage), 
596           pp_export_version (usg_exports usage),
597           int (usg_rules usage),
598           pp_versions (usg_entities usage) ]
599   where
600     pp_versions nvs = hsep [ ppr n <+> int v | (n,v) <- nvs ]
601     pp_export_version Nothing  = empty
602     pp_export_version (Just v) = int v
603
604 pprDeps :: Dependencies -> SDoc
605 pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs,
606                 dep_finsts = finsts })
607   = vcat [ptext SLIT("module dependencies:") <+> fsep (map ppr_mod mods),
608           ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs), 
609           ptext SLIT("orphans:") <+> fsep (map ppr orphs),
610           ptext SLIT("family instance modules:") <+> fsep (map ppr finsts)
611         ]
612   where
613     ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
614     ppr_boot True  = text "[boot]"
615     ppr_boot False = empty
616
617 pprIfaceDecl :: (Version, IfaceDecl) -> SDoc
618 pprIfaceDecl (ver, decl)
619   = ppr_vers ver <+> ppr decl
620   where
621         -- Print the version for the decl
622     ppr_vers v | v == initialVersion = empty
623                | otherwise           = int v
624
625 pprFixities :: [(OccName, Fixity)] -> SDoc
626 pprFixities []    = empty
627 pprFixities fixes = ptext SLIT("fixities") <+> pprWithCommas pprFix fixes
628                   where
629                     pprFix (occ,fix) = ppr fix <+> ppr occ 
630
631 pprDeprecs NoDeprecs        = empty
632 pprDeprecs (DeprecAll txt)  = ptext SLIT("Deprecate all") <+> doubleQuotes (ftext txt)
633 pprDeprecs (DeprecSome prs) = ptext SLIT("Deprecate") <+> vcat (map pprDeprec prs)
634                             where
635                               pprDeprec (name, txt) = ppr name <+> doubleQuotes (ftext txt)
636 \end{code}
637
638
639 %*********************************************************
640 %*                                                       *
641 \subsection{Errors}
642 %*                                                       *
643 %*********************************************************
644
645 \begin{code}
646 badIfaceFile file err
647   = vcat [ptext SLIT("Bad interface file:") <+> text file, 
648           nest 4 err]
649
650 hiModuleNameMismatchWarn :: Module -> Module -> Message
651 hiModuleNameMismatchWarn requested_mod read_mod = 
652   withPprStyle defaultUserStyle $
653     -- we want the Modules below to be qualified with package names,
654     -- so reset the PrintUnqualified setting.
655     hsep [ ptext SLIT("Something is amiss; requested module ")
656          , ppr requested_mod
657          , ptext SLIT("differs from name found in the interface file")
658          , ppr read_mod
659          ]
660
661 wrongIfaceModErr iface mod_name file_path 
662   = sep [ptext SLIT("Interface file") <+> iface_file,
663          ptext SLIT("contains module") <+> quotes (ppr (mi_module iface)) <> comma,
664          ptext SLIT("but we were expecting module") <+> quotes (ppr mod_name),
665          sep [ptext SLIT("Probable cause: the source code which generated"),
666              nest 2 iface_file,
667              ptext SLIT("has an incompatible module name")
668             ]
669         ]
670   where iface_file = doubleQuotes (text file_path)
671 \end{code}
672