2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section{Dealing with interface files}
8 loadInterface, loadInterfaceForName, loadWiredInHomeIface,
9 loadSrcInterface, loadSysInterface, loadOrphanModules,
10 findAndReadIface, readIface, -- Used when reading the module's old interface
11 loadDecls, ifaceStats, discardDeclPrags,
12 initExternalPackageState,
14 pprModIface, showIface -- Print the iface in Foo.hi
17 #include "HsVersions.h"
19 import {-# SOURCE #-} TcIface( tcIfaceDecl, tcIfaceRule, tcIfaceInst )
21 import DynFlags ( DynFlags(..), DynFlag( Opt_IgnoreInterfacePragmas ) )
22 import IfaceSyn ( IfaceDecl(..), IfaceConDecl(..), IfaceClassOp(..),
23 IfaceConDecls(..), IfaceFamInst(..),
25 import IfaceEnv ( newGlobalBinder, lookupIfaceTc )
26 import HscTypes ( ModIface(..), TyThing, IfaceExport, Usage(..),
27 Deprecs(..), Dependencies(..),
28 emptyModIface, EpsStats(..), GenAvailInfo(..),
29 addEpsInStats, ExternalPackageState(..),
30 PackageTypeEnv, emptyTypeEnv, HscEnv(..),
31 lookupIfaceByModule, emptyPackageIfaceTable,
32 IsBootInterface, mkIfaceFixCache,
36 import BasicTypes ( Version, initialVersion,
37 Fixity(..), FixityDirection(..), isMarkedStrict )
39 import Type ( TyThing(..) )
40 import Class ( classATs )
42 import PrelNames ( gHC_PRIM )
43 import PrelInfo ( ghcPrimExports )
44 import PrelRules ( builtinRules )
45 import Rules ( extendRuleBaseList, mkRuleBase )
46 import InstEnv ( emptyInstEnv, extendInstEnvList )
47 import Name ( Name {-instance NamedThing-}, getOccName,
48 nameModule, nameIsLocalOrFrom, isWiredInName )
52 import OccName ( OccName, mkOccEnv, lookupOccEnv, mkClassTyConOcc,
53 mkClassDataConOcc, mkSuperDictSelOcc,
54 mkDataConWrapperOcc, mkDataConWorkerOcc,
55 mkNewTyCoOcc, mkInstTyTcOcc, mkInstTyCoOcc )
56 import SrcLoc ( importedSrcLoc )
57 import Maybes ( MaybeErr(..) )
58 import ErrUtils ( Message )
59 import Finder ( findImportedModule, findExactModule,
60 FindResult(..), cannotFindInterface )
62 import StaticFlags ( opt_HiVersion )
64 import BinIface ( readBinIface, v_IgnoreHiWay )
65 import Binary ( getBinFileWithDict )
66 import Panic ( ghcError, tryMost, showException, GhcException(..) )
68 import Maybe ( isJust )
69 import DATA_IOREF ( writeIORef )
73 %************************************************************************
75 loadSrcInterface, loadOrphanModules, loadHomeInterface
77 These three are called from TcM-land
79 %************************************************************************
82 -- | Load the interface corresponding to an @import@ directive in
83 -- source code. On a failure, fail in the monad with an error message.
84 loadSrcInterface :: SDoc -> ModuleName -> IsBootInterface -> RnM ModIface
85 loadSrcInterface doc mod want_boot = do
86 -- We must first find which Module this import refers to. This involves
87 -- calling the Finder, which as a side effect will search the filesystem
88 -- and create a ModLocation. If successful, loadIface will read the
89 -- interface; it will call the Finder again, but the ModLocation will be
90 -- cached from the first search.
92 res <- ioToIOEnv $ findImportedModule hsc_env mod Nothing
95 mb_iface <- initIfaceTcRn $ loadInterface doc mod (ImportByUser want_boot)
97 Failed err -> failWithTc err
98 Succeeded iface -> return iface
100 let dflags = hsc_dflags hsc_env in
101 failWithTc (cannotFindInterface dflags mod err)
103 -- | Load interfaces for a collection of orphan modules.
104 loadOrphanModules :: [Module] -> TcM ()
105 loadOrphanModules mods
106 | null mods = returnM ()
107 | otherwise = initIfaceTcRn $
108 do { traceIf (text "Loading orphan modules:" <+>
113 load mod = loadSysInterface (mk_doc mod) mod
114 mk_doc mod = ppr mod <+> ptext SLIT("is a orphan-instance module")
116 -- | Loads the interface for a given Name.
117 loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
118 loadInterfaceForName doc name
121 -- Should not be called with a name from the module being compiled
122 this_mod <- getModule
123 ; ASSERT2( not (nameIsLocalOrFrom this_mod name), ppr name <+> parens doc )
125 initIfaceTcRn $ loadSysInterface doc (nameModule name)
128 -- | An 'IfM' function to load the home interface for a wired-in thing,
129 -- so that we're sure that we see its instance declarations and rules
130 loadWiredInHomeIface :: Name -> IfM lcl ()
131 loadWiredInHomeIface name
132 = ASSERT( isWiredInName name )
133 do loadSysInterface doc (nameModule name); return ()
135 doc = ptext SLIT("Need home interface for wired-in thing") <+> ppr name
137 -- | A wrapper for 'loadInterface' that throws an exception if it fails
138 loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
139 loadSysInterface doc mod_name
140 = do { mb_iface <- loadInterface doc mod_name ImportBySystem
142 Failed err -> ghcError (ProgramError (showSDoc err))
143 Succeeded iface -> return iface }
147 %*********************************************************
151 The main function to load an interface
152 for an imported module, and put it in
153 the External Package State
155 %*********************************************************
158 loadInterface :: SDoc -> Module -> WhereFrom
159 -> IfM lcl (MaybeErr Message ModIface)
161 -- If it can't find a suitable interface file, we
162 -- a) modify the PackageIfaceTable to have an empty entry
163 -- (to avoid repeated complaints)
164 -- b) return (Left message)
166 -- It's not necessarily an error for there not to be an interface
167 -- file -- perhaps the module has changed, and that interface
170 loadInterface doc_str mod from
171 = do { -- Read the state
172 (eps,hpt) <- getEpsAndHpt
174 ; traceIf (text "Considering whether to load" <+> ppr mod <+> ppr from)
176 -- Check whether we have the interface already
178 ; case lookupIfaceByModule dflags hpt (eps_PIT eps) mod of {
180 -> returnM (Succeeded iface) ; -- Already loaded
181 -- The (src_imp == mi_boot iface) test checks that the already-loaded
182 -- interface isn't a boot iface. This can conceivably happen,
183 -- if an earlier import had a before we got to real imports. I think.
186 { let { hi_boot_file = case from of
187 ImportByUser usr_boot -> usr_boot
188 ImportBySystem -> sys_boot
190 ; mb_dep = lookupUFM (eps_is_boot eps) (moduleName mod)
191 ; sys_boot = case mb_dep of
192 Just (_, is_boot) -> is_boot
194 -- The boot-ness of the requested interface,
195 } -- based on the dependencies in directly-imported modules
197 -- READ THE MODULE IN
198 ; read_result <- findAndReadIface doc_str mod hi_boot_file
200 ; case read_result of {
202 { let fake_iface = emptyModIface mod
204 ; updateEps_ $ \eps ->
205 eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
206 -- Not found, so add an empty iface to
207 -- the EPS map so that we don't look again
209 ; returnM (Failed err) } ;
212 Succeeded (iface, file_path) -- Sanity check:
213 | ImportBySystem <- from, -- system-importing...
214 modulePackageId (mi_module iface) == thisPackage dflags,
215 -- a home-package module...
216 Nothing <- mb_dep -- that we know nothing about
217 -> returnM (Failed (badDepMsg mod))
222 loc_doc = text file_path
224 initIfaceLcl mod loc_doc $ do
226 -- Load the new ModIface into the External Package State
227 -- Even home-package interfaces loaded by loadInterface
228 -- (which only happens in OneShot mode; in Batch/Interactive
229 -- mode, home-package modules are loaded one by one into the HPT)
230 -- are put in the EPS.
232 -- The main thing is to add the ModIface to the PIT, but
234 -- IfaceDecls, IfaceInst, IfaceRules
235 -- out of the ModIface and put them into the big EPS pools
237 -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
238 --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
239 -- If we do loadExport first the wrong info gets into the cache (unless we
240 -- explicitly tag each export which seems a bit of a bore)
242 ; ignore_prags <- doptM Opt_IgnoreInterfacePragmas
243 ; new_eps_decls <- loadDecls ignore_prags (mi_decls iface)
244 ; new_eps_insts <- mapM tcIfaceInst (mi_insts iface)
245 ; new_eps_rules <- if ignore_prags
247 else mapM tcIfaceRule (mi_rules iface)
249 ; let { final_iface = iface { mi_decls = panic "No mi_decls in PIT",
250 mi_insts = panic "No mi_insts in PIT",
251 mi_rules = panic "No mi_rules in PIT" } }
253 ; updateEps_ $ \ eps ->
254 eps { eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
255 eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
256 eps_rule_base = extendRuleBaseList (eps_rule_base eps) new_eps_rules,
257 eps_inst_env = extendInstEnvList (eps_inst_env eps) new_eps_insts,
258 eps_stats = addEpsInStats (eps_stats eps) (length new_eps_decls)
259 (length new_eps_insts) (length new_eps_rules) }
261 ; return (Succeeded final_iface)
265 = hang (ptext SLIT("Interface file inconsistency:"))
266 2 (sep [ptext SLIT("home-package module") <+> quotes (ppr mod) <+> ptext SLIT("is mentioned,"),
267 ptext SLIT("but does not appear in the dependencies of the interface")])
269 -----------------------------------------------------
270 -- Loading type/class/value decls
271 -- We pass the full Module name here, replete with
272 -- its package info, so that we can build a Name for
273 -- each binder with the right package info in it
274 -- All subsequent lookups, including crucially lookups during typechecking
275 -- the declaration itself, will find the fully-glorious Name
277 -- We handle ATs specially. They are not main declarations, but also not
278 -- implict things (in particular, adding them to `implicitTyThings' would mess
279 -- things up in the renaming/type checking of source programs).
280 -----------------------------------------------------
282 addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
283 addDeclsToPTE pte things = extendNameEnvList pte things
286 -> [(Version, IfaceDecl)]
287 -> IfL [(Name,TyThing)]
288 loadDecls ignore_prags ver_decls
289 = do { mod <- getIfModule
290 ; thingss <- mapM (loadDecl ignore_prags mod) ver_decls
291 ; return (concat thingss)
294 loadDecl :: Bool -- Don't load pragmas into the decl pool
296 -> (Version, IfaceDecl)
297 -> IfL [(Name,TyThing)] -- The list can be poked eagerly, but the
298 -- TyThings are forkM'd thunks
299 loadDecl ignore_prags mod (_version, decl)
300 = do { -- Populate the name cache with final versions of all
301 -- the names associated with the decl
302 main_name <- mk_new_bndr mod Nothing (ifName decl)
303 ; parent_name <- case ifFamily decl of -- make family the parent
304 Just famTyCon -> lookupIfaceTc famTyCon
305 _ -> return main_name
306 ; implicit_names <- mapM (mk_new_bndr mod (Just parent_name))
307 (ifaceDeclSubBndrs decl)
309 -- Typecheck the thing, lazily
310 -- NB. firstly, the laziness is there in case we never need the
311 -- declaration (in one-shot mode), and secondly it is there so that
312 -- we don't look up the occurrence of a name before calling mk_new_bndr
313 -- on the binder. This is important because we must get the right name
314 -- which includes its nameParent.
315 ; thing <- forkM doc (bumpDeclStats main_name >> tcIfaceDecl stripped_decl)
316 ; let mini_env = mkOccEnv [(getOccName t, t) | t <- implicitTyThings thing]
317 lookup n = case lookupOccEnv mini_env (getOccName n) of
320 pprPanic "loadDecl" (ppr main_name <+>
321 ppr n $$ ppr (stripped_decl))
323 ; returnM $ (main_name, thing) : [(n, lookup n) | n <- implicit_names]
325 -- We build a list from the *known* names, with (lookup n) thunks
326 -- as the TyThings. That way we can extend the PTE without poking the
329 stripped_decl | ignore_prags = discardDeclPrags decl
332 -- mk_new_bndr allocates in the name cache the final canonical
333 -- name for the thing, with the correct
336 -- imported name, to fix the module correctly in the cache
337 mk_new_bndr mod mb_parent occ
338 = newGlobalBinder mod occ mb_parent
339 (importedSrcLoc (showSDoc (ppr (moduleName mod))))
340 -- ToDo: qualify with the package name if necessary
342 ifFamily (IfaceData {
343 ifFamInst = Just (IfaceFamInst {ifFamInstTyCon = famTyCon})})
347 doc = ptext SLIT("Declaration for") <+> ppr (ifName decl)
349 discardDeclPrags :: IfaceDecl -> IfaceDecl
350 discardDeclPrags decl@(IfaceId {ifIdInfo = HasInfo _}) = decl { ifIdInfo = NoInfo }
351 discardDeclPrags decl = decl
353 bumpDeclStats :: Name -> IfL () -- Record that one more declaration has actually been used
355 = do { traceIf (text "Loading decl for" <+> ppr name)
356 ; updateEps_ (\eps -> let stats = eps_stats eps
357 in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
361 ifaceDeclSubBndrs :: IfaceDecl -> [OccName]
362 -- *Excludes* the 'main' name, but *includes* the implicitly-bound names
363 -- Deeply revolting, because it has to predict what gets bound,
364 -- especially the question of whether there's a wrapper for a datacon
366 -- If you change this, make sure you change HscTypes.implicitTyThings in sync
368 ifaceDeclSubBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_occ,
369 ifSigs = sigs, ifATs = ats })
371 [tc_occ, dc_occ, dcww_occ] ++
372 [op | IfaceClassOp op _ _ <- sigs] ++
373 [ifName at | at <- ats ] ++
374 [mkSuperDictSelOcc n cls_occ | n <- [1..n_ctxt]]
376 n_ctxt = length sc_ctxt
378 tc_occ = mkClassTyConOcc cls_occ
379 dc_occ = mkClassDataConOcc cls_occ
380 co_occs | is_newtype = [mkNewTyCoOcc tc_occ]
382 dcww_occ -- | is_newtype = mkDataConWrapperOcc dc_occ -- Newtypes have wrapper but no worker
383 | otherwise = mkDataConWorkerOcc dc_occ -- Otherwise worker but no wrapper
384 is_newtype = n_sigs + n_ctxt == 1 -- Sigh
386 ifaceDeclSubBndrs IfaceData {ifCons = IfAbstractTyCon}
389 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
390 ifCons = IfNewTyCon (
391 IfCon { ifConOcc = con_occ,
394 ifFamInst = famInst})
395 = fields ++ [con_occ, mkDataConWorkerOcc con_occ, mkNewTyCoOcc tc_occ]
396 ++ famInstCo famInst tc_occ
398 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
399 ifCons = IfDataTyCon cons,
400 ifFamInst = famInst})
401 = nub (concatMap ifConFields cons) -- Eliminate duplicate fields
402 ++ concatMap dc_occs cons
403 ++ famInstCo famInst tc_occ
406 | has_wrapper = [con_occ, work_occ, wrap_occ]
407 | otherwise = [con_occ, work_occ]
409 con_occ = ifConOcc con_decl
410 strs = ifConStricts con_decl
411 wrap_occ = mkDataConWrapperOcc con_occ
412 work_occ = mkDataConWorkerOcc con_occ
413 has_wrapper = any isMarkedStrict strs -- See MkId.mkDataConIds (sigh)
414 || not (null . ifConEqSpec $ con_decl)
416 -- ToDo: may miss strictness in existential dicts
418 ifaceDeclSubBndrs _other = []
420 -- coercion for data/newtype family instances
421 famInstCo Nothing baseOcc = []
422 famInstCo (Just _) baseOcc = [mkInstTyCoOcc baseOcc]
426 %*********************************************************
428 \subsection{Reading an interface file}
430 %*********************************************************
433 findAndReadIface :: SDoc -> Module
434 -> IsBootInterface -- True <=> Look for a .hi-boot file
435 -- False <=> Look for .hi file
436 -> TcRnIf gbl lcl (MaybeErr Message (ModIface, FilePath))
437 -- Nothing <=> file not found, or unreadable, or illegible
438 -- Just x <=> successfully found and parsed
440 -- It *doesn't* add an error to the monad, because
441 -- sometimes it's ok to fail... see notes with loadInterface
443 findAndReadIface doc_str mod hi_boot_file
444 = do { traceIf (sep [hsep [ptext SLIT("Reading"),
446 then ptext SLIT("[boot]")
448 ptext SLIT("interface for"),
450 nest 4 (ptext SLIT("reason:") <+> doc_str)])
452 -- Check for GHC.Prim, and return its static interface
455 then returnM (Succeeded (ghcPrimIface,
456 "<built in interface for GHC.Prim>"))
460 ; hsc_env <- getTopEnv
461 ; mb_found <- ioToIOEnv (findHiFile hsc_env mod hi_boot_file)
464 { traceIf (ptext SLIT("...not found"))
466 ; returnM (Failed (cannotFindInterface dflags
467 (moduleName mod) err)) } ;
469 Succeeded file_path -> do
471 -- Found file, so read it
472 { traceIf (ptext SLIT("readIFace") <+> text file_path)
473 ; read_result <- readIface mod file_path hi_boot_file
474 ; case read_result of
475 Failed err -> returnM (Failed (badIfaceFile file_path err))
477 | mi_module iface /= mod ->
478 return (Failed (wrongIfaceModErr iface mod file_path))
480 returnM (Succeeded (iface, file_path))
481 -- Don't forget to fill in the package name...
484 findHiFile :: HscEnv -> Module -> IsBootInterface
485 -> IO (MaybeErr FindResult FilePath)
486 findHiFile hsc_env mod hi_boot_file
488 maybe_found <- findExactModule hsc_env mod
490 Found loc mod -> return (Succeeded path)
492 path = addBootSuffix_maybe hi_boot_file (ml_hi_file loc)
493 err -> return (Failed err)
496 @readIface@ tries just the one file.
499 readIface :: Module -> FilePath -> IsBootInterface
500 -> TcRnIf gbl lcl (MaybeErr Message ModIface)
501 -- Failed err <=> file not found, or unreadable, or illegible
502 -- Succeeded iface <=> successfully found and parsed
504 readIface wanted_mod file_path is_hi_boot_file
505 = do { dflags <- getDOpts
507 { res <- tryMost (readBinIface file_path)
510 | wanted_mod == actual_mod -> return (Succeeded iface)
511 | otherwise -> return (Failed err)
513 actual_mod = mi_module iface
514 err = hiModuleNameMismatchWarn wanted_mod actual_mod
516 Left exn -> return (Failed (text (showException exn)))
521 %*********************************************************
523 Wired-in interface for GHC.Prim
525 %*********************************************************
528 initExternalPackageState :: ExternalPackageState
529 initExternalPackageState
531 eps_is_boot = emptyUFM,
532 eps_PIT = emptyPackageIfaceTable,
533 eps_PTE = emptyTypeEnv,
534 eps_inst_env = emptyInstEnv,
535 eps_rule_base = mkRuleBase builtinRules,
536 -- Initialise the EPS rule pool with the built-in rules
537 eps_stats = EpsStats { n_ifaces_in = 0, n_decls_in = 0, n_decls_out = 0
538 , n_insts_in = 0, n_insts_out = 0
539 , n_rules_in = length builtinRules, n_rules_out = 0 }
544 %*********************************************************
546 Wired-in interface for GHC.Prim
548 %*********************************************************
551 ghcPrimIface :: ModIface
553 = (emptyModIface gHC_PRIM) {
554 mi_exports = [(gHC_PRIM, ghcPrimExports)],
556 mi_fixities = fixities,
557 mi_fix_fn = mkIfaceFixCache fixities
560 fixities = [(getOccName seqId, Fixity 0 InfixR)]
564 %*********************************************************
566 \subsection{Statistics}
568 %*********************************************************
571 ifaceStats :: ExternalPackageState -> SDoc
573 = hcat [text "Renamer stats: ", msg]
575 stats = eps_stats eps
577 [int (n_ifaces_in stats) <+> text "interfaces read",
578 hsep [ int (n_decls_out stats), text "type/class/variable imported, out of",
579 int (n_decls_in stats), text "read"],
580 hsep [ int (n_insts_out stats), text "instance decls imported, out of",
581 int (n_insts_in stats), text "read"],
582 hsep [ int (n_rules_out stats), text "rule decls imported, out of",
583 int (n_rules_in stats), text "read"]
588 %************************************************************************
592 %************************************************************************
595 showIface :: FilePath -> IO ()
596 -- Read binary interface, and print it out
597 showIface filename = do
598 -- skip the version check; we don't want to worry about profiled vs.
599 -- non-profiled interfaces, for example.
600 writeIORef v_IgnoreHiWay True
601 iface <- Binary.getBinFileWithDict filename
602 printDump (pprModIface iface)
608 pprModIface :: ModIface -> SDoc
611 = vcat [ ptext SLIT("interface")
612 <+> ppr (mi_module iface) <+> pp_boot
613 <+> ppr (mi_mod_vers iface) <+> pp_sub_vers
614 <+> (if mi_orphan iface then ptext SLIT("[orphan module]") else empty)
615 <+> int opt_HiVersion
616 <+> ptext SLIT("where")
617 , vcat (map pprExport (mi_exports iface))
618 , pprDeps (mi_deps iface)
619 , vcat (map pprUsage (mi_usages iface))
620 , pprFixities (mi_fixities iface)
621 , vcat (map pprIfaceDecl (mi_decls iface))
622 , vcat (map ppr (mi_insts iface))
623 , vcat (map ppr (mi_rules iface))
624 , pprDeprecs (mi_deprecs iface)
627 pp_boot | mi_boot iface = ptext SLIT("[boot]")
630 exp_vers = mi_exp_vers iface
631 rule_vers = mi_rule_vers iface
633 pp_sub_vers | exp_vers == initialVersion && rule_vers == initialVersion = empty
634 | otherwise = brackets (ppr exp_vers <+> ppr rule_vers)
637 When printing export lists, we print like this:
639 AvailTC C [C, x, y] C(x,y)
640 AvailTC C [x, y] C!(x,y) -- Exporting x, y but not C
643 pprExport :: IfaceExport -> SDoc
644 pprExport (mod, items)
645 = hsep [ ptext SLIT("export"), ppr mod, hsep (map pp_avail items) ]
647 pp_avail :: GenAvailInfo OccName -> SDoc
648 pp_avail (Avail occ) = ppr occ
649 pp_avail (AvailTC _ []) = empty
650 pp_avail (AvailTC n (n':ns))
651 | n==n' = ppr n <> pp_export ns
652 | otherwise = ppr n <> char '|' <> pp_export (n':ns)
655 pp_export names = braces (hsep (map ppr names))
657 pprUsage :: Usage -> SDoc
659 = hsep [ptext SLIT("import"), ppr (usg_name usage),
661 pp_export_version (usg_exports usage),
662 int (usg_rules usage),
663 pp_versions (usg_entities usage) ]
665 pp_versions nvs = hsep [ ppr n <+> int v | (n,v) <- nvs ]
666 pp_export_version Nothing = empty
667 pp_export_version (Just v) = int v
669 pprDeps :: Dependencies -> SDoc
670 pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs})
671 = vcat [ptext SLIT("module dependencies:") <+> fsep (map ppr_mod mods),
672 ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs),
673 ptext SLIT("orphans:") <+> fsep (map ppr orphs)
676 ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
677 ppr_boot True = text "[boot]"
678 ppr_boot False = empty
680 pprIfaceDecl :: (Version, IfaceDecl) -> SDoc
681 pprIfaceDecl (ver, decl)
682 = ppr_vers ver <+> ppr decl
684 -- Print the version for the decl
685 ppr_vers v | v == initialVersion = empty
688 pprFixities :: [(OccName, Fixity)] -> SDoc
689 pprFixities [] = empty
690 pprFixities fixes = ptext SLIT("fixities") <+> pprWithCommas pprFix fixes
692 pprFix (occ,fix) = ppr fix <+> ppr occ
694 pprDeprecs NoDeprecs = empty
695 pprDeprecs (DeprecAll txt) = ptext SLIT("Deprecate all") <+> doubleQuotes (ftext txt)
696 pprDeprecs (DeprecSome prs) = ptext SLIT("Deprecate") <+> vcat (map pprDeprec prs)
698 pprDeprec (name, txt) = ppr name <+> doubleQuotes (ftext txt)
702 %*********************************************************
706 %*********************************************************
709 badIfaceFile file err
710 = vcat [ptext SLIT("Bad interface file:") <+> text file,
713 hiModuleNameMismatchWarn :: Module -> Module -> Message
714 hiModuleNameMismatchWarn requested_mod read_mod =
715 withPprStyle defaultUserStyle $
716 -- we want the Modules below to be qualified with package names,
717 -- so reset the PrintUnqualified setting.
718 hsep [ ptext SLIT("Something is amiss; requested module ")
720 , ptext SLIT("differs from name found in the interface file")
724 wrongIfaceModErr iface mod_name file_path
725 = sep [ptext SLIT("Interface file") <+> iface_file,
726 ptext SLIT("contains module") <+> quotes (ppr (mi_module iface)) <> comma,
727 ptext SLIT("but we were expecting module") <+> quotes (ppr mod_name),
728 sep [ptext SLIT("Probable cause: the source code which generated"),
730 ptext SLIT("has an incompatible module name")
733 where iface_file = doubleQuotes (text file_path)