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