[project @ 2000-10-30 18:13:15 by sewardj]
[ghc-hetmet.git] / ghc / compiler / rename / RnHiFiles.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section{Dealing with interface files}
5
6 \begin{code}
7 module RnHiFiles (
8         readIface, findAndReadIface, loadInterface, loadHomeInterface, 
9         tryLoadInterface, loadOrphanModules,
10         loadExports, loadFixDecls, loadDeprecs,
11
12         lookupFixityRn, 
13
14         getTyClDeclBinders, 
15         removeContext           -- removeContext probably belongs somewhere else
16    ) where
17
18 #include "HsVersions.h"
19
20 import CmdLineOpts      ( DynFlag(..), opt_IgnoreIfacePragmas )
21 import HscTypes         ( ModuleLocation(..),
22                           ModIface(..), emptyModIface,
23                           VersionInfo(..),
24                           lookupTableByModName, 
25                           ImportVersion, WhetherHasOrphans, IsBootInterface,
26                           DeclsMap, GatedDecl, IfaceInsts, IfaceRules,
27                           AvailInfo, GenAvailInfo(..), Avails, Deprecations(..)
28                          )
29 import HsSyn            ( HsDecl(..), TyClDecl(..), InstDecl(..),
30                           HsType(..), ConDecl(..), 
31                           FixitySig(..), RuleDecl(..),
32                           tyClDeclNames
33                         )
34 import RdrHsSyn         ( RdrNameTyClDecl, RdrNameInstDecl, RdrNameRuleDecl,
35                           extractHsTyRdrNames 
36                         )
37 import BasicTypes       ( Version, defaultFixity )
38 import RnEnv
39 import RnMonad
40 import ParseIface       ( parseIface, IfaceStuff(..) )
41
42 import Name             ( Name {-instance NamedThing-}, nameOccName,
43                           nameModule, isLocallyDefined, 
44                           NamedThing(..),
45                           mkNameEnv, extendNameEnv
46                          )
47 import Module           ( Module, 
48                           moduleName, isModuleInThisPackage,
49                           ModuleName, WhereFrom(..),
50                           extendModuleEnv, mkVanillaModule
51                         )
52 import RdrName          ( RdrName, rdrNameOcc )
53 import NameSet
54 import SrcLoc           ( mkSrcLoc )
55 import Maybes           ( maybeToBool, orElse )
56 import StringBuffer     ( hGetStringBuffer )
57 import FastString       ( mkFastString )
58 import ErrUtils         ( Message )
59 import Finder           ( findModule )
60 import Util             ( unJust )
61 import Lex
62 import FiniteMap
63 import Outputable
64 import Bag
65
66 import Monad            ( when )
67 \end{code}
68
69
70 %*********************************************************
71 %*                                                      *
72 \subsection{Loading a new interface file}
73 %*                                                      *
74 %*********************************************************
75
76 \begin{code}
77 loadHomeInterface :: SDoc -> Name -> RnM d ModIface
78 loadHomeInterface doc_str name
79   = loadInterface doc_str (moduleName (nameModule name)) ImportBySystem
80
81 loadOrphanModules :: [ModuleName] -> RnM d ()
82 loadOrphanModules mods
83   | null mods = returnRn ()
84   | otherwise = traceRn (text "Loading orphan modules:" <+> 
85                          fsep (map ppr mods))                   `thenRn_` 
86                 mapRn_ load mods                                `thenRn_`
87                 returnRn ()
88   where
89     load mod   = loadInterface (mk_doc mod) mod ImportBySystem
90     mk_doc mod = ppr mod <+> ptext SLIT("is a orphan-instance module")
91
92 loadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d ModIface
93 loadInterface doc mod from 
94   = tryLoadInterface doc mod from       `thenRn` \ (ifaces, maybe_err) ->
95     case maybe_err of
96         Nothing  -> returnRn ifaces
97         Just err -> failWithRn ifaces err
98
99 tryLoadInterface :: SDoc -> ModuleName -> WhereFrom -> RnM d (ModIface, Maybe Message)
100   -- Returns (Just err) if an error happened
101   -- It *doesn't* add an error to the monad, because sometimes it's ok to fail...
102   -- Specifically, when we read the usage information from an interface file,
103   -- we try to read the interfaces it mentions.  But it's OK to fail; perhaps
104   -- the module has changed, and that interface is no longer used.
105   
106   -- tryLoadInterface guarantees to return with iImpModInfo m --> (..., True)
107   -- (If the load fails, we plug in a vanilla placeholder)
108 tryLoadInterface doc_str mod_name from
109  = getHomeIfaceTableRn          `thenRn` \ hit ->
110    getIfacesRn                  `thenRn` \ ifaces@(Ifaces { iPIT = pit }) ->
111         
112         -- CHECK WHETHER WE HAVE IT ALREADY
113    case lookupTableByModName hit pit mod_name of {
114         Just iface  -> returnRn (iface, Nothing) ;      -- Already loaded
115         Nothing     -> 
116
117    let
118         mod_map  = iImpModInfo ifaces
119         mod_info = lookupFM mod_map mod_name
120
121         hi_boot_file 
122           = case (from, mod_info) of
123                 (ImportByUser,       _)             -> False    -- Not hi-boot
124                 (ImportByUserSource, _)             -> True     -- hi-boot
125                 (ImportBySystem, Just (_, is_boot)) -> is_boot
126                 (ImportBySystem, Nothing)           -> False
127                         -- We're importing a module we know absolutely
128                         -- nothing about, so we assume it's from
129                         -- another package, where we aren't doing 
130                         -- dependency tracking. So it won't be a hi-boot file.
131
132         redundant_source_import 
133           = case (from, mod_info) of 
134                 (ImportByUserSource, Just (_,False)) -> True
135                 other                                -> False
136    in
137
138         -- Issue a warning for a redundant {- SOURCE -} import
139         -- NB that we arrange to read all the ordinary imports before 
140         -- any of the {- SOURCE -} imports
141    warnCheckRn  (not redundant_source_import)
142                 (warnRedundantSourceImport mod_name)    `thenRn_`
143
144         -- READ THE MODULE IN
145    findAndReadIface doc_str mod_name hi_boot_file   `thenRn` \ read_result ->
146    case read_result of {
147         Left err ->     -- Not found, so add an empty export env to the Ifaces map
148                         -- so that we don't look again
149            let
150                 fake_mod    = mkVanillaModule mod_name
151                 fake_iface  = emptyModIface fake_mod
152                 new_ifaces  = ifaces { iPIT = extendModuleEnv pit fake_mod fake_iface }
153            in
154            setIfacesRn new_ifaces               `thenRn_`
155            returnRn (fake_iface, Just err) ;
156
157         -- Found and parsed!
158         Right (mod, iface) ->
159
160         -- LOAD IT INTO Ifaces
161
162         -- NB: *first* we do loadDecl, so that the provenance of all the locally-defined
163         ---    names is done correctly (notably, whether this is an .hi file or .hi-boot file).
164         --     If we do loadExport first the wrong info gets into the cache (unless we
165         --      explicitly tag each export which seems a bit of a bore)
166
167
168         -- Sanity check.  If we're system-importing a module we know nothing at all
169         -- about, it should be from a different package to this one
170     WARN( not (maybeToBool mod_info) && 
171           case from of { ImportBySystem -> True; other -> False } &&
172           isModuleInThisPackage mod,
173           ppr mod )
174
175     loadDecls mod               (iDecls ifaces)   (pi_decls iface)      `thenRn` \ (decls_vers, new_decls) ->
176     loadRules mod               (iRules ifaces)   (pi_rules iface)      `thenRn` \ (rule_vers, new_rules) ->
177     foldlRn (loadInstDecl mod)  (iInsts ifaces)   (pi_insts iface)      `thenRn` \ new_insts ->
178     loadExports                                   (pi_exports iface)    `thenRn` \ (export_vers, avails) ->
179     loadFixDecls mod                              (pi_fixity iface)     `thenRn` \ fix_env ->
180     loadDeprecs mod                               (pi_deprecs iface)    `thenRn` \ deprec_env ->
181     let
182         version = VersionInfo { vers_module  = pi_vers iface, 
183                                 vers_exports = export_vers,
184                                 vers_rules = rule_vers,
185                                 vers_decls = decls_vers }
186
187         -- For an explicit user import, add to mod_map info about
188         -- the things the imported module depends on, extracted
189         -- from its usage info; and delete the module itself, which is now in the PIT
190         mod_map1 = case from of
191                         ImportByUser -> addModDeps mod is_loaded (pi_usages iface) mod_map
192                         other        -> mod_map
193         mod_map2 = delFromFM mod_map1 mod_name
194         is_loaded m = maybeToBool (lookupTableByModName hit pit m)
195
196         -- Now add info about this module to the PIT
197         has_orphans = pi_orphan iface
198         new_pit   = extendModuleEnv pit mod mod_iface
199         mod_iface = ModIface { mi_module = mod, mi_version = version,
200                                mi_orphan = has_orphans, mi_boot = hi_boot_file,
201                                mi_exports = avails, 
202                                mi_fixities = fix_env, mi_deprecs = deprec_env,
203                                mi_usages  = [], -- Will be filled in later
204                                mi_decls   = panic "No mi_decls in PIT",
205                                mi_globals = panic "No mi_globals in PIT"
206                     }
207
208         new_ifaces = ifaces { iPIT        = new_pit,
209                               iDecls      = new_decls,
210                               iInsts      = new_insts,
211                               iRules      = new_rules,
212                               iImpModInfo = mod_map2  }
213     in
214     setIfacesRn new_ifaces              `thenRn_`
215     returnRn (mod_iface, Nothing)
216     }}
217
218 -----------------------------------------------------
219 --      Adding module dependencies from the 
220 --      import decls in the interface file
221 -----------------------------------------------------
222
223 addModDeps :: Module 
224            -> (ModuleName -> Bool)      -- True for module interfaces
225            -> [ImportVersion a] 
226            -> ImportedModuleInfo -> ImportedModuleInfo
227 -- (addModDeps M ivs deps)
228 -- We are importing module M, and M.hi contains 'import' decls given by ivs
229 addModDeps mod is_loaded new_deps mod_deps
230   = foldr add mod_deps filtered_new_deps
231   where
232         -- Don't record dependencies when importing a module from another package
233         -- Except for its descendents which contain orphans,
234         -- and in that case, forget about the boot indicator
235     filtered_new_deps :: [(ModuleName, (WhetherHasOrphans, IsBootInterface))]
236     filtered_new_deps
237         | isModuleInThisPackage mod 
238                             = [ (imp_mod, (has_orphans, is_boot))
239                               | (imp_mod, has_orphans, is_boot, _) <- new_deps,
240                                 not (is_loaded imp_mod)
241                               ]                       
242         | otherwise         = [ (imp_mod, (True, False))
243                               | (imp_mod, has_orphans, _, _) <- new_deps,
244                                 not (is_loaded imp_mod) && has_orphans
245                               ]
246     add (imp_mod, dep) deps = addToFM_C combine deps imp_mod dep
247
248     combine old@(old_has_orphans, old_is_boot) new@(new_has_orphans, new_is_boot)
249         | old_is_boot = new     -- Record the best is_boot info
250         | otherwise   = old
251
252 -----------------------------------------------------
253 --      Loading the export list
254 -----------------------------------------------------
255
256 loadExports :: (Version, [ExportItem]) -> RnM d (Version, [(ModuleName,Avails)])
257 loadExports (vers, items)
258   = getModuleRn                                 `thenRn` \ this_mod ->
259     mapRn (loadExport this_mod) items           `thenRn` \ avails_s ->
260     returnRn (vers, avails_s)
261
262
263 loadExport :: Module -> ExportItem -> RnM d (ModuleName, Avails)
264 loadExport this_mod (mod, entities)
265   | mod == moduleName this_mod = returnRn (mod, [])
266         -- If the module exports anything defined in this module, just ignore it.
267         -- Reason: otherwise it looks as if there are two local definition sites
268         -- for the thing, and an error gets reported.  Easiest thing is just to
269         -- filter them out up front. This situation only arises if a module
270         -- imports itself, or another module that imported it.  (Necessarily,
271         -- this invoves a loop.)  Consequence: if you say
272         --      module A where
273         --         import B( AType )
274         --         type AType = ...
275         --
276         --      module B( AType ) where
277         --         import {-# SOURCE #-} A( AType )
278         --
279         -- then you'll get a 'B does not export AType' message.  A bit bogus
280         -- but it's a bogus thing to do!
281
282   | otherwise
283   = mapRn (load_entity mod) entities    `thenRn` \ avails ->
284     returnRn (mod, avails)
285   where
286     load_entity mod (Avail occ)
287       = newGlobalName mod occ   `thenRn` \ name ->
288         returnRn (Avail name)
289     load_entity mod (AvailTC occ occs)
290       = newGlobalName mod occ           `thenRn` \ name ->
291         mapRn (newGlobalName mod) occs  `thenRn` \ names ->
292         returnRn (AvailTC name names)
293
294
295 -----------------------------------------------------
296 --      Loading type/class/value decls
297 -----------------------------------------------------
298
299 loadDecls :: Module 
300           -> DeclsMap
301           -> [(Version, RdrNameTyClDecl)]
302           -> RnM d (NameEnv Version, DeclsMap)
303 loadDecls mod decls_map decls
304   = foldlRn (loadDecl mod) (emptyNameEnv, decls_map) decls
305
306 loadDecl :: Module 
307          -> (NameEnv Version, DeclsMap)
308          -> (Version, RdrNameTyClDecl)
309          -> RnM d (NameEnv Version, DeclsMap)
310 loadDecl mod (version_map, decls_map) (version, decl)
311   = getIfaceDeclBinders mod decl        `thenRn` \ full_avail ->
312     let
313         main_name     = availName full_avail
314         new_decls_map = extendNameEnvList decls_map stuff
315         stuff         = [ (name, (full_avail, name==main_name, (mod, decl))) 
316                         | name <- availNames full_avail]
317
318         new_version_map = extendNameEnv version_map main_name version
319     in
320     returnRn (new_version_map, new_decls_map)
321
322 -----------------------------------------------------
323 --      Loading fixity decls
324 -----------------------------------------------------
325
326 loadFixDecls mod decls
327   = mapRn (loadFixDecl mod_name) decls  `thenRn` \ to_add ->
328     returnRn (mkNameEnv to_add)
329   where
330     mod_name = moduleName mod
331
332 loadFixDecl mod_name sig@(FixitySig rdr_name fixity loc)
333   = newGlobalName mod_name (rdrNameOcc rdr_name)        `thenRn` \ name ->
334     returnRn (name, fixity)
335
336
337 -----------------------------------------------------
338 --      Loading instance decls
339 -----------------------------------------------------
340
341 loadInstDecl :: Module
342              -> IfaceInsts
343              -> RdrNameInstDecl
344              -> RnM d IfaceInsts
345 loadInstDecl mod insts decl@(InstDecl inst_ty binds uprags dfun_name src_loc)
346   = 
347         -- Find out what type constructors and classes are "gates" for the
348         -- instance declaration.  If all these "gates" are slurped in then
349         -- we should slurp the instance decl too.
350         -- 
351         -- We *don't* want to count names in the context part as gates, though.
352         -- For example:
353         --              instance Foo a => Baz (T a) where ...
354         --
355         -- Here the gates are Baz and T, but *not* Foo.
356     let 
357         munged_inst_ty = removeContext inst_ty
358         free_names     = extractHsTyRdrNames munged_inst_ty
359     in
360     setModuleRn mod $
361     mapRn lookupOrigName free_names     `thenRn` \ gate_names ->
362     returnRn ((mkNameSet gate_names, (mod, InstD decl)) `consBag` insts)
363
364
365 -- In interface files, the instance decls now look like
366 --      forall a. Foo a -> Baz (T a)
367 -- so we have to strip off function argument types as well
368 -- as the bit before the '=>' (which is always empty in interface files)
369 removeContext (HsForAllTy tvs cxt ty) = HsForAllTy tvs [] (removeFuns ty)
370 removeContext ty                      = removeFuns ty
371
372 removeFuns (HsFunTy _ ty) = removeFuns ty
373 removeFuns ty               = ty
374
375
376 -----------------------------------------------------
377 --      Loading Rules
378 -----------------------------------------------------
379
380 loadRules :: Module -> IfaceRules 
381           -> (Version, [RdrNameRuleDecl])
382           -> RnM d (Version, IfaceRules)
383 loadRules mod rule_bag (version, rules)
384   | null rules || opt_IgnoreIfacePragmas 
385   = returnRn (version, rule_bag)
386   | otherwise
387   = setModuleRn mod                     $
388     mapRn (loadRule mod) rules          `thenRn` \ new_rules ->
389     returnRn (version, rule_bag `unionBags` listToBag new_rules)
390
391 loadRule :: Module -> RdrNameRuleDecl -> RnM d GatedDecl
392 -- "Gate" the rule simply by whether the rule variable is
393 -- needed.  We can refine this later.
394 loadRule mod decl@(IfaceRule _ _ var _ _ src_loc)
395   = lookupOrigName var          `thenRn` \ var_name ->
396     returnRn (unitNameSet var_name, (mod, RuleD decl))
397
398
399 -----------------------------------------------------
400 --      Loading Deprecations
401 -----------------------------------------------------
402
403 loadDeprecs :: Module -> IfaceDeprecs -> RnM d Deprecations
404 loadDeprecs m Nothing                                  = returnRn NoDeprecs
405 loadDeprecs m (Just (Left txt))  = returnRn (DeprecAll txt)
406 loadDeprecs m (Just (Right prs)) = setModuleRn m                                $
407                                    foldlRn loadDeprec emptyNameEnv prs  `thenRn` \ env ->
408                                    returnRn (DeprecSome env)
409 loadDeprec deprec_env (n, txt)
410   = lookupOrigName n            `thenRn` \ name ->
411     traceRn (text "Loaded deprecation(s) for" <+> ppr name <> colon <+> ppr txt) `thenRn_`
412     returnRn (extendNameEnv deprec_env name (name,txt))
413 \end{code}
414
415
416 %*********************************************************
417 %*                                                      *
418 \subsection{Getting binders out of a declaration}
419 %*                                                      *
420 %*********************************************************
421
422 @getDeclBinders@ returns the names for a @RdrNameHsDecl@.
423 It's used for both source code (from @availsFromDecl@) and interface files
424 (from @loadDecl@).
425
426 It doesn't deal with source-code specific things: @ValD@, @DefD@.  They
427 are handled by the sourc-code specific stuff in @RnNames@.
428
429 \begin{code}
430 getIfaceDeclBinders, getTyClDeclBinders
431         :: Module
432         -> RdrNameTyClDecl
433         -> RnM d AvailInfo
434
435 getIfaceDeclBinders mod tycl_decl
436   = getTyClDeclBinders    mod tycl_decl `thenRn` \ avail ->
437     getSysTyClDeclBinders mod tycl_decl `thenRn` \ extras ->
438     returnRn (addSysAvails avail extras)
439                 -- Add the sys-binders to avail.  When we import the decl,
440                 -- it's full_avail that will get added to the 'already-slurped' set (iSlurp)
441                 -- If we miss out sys-binders, we'll read the decl multiple times!
442
443 getTyClDeclBinders mod (IfaceSig var ty prags src_loc)
444   = newTopBinder mod var src_loc                        `thenRn` \ var_name ->
445     returnRn (Avail var_name)
446
447 getTyClDeclBinders mod tycl_decl
448   = mapRn do_one (tyClDeclNames tycl_decl)      `thenRn` \ (main_name:sub_names) ->
449     returnRn (AvailTC main_name (main_name : sub_names))
450   where
451     do_one (name,loc) = newTopBinder mod name loc
452 \end{code}
453
454 @getDeclSysBinders@ gets the implicit binders introduced by a decl.
455 A the moment that's just the tycon and datacon that come with a class decl.
456 They aren't returned by @getDeclBinders@ because they aren't in scope;
457 but they {\em should} be put into the @DeclsMap@ of this module.
458
459 Note that this excludes the default-method names of a class decl,
460 and the dict fun of an instance decl, because both of these have 
461 bindings of their own elsewhere.
462
463 \begin{code}
464 getSysTyClDeclBinders mod (ClassDecl _ cname _ _ sigs _ names src_loc)
465   = sequenceRn [newTopBinder mod n src_loc | n <- names]
466
467 getSysTyClDeclBinders mod (TyData _ _ _ _ cons _ _ _ _ _)
468   = sequenceRn [newTopBinder mod wkr_name src_loc | ConDecl _ wkr_name _ _ _ src_loc <- cons]
469
470 getSysTyClDeclBinders mod other_decl
471   = returnRn []
472 \end{code}
473
474 %*********************************************************
475 %*                                                      *
476 \subsection{Reading an interface file}
477 %*                                                      *
478 %*********************************************************
479
480 \begin{code}
481 findAndReadIface :: SDoc -> ModuleName 
482                  -> IsBootInterface     -- True  <=> Look for a .hi-boot file
483                                         -- False <=> Look for .hi file
484                  -> RnM d (Either Message (Module, ParsedIface))
485         -- Nothing <=> file not found, or unreadable, or illegible
486         -- Just x  <=> successfully found and parsed 
487
488 findAndReadIface doc_str mod_name hi_boot_file
489   = traceRn trace_msg                   `thenRn_`
490     ioToRnM (findModule mod_name)       `thenRn` \ maybe_found ->
491     doptRn Opt_D_dump_rn_trace          `thenRn` \ rn_trace ->
492     case maybe_found of
493       Right (Just (wanted_mod,locn))
494         -> ioToRnM_no_fail (
495               readIface rn_trace 
496                  (unJust (ml_hi_file locn) "findAndReadIface"
497                   ++ if hi_boot_file then "-boot" else "")
498            )
499                                         `thenRn` \ read_result ->
500            case read_result of
501               Left bad -> returnRn (Left bad)
502               Right iface 
503                  -> let read_mod = pi_mod iface
504                     in warnCheckRn (wanted_mod == read_mod)
505                                    (hiModuleNameMismatchWarn wanted_mod read_mod) 
506                                         `thenRn_`
507                        returnRn (Right (wanted_mod, iface))
508         -- Can't find it
509       other   -> traceRn (ptext SLIT("...not found"))   `thenRn_`
510                  returnRn (Left (noIfaceErr mod_name hi_boot_file))
511
512   where
513     trace_msg = sep [hsep [ptext SLIT("Reading"), 
514                            if hi_boot_file then ptext SLIT("[boot]") else empty,
515                            ptext SLIT("interface for"), 
516                            ppr mod_name <> semi],
517                      nest 4 (ptext SLIT("reason:") <+> doc_str)]
518 \end{code}
519
520 @readIface@ tries just the one file.
521
522 \begin{code}
523 readIface :: Bool -> String -> IO (Either Message ParsedIface)
524         -- Nothing <=> file not found, or unreadable, or illegible
525         -- Just x  <=> successfully found and parsed 
526 readIface tr file_path
527   = when tr (printErrs (ptext SLIT("readIFace") <+> text file_path)) 
528     >>
529     ((hGetStringBuffer False file_path  >>= \ contents ->
530         case parseIface contents
531                         PState{ bol = 0#, atbol = 1#,
532                                 context = [],
533                                 glasgow_exts = 1#,
534                                 loc = mkSrcLoc (mkFastString file_path) 1 } of
535                   POk _  (PIface iface) -> return (Right iface)
536                   PFailed err   -> bale_out err
537                   parse_result  -> bale_out empty
538                         -- This last case can happen if the interface file is (say) empty
539                         -- in which case the parser thinks it looks like an IdInfo or
540                         -- something like that.  Just an artefact of the fact that the
541                         -- parser is used for several purposes at once.
542    )
543    `catch` 
544    (\ io_err -> bale_out (text (show io_err))))
545   where
546     bale_out err = return (Left (badIfaceFile file_path err))
547 \end{code}
548
549
550 %*********************************************************
551 %*                                                      *
552 \subsection{Looking up fixities}
553 %*                                                      *
554 %*********************************************************
555
556 This has to be in RnIfaces (or RnHiFiles) because it calls loadHomeInterface
557
558 \begin{code}
559 lookupFixityRn :: Name -> RnMS Fixity
560 lookupFixityRn name
561   | isLocallyDefined name
562   = getFixityEnv                        `thenRn` \ local_fix_env ->
563     returnRn (lookupLocalFixity local_fix_env name)
564
565   | otherwise   -- Imported
566       -- For imported names, we have to get their fixities by doing a loadHomeInterface,
567       -- and consulting the Ifaces that comes back from that, because the interface
568       -- file for the Name might not have been loaded yet.  Why not?  Suppose you import module A,
569       -- which exports a function 'f', which is defined in module B.  Then B isn't loaded
570       -- right away (after all, it's possible that nothing from B will be used).
571       -- When we come across a use of 'f', we need to know its fixity, and it's then,
572       -- and only then, that we load B.hi.  That is what's happening here.
573   = getHomeIfaceTableRn                 `thenRn` \ hit ->
574     loadHomeInterface doc name          `thenRn` \ iface ->
575     returnRn (lookupNameEnv (mi_fixities iface) name `orElse` defaultFixity)
576   where
577     doc = ptext SLIT("Checking fixity for") <+> ppr name
578 \end{code}
579
580
581 %*********************************************************
582 %*                                                       *
583 \subsection{Errors}
584 %*                                                       *
585 %*********************************************************
586
587 \begin{code}
588 noIfaceErr mod_name boot_file
589   = ptext SLIT("Could not find interface file for") <+> quotes (ppr mod_name)
590         -- We used to print the search path, but we can't do that
591         -- now, because it's hidden inside the finder.
592         -- Maybe the finder should expose more functions.
593
594 badIfaceFile file err
595   = vcat [ptext SLIT("Bad interface file:") <+> text file, 
596           nest 4 err]
597
598 hiModuleNameMismatchWarn :: Module -> Module  -> Message
599 hiModuleNameMismatchWarn requested_mod read_mod = 
600     hsep [ ptext SLIT("Something is amiss; requested module name")
601          , ppr (moduleName requested_mod)
602          , ptext SLIT("differs from name found in the interface file")
603          , ppr read_mod
604          ]
605
606 warnRedundantSourceImport mod_name
607   = ptext SLIT("Unnecessary {- SOURCE -} in the import of module")
608           <+> quotes (ppr mod_name)
609 \end{code}
610