[project @ 1998-12-18 17:40:31 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnNames.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnNames]{Extracting imported and top-level names in scope}
5
6 \begin{code}
7 module RnNames (
8         getGlobalNames
9     ) where
10
11 #include "HsVersions.h"
12
13 import CmdLineOpts    ( opt_NoImplicitPrelude, opt_WarnDuplicateExports, 
14                         opt_SourceUnchanged
15                       )
16
17 import HsSyn    ( HsModule(..), ImportDecl(..), HsDecl(..), TyClDecl(..),
18                   IE(..), ieName, 
19                   ForeignDecl(..), ExtName(..), ForKind(..),
20                   FixitySig(..), Sig(..),
21                   collectTopBinders
22                 )
23 import RdrHsSyn ( RdrName(..), RdrNameIE, RdrNameImportDecl,
24                   RdrNameHsModule, RdrNameHsDecl,
25                   rdrNameOcc, ieOcc
26                 )
27 import RnIfaces ( getInterfaceExports, getDeclBinders, getImportedFixities, 
28                   recordSlurp, checkUpToDate, loadHomeInterface
29                 )
30 import BasicTypes ( IfaceFlavour(..) )
31 import RnEnv
32 import RnMonad
33
34 import FiniteMap
35 import PrelMods
36 import UniqFM   ( lookupUFM )
37 import Bag      ( bagToList )
38 import Maybes   ( maybeToBool )
39 import Name
40 import SrcLoc   ( SrcLoc )
41 import NameSet  ( elemNameSet, emptyNameSet )
42 import Outputable
43 import Unique   ( getUnique )
44 import Util     ( removeDups, equivClassesByUniq )
45 import List     ( nubBy )
46 \end{code}
47
48
49
50 %************************************************************************
51 %*                                                                      *
52 \subsection{Get global names}
53 %*                                                                      *
54 %************************************************************************
55
56 \begin{code}
57 getGlobalNames :: RdrNameHsModule
58                -> RnMG (Maybe (ExportEnv, 
59                                RnEnv,
60                                NameEnv AvailInfo        -- Maps a name to its parent AvailInfo
61                                                         -- Just for in-scope things only
62                                ))
63                         -- Nothing => no need to recompile
64
65 getGlobalNames (HsModule this_mod _ exports imports decls mod_loc)
66   =     -- These two fix-loops are to get the right
67         -- provenance information into a Name
68     fixRn (\ ~(rec_exp_fn, _) ->
69
70       fixRn (\ ~(rec_rn_env, _) ->
71         let
72            rec_unqual_fn :: Name -> Bool        -- Is this chap in scope unqualified?
73            rec_unqual_fn = mkPrintUnqualFn rec_rn_env
74         in
75                 -- PROCESS LOCAL DECLS
76                 -- Do these *first* so that the correct provenance gets
77                 -- into the global name cache.
78         importsFromLocalDecls this_mod rec_exp_fn decls `thenRn` \ (local_gbl_env, local_mod_avails) ->
79
80                 -- PROCESS IMPORT DECLS
81         mapAndUnzipRn (importsFromImportDecl rec_unqual_fn)
82                       all_imports                       `thenRn` \ (imp_gbl_envs, imp_avails_s) ->
83
84                 -- COMBINE RESULTS
85                 -- We put the local env second, so that a local provenance
86                 -- "wins", even if a module imports itself.
87         let
88             gbl_env :: GlobalRdrEnv
89             imp_gbl_env = foldr plusGlobalRdrEnv emptyRdrEnv imp_gbl_envs
90             gbl_env     = imp_gbl_env `plusGlobalRdrEnv` local_gbl_env
91
92             export_avails :: ExportAvails
93             export_avails = foldr plusExportAvails local_mod_avails imp_avails_s
94         in
95         returnRn (gbl_env, export_avails)
96       )                                                 `thenRn` \ (gbl_env, export_avails) ->
97
98         -- TRY FOR EARLY EXIT
99         -- We can't go for an early exit before this because we have to check
100         -- for name clashes.  Consider:
101         --
102         --      module A where          module B where
103         --         import B                h = True
104         --         f = h
105         --
106         -- Suppose I've compiled everything up, and then I add a
107         -- new definition to module B, that defines "f".
108         --
109         -- Then I must detect the name clash in A before going for an early
110         -- exit.  The early-exit code checks what's actually needed from B
111         -- to compile A, and of course that doesn't include B.f.  That's
112         -- why we wait till after the plusRnEnv stuff to do the early-exit.
113       checkEarlyExit this_mod                   `thenRn` \ up_to_date ->
114       if up_to_date then
115         returnRn (junk_exp_fn, Nothing)
116       else
117  
118         -- FIXITIES
119       fixitiesFromLocalDecls gbl_env decls              `thenRn` \ local_fixity_env ->
120       getImportedFixities                               `thenRn` \ imp_fixity_env ->
121       let
122         fixity_env = imp_fixity_env `plusNameEnv` local_fixity_env
123         rn_env     = RnEnv gbl_env fixity_env
124         (_, global_avail_env) = export_avails
125       in
126       traceRn (text "fixity env" <+> vcat (map ppr (nameEnvElts fixity_env)))   `thenRn_`
127
128         -- PROCESS EXPORT LISTS
129       exportsFromAvail this_mod exports export_avails rn_env    `thenRn` \ (export_fn, export_env) ->
130
131         -- DONE
132       returnRn (export_fn, Just (export_env, rn_env, global_avail_env))
133     )                                                   `thenRn` \ (_, result) ->
134     returnRn result
135   where
136     junk_exp_fn = error "RnNames:export_fn"
137
138     all_imports = prel_imports ++ imports
139
140         -- NB: opt_NoImplicitPrelude is slightly different to import Prelude ();
141         -- because the former doesn't even look at Prelude.hi for instance declarations,
142         -- whereas the latter does.
143     prel_imports | this_mod == pRELUDE ||
144                    explicit_prelude_import ||
145                    opt_NoImplicitPrelude
146                  = []
147
148                  | otherwise               = [ImportDecl pRELUDE 
149                                                          False          {- Not qualified -}
150                                                          HiFile         {- Not source imported -}
151                                                          Nothing        {- No "as" -}
152                                                          Nothing        {- No import list -}
153                                                          mod_loc]
154     
155     explicit_prelude_import
156       = not (null [ () | (ImportDecl mod qual _ _ _ _) <- imports, mod == pRELUDE ])
157 \end{code}
158         
159 \begin{code}
160 checkEarlyExit mod
161   = checkErrsRn                         `thenRn` \ no_errs_so_far ->
162     if not no_errs_so_far then
163         -- Found errors already, so exit now
164         returnRn True
165     else
166
167     traceRn (text "Considering whether compilation is required...")     `thenRn_`
168     if not opt_SourceUnchanged then
169         -- Source code changed and no errors yet... carry on 
170         traceRn (nest 4 (text "source file changed or recompilation check turned off")) `thenRn_` 
171         returnRn False
172     else
173
174         -- Unchanged source, and no errors yet; see if usage info
175         -- up to date, and exit if so
176     checkUpToDate mod                                           `thenRn` \ up_to_date ->
177     putDocRn (text "Compilation" <+> 
178               text (if up_to_date then "IS NOT" else "IS") <+>
179               text "required")                                  `thenRn_`
180     returnRn up_to_date
181 \end{code}
182         
183 \begin{code}
184 importsFromImportDecl :: (Name -> Bool)         -- True => print unqualified
185                       -> RdrNameImportDecl
186                       -> RnMG (GlobalRdrEnv, 
187                                ExportAvails) 
188
189 importsFromImportDecl rec_unqual_fn (ImportDecl mod qual_only as_source as_mod import_spec iloc)
190   = pushSrcLocRn iloc $
191     getInterfaceExports mod as_source           `thenRn` \ avails ->
192
193     if null avails then
194         -- If there's an error in getInterfaceExports, (e.g. interface
195         -- file not found) then avail might be NotAvailable, so availName
196         -- in home_modules fails.  Hence the guard here.  Also we get lots
197         -- of spurious errors from 'filterImports' if we don't find the interface file
198         returnRn (emptyRdrEnv, mkEmptyExportAvails mod)
199     else
200
201     filterImports mod import_spec avails        `thenRn` \ (filtered_avails, hides, explicits) ->
202
203         -- Load all the home modules for the things being
204         -- bought into scope.  This makes sure their fixities
205         -- are loaded before we grab the FixityEnv from Ifaces
206     let
207         home_modules = [name | avail <- filtered_avails,
208                                 -- Doesn't take account of hiding, but that doesn't matter
209                 
210                                let name = availName avail,
211                                nameModule name /= mod]
212                                 -- This predicate is a bit of a hack.
213                                 -- PrelBase imports error from PrelErr.hi-boot; but error is
214                                 -- wired in, so its provenance doesn't say it's from an hi-boot
215                                 -- file. Result: disaster when PrelErr.hi doesn't exist.
216                                 
217         same_module n1 n2 = nameModule n1 == nameModule n2
218         load n            = loadHomeInterface (doc_str n) n
219         doc_str n         = ptext SLIT("Need fixities from") <+> ppr (nameModule n) <+> parens (ppr n)
220     in
221     mapRn load (nubBy same_module home_modules)                 `thenRn_`
222     
223         -- We 'improve' the provenance by setting
224         --      (a) the import-reason field, so that the Name says how it came into scope
225         --              including whether it's explicitly imported
226         --      (b) the print-unqualified field
227         -- But don't fiddle with wired-in things or we get in a twist
228     let
229         improve_prov name | isWiredInName name = name
230                           | otherwise          = setNameProvenance name (mk_new_prov name)
231
232         is_explicit name = name `elemNameSet` explicits
233         mk_new_prov name = NonLocalDef (UserImport mod iloc (is_explicit name))
234                                        as_source
235                                        (rec_unqual_fn name)
236     in
237     qualifyImports mod 
238                    (not qual_only)      -- Maybe want unqualified names
239                    as_mod hides
240                    filtered_avails improve_prov         `thenRn` \ (rdr_name_env, mod_avails) ->
241
242     returnRn (rdr_name_env, mod_avails)
243 \end{code}
244
245
246 \begin{code}
247 importsFromLocalDecls mod rec_exp_fn decls
248   = mapRn (getLocalDeclBinders newLocalName) decls      `thenRn` \ avails_s ->
249
250     let
251         avails = concat avails_s
252
253         all_names :: [Name]     -- All the defns; no dups eliminated
254         all_names = [name | avail <- avails, name <- availNames avail]
255
256         dups :: [[Name]]
257         dups = filter non_singleton (equivClassesByUniq getUnique all_names)
258              where
259                 non_singleton (x1:x2:xs) = True
260                 non_singleton other      = False
261     in
262         -- Check for duplicate definitions
263     mapRn (addErrRn . dupDeclErr) dups                          `thenRn_` 
264
265         -- Record that locally-defined things are available
266     mapRn (recordSlurp Nothing Compulsory) avails       `thenRn_`
267
268         -- Build the environment
269     qualifyImports mod 
270                    True         -- Want unqualified names
271                    Nothing      -- no 'as M'
272                    []           -- Hide nothing
273                    avails
274                    (\n -> n)
275
276   where
277     newLocalName rdr_name loc = newLocallyDefinedGlobalName mod (rdrNameOcc rdr_name)
278                                                             rec_exp_fn loc
279
280 getLocalDeclBinders :: (RdrName -> SrcLoc -> RnMG Name) -- New-name function
281                     -> RdrNameHsDecl
282                     -> RnMG Avails
283 getLocalDeclBinders new_name (ValD binds)
284   = mapRn do_one (bagToList (collectTopBinders binds))
285   where
286     do_one (rdr_name, loc) = new_name rdr_name loc      `thenRn` \ name ->
287                              returnRn (Avail name)
288
289     -- foreign import declaration
290 getLocalDeclBinders new_name (ForD (ForeignDecl nm kind _ _ _ loc))
291   | binds_haskell_name kind
292   = new_name nm loc                 `thenRn` \ name ->
293     returnRn [Avail name]
294
295   | otherwise
296   = returnRn []
297
298 getLocalDeclBinders new_name decl
299   = getDeclBinders new_name decl        `thenRn` \ avail ->
300     case avail of
301         NotAvailable -> returnRn []             -- Instance decls and suchlike
302         other        -> returnRn [avail]
303
304 binds_haskell_name (FoImport _) = True
305 binds_haskell_name FoLabel      = True
306 binds_haskell_name FoExport     = False
307
308 fixitiesFromLocalDecls :: GlobalRdrEnv -> [RdrNameHsDecl] -> RnMG FixityEnv
309 fixitiesFromLocalDecls gbl_env decls
310   = foldlRn getFixities emptyNameEnv decls
311   where
312     getFixities :: FixityEnv -> RdrNameHsDecl -> RnMG FixityEnv
313     getFixities acc (FixD fix)
314       = fix_decl acc fix
315
316     getFixities acc (TyClD (ClassDecl _ _ _ sigs _ _ _ _ _))
317       = foldlRn fix_decl acc [sig | FixSig sig <- sigs]
318                 -- Get fixities from class decl sigs too
319
320     getFixities acc other_decl
321       = returnRn acc
322
323     fix_decl acc (FixitySig rdr_name fixity loc)
324         =       -- Check for fixity decl for something not declared
325           case lookupRdrEnv gbl_env rdr_name of {
326             Nothing   -> pushSrcLocRn loc                               $
327                          addWarnRn (unusedFixityDecl rdr_name fixity)   `thenRn_`
328                          returnRn acc ;
329             Just (name:_) ->
330
331                 -- Check for duplicate fixity decl
332           case lookupNameEnv acc name of {
333             Just (FixitySig _ _ loc') -> addErrRn (dupFixityDecl rdr_name loc loc')     `thenRn_`
334                                          returnRn acc ;
335
336
337             Nothing -> returnRn (addToNameEnv acc name (FixitySig name fixity loc))
338           }}
339 \end{code}
340
341 %************************************************************************
342 %*                                                                      *
343 \subsection{Filtering imports}
344 %*                                                                      *
345 %************************************************************************
346
347 @filterImports@ takes the @ExportEnv@ telling what the imported module makes
348 available, and filters it through the import spec (if any).
349
350 \begin{code}
351 filterImports :: Module
352               -> Maybe (Bool, [RdrNameIE])      -- Import spec; True => hiding
353               -> [AvailInfo]                    -- What's available
354               -> RnMG ([AvailInfo],             -- What's actually imported
355                        [AvailInfo],             -- What's to be hidden (the unqualified version, that is)
356                        NameSet)                 -- What was imported explicitly
357
358         -- Complains if import spec mentions things that the module doesn't export
359         -- Warns/informs if import spec contains duplicates.
360 filterImports mod Nothing imports
361   = returnRn (imports, [], emptyNameSet)
362
363 filterImports mod (Just (want_hiding, import_items)) avails
364   = mapRn check_item import_items               `thenRn` \ item_avails ->
365     if want_hiding 
366     then        
367         -- All imported; item_avails to be hidden
368         returnRn (avails, item_avails, emptyNameSet)
369     else
370         -- Just item_avails imported; nothing to be hidden
371         returnRn (item_avails, [], availsToNameSet item_avails)
372
373   where
374     import_fm :: FiniteMap OccName AvailInfo
375     import_fm = listToFM [ (nameOccName name, avail) 
376                          | avail <- avails,
377                            name  <- availNames avail]
378         -- Even though availNames returns data constructors too,
379         -- they won't make any difference because naked entities like T
380         -- in an import list map to TCOccs, not VarOccs.
381
382     check_item item@(IEModuleContents _)
383       = addErrRn (badImportItemErr mod item)    `thenRn_`
384         returnRn NotAvailable
385
386     check_item item
387       | not (maybeToBool maybe_in_import_avails) ||
388         (case filtered_avail of { NotAvailable -> True; other -> False })
389       = addErrRn (badImportItemErr mod item)    `thenRn_`
390         returnRn NotAvailable
391
392       | dodgy_import = addWarnRn (dodgyImportWarn mod item)     `thenRn_`
393                        returnRn filtered_avail
394
395       | otherwise    = returnRn filtered_avail
396                 
397       where
398         maybe_in_import_avails = lookupFM import_fm (ieOcc item)
399         Just avail             = maybe_in_import_avails
400         filtered_avail         = filterAvail item avail
401         dodgy_import           = case (item, avail) of
402                                    (IEThingAll _, AvailTC _ [n]) -> True
403                                         -- This occurs when you import T(..), but
404                                         -- only export T abstractly.  The single [n]
405                                         -- in the AvailTC is the type or class itself
406                                         
407                                    other -> False
408                                         
409 \end{code}
410
411
412
413 %************************************************************************
414 %*                                                                      *
415 \subsection{Qualifiying imports}
416 %*                                                                      *
417 %************************************************************************
418
419 @qualifyImports@ takes the @ExportEnv@ after filtering through the import spec
420 of an import decl, and deals with producing an @RnEnv@ with the 
421 right qualified names.  It also turns the @Names@ in the @ExportEnv@ into
422 fully fledged @Names@.
423
424 \begin{code}
425 qualifyImports :: Module                -- Imported module
426                -> Bool                  -- True <=> want unqualified import
427                -> Maybe Module          -- Optional "as M" part 
428                -> [AvailInfo]           -- What's to be hidden
429                -> Avails                -- Whats imported and how
430                -> (Name -> Name)        -- Improves the provenance on imported things
431                -> RnMG (GlobalRdrEnv, ExportAvails)
432         -- NB: the Names in ExportAvails don't have the improve-provenance
433         --     function applied to them
434         -- We could fix that, but I don't think it matters
435
436 qualifyImports this_mod unqual_imp as_mod hides
437                avails improve_prov
438   = 
439         -- Make the name environment.  We're talking about a 
440         -- single module here, so there must be no name clashes.
441         -- In practice there only ever will be if it's the module
442         -- being compiled.
443     let
444         -- Add the things that are available
445         name_env1 = foldl add_avail emptyRdrEnv avails
446
447         -- Delete things that are hidden
448         name_env2 = foldl del_avail name_env1 hides
449
450         -- Create the export-availability info
451         export_avails = mkExportAvails qual_mod unqual_imp name_env2 avails
452     in
453     returnRn (name_env2, export_avails)
454
455   where
456     qual_mod = case as_mod of
457                   Nothing           -> this_mod
458                   Just another_name -> another_name
459
460     add_avail :: GlobalRdrEnv -> AvailInfo -> GlobalRdrEnv
461     add_avail env avail = foldl add_name env (availNames avail)
462
463     add_name env name
464         | unqual_imp = env2
465         | otherwise  = env1
466         where
467           env1 = addOneToGlobalRdrEnv env  (Qual qual_mod occ err_hif) better_name
468           env2 = addOneToGlobalRdrEnv env1 (Unqual occ)                better_name
469           occ         = nameOccName name
470           better_name = improve_prov name
471
472     del_avail env avail = foldl delOneFromGlobalRdrEnv env rdr_names
473                         where
474                           rdr_names = map (Unqual . nameOccName) (availNames avail)
475                         
476 err_hif = error "qualifyImports: hif"   -- Not needed in key to mapping
477 \end{code}
478
479
480 %************************************************************************
481 %*                                                                      *
482 \subsection{Export list processing
483 %*                                                                      *
484 %************************************************************************
485
486 Processing the export list.
487
488 You might think that we should record things that appear in the export list as
489 ``occurrences'' (using addOccurrenceName), but you'd be wrong.  We do check (here)
490 that they are in scope, but there is no need to slurp in their actual declaration
491 (which is what addOccurrenceName forces).  Indeed, doing so would big trouble when
492 compiling PrelBase, because it re-exports GHC, which includes takeMVar#, whose type
493 includes ConcBase.StateAndSynchVar#, and so on...
494
495 \begin{code}
496 type ExportAccum        -- The type of the accumulating parameter of
497                         -- the main worker function in exportsFromAvail
498      = ([Module],               -- 'module M's seen so far
499         ExportOccMap,           -- Tracks exported occurrence names
500         NameEnv AvailInfo)      -- The accumulated exported stuff, kept in an env
501                                 --   so we can common-up related AvailInfos
502
503 type ExportOccMap = FiniteMap OccName (Name, RdrNameIE)
504         -- Tracks what a particular exported OccName
505         --   in an export list refers to, and which item
506         --   it came from.  It's illegal to export two distinct things
507         --   that have the same occurrence name
508
509
510 exportsFromAvail :: Module
511                  -> Maybe [RdrNameIE]   -- Export spec
512                  -> ExportAvails
513                  -> RnEnv
514                  -> RnMG (Name -> ExportFlag, ExportEnv)
515         -- Complains if two distinct exports have same OccName
516         -- Warns about identical exports.
517         -- Complains about exports items not in scope
518 exportsFromAvail this_mod Nothing export_avails rn_env
519   = exportsFromAvail this_mod (Just [IEModuleContents this_mod]) export_avails rn_env
520
521 exportsFromAvail this_mod (Just export_items) 
522                  (mod_avail_env, entity_avail_env)
523                  (RnEnv global_name_env fixity_env)
524   = foldlRn exports_from_item
525             ([], emptyFM, emptyNameEnv) export_items    `thenRn` \ (_, _, export_avail_map) ->
526     let
527         export_avails :: [AvailInfo]
528         export_avails   = nameEnvElts export_avail_map
529
530         export_names :: NameSet
531         export_names = availsToNameSet export_avails
532
533         -- Export only those fixities that are for names that are
534         --      (a) defined in this module
535         --      (b) exported
536         export_fixities :: [(Name,Fixity)]
537         export_fixities = [ (name,fixity) 
538                           | FixitySig name fixity _ <- nameEnvElts fixity_env,
539                             name `elemNameSet` export_names,
540                             isLocallyDefined name
541                           ]
542
543         export_fn :: Name -> ExportFlag
544         export_fn = mk_export_fn export_names
545     in
546     returnRn (export_fn, ExportEnv export_avails export_fixities)
547
548   where
549     exports_from_item :: ExportAccum -> RdrNameIE -> RnMG ExportAccum
550
551     exports_from_item acc@(mods, occs, avails) ie@(IEModuleContents mod)
552         | mod `elem` mods       -- Duplicate export of M
553         = warnCheckRn opt_WarnDuplicateExports
554                       (dupModuleExport mod)     `thenRn_`
555           returnRn acc
556
557         | otherwise
558         = case lookupFM mod_avail_env mod of
559                 Nothing         -> failWithRn acc (modExportErr mod)
560                 Just mod_avails -> foldlRn (check_occs ie) occs mod_avails      `thenRn` \ occs' ->
561                                    let
562                                         avails' = foldl add_avail avails mod_avails
563                                    in
564                                    returnRn (mod:mods, occs', avails')
565
566     exports_from_item acc@(mods, occs, avails) ie
567         | not (maybeToBool maybe_in_scope) 
568         = failWithRn acc (unknownNameErr (ieName ie))
569
570         | not (null dup_names)
571         = addNameClashErrRn rdr_name (name:dup_names)   `thenRn_`
572           returnRn acc
573
574 #ifdef DEBUG
575         -- I can't see why this should ever happen; if the thing is in scope
576         -- at all it ought to have some availability
577         | not (maybeToBool maybe_avail)
578         = pprTrace "exportsFromAvail: curious Nothing:" (ppr name)
579           returnRn acc
580 #endif
581
582         | not enough_avail
583         = failWithRn acc (exportItemErr ie export_avail)
584
585         | otherwise     -- Phew!  It's OK!  Now to check the occurrence stuff!
586         = check_occs ie occs export_avail       `thenRn` \ occs' ->
587           returnRn (mods, occs', add_avail avails export_avail)
588
589        where
590           rdr_name        = ieName ie
591           maybe_in_scope  = lookupFM global_name_env rdr_name
592           Just (name:dup_names) = maybe_in_scope
593           maybe_avail     = lookupUFM entity_avail_env name
594           Just avail      = maybe_avail
595           export_avail    = filterAvail ie avail
596           enough_avail    = case export_avail of {NotAvailable -> False; other -> True}
597
598 add_avail avails avail = addToNameEnv_C plusAvail avails (availName avail) avail
599
600 check_occs :: RdrNameIE -> ExportOccMap -> AvailInfo -> RnMG ExportOccMap
601 check_occs ie occs avail 
602   = foldlRn check occs (availNames avail)
603   where
604     check occs name
605       = case lookupFM occs name_occ of
606           Nothing           -> returnRn (addToFM occs name_occ (name, ie))
607           Just (name', ie') 
608             | name == name' ->  -- Duplicate export
609                                 warnCheckRn opt_WarnDuplicateExports
610                                             (dupExportWarn name_occ ie ie')     `thenRn_`
611                                 returnRn occs
612
613             | otherwise     ->  -- Same occ name but different names: an error
614                                 failWithRn occs (exportClashErr name_occ ie ie')
615       where
616         name_occ = nameOccName name
617         
618 mk_export_fn :: NameSet -> (Name -> ExportFlag)
619 mk_export_fn exported_names
620   = \name -> if name `elemNameSet` exported_names
621              then Exported
622              else NotExported
623 \end{code}
624
625 %************************************************************************
626 %*                                                                      *
627 \subsection{Errors}
628 %*                                                                      *
629 %************************************************************************
630
631 \begin{code}
632 badImportItemErr mod ie
633   = sep [ptext SLIT("Module"), quotes (pprModule mod), 
634          ptext SLIT("does not export"), quotes (ppr ie)]
635
636 dodgyImportWarn mod (IEThingAll tc)
637   = sep [ptext SLIT("Module") <+> quotes (pprModule mod) <+> ptext SLIT("exports") <+> quotes (ppr tc), 
638          ptext SLIT("with no constructors/class operations;"),
639          ptext SLIT("yet it is imported with a (..)")]
640
641 modExportErr mod
642   = hsep [ ptext SLIT("Unknown module in export list: module"), quotes (pprModule mod)]
643
644 exportItemErr export_item NotAvailable
645   = sep [ ptext SLIT("Export item not in scope:"), quotes (ppr export_item)]
646
647 exportItemErr export_item avail
648   = hang (ptext SLIT("Export item not fully in scope:"))
649            4 (vcat [hsep [ptext SLIT("Wanted:   "), ppr export_item],
650                     hsep [ptext SLIT("Available:"), ppr (ieOcc export_item), pprAvail avail]])
651
652 exportClashErr occ_name ie1 ie2
653   = hsep [ptext SLIT("The export items"), quotes (ppr ie1), ptext SLIT("and"), quotes (ppr ie2),
654           ptext SLIT("create conflicting exports for"), quotes (ppr occ_name)]
655
656 dupDeclErr (n:ns)
657   = vcat [ptext SLIT("Multiple declarations of") <+> quotes (ppr n),
658           nest 4 (vcat (map pp (n:ns)))]
659   where
660     pp n = pprProvenance (getNameProvenance n)
661
662 dupExportWarn occ_name ie1 ie2
663   = hsep [quotes (ppr occ_name), 
664           ptext SLIT("is exported by"), quotes (ppr ie1),
665           ptext SLIT("and"),            quotes (ppr ie2)]
666
667 dupModuleExport mod
668   = hsep [ptext SLIT("Duplicate"),
669           quotes (ptext SLIT("Module") <+> pprModule mod), 
670           ptext SLIT("in export list")]
671
672 unusedFixityDecl rdr_name fixity
673   = hsep [ptext SLIT("Unused fixity declaration for"), quotes (ppr rdr_name)]
674
675 dupFixityDecl rdr_name loc1 loc2
676   = vcat [ptext SLIT("Multiple fixity declarations for") <+> quotes (ppr rdr_name),
677           ptext SLIT("at ") <+> ppr loc1,
678           ptext SLIT("and") <+> ppr loc2]
679
680 \end{code}