0edf5d9794170985b28a3c5f3d33c81d8fb23386
[ghc.git] / compiler / iface / LoadIface.hs
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
9 {-# LANGUAGE CPP #-}
10 {-# OPTIONS_GHC -fno-warn-orphans #-}
11 module LoadIface (
12 -- Importing one thing
13 tcLookupImported_maybe, importDecl,
14 checkWiredInTyCon, ifCheckWiredInThing,
15
16 -- RnM/TcM functions
17 loadModuleInterface, loadModuleInterfaces,
18 loadSrcInterface, loadSrcInterface_maybe,
19 loadInterfaceForName, loadInterfaceForModule,
20
21 -- IfM functions
22 loadInterface,
23 loadSysInterface, loadUserInterface, loadPluginInterface,
24 findAndReadIface, readIface, -- Used when reading the module's old interface
25 loadDecls, -- Should move to TcIface and be renamed
26 initExternalPackageState,
27 moduleFreeHolesPrecise,
28
29 pprModIfaceSimple,
30 ifaceStats, pprModIface, showIface
31 ) where
32
33 #include "HsVersions.h"
34
35 import {-# SOURCE #-} TcIface( tcIfaceDecl, tcIfaceRules, tcIfaceInst,
36 tcIfaceFamInst, tcIfaceVectInfo, tcIfaceAnnotations )
37
38 import DynFlags
39 import IfaceSyn
40 import IfaceEnv
41 import HscTypes
42
43 import BasicTypes hiding (SuccessFlag(..))
44 import TcRnMonad
45
46 import Constants
47 import PrelNames
48 import PrelInfo
49 import PrimOp ( allThePrimOps, primOpFixity, primOpOcc )
50 import MkId ( seqId )
51 import TysPrim ( funTyConName )
52 import Rules
53 import TyCon
54 import Annotations
55 import InstEnv
56 import FamInstEnv
57 import Name
58 import NameEnv
59 import Avail
60 import Module
61 import Maybes
62 import ErrUtils
63 import Finder
64 import UniqFM
65 import SrcLoc
66 import Outputable
67 import BinIface
68 import Panic
69 import Util
70 import FastString
71 import Fingerprint
72 import Hooks
73 import FieldLabel
74 import RnModIface
75 import UniqDSet
76
77 import Control.Monad
78 import Control.Exception
79 import Data.IORef
80 import System.FilePath
81
82 {-
83 ************************************************************************
84 * *
85 * tcImportDecl is the key function for "faulting in" *
86 * imported things
87 * *
88 ************************************************************************
89
90 The main idea is this. We are chugging along type-checking source code, and
91 find a reference to GHC.Base.map. We call tcLookupGlobal, which doesn't find
92 it in the EPS type envt. So it
93 1 loads GHC.Base.hi
94 2 gets the decl for GHC.Base.map
95 3 typechecks it via tcIfaceDecl
96 4 and adds it to the type env in the EPS
97
98 Note that DURING STEP 4, we may find that map's type mentions a type
99 constructor that also
100
101 Notice that for imported things we read the current version from the EPS
102 mutable variable. This is important in situations like
103 ...$(e1)...$(e2)...
104 where the code that e1 expands to might import some defns that
105 also turn out to be needed by the code that e2 expands to.
106 -}
107
108 tcLookupImported_maybe :: Name -> TcM (MaybeErr MsgDoc TyThing)
109 -- Returns (Failed err) if we can't find the interface file for the thing
110 tcLookupImported_maybe name
111 = do { hsc_env <- getTopEnv
112 ; mb_thing <- liftIO (lookupTypeHscEnv hsc_env name)
113 ; case mb_thing of
114 Just thing -> return (Succeeded thing)
115 Nothing -> tcImportDecl_maybe name }
116
117 tcImportDecl_maybe :: Name -> TcM (MaybeErr MsgDoc TyThing)
118 -- Entry point for *source-code* uses of importDecl
119 tcImportDecl_maybe name
120 | Just thing <- wiredInNameTyThing_maybe name
121 = do { when (needWiredInHomeIface thing)
122 (initIfaceTcRn (loadWiredInHomeIface name))
123 -- See Note [Loading instances for wired-in things]
124 ; return (Succeeded thing) }
125 | otherwise
126 = initIfaceTcRn (importDecl name)
127
128 importDecl :: Name -> IfM lcl (MaybeErr MsgDoc TyThing)
129 -- Get the TyThing for this Name from an interface file
130 -- It's not a wired-in thing -- the caller caught that
131 importDecl name
132 = ASSERT( not (isWiredInName name) )
133 do { traceIf nd_doc
134
135 -- Load the interface, which should populate the PTE
136 ; mb_iface <- ASSERT2( isExternalName name, ppr name )
137 loadInterface nd_doc (nameModule name) ImportBySystem
138 ; case mb_iface of {
139 Failed err_msg -> return (Failed err_msg) ;
140 Succeeded _ -> do
141
142 -- Now look it up again; this time we should find it
143 { eps <- getEps
144 ; case lookupTypeEnv (eps_PTE eps) name of
145 Just thing -> return $ Succeeded thing
146 Nothing -> let doc = ifPprDebug (found_things_msg eps $$ empty)
147 $$ not_found_msg
148 in return $ Failed doc
149 }}}
150 where
151 nd_doc = text "Need decl for" <+> ppr name
152 not_found_msg = hang (text "Can't find interface-file declaration for" <+>
153 pprNameSpace (occNameSpace (nameOccName name)) <+> ppr name)
154 2 (vcat [text "Probable cause: bug in .hi-boot file, or inconsistent .hi file",
155 text "Use -ddump-if-trace to get an idea of which file caused the error"])
156 found_things_msg eps =
157 hang (text "Found the following declarations in" <+> ppr (nameModule name) <> colon)
158 2 (vcat (map ppr $ filter is_interesting $ nameEnvElts $ eps_PTE eps))
159 where
160 is_interesting thing = nameModule name == nameModule (getName thing)
161
162
163 {-
164 ************************************************************************
165 * *
166 Checks for wired-in things
167 * *
168 ************************************************************************
169
170 Note [Loading instances for wired-in things]
171 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172 We need to make sure that we have at least *read* the interface files
173 for any module with an instance decl or RULE that we might want.
174
175 * If the instance decl is an orphan, we have a whole separate mechanism
176 (loadOrphanModules)
177
178 * If the instance decl is not an orphan, then the act of looking at the
179 TyCon or Class will force in the defining module for the
180 TyCon/Class, and hence the instance decl
181
182 * BUT, if the TyCon is a wired-in TyCon, we don't really need its interface;
183 but we must make sure we read its interface in case it has instances or
184 rules. That is what LoadIface.loadWiredInHomeIface does. It's called
185 from TcIface.{tcImportDecl, checkWiredInTyCon, ifCheckWiredInThing}
186
187 * HOWEVER, only do this for TyCons. There are no wired-in Classes. There
188 are some wired-in Ids, but we don't want to load their interfaces. For
189 example, Control.Exception.Base.recSelError is wired in, but that module
190 is compiled late in the base library, and we don't want to force it to
191 load before it's been compiled!
192
193 All of this is done by the type checker. The renamer plays no role.
194 (It used to, but no longer.)
195 -}
196
197 checkWiredInTyCon :: TyCon -> TcM ()
198 -- Ensure that the home module of the TyCon (and hence its instances)
199 -- are loaded. See Note [Loading instances for wired-in things]
200 -- It might not be a wired-in tycon (see the calls in TcUnify),
201 -- in which case this is a no-op.
202 checkWiredInTyCon tc
203 | not (isWiredInName tc_name)
204 = return ()
205 | otherwise
206 = do { mod <- getModule
207 ; traceIf (text "checkWiredInTyCon" <+> ppr tc_name $$ ppr mod)
208 ; ASSERT( isExternalName tc_name )
209 when (mod /= nameModule tc_name)
210 (initIfaceTcRn (loadWiredInHomeIface tc_name))
211 -- Don't look for (non-existent) Float.hi when
212 -- compiling Float.hs, which mentions Float of course
213 -- A bit yukky to call initIfaceTcRn here
214 }
215 where
216 tc_name = tyConName tc
217
218 ifCheckWiredInThing :: TyThing -> IfL ()
219 -- Even though we are in an interface file, we want to make
220 -- sure the instances of a wired-in thing are loaded (imagine f :: Double -> Double)
221 -- Ditto want to ensure that RULES are loaded too
222 -- See Note [Loading instances for wired-in things]
223 ifCheckWiredInThing thing
224 = do { mod <- getIfModule
225 -- Check whether we are typechecking the interface for this
226 -- very module. E.g when compiling the base library in --make mode
227 -- we may typecheck GHC.Base.hi. At that point, GHC.Base is not in
228 -- the HPT, so without the test we'll demand-load it into the PIT!
229 -- C.f. the same test in checkWiredInTyCon above
230 ; let name = getName thing
231 ; ASSERT2( isExternalName name, ppr name )
232 when (needWiredInHomeIface thing && mod /= nameModule name)
233 (loadWiredInHomeIface name) }
234
235 needWiredInHomeIface :: TyThing -> Bool
236 -- Only for TyCons; see Note [Loading instances for wired-in things]
237 needWiredInHomeIface (ATyCon {}) = True
238 needWiredInHomeIface _ = False
239
240
241 {-
242 ************************************************************************
243 * *
244 loadSrcInterface, loadOrphanModules, loadInterfaceForName
245
246 These three are called from TcM-land
247 * *
248 ************************************************************************
249 -}
250
251 -- | Load the interface corresponding to an @import@ directive in
252 -- source code. On a failure, fail in the monad with an error message.
253 loadSrcInterface :: SDoc
254 -> ModuleName
255 -> IsBootInterface -- {-# SOURCE #-} ?
256 -> Maybe FastString -- "package", if any
257 -> RnM ModIface
258
259 loadSrcInterface doc mod want_boot maybe_pkg
260 = do { res <- loadSrcInterface_maybe doc mod want_boot maybe_pkg
261 ; case res of
262 Failed err -> failWithTc err
263 Succeeded iface -> return iface }
264
265 -- | Like 'loadSrcInterface', but returns a 'MaybeErr'.
266 loadSrcInterface_maybe :: SDoc
267 -> ModuleName
268 -> IsBootInterface -- {-# SOURCE #-} ?
269 -> Maybe FastString -- "package", if any
270 -> RnM (MaybeErr MsgDoc ModIface)
271
272 loadSrcInterface_maybe doc mod want_boot maybe_pkg
273 -- We must first find which Module this import refers to. This involves
274 -- calling the Finder, which as a side effect will search the filesystem
275 -- and create a ModLocation. If successful, loadIface will read the
276 -- interface; it will call the Finder again, but the ModLocation will be
277 -- cached from the first search.
278 = do { hsc_env <- getTopEnv
279 ; res <- liftIO $ findImportedModule hsc_env mod maybe_pkg
280 ; case res of
281 Found _ mod -> initIfaceTcRn $ loadInterface doc mod (ImportByUser want_boot)
282 -- TODO: Make sure this error message is good
283 err -> return (Failed (cannotFindModule (hsc_dflags hsc_env) mod err)) }
284
285 -- | Load interface directly for a fully qualified 'Module'. (This is a fairly
286 -- rare operation, but in particular it is used to load orphan modules
287 -- in order to pull their instances into the global package table and to
288 -- handle some operations in GHCi).
289 loadModuleInterface :: SDoc -> Module -> TcM ModIface
290 loadModuleInterface doc mod = initIfaceTcRn (loadSysInterface doc mod)
291
292 -- | Load interfaces for a collection of modules.
293 loadModuleInterfaces :: SDoc -> [Module] -> TcM ()
294 loadModuleInterfaces doc mods
295 | null mods = return ()
296 | otherwise = initIfaceTcRn (mapM_ load mods)
297 where
298 load mod = loadSysInterface (doc <+> parens (ppr mod)) mod
299
300 -- | Loads the interface for a given Name.
301 -- Should only be called for an imported name;
302 -- otherwise loadSysInterface may not find the interface
303 loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
304 loadInterfaceForName doc name
305 = do { when debugIsOn $ -- Check pre-condition
306 do { this_mod <- getModule
307 ; MASSERT2( not (nameIsLocalOrFrom this_mod name), ppr name <+> parens doc ) }
308 ; ASSERT2( isExternalName name, ppr name )
309 initIfaceTcRn $ loadSysInterface doc (nameModule name) }
310
311 -- | Loads the interface for a given Module.
312 loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface
313 loadInterfaceForModule doc m
314 = do
315 -- Should not be called with this module
316 when debugIsOn $ do
317 this_mod <- getModule
318 MASSERT2( this_mod /= m, ppr m <+> parens doc )
319 initIfaceTcRn $ loadSysInterface doc m
320
321 {-
322 *********************************************************
323 * *
324 loadInterface
325
326 The main function to load an interface
327 for an imported module, and put it in
328 the External Package State
329 * *
330 *********************************************************
331 -}
332
333 -- | An 'IfM' function to load the home interface for a wired-in thing,
334 -- so that we're sure that we see its instance declarations and rules
335 -- See Note [Loading instances for wired-in things]
336 loadWiredInHomeIface :: Name -> IfM lcl ()
337 loadWiredInHomeIface name
338 = ASSERT( isWiredInName name )
339 do _ <- loadSysInterface doc (nameModule name); return ()
340 where
341 doc = text "Need home interface for wired-in thing" <+> ppr name
342
343 ------------------
344 -- | Loads a system interface and throws an exception if it fails
345 loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
346 loadSysInterface doc mod_name = loadInterfaceWithException doc mod_name ImportBySystem
347
348 ------------------
349 -- | Loads a user interface and throws an exception if it fails. The first parameter indicates
350 -- whether we should import the boot variant of the module
351 loadUserInterface :: Bool -> SDoc -> Module -> IfM lcl ModIface
352 loadUserInterface is_boot doc mod_name
353 = loadInterfaceWithException doc mod_name (ImportByUser is_boot)
354
355 loadPluginInterface :: SDoc -> Module -> IfM lcl ModIface
356 loadPluginInterface doc mod_name
357 = loadInterfaceWithException doc mod_name ImportByPlugin
358
359 ------------------
360 -- | A wrapper for 'loadInterface' that throws an exception if it fails
361 loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl ModIface
362 loadInterfaceWithException doc mod_name where_from
363 = withException (loadInterface doc mod_name where_from)
364
365 ------------------
366 loadInterface :: SDoc -> Module -> WhereFrom
367 -> IfM lcl (MaybeErr MsgDoc ModIface)
368
369 -- loadInterface looks in both the HPT and PIT for the required interface
370 -- If not found, it loads it, and puts it in the PIT (always).
371
372 -- If it can't find a suitable interface file, we
373 -- a) modify the PackageIfaceTable to have an empty entry
374 -- (to avoid repeated complaints)
375 -- b) return (Left message)
376 --
377 -- It's not necessarily an error for there not to be an interface
378 -- file -- perhaps the module has changed, and that interface
379 -- is no longer used
380
381 loadInterface doc_str mod from
382 | isHoleModule mod
383 -- Hole modules get special treatment
384 = do dflags <- getDynFlags
385 -- Redo search for our local hole module
386 loadInterface doc_str (mkModule (thisPackage dflags) (moduleName mod)) from
387 | otherwise
388 = do { -- Read the state
389 (eps,hpt) <- getEpsAndHpt
390 ; gbl_env <- getGblEnv
391
392 ; traceIf (text "Considering whether to load" <+> ppr mod <+> ppr from)
393
394 -- Check whether we have the interface already
395 ; dflags <- getDynFlags
396 ; case lookupIfaceByModule dflags hpt (eps_PIT eps) mod of {
397 Just iface
398 -> return (Succeeded iface) ; -- Already loaded
399 -- The (src_imp == mi_boot iface) test checks that the already-loaded
400 -- interface isn't a boot iface. This can conceivably happen,
401 -- if an earlier import had a before we got to real imports. I think.
402 _ -> do {
403
404 -- READ THE MODULE IN
405 ; read_result <- case (wantHiBootFile dflags eps mod from) of
406 Failed err -> return (Failed err)
407 Succeeded hi_boot_file ->
408 -- Stoutly warn against an EPS-updating import
409 -- of one's own boot file! (one-shot only)
410 --See Note [Do not update EPS with your own hi-boot]
411 -- in MkIface.
412 WARN( hi_boot_file &&
413 fmap fst (if_rec_types gbl_env) == Just mod,
414 ppr mod )
415 computeInterface doc_str hi_boot_file mod
416 ; case read_result of {
417 Failed err -> do
418 { let fake_iface = emptyModIface mod
419
420 ; updateEps_ $ \eps ->
421 eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
422 -- Not found, so add an empty iface to
423 -- the EPS map so that we don't look again
424
425 ; return (Failed err) } ;
426
427 -- Found and parsed!
428 -- We used to have a sanity check here that looked for:
429 -- * System importing ..
430 -- * a home package module ..
431 -- * that we know nothing about (mb_dep == Nothing)!
432 --
433 -- But this is no longer valid because thNameToGhcName allows users to
434 -- cause the system to load arbitrary interfaces (by supplying an appropriate
435 -- Template Haskell original-name).
436 Succeeded (iface, loc) ->
437 let
438 loc_doc = text loc
439 in
440 initIfaceLcl (mi_semantic_module iface) loc_doc (mi_boot iface) $ do
441
442 -- Load the new ModIface into the External Package State
443 -- Even home-package interfaces loaded by loadInterface
444 -- (which only happens in OneShot mode; in Batch/Interactive
445 -- mode, home-package modules are loaded one by one into the HPT)
446 -- are put in the EPS.
447 --
448 -- The main thing is to add the ModIface to the PIT, but
449 -- we also take the
450 -- IfaceDecls, IfaceClsInst, IfaceFamInst, IfaceRules, IfaceVectInfo
451 -- out of the ModIface and put them into the big EPS pools
452
453 -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
454 --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
455 -- If we do loadExport first the wrong info gets into the cache (unless we
456 -- explicitly tag each export which seems a bit of a bore)
457
458 ; ignore_prags <- goptM Opt_IgnoreInterfacePragmas
459 ; new_eps_decls <- loadDecls ignore_prags (mi_decls iface)
460 ; new_eps_insts <- mapM tcIfaceInst (mi_insts iface)
461 ; new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
462 ; new_eps_rules <- tcIfaceRules ignore_prags (mi_rules iface)
463 ; new_eps_anns <- tcIfaceAnnotations (mi_anns iface)
464 ; new_eps_vect_info <- tcIfaceVectInfo mod (mkNameEnv new_eps_decls) (mi_vect_info iface)
465
466 ; let { final_iface = iface {
467 mi_decls = panic "No mi_decls in PIT",
468 mi_insts = panic "No mi_insts in PIT",
469 mi_fam_insts = panic "No mi_fam_insts in PIT",
470 mi_rules = panic "No mi_rules in PIT",
471 mi_anns = panic "No mi_anns in PIT"
472 }
473 }
474
475 ; updateEps_ $ \ eps ->
476 if elemModuleEnv mod (eps_PIT eps) || is_external_sig dflags iface
477 then eps else
478 eps {
479 eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
480 eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
481 eps_rule_base = extendRuleBaseList (eps_rule_base eps)
482 new_eps_rules,
483 eps_inst_env = extendInstEnvList (eps_inst_env eps)
484 new_eps_insts,
485 eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
486 new_eps_fam_insts,
487 eps_vect_info = plusVectInfo (eps_vect_info eps)
488 new_eps_vect_info,
489 eps_ann_env = extendAnnEnvList (eps_ann_env eps)
490 new_eps_anns,
491 eps_mod_fam_inst_env
492 = let
493 fam_inst_env =
494 extendFamInstEnvList emptyFamInstEnv
495 new_eps_fam_insts
496 in
497 extendModuleEnv (eps_mod_fam_inst_env eps)
498 mod
499 fam_inst_env,
500 eps_stats = addEpsInStats (eps_stats eps)
501 (length new_eps_decls)
502 (length new_eps_insts)
503 (length new_eps_rules) }
504
505 ; return (Succeeded final_iface)
506 }}}}
507
508 -- | Returns @True@ if a 'ModIface' comes from an external package.
509 -- In this case, we should NOT load it into the EPS; the entities
510 -- should instead come from the local merged signature interface.
511 is_external_sig :: DynFlags -> ModIface -> Bool
512 is_external_sig dflags iface =
513 -- It's a signature iface...
514 mi_semantic_module iface /= mi_module iface &&
515 -- and it's not from the local package
516 moduleUnitId (mi_module iface) /= thisPackage dflags
517
518 -- | This is an improved version of 'findAndReadIface' which can also
519 -- handle the case when a user requests @p[A=<B>]:M@ but we only
520 -- have an interface for @p[A=<A>]:M@ (the indefinite interface.
521 -- If we are not trying to build code, we load the interface we have,
522 -- *instantiating it* according to how the holes are specified.
523 -- (Of course, if we're actually building code, this is a hard error.)
524 --
525 -- In the presence of holes, 'computeInterface' has an important invariant:
526 -- to load module M, its set of transitively reachable requirements must
527 -- have an up-to-date local hi file for that requirement. Note that if
528 -- we are loading the interface of a requirement, this does not
529 -- apply to the requirement itself; e.g., @p[A=<A>]:A@ does not require
530 -- A.hi to be up-to-date (and indeed, we MUST NOT attempt to read A.hi, unless
531 -- we are actually typechecking p.)
532 computeInterface ::
533 SDoc -> IsBootInterface -> Module
534 -> TcRnIf gbl lcl (MaybeErr MsgDoc (ModIface, FilePath))
535 computeInterface doc_str hi_boot_file mod0 = do
536 MASSERT( not (isHoleModule mod0) )
537 dflags <- getDynFlags
538 case splitModuleInsts mod0 of
539 (imod, Just indef) | not (unitIdIsDefinite (thisPackage dflags)) -> do
540 r <- findAndReadIface doc_str imod mod0 hi_boot_file
541 case r of
542 Succeeded (iface0, path) -> do
543 hsc_env <- getTopEnv
544 r <- liftIO $
545 rnModIface hsc_env (indefUnitIdInsts (indefModuleUnitId indef))
546 Nothing iface0
547 case r of
548 Right x -> return (Succeeded (x, path))
549 Left errs -> liftIO . throwIO . mkSrcErr $ errs
550 Failed err -> return (Failed err)
551 (mod, _) ->
552 findAndReadIface doc_str mod mod0 hi_boot_file
553
554 -- | Compute the signatures which must be compiled in order to
555 -- load the interface for a 'Module'. The output of this function
556 -- is always a subset of 'moduleFreeHoles'; it is more precise
557 -- because in signature @p[A=<A>,B=<B>]:B@, although the free holes
558 -- are A and B, B might not depend on A at all!
559 --
560 -- If this is invoked on a signature, this does NOT include the
561 -- signature itself; e.g. precise free module holes of
562 -- @p[A=<A>,B=<B>]:B@ never includes B.
563 moduleFreeHolesPrecise
564 :: SDoc -> Module
565 -> TcRnIf gbl lcl (MaybeErr MsgDoc (UniqDSet ModuleName))
566 moduleFreeHolesPrecise doc_str mod
567 | moduleIsDefinite mod = return (Succeeded emptyUniqDSet)
568 | otherwise =
569 case splitModuleInsts mod of
570 (imod, Just indef) -> do
571 let insts = indefUnitIdInsts (indefModuleUnitId indef)
572 traceIf (text "Considering whether to load" <+> ppr mod <+>
573 text "to compute precise free module holes")
574 (eps, hpt) <- getEpsAndHpt
575 dflags <- getDynFlags
576 case tryEpsAndHpt dflags eps hpt `firstJust` tryDepsCache eps imod insts of
577 Just r -> return (Succeeded r)
578 Nothing -> readAndCache imod insts
579 (_, Nothing) -> return (Succeeded emptyUniqDSet)
580 where
581 tryEpsAndHpt dflags eps hpt =
582 fmap mi_free_holes (lookupIfaceByModule dflags hpt (eps_PIT eps) mod)
583 tryDepsCache eps imod insts =
584 case lookupInstalledModuleEnv (eps_free_holes eps) imod of
585 Just ifhs -> Just (renameFreeHoles ifhs insts)
586 _otherwise -> Nothing
587 readAndCache imod insts = do
588 mb_iface <- findAndReadIface (text "moduleFreeHolesPrecise" <+> doc_str) imod mod False
589 case mb_iface of
590 Succeeded (iface, _) -> do
591 let ifhs = mi_free_holes iface
592 -- Cache it
593 updateEps_ (\eps ->
594 eps { eps_free_holes = extendInstalledModuleEnv (eps_free_holes eps) imod ifhs })
595 return (Succeeded (renameFreeHoles ifhs insts))
596 Failed err -> return (Failed err)
597
598 wantHiBootFile :: DynFlags -> ExternalPackageState -> Module -> WhereFrom
599 -> MaybeErr MsgDoc IsBootInterface
600 -- Figure out whether we want Foo.hi or Foo.hi-boot
601 wantHiBootFile dflags eps mod from
602 = case from of
603 ImportByUser usr_boot
604 | usr_boot && not this_package
605 -> Failed (badSourceImport mod)
606 | otherwise -> Succeeded usr_boot
607
608 ImportByPlugin
609 -> Succeeded False
610
611 ImportBySystem
612 | not this_package -- If the module to be imported is not from this package
613 -> Succeeded False -- don't look it up in eps_is_boot, because that is keyed
614 -- on the ModuleName of *home-package* modules only.
615 -- We never import boot modules from other packages!
616
617 | otherwise
618 -> case lookupUFM (eps_is_boot eps) (moduleName mod) of
619 Just (_, is_boot) -> Succeeded is_boot
620 Nothing -> Succeeded False
621 -- The boot-ness of the requested interface,
622 -- based on the dependencies in directly-imported modules
623 where
624 this_package = thisPackage dflags == moduleUnitId mod
625
626 badSourceImport :: Module -> SDoc
627 badSourceImport mod
628 = hang (text "You cannot {-# SOURCE #-} import a module from another package")
629 2 (text "but" <+> quotes (ppr mod) <+> ptext (sLit "is from package")
630 <+> quotes (ppr (moduleUnitId mod)))
631
632 -----------------------------------------------------
633 -- Loading type/class/value decls
634 -- We pass the full Module name here, replete with
635 -- its package info, so that we can build a Name for
636 -- each binder with the right package info in it
637 -- All subsequent lookups, including crucially lookups during typechecking
638 -- the declaration itself, will find the fully-glorious Name
639 --
640 -- We handle ATs specially. They are not main declarations, but also not
641 -- implicit things (in particular, adding them to `implicitTyThings' would mess
642 -- things up in the renaming/type checking of source programs).
643 -----------------------------------------------------
644
645 addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
646 addDeclsToPTE pte things = extendNameEnvList pte things
647
648 loadDecls :: Bool
649 -> [(Fingerprint, IfaceDecl)]
650 -> IfL [(Name,TyThing)]
651 loadDecls ignore_prags ver_decls
652 = do { thingss <- mapM (loadDecl ignore_prags) ver_decls
653 ; return (concat thingss)
654 }
655
656 loadDecl :: Bool -- Don't load pragmas into the decl pool
657 -> (Fingerprint, IfaceDecl)
658 -> IfL [(Name,TyThing)] -- The list can be poked eagerly, but the
659 -- TyThings are forkM'd thunks
660 loadDecl ignore_prags (_version, decl)
661 = do { -- Populate the name cache with final versions of all
662 -- the names associated with the decl
663 let main_name = ifName decl
664
665 -- Typecheck the thing, lazily
666 -- NB. Firstly, the laziness is there in case we never need the
667 -- declaration (in one-shot mode), and secondly it is there so that
668 -- we don't look up the occurrence of a name before calling mk_new_bndr
669 -- on the binder. This is important because we must get the right name
670 -- which includes its nameParent.
671
672 ; thing <- forkM doc $ do { bumpDeclStats main_name
673 ; tcIfaceDecl ignore_prags decl }
674
675 -- Populate the type environment with the implicitTyThings too.
676 --
677 -- Note [Tricky iface loop]
678 -- ~~~~~~~~~~~~~~~~~~~~~~~~
679 -- Summary: The delicate point here is that 'mini-env' must be
680 -- buildable from 'thing' without demanding any of the things
681 -- 'forkM'd by tcIfaceDecl.
682 --
683 -- In more detail: Consider the example
684 -- data T a = MkT { x :: T a }
685 -- The implicitTyThings of T are: [ <datacon MkT>, <selector x>]
686 -- (plus their workers, wrappers, coercions etc etc)
687 --
688 -- We want to return an environment
689 -- [ "MkT" -> <datacon MkT>, "x" -> <selector x>, ... ]
690 -- (where the "MkT" is the *Name* associated with MkT, etc.)
691 --
692 -- We do this by mapping the implicit_names to the associated
693 -- TyThings. By the invariant on ifaceDeclImplicitBndrs and
694 -- implicitTyThings, we can use getOccName on the implicit
695 -- TyThings to make this association: each Name's OccName should
696 -- be the OccName of exactly one implicitTyThing. So the key is
697 -- to define a "mini-env"
698 --
699 -- [ 'MkT' -> <datacon MkT>, 'x' -> <selector x>, ... ]
700 -- where the 'MkT' here is the *OccName* associated with MkT.
701 --
702 -- However, there is a subtlety: due to how type checking needs
703 -- to be staged, we can't poke on the forkM'd thunks inside the
704 -- implicitTyThings while building this mini-env.
705 -- If we poke these thunks too early, two problems could happen:
706 -- (1) When processing mutually recursive modules across
707 -- hs-boot boundaries, poking too early will do the
708 -- type-checking before the recursive knot has been tied,
709 -- so things will be type-checked in the wrong
710 -- environment, and necessary variables won't be in
711 -- scope.
712 --
713 -- (2) Looking up one OccName in the mini_env will cause
714 -- others to be looked up, which might cause that
715 -- original one to be looked up again, and hence loop.
716 --
717 -- The code below works because of the following invariant:
718 -- getOccName on a TyThing does not force the suspended type
719 -- checks in order to extract the name. For example, we don't
720 -- poke on the "T a" type of <selector x> on the way to
721 -- extracting <selector x>'s OccName. Of course, there is no
722 -- reason in principle why getting the OccName should force the
723 -- thunks, but this means we need to be careful in
724 -- implicitTyThings and its helper functions.
725 --
726 -- All a bit too finely-balanced for my liking.
727
728 -- This mini-env and lookup function mediates between the
729 --'Name's n and the map from 'OccName's to the implicit TyThings
730 ; let mini_env = mkOccEnv [(getOccName t, t) | t <- implicitTyThings thing]
731 lookup n = case lookupOccEnv mini_env (getOccName n) of
732 Just thing -> thing
733 Nothing ->
734 pprPanic "loadDecl" (ppr main_name <+> ppr n $$ ppr (decl))
735
736 ; implicit_names <- mapM lookupIfaceTop (ifaceDeclImplicitBndrs decl)
737
738 -- ; traceIf (text "Loading decl for " <> ppr main_name $$ ppr implicit_names)
739 ; return $ (main_name, thing) :
740 -- uses the invariant that implicit_names and
741 -- implicitTyThings are bijective
742 [(n, lookup n) | n <- implicit_names]
743 }
744 where
745 doc = text "Declaration for" <+> ppr (ifName decl)
746
747 bumpDeclStats :: Name -> IfL () -- Record that one more declaration has actually been used
748 bumpDeclStats name
749 = do { traceIf (text "Loading decl for" <+> ppr name)
750 ; updateEps_ (\eps -> let stats = eps_stats eps
751 in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
752 }
753
754 {-
755 *********************************************************
756 * *
757 \subsection{Reading an interface file}
758 * *
759 *********************************************************
760
761 Note [Home module load error]
762 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
763 If the sought-for interface is in the current package (as determined
764 by -package-name flag) then it jolly well should already be in the HPT
765 because we process home-package modules in dependency order. (Except
766 in one-shot mode; see notes with hsc_HPT decl in HscTypes).
767
768 It is possible (though hard) to get this error through user behaviour.
769 * Suppose package P (modules P1, P2) depends on package Q (modules Q1,
770 Q2, with Q2 importing Q1)
771 * We compile both packages.
772 * Now we edit package Q so that it somehow depends on P
773 * Now recompile Q with --make (without recompiling P).
774 * Then Q1 imports, say, P1, which in turn depends on Q2. So Q2
775 is a home-package module which is not yet in the HPT! Disaster.
776
777 This actually happened with P=base, Q=ghc-prim, via the AMP warnings.
778 See Trac #8320.
779 -}
780
781 findAndReadIface :: SDoc
782 -- The unique identifier of the on-disk module we're
783 -- looking for
784 -> InstalledModule
785 -- The *actual* module we're looking for. We use
786 -- this to check the consistency of the requirements
787 -- of the module we read out.
788 -> Module
789 -> IsBootInterface -- True <=> Look for a .hi-boot file
790 -- False <=> Look for .hi file
791 -> TcRnIf gbl lcl (MaybeErr MsgDoc (ModIface, FilePath))
792 -- Nothing <=> file not found, or unreadable, or illegible
793 -- Just x <=> successfully found and parsed
794
795 -- It *doesn't* add an error to the monad, because
796 -- sometimes it's ok to fail... see notes with loadInterface
797 findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
798 = do traceIf (sep [hsep [text "Reading",
799 if hi_boot_file
800 then text "[boot]"
801 else Outputable.empty,
802 text "interface for",
803 ppr mod <> semi],
804 nest 4 (text "reason:" <+> doc_str)])
805
806 -- Check for GHC.Prim, and return its static interface
807 -- TODO: make this check a function
808 if mod `installedModuleEq` gHC_PRIM
809 then do
810 iface <- getHooked ghcPrimIfaceHook ghcPrimIface
811 return (Succeeded (iface,
812 "<built in interface for GHC.Prim>"))
813 else do
814 dflags <- getDynFlags
815 -- Look for the file
816 hsc_env <- getTopEnv
817 mb_found <- liftIO (findExactModule hsc_env mod)
818 case mb_found of
819 InstalledFound loc mod -> do
820 -- Found file, so read it
821 let file_path = addBootSuffix_maybe hi_boot_file
822 (ml_hi_file loc)
823
824 -- See Note [Home module load error]
825 if installedModuleUnitId mod `installedUnitIdEq` thisPackage dflags &&
826 not (isOneShot (ghcMode dflags))
827 then return (Failed (homeModError mod loc))
828 else do r <- read_file file_path
829 checkBuildDynamicToo r
830 return r
831 err -> do
832 traceIf (text "...not found")
833 dflags <- getDynFlags
834 return (Failed (cannotFindInterface dflags
835 (installedModuleName mod) err))
836 where read_file file_path = do
837 traceIf (text "readIFace" <+> text file_path)
838 -- Figure out what is recorded in mi_module. If this is
839 -- a fully definite interface, it'll match exactly, but
840 -- if it's indefinite, the inside will be uninstantiated!
841 dflags <- getDynFlags
842 let wanted_mod =
843 case splitModuleInsts wanted_mod_with_insts of
844 (_, Nothing) -> wanted_mod_with_insts
845 (_, Just indef_mod) ->
846 indefModuleToModule dflags
847 (generalizeIndefModule indef_mod)
848 read_result <- readIface wanted_mod file_path
849 case read_result of
850 Failed err -> return (Failed (badIfaceFile file_path err))
851 Succeeded iface -> return (Succeeded (iface, file_path))
852 -- Don't forget to fill in the package name...
853 checkBuildDynamicToo (Succeeded (iface, filePath)) = do
854 dflags <- getDynFlags
855 -- Indefinite interfaces are ALWAYS non-dynamic, and
856 -- that's OK.
857 let is_definite_iface = moduleIsDefinite (mi_module iface)
858 when is_definite_iface $
859 whenGeneratingDynamicToo dflags $ withDoDynamicToo $ do
860 let ref = canGenerateDynamicToo dflags
861 dynFilePath = addBootSuffix_maybe hi_boot_file
862 $ replaceExtension filePath (dynHiSuf dflags)
863 r <- read_file dynFilePath
864 case r of
865 Succeeded (dynIface, _)
866 | mi_mod_hash iface == mi_mod_hash dynIface ->
867 return ()
868 | otherwise ->
869 do traceIf (text "Dynamic hash doesn't match")
870 liftIO $ writeIORef ref False
871 Failed err ->
872 do traceIf (text "Failed to load dynamic interface file:" $$ err)
873 liftIO $ writeIORef ref False
874 checkBuildDynamicToo _ = return ()
875
876 -- @readIface@ tries just the one file.
877
878 readIface :: Module -> FilePath
879 -> TcRnIf gbl lcl (MaybeErr MsgDoc ModIface)
880 -- Failed err <=> file not found, or unreadable, or illegible
881 -- Succeeded iface <=> successfully found and parsed
882
883 readIface wanted_mod file_path
884 = do { res <- tryMostM $
885 readBinIface CheckHiWay QuietBinIFaceReading file_path
886 ; dflags <- getDynFlags
887 ; case res of
888 Right iface
889 -- NB: This check is NOT just a sanity check, it is
890 -- critical for correctness of recompilation checking
891 -- (it lets us tell when -this-unit-id has changed.)
892 | wanted_mod == actual_mod
893 -> return (Succeeded iface)
894 | otherwise -> return (Failed err)
895 where
896 actual_mod = mi_module iface
897 err = hiModuleNameMismatchWarn dflags wanted_mod actual_mod
898
899 Left exn -> return (Failed (text (showException exn)))
900 }
901
902 {-
903 *********************************************************
904 * *
905 Wired-in interface for GHC.Prim
906 * *
907 *********************************************************
908 -}
909
910 initExternalPackageState :: ExternalPackageState
911 initExternalPackageState
912 = EPS {
913 eps_is_boot = emptyUFM,
914 eps_PIT = emptyPackageIfaceTable,
915 eps_free_holes = emptyInstalledModuleEnv,
916 eps_PTE = emptyTypeEnv,
917 eps_inst_env = emptyInstEnv,
918 eps_fam_inst_env = emptyFamInstEnv,
919 eps_rule_base = mkRuleBase builtinRules,
920 -- Initialise the EPS rule pool with the built-in rules
921 eps_mod_fam_inst_env
922 = emptyModuleEnv,
923 eps_vect_info = noVectInfo,
924 eps_ann_env = emptyAnnEnv,
925 eps_stats = EpsStats { n_ifaces_in = 0, n_decls_in = 0, n_decls_out = 0
926 , n_insts_in = 0, n_insts_out = 0
927 , n_rules_in = length builtinRules, n_rules_out = 0 }
928 }
929
930 {-
931 *********************************************************
932 * *
933 Wired-in interface for GHC.Prim
934 * *
935 *********************************************************
936 -}
937
938 ghcPrimIface :: ModIface
939 ghcPrimIface
940 = (emptyModIface gHC_PRIM) {
941 mi_exports = ghcPrimExports,
942 mi_decls = [],
943 mi_fixities = fixities,
944 mi_fix_fn = mkIfaceFixCache fixities
945 }
946 where
947 fixities = (getOccName seqId, Fixity NoSourceText 0 InfixR)
948 -- seq is infixr 0
949 : (occName funTyConName, funTyFixity) -- trac #10145
950 : mapMaybe mkFixity allThePrimOps
951 mkFixity op = (,) (primOpOcc op) <$> primOpFixity op
952
953 {-
954 *********************************************************
955 * *
956 \subsection{Statistics}
957 * *
958 *********************************************************
959 -}
960
961 ifaceStats :: ExternalPackageState -> SDoc
962 ifaceStats eps
963 = hcat [text "Renamer stats: ", msg]
964 where
965 stats = eps_stats eps
966 msg = vcat
967 [int (n_ifaces_in stats) <+> text "interfaces read",
968 hsep [ int (n_decls_out stats), text "type/class/variable imported, out of",
969 int (n_decls_in stats), text "read"],
970 hsep [ int (n_insts_out stats), text "instance decls imported, out of",
971 int (n_insts_in stats), text "read"],
972 hsep [ int (n_rules_out stats), text "rule decls imported, out of",
973 int (n_rules_in stats), text "read"]
974 ]
975
976 {-
977 ************************************************************************
978 * *
979 Printing interfaces
980 * *
981 ************************************************************************
982 -}
983
984 -- | Read binary interface, and print it out
985 showIface :: HscEnv -> FilePath -> IO ()
986 showIface hsc_env filename = do
987 -- skip the hi way check; we don't want to worry about profiled vs.
988 -- non-profiled interfaces, for example.
989 iface <- initTcRnIf 's' hsc_env () () $
990 readBinIface IgnoreHiWay TraceBinIFaceReading filename
991 let dflags = hsc_dflags hsc_env
992 log_action dflags dflags NoReason SevDump noSrcSpan
993 (defaultDumpStyle dflags) (pprModIface iface)
994
995 -- Show a ModIface but don't display details; suitable for ModIfaces stored in
996 -- the EPT.
997 pprModIfaceSimple :: ModIface -> SDoc
998 pprModIfaceSimple iface = ppr (mi_module iface) $$ pprDeps (mi_deps iface) $$ nest 2 (vcat (map pprExport (mi_exports iface)))
999
1000 pprModIface :: ModIface -> SDoc
1001 -- Show a ModIface
1002 pprModIface iface
1003 = vcat [ text "interface"
1004 <+> ppr (mi_module iface) <+> pp_hsc_src (mi_hsc_src iface)
1005 <+> (if mi_orphan iface then text "[orphan module]" else Outputable.empty)
1006 <+> (if mi_finsts iface then text "[family instance module]" else Outputable.empty)
1007 <+> (if mi_hpc iface then text "[hpc]" else Outputable.empty)
1008 <+> integer hiVersion
1009 , nest 2 (text "interface hash:" <+> ppr (mi_iface_hash iface))
1010 , nest 2 (text "ABI hash:" <+> ppr (mi_mod_hash iface))
1011 , nest 2 (text "export-list hash:" <+> ppr (mi_exp_hash iface))
1012 , nest 2 (text "orphan hash:" <+> ppr (mi_orphan_hash iface))
1013 , nest 2 (text "flag hash:" <+> ppr (mi_flag_hash iface))
1014 , nest 2 (text "sig of:" <+> ppr (mi_sig_of iface))
1015 , nest 2 (text "used TH splices:" <+> ppr (mi_used_th iface))
1016 , nest 2 (text "where")
1017 , text "exports:"
1018 , nest 2 (vcat (map pprExport (mi_exports iface)))
1019 , pprDeps (mi_deps iface)
1020 , vcat (map pprUsage (mi_usages iface))
1021 , vcat (map pprIfaceAnnotation (mi_anns iface))
1022 , pprFixities (mi_fixities iface)
1023 , vcat [ppr ver $$ nest 2 (ppr decl) | (ver,decl) <- mi_decls iface]
1024 , vcat (map ppr (mi_insts iface))
1025 , vcat (map ppr (mi_fam_insts iface))
1026 , vcat (map ppr (mi_rules iface))
1027 , pprVectInfo (mi_vect_info iface)
1028 , ppr (mi_warns iface)
1029 , pprTrustInfo (mi_trust iface)
1030 , pprTrustPkg (mi_trust_pkg iface)
1031 , vcat (map ppr (mi_complete_sigs iface))
1032 ]
1033 where
1034 pp_hsc_src HsBootFile = text "[boot]"
1035 pp_hsc_src HsigFile = text "[hsig]"
1036 pp_hsc_src HsSrcFile = Outputable.empty
1037
1038 {-
1039 When printing export lists, we print like this:
1040 Avail f f
1041 AvailTC C [C, x, y] C(x,y)
1042 AvailTC C [x, y] C!(x,y) -- Exporting x, y but not C
1043 -}
1044
1045 pprExport :: IfaceExport -> SDoc
1046 pprExport (Avail n) = ppr n
1047 pprExport (AvailTC _ [] []) = Outputable.empty
1048 pprExport (AvailTC n ns0 fs)
1049 = case ns0 of
1050 (n':ns) | n==n' -> ppr n <> pp_export ns fs
1051 _ -> ppr n <> vbar <> pp_export ns0 fs
1052 where
1053 pp_export [] [] = Outputable.empty
1054 pp_export names fs = braces (hsep (map ppr names ++ map (ppr . flLabel) fs))
1055
1056 pprUsage :: Usage -> SDoc
1057 pprUsage usage@UsagePackageModule{}
1058 = pprUsageImport usage usg_mod
1059 pprUsage usage@UsageHomeModule{}
1060 = pprUsageImport usage usg_mod_name $$
1061 nest 2 (
1062 maybe Outputable.empty (\v -> text "exports: " <> ppr v) (usg_exports usage) $$
1063 vcat [ ppr n <+> ppr v | (n,v) <- usg_entities usage ]
1064 )
1065 pprUsage usage@UsageFile{}
1066 = hsep [text "addDependentFile",
1067 doubleQuotes (text (usg_file_path usage))]
1068 pprUsage usage@UsageMergedRequirement{}
1069 = hsep [text "merged", ppr (usg_mod usage), ppr (usg_mod_hash usage)]
1070
1071 pprUsageImport :: Outputable a => Usage -> (Usage -> a) -> SDoc
1072 pprUsageImport usage usg_mod'
1073 = hsep [text "import", safe, ppr (usg_mod' usage),
1074 ppr (usg_mod_hash usage)]
1075 where
1076 safe | usg_safe usage = text "safe"
1077 | otherwise = text " -/ "
1078
1079 pprDeps :: Dependencies -> SDoc
1080 pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs,
1081 dep_finsts = finsts })
1082 = vcat [text "module dependencies:" <+> fsep (map ppr_mod mods),
1083 text "package dependencies:" <+> fsep (map ppr_pkg pkgs),
1084 text "orphans:" <+> fsep (map ppr orphs),
1085 text "family instance modules:" <+> fsep (map ppr finsts)
1086 ]
1087 where
1088 ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
1089 ppr_pkg (pkg,trust_req) = ppr pkg <>
1090 (if trust_req then text "*" else Outputable.empty)
1091 ppr_boot True = text "[boot]"
1092 ppr_boot False = Outputable.empty
1093
1094 pprFixities :: [(OccName, Fixity)] -> SDoc
1095 pprFixities [] = Outputable.empty
1096 pprFixities fixes = text "fixities" <+> pprWithCommas pprFix fixes
1097 where
1098 pprFix (occ,fix) = ppr fix <+> ppr occ
1099
1100 pprVectInfo :: IfaceVectInfo -> SDoc
1101 pprVectInfo (IfaceVectInfo { ifaceVectInfoVar = vars
1102 , ifaceVectInfoTyCon = tycons
1103 , ifaceVectInfoTyConReuse = tyconsReuse
1104 , ifaceVectInfoParallelVars = parallelVars
1105 , ifaceVectInfoParallelTyCons = parallelTyCons
1106 }) =
1107 vcat
1108 [ text "vectorised variables:" <+> hsep (map ppr vars)
1109 , text "vectorised tycons:" <+> hsep (map ppr tycons)
1110 , text "vectorised reused tycons:" <+> hsep (map ppr tyconsReuse)
1111 , text "parallel variables:" <+> hsep (map ppr parallelVars)
1112 , text "parallel tycons:" <+> hsep (map ppr parallelTyCons)
1113 ]
1114
1115 pprTrustInfo :: IfaceTrustInfo -> SDoc
1116 pprTrustInfo trust = text "trusted:" <+> ppr trust
1117
1118 pprTrustPkg :: Bool -> SDoc
1119 pprTrustPkg tpkg = text "require own pkg trusted:" <+> ppr tpkg
1120
1121 instance Outputable Warnings where
1122 ppr = pprWarns
1123
1124 pprWarns :: Warnings -> SDoc
1125 pprWarns NoWarnings = Outputable.empty
1126 pprWarns (WarnAll txt) = text "Warn all" <+> ppr txt
1127 pprWarns (WarnSome prs) = text "Warnings"
1128 <+> vcat (map pprWarning prs)
1129 where pprWarning (name, txt) = ppr name <+> ppr txt
1130
1131 pprIfaceAnnotation :: IfaceAnnotation -> SDoc
1132 pprIfaceAnnotation (IfaceAnnotation { ifAnnotatedTarget = target, ifAnnotatedValue = serialized })
1133 = ppr target <+> text "annotated by" <+> ppr serialized
1134
1135 {-
1136 *********************************************************
1137 * *
1138 \subsection{Errors}
1139 * *
1140 *********************************************************
1141 -}
1142
1143 badIfaceFile :: String -> SDoc -> SDoc
1144 badIfaceFile file err
1145 = vcat [text "Bad interface file:" <+> text file,
1146 nest 4 err]
1147
1148 hiModuleNameMismatchWarn :: DynFlags -> Module -> Module -> MsgDoc
1149 hiModuleNameMismatchWarn dflags requested_mod read_mod
1150 | moduleUnitId requested_mod == moduleUnitId read_mod =
1151 sep [text "Interface file contains module" <+> quotes (ppr read_mod) <> comma,
1152 text "but we were expecting module" <+> quotes (ppr requested_mod),
1153 sep [text "Probable cause: the source code which generated interface file",
1154 text "has an incompatible module name"
1155 ]
1156 ]
1157 | otherwise =
1158 -- ToDo: This will fail to have enough qualification when the package IDs
1159 -- are the same
1160 withPprStyle (mkUserStyle dflags alwaysQualify AllTheWay) $
1161 -- we want the Modules below to be qualified with package names,
1162 -- so reset the PrintUnqualified setting.
1163 hsep [ text "Something is amiss; requested module "
1164 , ppr requested_mod
1165 , text "differs from name found in the interface file"
1166 , ppr read_mod
1167 , parens (text "if these names look the same, try again with -dppr-debug")
1168 ]
1169
1170 homeModError :: InstalledModule -> ModLocation -> SDoc
1171 -- See Note [Home module load error]
1172 homeModError mod location
1173 = text "attempting to use module " <> quotes (ppr mod)
1174 <> (case ml_hs_file location of
1175 Just file -> space <> parens (text file)
1176 Nothing -> Outputable.empty)
1177 <+> text "which is not loaded"