2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section{Dealing with interface files}
8 loadHomeInterface, loadInterface,
9 loadSrcInterface, loadOrphanModules,
10 readIface, -- Used when reading the module's old interface
11 predInstGates, ifaceInstGates, ifaceStats, discardDeclPrags,
12 initExternalPackageState
15 #include "HsVersions.h"
17 import {-# SOURCE #-} TcIface( tcIfaceDecl )
19 import DriverState ( v_GhcMode, isCompManagerMode )
20 import DriverUtil ( replaceFilenameSuffix )
21 import CmdLineOpts ( DynFlags( verbosity ), DynFlag( Opt_IgnoreInterfacePragmas ),
23 import Parser ( parseIface )
25 import IfaceSyn ( IfaceDecl(..), IfaceConDecl(..), IfaceClassOp(..), IfaceConDecls(..),
26 IfaceInst(..), IfaceRule(..), IfaceExpr(..), IfaceTyCon(..), IfaceIdInfo(..),
27 IfaceType(..), IfacePredType(..), IfaceExtName, mkIfaceExtName )
28 import IfaceEnv ( newGlobalBinder, lookupIfaceExt, lookupIfaceTc )
29 import HscTypes ( ModIface(..), TyThing, emptyModIface, EpsStats(..), addEpsInStats,
30 ExternalPackageState(..), PackageTypeEnv, emptyTypeEnv,
31 lookupIfaceByModName, emptyPackageIfaceTable,
32 IsBootInterface, mkIfaceFixCache, Gated, implicitTyThings,
33 addRulesToPool, addInstsToPool
36 import BasicTypes ( Version, Fixity(..), FixityDirection(..), isMarkedStrict )
37 import TcType ( Type, tcSplitTyConApp_maybe )
38 import Type ( funTyCon )
41 import PrelNames ( gHC_PRIM_Name )
42 import PrelInfo ( ghcPrimExports )
43 import PrelRules ( builtinRules )
44 import Rules ( emptyRuleBase )
45 import InstEnv ( emptyInstEnv )
46 import Name ( Name {-instance NamedThing-}, getOccName,
47 nameModuleName, isInternalName )
50 import Packages ( basePackage )
51 import Module ( Module, ModuleName, ModLocation(ml_hi_file),
52 moduleName, isHomeModule, emptyModuleEnv,
53 extendModuleEnv, lookupModuleEnvByName, moduleUserString
55 import OccName ( OccName, mkOccEnv, lookupOccEnv, mkClassTyConOcc, mkClassDataConOcc,
56 mkSuperDictSelOcc, mkDataConWrapperOcc, mkDataConWorkerOcc )
57 import Class ( Class, className )
58 import TyCon ( tyConName )
59 import SrcLoc ( mkSrcLoc, importedSrcLoc )
60 import Maybes ( isJust, mapCatMaybes )
61 import StringBuffer ( hGetStringBuffer )
62 import FastString ( mkFastString )
63 import ErrUtils ( Message, mkLocMessage )
64 import Finder ( findModule, findPackageModule,
65 hiBootExt, hiBootVerExt )
68 import BinIface ( readBinIface )
72 import DATA_IOREF ( readIORef )
78 %************************************************************************
80 loadSrcInterface, loadOrphanModules
82 These two are called from TcM-land
84 %************************************************************************
87 loadSrcInterface :: SDoc -> ModuleName -> IsBootInterface -> RnM ModIface
88 -- This is called for each 'import' declaration in the source code
89 -- On a failure, fail in the monad with an error message
91 loadSrcInterface doc mod_name want_boot
92 = do { mb_iface <- initIfaceTcRn $ loadInterface doc mod_name
93 (ImportByUser want_boot)
95 Left err -> failWithTc (elaborate err)
96 Right iface -> return iface
99 elaborate err = hang (ptext SLIT("Failed to load interface for") <+>
100 quotes (ppr mod_name) <> colon) 4 err
102 loadOrphanModules :: [ModuleName] -> TcM ()
103 loadOrphanModules mods
104 | null mods = returnM ()
105 | otherwise = initIfaceTcRn $
106 do { traceIf (text "Loading orphan modules:" <+>
111 load mod = loadSysInterface (mk_doc mod) mod
112 mk_doc mod = ppr mod <+> ptext SLIT("is a orphan-instance module")
115 %*********************************************************
118 Called from Iface-land
120 %*********************************************************
123 loadHomeInterface :: SDoc -> Name -> IfM lcl ModIface
124 loadHomeInterface doc name
125 = ASSERT2( not (isInternalName name), ppr name <+> parens doc )
126 loadSysInterface doc (nameModuleName name)
128 loadSysInterface :: SDoc -> ModuleName -> IfM lcl ModIface
129 -- A wrapper for loadInterface that Throws an exception if it fails
130 loadSysInterface doc mod_name
131 = do { mb_iface <- loadInterface doc mod_name ImportBySystem
133 Left err -> ghcError (ProgramError (showSDoc err))
134 Right iface -> return iface }
138 %*********************************************************
142 The main function to load an interface
143 for an imported module, and put it in
144 the External Package State
146 %*********************************************************
149 loadInterface :: SDoc -> ModuleName -> WhereFrom
150 -> IfM lcl (Either Message ModIface)
151 -- If it can't find a suitable interface file, we
152 -- a) modify the PackageIfaceTable to have an empty entry
153 -- (to avoid repeated complaints)
154 -- b) return (Left message)
156 -- It's not necessarily an error for there not to be an interface
157 -- file -- perhaps the module has changed, and that interface
158 -- is no longer used -- but the caller can deal with that by
159 -- catching the exception
161 loadInterface doc_str mod_name from
162 = do { -- Read the state
163 (eps,hpt) <- getEpsAndHpt
165 -- Check whether we have the interface already
166 ; case lookupIfaceByModName hpt (eps_PIT eps) mod_name of {
168 -> returnM (Right iface) ; -- Already loaded
169 -- The (src_imp == mi_boot iface) test checks that the already-loaded
170 -- interface isn't a boot iface. This can conceivably happen,
171 -- if an earlier import had a before we got to real imports. I think.
174 { let { hi_boot_file = case from of
175 ImportByUser usr_boot -> usr_boot
176 ImportBySystem -> sys_boot
178 ; mb_dep = lookupModuleEnvByName (eps_is_boot eps) mod_name
179 ; sys_boot = case mb_dep of
180 Just (_, is_boot) -> is_boot
182 -- The boot-ness of the requested interface,
183 } -- based on the dependencies in directly-imported modules
185 -- READ THE MODULE IN
186 ; read_result <- findAndReadIface doc_str mod_name hi_boot_file
187 ; case read_result of {
189 { let fake_iface = emptyModIface opt_InPackage mod_name
191 ; updateEps_ $ \eps ->
192 eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
193 -- Not found, so add an empty iface to
194 -- the EPS map so that we don't look again
196 ; returnM (Left err) } ;
201 let { mod = mi_module iface
202 ; mod_name = moduleName mod } in
204 -- Sanity check. If we're system-importing a module we know nothing at all
205 -- about, it should be from a different package to this one
206 WARN( case from of { ImportBySystem -> True; other -> False } &&
207 not (isJust mb_dep) &&
209 ppr mod $$ ppr mb_dep $$ ppr (eps_is_boot eps) )
211 initIfaceLcl mod_name $ do
212 -- Load the new ModIface into the External Package State
213 -- Even home-package interfaces loaded by loadInterface
214 -- (which only happens in OneShot mode; in Batch/Interactive
215 -- mode, home-package modules are loaded one by one into the HPT)
216 -- are put in the EPS.
218 -- The main thing is to add the ModIface to the PIT, but
220 -- IfaceDecls, IfaceInst, IfaceRules
221 -- out of the ModIface and put them into the big EPS pools
223 -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
224 --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
225 -- If we do loadExport first the wrong info gets into the cache (unless we
226 -- explicitly tag each export which seems a bit of a bore)
228 { ignore_prags <- doptM Opt_IgnoreInterfacePragmas
229 ; new_eps_decls <- loadDecls ignore_prags mod (mi_decls iface)
230 ; new_eps_rules <- loadRules ignore_prags mod_name (mi_rules iface)
231 ; new_eps_insts <- loadInsts mod_name (mi_insts iface)
233 ; let { final_iface = iface { mi_decls = panic "No mi_decls in PIT",
234 mi_insts = panic "No mi_insts in PIT",
235 mi_rules = panic "No mi_rules in PIT" } }
237 ; traceIf (text "Extending PTE" <+> ppr (map fst (concat new_eps_decls)))
239 ; updateEps_ $ \ eps ->
240 eps { eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
241 eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
242 eps_rules = addRulesToPool (eps_rules eps) new_eps_rules,
243 eps_insts = addInstsToPool (eps_insts eps) new_eps_insts,
244 eps_stats = addEpsInStats (eps_stats eps) (length new_eps_decls)
245 (length new_eps_insts) (length new_eps_rules) }
247 ; return (Right final_iface)
250 -----------------------------------------------------
251 -- Loading type/class/value decls
252 -- We pass the full Module name here, replete with
253 -- its package info, so that we can build a Name for
254 -- each binder with the right package info in it
255 -- All subsequent lookups, including crucially lookups during typechecking
256 -- the declaration itself, will find the fully-glorious Name
257 -----------------------------------------------------
259 addDeclsToPTE :: PackageTypeEnv -> [[(Name,TyThing)]] -> PackageTypeEnv
260 addDeclsToPTE pte things = foldl extendNameEnvList pte things
262 loadDecls :: Bool -- Don't load pragmas into the decl pool
264 -> [(Version, IfaceDecl)]
265 -> IfL [[(Name,TyThing)]] -- The list can be poked eagerly, but the
266 -- TyThings are forkM'd thunks
267 loadDecls ignore_prags mod decls = mapM (loadDecl ignore_prags mod) decls
269 loadDecl ignore_prags mod (_version, decl)
270 = do { -- Populate the name cache with final versions of all
271 -- the names associated with the decl
272 main_name <- mk_new_bndr Nothing (ifName decl)
273 ; implicit_names <- mapM (mk_new_bndr (Just main_name)) (ifaceDeclSubBndrs decl)
275 -- Typecheck the thing, lazily
276 ; thing <- forkM doc (bumpDeclStats main_name >> tcIfaceDecl stripped_decl)
277 ; let mini_env = mkOccEnv [(getOccName t, t) | t <- implicitTyThings thing]
278 lookup n = case lookupOccEnv mini_env (getOccName n) of
280 Nothing -> pprPanic "loadDecl" (ppr main_name <+> ppr n)
282 ; returnM ((main_name, thing) : [(n, lookup n) | n <- implicit_names]) }
283 -- We build a list from the *known* names, with (lookup n) thunks
284 -- as the TyThings. That way we can extend the PTE without poking the
287 stripped_decl | ignore_prags = discardDeclPrags decl
290 -- mk_new_bndr allocates in the name cache the final canonical
291 -- name for the thing, with the correct
295 -- imported name, to fix the module correctly in the cache
296 mk_new_bndr mb_parent occ = newGlobalBinder mod occ mb_parent loc
297 loc = importedSrcLoc (moduleUserString mod)
298 doc = ptext SLIT("Declaration for") <+> ppr (ifName decl)
300 discardDeclPrags :: IfaceDecl -> IfaceDecl
301 discardDeclPrags decl@(IfaceId {ifIdInfo = HasInfo _}) = decl { ifIdInfo = NoInfo }
302 discardDeclPrags decl = decl
304 bumpDeclStats :: Name -> IfL () -- Record that one more declaration has actually been used
306 = do { traceIf (text "Loading decl for" <+> ppr name)
307 ; updateEps_ (\eps -> let stats = eps_stats eps
308 in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
312 ifaceDeclSubBndrs :: IfaceDecl -> [OccName]
313 -- *Excludes* the 'main' name, but *includes* the implicitly-bound names
314 -- Deeply revolting, because it has to predict what gets bound,
315 -- especially the question of whether there's a wrapper for a datacon
317 ifaceDeclSubBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_occ, ifSigs = sigs })
318 = [tc_occ, dc_occ, dcww_occ] ++
319 [op | IfaceClassOp op _ _ <- sigs] ++
320 [mkSuperDictSelOcc n cls_occ | n <- [1..n_ctxt]]
322 n_ctxt = length sc_ctxt
324 tc_occ = mkClassTyConOcc cls_occ
325 dc_occ = mkClassDataConOcc cls_occ
326 dcww_occ | is_newtype = mkDataConWrapperOcc dc_occ -- Newtypes have wrapper but no worker
327 | otherwise = mkDataConWorkerOcc dc_occ -- Otherwise worker but no wrapper
328 is_newtype = n_sigs + n_ctxt == 1 -- Sigh
330 ifaceDeclSubBndrs (IfaceData {ifCons = IfAbstractTyCon})
333 ifaceDeclSubBndrs (IfaceData {ifCons = IfNewTyCon (IfVanillaCon { ifConOcc = con_occ,
334 ifConFields = fields})})
335 = fields ++ [con_occ, mkDataConWrapperOcc con_occ]
336 -- Wrapper, no worker; see MkId.mkDataConIds
338 ifaceDeclSubBndrs (IfaceData {ifCons = IfDataTyCon _ cons})
339 = nub (concatMap fld_occs cons) -- Eliminate duplicate fields
340 ++ concatMap dc_occs cons
342 fld_occs (IfVanillaCon { ifConFields = fields }) = fields
343 fld_occs (IfGadtCon {}) = []
345 | has_wrapper = [con_occ, work_occ, wrap_occ]
346 | otherwise = [con_occ, work_occ]
348 con_occ = ifConOcc con_decl
349 strs = ifConStricts con_decl
350 wrap_occ = mkDataConWrapperOcc con_occ
351 work_occ = mkDataConWorkerOcc con_occ
352 has_wrapper = any isMarkedStrict strs -- See MkId.mkDataConIds (sigh)
353 -- ToDo: may miss strictness in existential dicts
355 ifaceDeclSubBndrs _other = []
357 -----------------------------------------------------
358 -- Loading instance decls
359 -----------------------------------------------------
361 loadInsts :: ModuleName -> [IfaceInst] -> IfL [(Name, Gated IfaceInst)]
362 loadInsts mod decls = mapM (loadInstDecl mod) decls
364 loadInstDecl mod decl@(IfaceInst {ifInstHead = inst_ty})
366 -- Find out what type constructors and classes are "gates" for the
367 -- instance declaration. If all these "gates" are slurped in then
368 -- we should slurp the instance decl too.
370 -- We *don't* want to count names in the context part as gates, though.
372 -- instance Foo a => Baz (T a) where ...
374 -- Here the gates are Baz and T, but *not* Foo.
376 -- HOWEVER: functional dependencies make things more complicated
377 -- class C a b | a->b where ...
378 -- instance C Foo Baz where ...
379 -- Here, the gates are really only C and Foo, *not* Baz.
380 -- That is, if C and Foo are visible, even if Baz isn't, we must
383 -- Rather than take fundeps into account "properly", we just slurp
384 -- if C is visible and *any one* of the Names in the types
385 -- This is a slightly brutal approximation, but most instance decls
386 -- are regular H98 ones and it's perfect for them.
388 -- NOTICE that we rename the type before extracting its free
389 -- variables. The free-variable finder for a renamed HsType
390 -- does the Right Thing for built-in syntax like [] and (,).
391 let { (cls_ext, tc_exts) = ifaceInstGates inst_ty }
392 ; cls <- lookupIfaceExt cls_ext
393 ; tcs <- mapM lookupIfaceTc tc_exts
394 ; returnM (cls, (tcs, (mod,decl)))
397 -----------------------------------------------------
399 -----------------------------------------------------
401 loadRules :: Bool -- Don't load pragmas into the decl pool
403 -> [IfaceRule] -> IfL [Gated IfaceRule]
404 loadRules ignore_prags mod rules
405 | ignore_prags = returnM []
406 | otherwise = mapM (loadRule mod) rules
408 loadRule :: ModuleName -> IfaceRule -> IfL (Gated IfaceRule)
409 -- "Gate" the rule simply by a crude notion of the free vars of
410 -- the LHS. It can be crude, because having too few free vars is safe.
411 loadRule mod decl@(IfaceRule {ifRuleHead = fn, ifRuleArgs = args})
412 = do { names <- mapM lookupIfaceExt (fn : arg_fvs)
413 ; returnM (names, (mod, decl)) }
415 arg_fvs = [n | arg <- args, n <- crudeIfExprGblFvs arg]
418 ---------------------------
419 crudeIfExprGblFvs :: IfaceExpr -> [IfaceExtName]
420 -- A crude approximation to the free external names of an IfExpr
421 -- Returns a subset of the true answer
422 crudeIfExprGblFvs (IfaceType ty) = get_tcs ty
423 crudeIfExprGblFvs (IfaceExt v) = [v]
424 crudeIfExprGblFvs other = [] -- Well, I said it was crude
426 get_tcs :: IfaceType -> [IfaceExtName]
427 -- Get a crude subset of the TyCons of an IfaceType
428 get_tcs (IfaceTyVar _) = []
429 get_tcs (IfaceAppTy t1 t2) = get_tcs t1 ++ get_tcs t2
430 get_tcs (IfaceFunTy t1 t2) = get_tcs t1 ++ get_tcs t2
431 get_tcs (IfaceForAllTy _ t) = get_tcs t
432 get_tcs (IfacePredTy st) = case st of
433 IfaceClassP cl ts -> get_tcs_s ts
434 IfaceIParam _ t -> get_tcs t
435 get_tcs (IfaceTyConApp (IfaceTc tc) ts) = tc : get_tcs_s ts
436 get_tcs (IfaceTyConApp other ts) = get_tcs_s ts
438 -- The lists are always small => appending is fine
439 get_tcs_s :: [IfaceType] -> [IfaceExtName]
440 get_tcs_s tys = foldr ((++) . get_tcs) [] tys
444 %*********************************************************
448 %*********************************************************
450 Extract the gates of an instance declaration
453 ifaceInstGates :: IfaceType -> (IfaceExtName, [IfaceTyCon])
454 -- Return the class, and the tycons mentioned in the rest of the head
455 -- We only pick the TyCon at the root of each type, to avoid
456 -- difficulties with overlap. For example, suppose there are interfaces
461 -- Then, if we are trying to resolve (C Int x), we need the first
462 -- if we are trying to resolve (C x [y]), we need *both* the latter
463 -- two, even though T is not involved yet, so that we spot the overlap
465 ifaceInstGates (IfaceForAllTy _ t) = ifaceInstGates t
466 ifaceInstGates (IfaceFunTy _ t) = ifaceInstGates t
467 ifaceInstGates (IfacePredTy (IfaceClassP cls tys)) = instHeadGates cls tys
468 ifaceInstGates other = pprPanic "ifaceInstGates" (ppr other)
469 -- The other cases should not happen
471 instHeadGates cls tys = (cls, mapCatMaybes root_tycon tys)
473 root_tycon (IfaceFunTy _ _) = Just (IfaceTc funTyConExtName)
474 root_tycon (IfaceTyConApp tc _) = Just tc
475 root_tycon other = Nothing
477 funTyConExtName = mkIfaceExtName (tyConName funTyCon)
480 predInstGates :: Class -> [Type] -> (Name, [Name])
481 -- The same function, only this time on the predicate found in a dictionary
482 predInstGates cls tys
483 = (className cls, mapCatMaybes root_tycon tys)
485 root_tycon ty = case tcSplitTyConApp_maybe ty of
486 Just (tc, _) -> Just (tyConName tc)
491 %*********************************************************
493 \subsection{Reading an interface file}
495 %*********************************************************
498 findAndReadIface :: SDoc -> ModuleName
499 -> IsBootInterface -- True <=> Look for a .hi-boot file
500 -- False <=> Look for .hi file
501 -> IfM lcl (Either Message ModIface)
502 -- Nothing <=> file not found, or unreadable, or illegible
503 -- Just x <=> successfully found and parsed
505 -- It *doesn't* add an error to the monad, because
506 -- sometimes it's ok to fail... see notes with loadInterface
508 findAndReadIface doc_str mod_name hi_boot_file
509 = do { traceIf (sep [hsep [ptext SLIT("Reading"),
511 then ptext SLIT("[boot]")
513 ptext SLIT("interface for"),
514 ppr mod_name <> semi],
515 nest 4 (ptext SLIT("reason:") <+> doc_str)])
517 -- Check for GHC.Prim, and return its static interface
518 ; if mod_name == gHC_PRIM_Name
519 then returnM (Right ghcPrimIface)
523 ; mb_found <- ioToIOEnv (findHiFile mod_name hi_boot_file)
526 { traceIf (ptext SLIT("...not found"))
528 ; returnM (Left (noIfaceErr dflags mod_name hi_boot_file files)) } ;
530 Right file_path -> do
532 -- Found file, so read it
533 { traceIf (ptext SLIT("readIFace") <+> text file_path)
534 ; read_result <- readIface mod_name file_path hi_boot_file
535 ; case read_result of
536 Left err -> returnM (Left (badIfaceFile file_path err))
538 | moduleName (mi_module iface) /= mod_name ->
539 return (Left (wrongIfaceModErr iface mod_name file_path))
541 returnM (Right iface)
544 findHiFile :: ModuleName -> IsBootInterface
545 -> IO (Either [FilePath] FilePath)
546 findHiFile mod_name hi_boot_file
548 -- In interactive or --make mode, we are *not allowed* to demand-load
549 -- a home package .hi file. So don't even look for them.
550 -- This helps in the case where you are sitting in eg. ghc/lib/std
551 -- and start up GHCi - it won't complain that all the modules it tries
552 -- to load are found in the home location.
553 ghci_mode <- readIORef v_GhcMode ;
554 let { home_allowed = hi_boot_file ||
555 not (isCompManagerMode ghci_mode) } ;
556 maybe_found <- if home_allowed
557 then findModule mod_name
558 else findPackageModule mod_name ;
560 case maybe_found of {
561 Left files -> return (Left files) ;
563 Right (_, loc) -> do { -- Don't need module returned by finder
565 -- Return the path to M.hi, M.hi-boot, or M.hi-boot-n as appropriate
566 let { hi_path = ml_hi_file loc ;
567 hi_boot_path = replaceFilenameSuffix hi_path hiBootExt ;
568 hi_boot_ver_path = replaceFilenameSuffix hi_path hiBootVerExt
571 if not hi_boot_file then
572 return (Right hi_path)
574 hi_ver_exists <- doesFileExist hi_boot_ver_path ;
575 if hi_ver_exists then return (Right hi_boot_ver_path)
576 else return (Right hi_boot_path)
580 @readIface@ tries just the one file.
583 readIface :: ModuleName -> String -> IsBootInterface
584 -> IfM lcl (Either Message ModIface)
585 -- Left err <=> file not found, or unreadable, or illegible
586 -- Right iface <=> successfully found and parsed
588 readIface wanted_mod_name file_path is_hi_boot_file
589 = do { dflags <- getDOpts
590 ; ioToIOEnv (read_iface dflags wanted_mod_name file_path is_hi_boot_file) }
592 read_iface dflags wanted_mod file_path is_hi_boot_file
593 | is_hi_boot_file -- Read ascii
594 = do { res <- tryMost (hGetStringBuffer file_path) ;
596 Left exn -> return (Left (text (showException exn))) ;
598 case unP parseIface (mkPState buffer loc dflags) of
599 PFailed span err -> return (Left (mkLocMessage span err))
601 | wanted_mod == actual_mod -> return (Right iface)
602 | otherwise -> return (Left err)
604 actual_mod = moduleName (mi_module iface)
605 err = hiModuleNameMismatchWarn wanted_mod actual_mod
608 | otherwise -- Read binary
609 = do { res <- tryMost (readBinIface file_path)
611 Right iface -> return (Right iface)
612 Left exn -> return (Left (text (showException exn))) }
614 loc = mkSrcLoc (mkFastString file_path) 1 0
618 %*********************************************************
620 Wired-in interface for GHC.Prim
622 %*********************************************************
625 initExternalPackageState :: ExternalPackageState
626 initExternalPackageState
628 eps_is_boot = emptyModuleEnv,
629 eps_PIT = emptyPackageIfaceTable,
630 eps_PTE = emptyTypeEnv,
631 eps_inst_env = emptyInstEnv,
632 eps_rule_base = emptyRuleBase,
633 eps_insts = emptyNameEnv,
634 eps_rules = addRulesToPool [] (map mk_gated_rule builtinRules),
635 -- Initialise the EPS rule pool with the built-in rules
636 eps_stats = EpsStats { n_ifaces_in = 0, n_decls_in = 0, n_decls_out = 0
637 , n_insts_in = 0, n_insts_out = 0
638 , n_rules_in = length builtinRules, n_rules_out = 0 }
641 mk_gated_rule (fn_name, core_rule)
642 = ([fn_name], (nameModuleName fn_name, IfaceBuiltinRule (mkIfaceExtName fn_name) core_rule))
646 %*********************************************************
648 Wired-in interface for GHC.Prim
650 %*********************************************************
653 ghcPrimIface :: ModIface
655 = (emptyModIface basePackage gHC_PRIM_Name) {
656 mi_exports = [(gHC_PRIM_Name, ghcPrimExports)],
658 mi_fixities = fixities,
659 mi_fix_fn = mkIfaceFixCache fixities
662 fixities = [(getOccName seqId, Fixity 0 InfixR)]
666 %*********************************************************
668 \subsection{Statistics}
670 %*********************************************************
673 ifaceStats :: ExternalPackageState -> SDoc
675 = hcat [text "Renamer stats: ", msg]
677 stats = eps_stats eps
679 [int (n_ifaces_in stats) <+> text "interfaces read",
680 hsep [ int (n_decls_out stats), text "type/class/variable imported, out of",
681 int (n_decls_in stats), text "read"],
682 hsep [ int (n_insts_out stats), text "instance decls imported, out of",
683 int (n_insts_in stats), text "read"],
684 hsep [ int (n_rules_out stats), text "rule decls imported, out of",
685 int (n_rules_in stats), text "read"]
690 %*********************************************************
694 %*********************************************************
697 badIfaceFile file err
698 = vcat [ptext SLIT("Bad interface file:") <+> text file,
701 hiModuleNameMismatchWarn :: ModuleName -> ModuleName -> Message
702 hiModuleNameMismatchWarn requested_mod read_mod =
703 hsep [ ptext SLIT("Something is amiss; requested module name")
705 , ptext SLIT("differs from name found in the interface file")
709 noIfaceErr dflags mod_name boot_file files
710 = ptext SLIT("Could not find interface file for") <+> quotes (ppr mod_name)
714 | verbosity dflags < 3 =
715 text "(use -v to see a list of the files searched for)"
717 hang (ptext SLIT("locations searched:")) 4 (vcat (map text files))
719 wrongIfaceModErr iface mod_name file_path
720 = sep [ptext SLIT("Interface file") <+> iface_file,
721 ptext SLIT("contains module") <+> quotes (ppr (mi_module iface)) <> comma,
722 ptext SLIT("but we were expecting module") <+> quotes (ppr mod_name),
723 sep [ptext SLIT("Probable cause: the source code which generated"),
725 ptext SLIT("has an incompatible module name")
728 where iface_file = doubleQuotes (text file_path)