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