[project @ 2000-11-20 16:07:12 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, exportsFromAvail
9     ) where
10
11 #include "HsVersions.h"
12
13 import CmdLineOpts      ( DynFlag(..) )
14
15 import HsSyn            ( HsModule(..), HsDecl(..), IE(..), ieName, ImportDecl(..),
16                           ForeignDecl(..), ForKind(..), isDynamicExtName,
17                           collectTopBinders
18                         )
19 import RdrHsSyn         ( RdrNameIE, RdrNameImportDecl,
20                           RdrNameHsModule, RdrNameHsDecl
21                         )
22 import RnIfaces         ( getInterfaceExports, recordLocalSlurps )
23 import RnHiFiles        ( getTyClDeclBinders )
24 import RnEnv
25 import RnMonad
26
27 import FiniteMap
28 import PrelNames        ( pRELUDE_Name, mAIN_Name, main_RDR_Unqual, isUnboundName )
29 import UniqFM           ( lookupUFM )
30 import Bag              ( bagToList )
31 import Module           ( ModuleName, moduleName, WhereFrom(..) )
32 import NameSet
33 import Name             ( Name, nameSrcLoc, nameOccName,  nameEnvElts )
34 import HscTypes         ( Provenance(..), ImportReason(..), GlobalRdrEnv,
35                           GenAvailInfo(..), AvailInfo, Avails, AvailEnv )
36 import RdrName          ( RdrName, rdrNameOcc, setRdrNameOcc, mkRdrQual, mkRdrUnqual )
37 import OccName          ( setOccNameSpace, dataName )
38 import NameSet          ( elemNameSet, emptyNameSet )
39 import Outputable
40 import Maybes           ( maybeToBool, catMaybes, mapMaybe )
41 import UniqFM           ( emptyUFM, listToUFM )
42 import ListSetOps       ( removeDups )
43 import Util             ( sortLt )
44 import List             ( partition )
45 \end{code}
46
47
48
49 %************************************************************************
50 %*                                                                      *
51 \subsection{Get global names}
52 %*                                                                      *
53 %************************************************************************
54
55 \begin{code}
56 getGlobalNames :: Module -> RdrNameHsModule
57                -> RnMG (GlobalRdrEnv,   -- Maps all in-scope things
58                         GlobalRdrEnv,   -- Maps just *local* things
59                         ExportAvails)   -- The exported stuff
60
61 getGlobalNames this_mod (HsModule _ _ _ imports decls _ mod_loc)
62   =             -- PROCESS LOCAL DECLS
63                 -- Do these *first* so that the correct provenance gets
64                 -- into the global name cache.
65         importsFromLocalDecls this_mod decls            `thenRn` \ (local_gbl_env, local_mod_avails) ->
66
67                 -- PROCESS IMPORT DECLS
68                 -- Do the non {- SOURCE -} ones first, so that we get a helpful
69                 -- warning for {- SOURCE -} ones that are unnecessary
70         doptRn Opt_NoImplicitPrelude                            `thenRn` \ opt_no_prelude -> 
71         let
72           all_imports        = mk_prel_imports opt_no_prelude ++ imports
73           (source, ordinary) = partition is_source_import all_imports
74           is_source_import (ImportDecl _ ImportByUserSource _ _ _ _) = True
75           is_source_import other                                     = False
76
77           get_imports = importsFromImportDecl this_mod_name
78         in
79         mapAndUnzipRn get_imports ordinary      `thenRn` \ (imp_gbl_envs1, imp_avails_s1) ->
80         mapAndUnzipRn get_imports source        `thenRn` \ (imp_gbl_envs2, imp_avails_s2) ->
81
82                 -- COMBINE RESULTS
83                 -- We put the local env second, so that a local provenance
84                 -- "wins", even if a module imports itself.
85         let
86             gbl_env :: GlobalRdrEnv
87             imp_gbl_env = foldr plusGlobalRdrEnv emptyRdrEnv (imp_gbl_envs2 ++ imp_gbl_envs1)
88             gbl_env     = imp_gbl_env `plusGlobalRdrEnv` local_gbl_env
89
90             all_avails :: ExportAvails
91             all_avails = foldr plusExportAvails local_mod_avails (imp_avails_s2 ++ imp_avails_s1)
92         in
93
94                 -- ALL DONE
95         returnRn (gbl_env, local_gbl_env, all_avails)
96   where
97     this_mod_name = moduleName this_mod
98
99         -- NB: opt_NoImplicitPrelude is slightly different to import Prelude ();
100         -- because the former doesn't even look at Prelude.hi for instance declarations,
101         -- whereas the latter does.
102     mk_prel_imports no_prelude
103         | this_mod_name == pRELUDE_Name ||
104           explicit_prelude_import ||
105           no_prelude
106         = []
107
108         | otherwise = [ImportDecl pRELUDE_Name
109                                   ImportByUser
110                                   False {- Not qualified -}
111                                   Nothing       {- No "as" -}
112                                   Nothing       {- No import list -}
113                                   mod_loc]
114     
115     explicit_prelude_import
116       = not (null [ () | (ImportDecl mod _ _ _ _ _) <- imports, mod == pRELUDE_Name ])
117 \end{code}
118         
119 \begin{code}
120 importsFromImportDecl :: ModuleName
121                       -> RdrNameImportDecl
122                       -> RnMG (GlobalRdrEnv, 
123                                ExportAvails) 
124
125 importsFromImportDecl this_mod_name (ImportDecl imp_mod_name from qual_only as_mod import_spec iloc)
126   = pushSrcLocRn iloc $
127     getInterfaceExports imp_mod_name from       `thenRn` \ (imp_mod, avails_by_module) ->
128
129     if null avails_by_module then
130         -- If there's an error in getInterfaceExports, (e.g. interface
131         -- file not found) we get lots of spurious errors from 'filterImports'
132         returnRn (emptyRdrEnv, mkEmptyExportAvails imp_mod_name)
133     else
134
135     let
136         avails :: Avails
137         avails = [ avail | (mod_name, avails) <- avails_by_module,
138                            mod_name /= this_mod_name,
139                            avail <- avails ]
140         -- If the module exports anything defined in this module, just ignore it.
141         -- Reason: otherwise it looks as if there are two local definition sites
142         -- for the thing, and an error gets reported.  Easiest thing is just to
143         -- filter them out up front. This situation only arises if a module
144         -- imports itself, or another module that imported it.  (Necessarily,
145         -- this invoves a loop.)  
146         --
147         -- Tiresome consequence: if you say
148         --      module A where
149         --         import B( AType )
150         --         type AType = ...
151         --
152         --      module B( AType ) where
153         --         import {-# SOURCE #-} A( AType )
154         --
155         -- then you'll get a 'B does not export AType' message.  Oh well.
156
157     in
158     filterImports imp_mod_name from import_spec avails  `thenRn` \ (filtered_avails, hides, explicits) ->
159
160     let
161         mk_provenance name = NonLocalDef (UserImport imp_mod iloc (name `elemNameSet` explicits)) 
162     in
163
164     qualifyImports imp_mod_name
165                    (not qual_only)      -- Maybe want unqualified names
166                    as_mod hides
167                    mk_provenance
168                    filtered_avails
169 \end{code}
170
171
172 \begin{code}
173 importsFromLocalDecls this_mod decls
174   = mapRn (getLocalDeclBinders this_mod) decls  `thenRn` \ avails_s ->
175
176     let
177         avails = concat avails_s
178
179         all_names :: [Name]     -- All the defns; no dups eliminated
180         all_names = [name | avail <- avails, name <- availNames avail]
181
182         dups :: [[Name]]
183         (_, dups) = removeDups compare all_names
184     in
185         -- Check for duplicate definitions
186     mapRn_ (addErrRn . dupDeclErr) dups                 `thenRn_` 
187
188         -- Record that locally-defined things are available
189     recordLocalSlurps (availsToNameSet avails)          `thenRn_`
190
191         -- Build the environment
192     qualifyImports (moduleName this_mod)
193                    True                 -- Want unqualified names
194                    Nothing              -- no 'as M'
195                    []                   -- Hide nothing
196                    (\n -> LocalDef)     -- Provenance is local
197                    avails
198
199 ---------------------------
200 getLocalDeclBinders :: Module 
201                     -> RdrNameHsDecl -> RnMG Avails
202 getLocalDeclBinders mod (TyClD tycl_decl)
203   =     -- For type and class decls, we generate Global names, with
204         -- no export indicator.  They need to be global because they get
205         -- permanently bound into the TyCons and Classes.  They don't need
206         -- an export indicator because they are all implicitly exported.
207     getTyClDeclBinders mod tycl_decl    `thenRn` \ avail ->
208     returnRn [avail]
209
210 getLocalDeclBinders mod (ValD binds)
211   = mapRn new (bagToList (collectTopBinders binds))
212   where
213     new (rdr_name, loc) = newTopBinder mod rdr_name loc         `thenRn` \ name ->
214                           returnRn (Avail name)
215
216 getLocalDeclBinders mod (ForD (ForeignDecl nm kind _ ext_nm _ loc))
217   | binds_haskell_name kind
218   = newTopBinder mod nm loc         `thenRn` \ name ->
219     returnRn [Avail name]
220
221   | otherwise           -- a foreign export
222   = returnRn []
223   where
224     binds_haskell_name (FoImport _) = True
225     binds_haskell_name FoLabel      = True
226     binds_haskell_name FoExport     = isDynamicExtName ext_nm
227
228 getLocalDeclBinders mod (FixD _)    = returnRn []
229 getLocalDeclBinders mod (DeprecD _) = returnRn []
230 getLocalDeclBinders mod (DefD _)    = returnRn []
231 getLocalDeclBinders mod (InstD _)   = returnRn []
232 getLocalDeclBinders mod (RuleD _)   = returnRn []
233 \end{code}
234
235
236 %************************************************************************
237 %*                                                                      *
238 \subsection{Filtering imports}
239 %*                                                                      *
240 %************************************************************************
241
242 @filterImports@ takes the @ExportEnv@ telling what the imported module makes
243 available, and filters it through the import spec (if any).
244
245 \begin{code}
246 filterImports :: ModuleName                     -- The module being imported
247               -> WhereFrom                      -- Tells whether it's a {-# SOURCE #-} import
248               -> Maybe (Bool, [RdrNameIE])      -- Import spec; True => hiding
249               -> [AvailInfo]                    -- What's available
250               -> RnMG ([AvailInfo],             -- What's actually imported
251                        [AvailInfo],             -- What's to be hidden
252                                                 -- (the unqualified version, that is)
253                         -- (We need to return both the above sets, because
254                         --  the qualified version is never hidden; so we can't
255                         --  implement hiding by reducing what's imported.)
256                        NameSet)                 -- What was imported explicitly
257
258         -- Complains if import spec mentions things that the module doesn't export
259         -- Warns/informs if import spec contains duplicates.
260 filterImports mod from Nothing imports
261   = returnRn (imports, [], emptyNameSet)
262
263 filterImports mod from (Just (want_hiding, import_items)) total_avails
264   = flatMapRn get_item import_items             `thenRn` \ avails_w_explicits ->
265     let
266         (item_avails, explicits_s) = unzip avails_w_explicits
267         explicits                  = foldl addListToNameSet emptyNameSet explicits_s
268     in
269     if want_hiding 
270     then        
271         -- All imported; item_avails to be hidden
272         returnRn (total_avails, item_avails, emptyNameSet)
273     else
274         -- Just item_avails imported; nothing to be hidden
275         returnRn (item_avails, [], explicits)
276   where
277     import_fm :: FiniteMap OccName AvailInfo
278     import_fm = listToFM [ (nameOccName name, avail) 
279                          | avail <- total_avails,
280                            name  <- availNames avail]
281         -- Even though availNames returns data constructors too,
282         -- they won't make any difference because naked entities like T
283         -- in an import list map to TcOccs, not VarOccs.
284
285     bale_out item = addErrRn (badImportItemErr mod from item)   `thenRn_`
286                     returnRn []
287
288     get_item item@(IEModuleContents _) = bale_out item
289
290     get_item item@(IEThingAll _)
291       = case check_item item of
292           Nothing                    -> bale_out item
293           Just avail@(AvailTC _ [n]) ->         -- This occurs when you import T(..), but
294                                                 -- only export T abstractly.  The single [n]
295                                                 -- in the AvailTC is the type or class itself
296                                         addWarnRn (dodgyImportWarn mod item)    `thenRn_`
297                                         returnRn [(avail, [availName avail])]
298           Just avail                 -> returnRn [(avail, [availName avail])]
299
300     get_item item@(IEThingAbs n)
301       | want_hiding     -- hiding( C ) 
302                         -- Here the 'C' can be a data constructor *or* a type/class
303       = case catMaybes [check_item item, check_item (IEThingAbs data_n)] of
304                 []     -> bale_out item
305                 avails -> returnRn [(a, []) | a <- avails]
306                                 -- The 'explicits' list is irrelevant when hiding
307       where
308         data_n = setRdrNameOcc n (setOccNameSpace (rdrNameOcc n) dataName)
309
310     get_item item
311       = case check_item item of
312           Nothing    -> bale_out item
313           Just avail -> returnRn [(avail, availNames avail)]
314
315     check_item item
316       | not (maybeToBool maybe_in_import_avails) ||
317         not (maybeToBool maybe_filtered_avail)
318       = Nothing
319
320       | otherwise    
321       = Just filtered_avail
322                 
323       where
324         wanted_occ             = rdrNameOcc (ieName item)
325         maybe_in_import_avails = lookupFM import_fm wanted_occ
326
327         Just avail             = maybe_in_import_avails
328         maybe_filtered_avail   = filterAvail item avail
329         Just filtered_avail    = maybe_filtered_avail
330 \end{code}
331
332
333
334 %************************************************************************
335 %*                                                                      *
336 \subsection{Qualifiying imports}
337 %*                                                                      *
338 %************************************************************************
339
340 @qualifyImports@ takes the @ExportEnv@ after filtering through the import spec
341 of an import decl, and deals with producing an @RnEnv@ with the 
342 right qualified names.  It also turns the @Names@ in the @ExportEnv@ into
343 fully fledged @Names@.
344
345 \begin{code}
346 qualifyImports :: ModuleName            -- Imported module
347                -> Bool                  -- True <=> want unqualified import
348                -> Maybe ModuleName      -- Optional "as M" part 
349                -> [AvailInfo]           -- What's to be hidden
350                -> (Name -> Provenance)
351                -> Avails                -- Whats imported and how
352                -> RnMG (GlobalRdrEnv, ExportAvails)
353
354 qualifyImports this_mod unqual_imp as_mod hides mk_provenance avails
355   = 
356         -- Make the name environment.  We're talking about a 
357         -- single module here, so there must be no name clashes.
358         -- In practice there only ever will be if it's the module
359         -- being compiled.
360     let
361         -- Add the things that are available
362         name_env1 = foldl add_avail emptyRdrEnv avails
363
364         -- Delete things that are hidden
365         name_env2 = foldl del_avail name_env1 hides
366
367         -- Create the export-availability info
368         export_avails = mkExportAvails qual_mod unqual_imp name_env2 avails
369     in
370     returnRn (name_env2, export_avails)
371
372   where
373     qual_mod = case as_mod of
374                   Nothing           -> this_mod
375                   Just another_name -> another_name
376
377     add_avail :: GlobalRdrEnv -> AvailInfo -> GlobalRdrEnv
378     add_avail env avail = foldl add_name env (availNames avail)
379
380     add_name env name
381         | unqual_imp = env2
382         | otherwise  = env1
383         where
384           env1 = addOneToGlobalRdrEnv env  (mkRdrQual qual_mod occ) (name,prov)
385           env2 = addOneToGlobalRdrEnv env1 (mkRdrUnqual occ)        (name,prov)
386           occ  = nameOccName name
387           prov = mk_provenance name
388
389     del_avail env avail = foldl delOneFromGlobalRdrEnv env rdr_names
390                         where
391                           rdr_names = map (mkRdrUnqual . nameOccName) (availNames avail)
392
393
394 mkEmptyExportAvails :: ModuleName -> ExportAvails
395 mkEmptyExportAvails mod_name = (unitFM mod_name [], emptyUFM)
396
397 mkExportAvails :: ModuleName -> Bool -> GlobalRdrEnv -> [AvailInfo] -> ExportAvails
398 mkExportAvails mod_name unqual_imp name_env avails
399   = (mod_avail_env, entity_avail_env)
400   where
401     mod_avail_env = unitFM mod_name unqual_avails 
402
403         -- unqual_avails is the Avails that are visible in *unqualfied* form
404         -- (1.4 Report, Section 5.1.1)
405         -- For example, in 
406         --      import T hiding( f )
407         -- we delete f from avails
408
409     unqual_avails | not unqual_imp = [] -- Short cut when no unqualified imports
410                   | otherwise      = mapMaybe prune avails
411
412     prune (Avail n) | unqual_in_scope n = Just (Avail n)
413     prune (Avail n) | otherwise         = Nothing
414     prune (AvailTC n ns) | null uqs     = Nothing
415                          | otherwise    = Just (AvailTC n uqs)
416                          where
417                            uqs = filter unqual_in_scope ns
418
419     unqual_in_scope n = unQualInScope name_env n
420
421     entity_avail_env = listToUFM [ (name,avail) | avail <- avails, 
422                                                   name  <- availNames avail]
423
424 plusExportAvails ::  ExportAvails ->  ExportAvails ->  ExportAvails
425 plusExportAvails (m1, e1) (m2, e2)
426   = (plusFM_C (++) m1 m2, plusAvailEnv e1 e2)
427         -- ToDo: wasteful: we do this once for each constructor!
428 \end{code}
429
430
431 %************************************************************************
432 %*                                                                      *
433 \subsection{Export list processing}
434 %*                                                                      *
435 %************************************************************************
436
437 Processing the export list.
438
439 You might think that we should record things that appear in the export list
440 as ``occurrences'' (using @addOccurrenceName@), but you'd be wrong.
441 We do check (here) that they are in scope,
442 but there is no need to slurp in their actual declaration
443 (which is what @addOccurrenceName@ forces).
444
445 Indeed, doing so would big trouble when
446 compiling @PrelBase@, because it re-exports @GHC@, which includes @takeMVar#@,
447 whose type includes @ConcBase.StateAndSynchVar#@, and so on...
448
449 \begin{code}
450 type ExportAccum        -- The type of the accumulating parameter of
451                         -- the main worker function in exportsFromAvail
452      = ([ModuleName],           -- 'module M's seen so far
453         ExportOccMap,           -- Tracks exported occurrence names
454         AvailEnv)               -- The accumulated exported stuff, kept in an env
455                                 --   so we can common-up related AvailInfos
456
457 type ExportOccMap = FiniteMap OccName (Name, RdrNameIE)
458         -- Tracks what a particular exported OccName
459         --   in an export list refers to, and which item
460         --   it came from.  It's illegal to export two distinct things
461         --   that have the same occurrence name
462
463
464 exportsFromAvail :: ModuleName
465                  -> Maybe [RdrNameIE]   -- Export spec
466                  -> ExportAvails
467                  -> GlobalRdrEnv 
468                  -> RnMG Avails
469         -- Complains if two distinct exports have same OccName
470         -- Warns about identical exports.
471         -- Complains about exports items not in scope
472 exportsFromAvail this_mod Nothing export_avails global_name_env
473   = exportsFromAvail this_mod true_exports export_avails global_name_env
474   where
475     true_exports = Just $ if this_mod == mAIN_Name
476                           then [IEVar main_RDR_Unqual]
477                                -- export Main.main *only* unless otherwise specified,
478                           else [IEModuleContents this_mod]
479                                -- but for all other modules export everything.
480
481 exportsFromAvail this_mod (Just export_items) 
482                  (mod_avail_env, entity_avail_env)
483                  global_name_env
484   = doptRn Opt_WarnDuplicateExports             `thenRn` \ warn_dup_exports ->
485     foldlRn (exports_from_item warn_dup_exports)
486             ([], emptyFM, emptyAvailEnv) export_items
487                                                 `thenRn` \ (_, _, export_avail_map) ->
488     let
489         export_avails :: [AvailInfo]
490         export_avails   = nameEnvElts export_avail_map
491     in
492     returnRn export_avails
493
494   where
495     exports_from_item :: Bool -> ExportAccum -> RdrNameIE -> RnMG ExportAccum
496
497     exports_from_item warn_dups acc@(mods, occs, avails) ie@(IEModuleContents mod)
498         | mod `elem` mods       -- Duplicate export of M
499         = warnCheckRn warn_dups (dupModuleExport mod)   `thenRn_`
500           returnRn acc
501
502         | otherwise
503         = case lookupFM mod_avail_env mod of
504                 Nothing         -> failWithRn acc (modExportErr mod)
505                 Just mod_avails -> foldlRn (check_occs ie) occs mod_avails
506                                    `thenRn` \ occs' ->
507                                    let
508                                         avails' = foldl addAvail avails mod_avails
509                                    in
510                                    returnRn (mod:mods, occs', avails')
511
512     exports_from_item warn_dups acc@(mods, occs, avails) ie
513         = lookupSrcName global_name_env (ieName ie)     `thenRn` \ name -> 
514
515                 -- See what's available in the current environment
516           case lookupUFM entity_avail_env name of {
517             Nothing ->  -- Presumably this happens because lookupSrcName didn't find
518                         -- the name and returned an unboundName, which won't be in
519                         -- the entity_avail_env, of course
520                         WARN( not (isUnboundName name), ppr name )
521                         returnRn acc ;
522
523             Just avail ->
524
525                 -- Filter out the bits we want
526           case filterAvail ie avail of {
527             Nothing ->  -- Not enough availability
528                            failWithRn acc (exportItemErr ie) ;
529
530             Just export_avail ->        
531
532                 -- Phew!  It's OK!  Now to check the occurrence stuff!
533           warnCheckRn (ok_item ie avail) (dodgyExportWarn ie)   `thenRn_`
534           check_occs ie occs export_avail                       `thenRn` \ occs' ->
535           returnRn (mods, occs', addAvail avails export_avail)
536           }}
537
538
539
540 ok_item (IEThingAll _) (AvailTC _ [n]) = False
541   -- This occurs when you import T(..), but
542   -- only export T abstractly.  The single [n]
543   -- in the AvailTC is the type or class itself
544 ok_item _ _ = True
545
546 check_occs :: RdrNameIE -> ExportOccMap -> AvailInfo -> RnMG ExportOccMap
547 check_occs ie occs avail 
548   = doptRn Opt_WarnDuplicateExports     `thenRn` \ warn_dup_exports ->
549     foldlRn (check warn_dup_exports) occs (availNames avail)
550   where
551     check warn_dup occs name
552       = case lookupFM occs name_occ of
553           Nothing           -> returnRn (addToFM occs name_occ (name, ie))
554           Just (name', ie') 
555             | name == name' ->  -- Duplicate export
556                                 warnCheckRn warn_dup
557                                             (dupExportWarn name_occ ie ie')
558                                 `thenRn_` returnRn occs
559
560             | otherwise     ->  -- Same occ name but different names: an error
561                                 failWithRn occs (exportClashErr name_occ ie ie')
562       where
563         name_occ = nameOccName name
564 \end{code}
565
566 %************************************************************************
567 %*                                                                      *
568 \subsection{Errors}
569 %*                                                                      *
570 %************************************************************************
571
572 \begin{code}
573 badImportItemErr mod from ie
574   = sep [ptext SLIT("Module"), quotes (ppr mod), source_import,
575          ptext SLIT("does not export"), quotes (ppr ie)]
576   where
577     source_import = case from of
578                       ImportByUserSource -> ptext SLIT("(hi-boot interface)")
579                       other              -> empty
580
581 dodgyImportWarn mod item = dodgyMsg (ptext SLIT("import")) item
582 dodgyExportWarn     item = dodgyMsg (ptext SLIT("export")) item
583
584 dodgyMsg kind item@(IEThingAll tc)
585   = sep [ ptext SLIT("The") <+> kind <+> ptext SLIT("item") <+> quotes (ppr item),
586           ptext SLIT("suggests that") <+> quotes (ppr tc) <+> ptext SLIT("has constructor or class methods"),
587           ptext SLIT("but it has none; it is a type synonym or abstract type or class") ]
588           
589 modExportErr mod
590   = hsep [ ptext SLIT("Unknown module in export list: module"), quotes (ppr mod)]
591
592 exportItemErr export_item
593   = sep [ ptext SLIT("The export item") <+> quotes (ppr export_item),
594           ptext SLIT("attempts to export constructors or class methods that are not visible here") ]
595
596 exportClashErr occ_name ie1 ie2
597   = hsep [ptext SLIT("The export items"), quotes (ppr ie1)
598          ,ptext SLIT("and"), quotes (ppr ie2)
599          ,ptext SLIT("create conflicting exports for"), quotes (ppr occ_name)]
600
601 dupDeclErr (n:ns)
602   = vcat [ptext SLIT("Multiple declarations of") <+> quotes (ppr n),
603           nest 4 (vcat (map ppr sorted_locs))]
604   where
605     sorted_locs = sortLt occ'ed_before (map nameSrcLoc (n:ns))
606     occ'ed_before a b = LT == compare a b
607
608 dupExportWarn occ_name ie1 ie2
609   = hsep [quotes (ppr occ_name), 
610           ptext SLIT("is exported by"), quotes (ppr ie1),
611           ptext SLIT("and"),            quotes (ppr ie2)]
612
613 dupModuleExport mod
614   = hsep [ptext SLIT("Duplicate"),
615           quotes (ptext SLIT("Module") <+> ppr mod), 
616           ptext SLIT("in export list")]
617 \end{code}