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