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