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