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