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