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