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