[project @ 2001-12-07 08:12:53 by sof]
[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(..), 
17                           collectLocatedHsBinders
18                         )
19 import RdrHsSyn         ( RdrNameIE, RdrNameImportDecl,
20                           RdrNameHsModule, RdrNameHsDecl
21                         )
22 import RnIfaces         ( recordLocalSlurps )
23 import RnHiFiles        ( getTyClDeclBinders, loadInterface )
24 import RnEnv
25 import RnMonad
26
27 import FiniteMap
28 import PrelNames        ( pRELUDE_Name, mAIN_Name, main_RDR_Unqual, isUnboundName )
29 import Module           ( ModuleName, moduleName, WhereFrom(..) )
30 import Name             ( Name, nameSrcLoc, nameOccName )
31 import NameSet
32 import NameEnv
33 import HscTypes         ( Provenance(..), ImportReason(..), GlobalRdrEnv,
34                           GenAvailInfo(..), AvailInfo, Avails, AvailEnv, 
35                           Deprecations(..), ModIface(..), emptyAvailEnv
36                         )
37 import RdrName          ( rdrNameOcc, setRdrNameOcc )
38 import OccName          ( setOccNameSpace, dataName )
39 import NameSet          ( elemNameSet, emptyNameSet )
40 import Outputable
41 import Maybes           ( maybeToBool, catMaybes, mapMaybe )
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
128     loadInterface (ppr imp_mod_name <+> ptext SLIT("is directly imported"))
129                   imp_mod_name from                     `thenRn` \ iface ->
130     let
131         imp_mod          = mi_module iface
132         avails_by_module = mi_exports iface
133         deprecs          = mi_deprecs iface
134
135         avails :: Avails
136         avails = [ avail | (mod_name, avails) <- avails_by_module,
137                            mod_name /= this_mod_name,
138                            avail <- avails ]
139         -- If the module exports anything defined in this module, just ignore it.
140         -- Reason: otherwise it looks as if there are two local definition sites
141         -- for the thing, and an error gets reported.  Easiest thing is just to
142         -- filter them out up front. This situation only arises if a module
143         -- imports itself, or another module that imported it.  (Necessarily,
144         -- this invoves a loop.)  
145         --
146         -- Tiresome consequence: if you say
147         --      module A where
148         --         import B( AType )
149         --         type AType = ...
150         --
151         --      module B( AType ) where
152         --         import {-# SOURCE #-} A( AType )
153         --
154         -- then you'll get a 'B does not export AType' message.  Oh well.
155
156     in
157     if null avails_by_module then
158         -- If there's an error in loadInterface, (e.g. interface
159         -- file not found) we get lots of spurious errors from 'filterImports'
160         returnRn (emptyRdrEnv, mkEmptyExportAvails imp_mod_name)
161     else
162
163         -- Complain if we import a deprecated module
164     ifOptRn Opt_WarnDeprecations        (
165        case deprecs of  
166           DeprecAll txt -> addWarnRn (moduleDeprec imp_mod_name txt)
167           other         -> returnRn ()
168     )                                                   `thenRn_`
169
170         -- Filter the imports according to the import list
171     filterImports imp_mod_name from import_spec avails  `thenRn` \ (filtered_avails, hides, explicits) ->
172
173     let
174         unqual_imp = not qual_only              -- Maybe want unqualified names
175         qual_mod   = case as_mod of
176                         Nothing           -> imp_mod_name
177                         Just another_name -> another_name
178
179         mk_prov name = NonLocalDef (UserImport imp_mod iloc (name `elemNameSet` explicits)) 
180         gbl_env      = mkGlobalRdrEnv qual_mod unqual_imp mk_prov filtered_avails hides deprecs
181         exports      = mkExportAvails qual_mod unqual_imp gbl_env hides filtered_avails
182     in
183     returnRn (gbl_env, exports)
184 \end{code}
185
186
187 \begin{code}
188 importsFromLocalDecls this_mod decls
189   = mapRn (getLocalDeclBinders this_mod) decls  `thenRn` \ avails_s ->
190         -- The avails that are returned don't include the "system" names
191     let
192         avails = concat avails_s
193
194         all_names :: [Name]     -- All the defns; no dups eliminated
195         all_names = [name | avail <- avails, name <- availNames avail]
196
197         dups :: [[Name]]
198         (_, dups) = removeDups compare all_names
199     in
200         -- Check for duplicate definitions
201         -- The complaint will come out as "Multiple declarations of Foo.f" because
202         -- since 'f' is in the env twice, the unQualInScope used by the error-msg
203         -- printer returns False.  It seems awkward to fix, unfortunately.
204     mapRn_ (addErrRn . dupDeclErr) dups                 `thenRn_` 
205
206
207         -- Record that locally-defined things are available
208     recordLocalSlurps (availsToNameSet avails)          `thenRn_`
209     let
210         mod_name   = moduleName this_mod
211         unqual_imp = True       -- Want unqualified names
212         mk_prov n  = LocalDef   -- Provenance is local
213         hides      = []         -- Hide nothing
214
215         gbl_env    = mkGlobalRdrEnv mod_name unqual_imp mk_prov avails hides NoDeprecs
216             -- NoDeprecs: don't complain about locally defined names
217             -- For a start, we may be exporting a deprecated thing
218             -- Also we may use a deprecated thing in the defn of another
219             -- deprecated things.  We may even use a deprecated thing in
220             -- the defn of a non-deprecated thing, when changing a module's 
221             -- interface
222
223         exports    = mkExportAvails mod_name unqual_imp gbl_env hides avails
224     in
225     returnRn (gbl_env, exports)
226
227 ---------------------------
228 getLocalDeclBinders :: Module -> RdrNameHsDecl -> RnMG [AvailInfo]
229 getLocalDeclBinders mod (TyClD tycl_decl)
230   =     -- For type and class decls, we generate Global names, with
231         -- no export indicator.  They need to be global because they get
232         -- permanently bound into the TyCons and Classes.  They don't need
233         -- an export indicator because they are all implicitly exported.
234     getTyClDeclBinders mod tycl_decl    `thenRn` \ (avail, sys_names) ->
235
236         -- Record that the system names are available
237     recordLocalSlurps (mkNameSet sys_names)     `thenRn_`
238     returnRn [avail]
239
240 getLocalDeclBinders mod (ValD binds)
241   = mapRn new (collectLocatedHsBinders binds)           `thenRn` \ avails ->
242     returnRn avails
243   where
244     new (rdr_name, loc) = newTopBinder mod rdr_name loc         `thenRn` \ name ->
245                           returnRn (Avail name)
246
247 getLocalDeclBinders mod (ForD (ForeignImport nm _ _ loc))
248   = newTopBinder mod nm loc         `thenRn` \ name ->
249     returnRn [Avail name]
250 getLocalDeclBinders mod (ForD _)
251   = returnRn []
252
253 getLocalDeclBinders mod (FixD _)    = returnRn []
254 getLocalDeclBinders mod (DeprecD _) = returnRn []
255 getLocalDeclBinders mod (DefD _)    = returnRn []
256 getLocalDeclBinders mod (InstD _)   = returnRn []
257 getLocalDeclBinders mod (RuleD _)   = returnRn []
258 \end{code}
259
260
261 %************************************************************************
262 %*                                                                      *
263 \subsection{Filtering imports}
264 %*                                                                      *
265 %************************************************************************
266
267 @filterImports@ takes the @ExportEnv@ telling what the imported module makes
268 available, and filters it through the import spec (if any).
269
270 \begin{code}
271 filterImports :: ModuleName                     -- The module being imported
272               -> WhereFrom                      -- Tells whether it's a {-# SOURCE #-} import
273               -> Maybe (Bool, [RdrNameIE])      -- Import spec; True => hiding
274               -> [AvailInfo]                    -- What's available
275               -> RnMG ([AvailInfo],             -- "chosens"
276                        [AvailInfo],             -- "hides"
277                         -- The true imports are "chosens" - "hides"
278                         -- (It's convenient to return both the above sets, because
279                         --  the substraction can be done more efficiently when
280                         --  building the environment.)
281                        NameSet)                 -- What was imported explicitly
282
283         -- Complains if import spec mentions things that the module doesn't export
284         -- Warns/informs if import spec contains duplicates.
285 filterImports mod from Nothing imports
286   = returnRn (imports, [], emptyNameSet)
287
288 filterImports mod from (Just (want_hiding, import_items)) total_avails
289   = flatMapRn get_item import_items             `thenRn` \ avails_w_explicits ->
290     let
291         (item_avails, explicits_s) = unzip avails_w_explicits
292         explicits                  = foldl addListToNameSet emptyNameSet explicits_s
293     in
294     if want_hiding 
295     then        
296         -- All imported; item_avails to be hidden
297         returnRn (total_avails, item_avails, emptyNameSet)
298     else
299         -- Just item_avails imported; nothing to be hidden
300         returnRn (item_avails, [], explicits)
301   where
302     import_fm :: FiniteMap OccName AvailInfo
303     import_fm = listToFM [ (nameOccName name, avail) 
304                          | avail <- total_avails,
305                            name  <- availNames avail]
306         -- Even though availNames returns data constructors too,
307         -- they won't make any difference because naked entities like T
308         -- in an import list map to TcOccs, not VarOccs.
309
310     bale_out item = addErrRn (badImportItemErr mod from item)   `thenRn_`
311                     returnRn []
312
313     get_item :: RdrNameIE -> RnMG [(AvailInfo, [Name])]
314     get_item item@(IEModuleContents _) = bale_out item
315
316     get_item item@(IEThingAll _)
317       = case check_item item of
318           Nothing                    -> bale_out item
319           Just avail@(AvailTC _ [n]) ->         -- This occurs when you import T(..), but
320                                                 -- only export T abstractly.  The single [n]
321                                                 -- in the AvailTC is the type or class itself
322                                         ifOptRn Opt_WarnMisc (addWarnRn (dodgyImportWarn mod item))     `thenRn_`
323                                         returnRn [(avail, [availName avail])]
324           Just avail                 -> returnRn [(avail, [availName avail])]
325
326     get_item item@(IEThingAbs n)
327       | want_hiding     -- hiding( C ) 
328                         -- Here the 'C' can be a data constructor *or* a type/class
329       = case catMaybes [check_item item, check_item (IEVar data_n)] of
330                 []     -> bale_out item
331                 avails -> returnRn [(a, []) | a <- avails]
332                                 -- The 'explicits' list is irrelevant when hiding
333       where
334         data_n = setRdrNameOcc n (setOccNameSpace (rdrNameOcc n) dataName)
335
336     get_item item
337       = case check_item item of
338           Nothing    -> bale_out item
339           Just avail -> returnRn [(avail, availNames avail)]
340
341     check_item item
342       | not (maybeToBool maybe_in_import_avails) ||
343         not (maybeToBool maybe_filtered_avail)
344       = Nothing
345
346       | otherwise    
347       = Just filtered_avail
348                 
349       where
350         wanted_occ             = rdrNameOcc (ieName item)
351         maybe_in_import_avails = lookupFM import_fm wanted_occ
352
353         Just avail             = maybe_in_import_avails
354         maybe_filtered_avail   = filterAvail item avail
355         Just filtered_avail    = maybe_filtered_avail
356 \end{code}
357
358
359
360 %************************************************************************
361 %*                                                                      *
362 \subsection{Qualifiying imports}
363 %*                                                                      *
364 %************************************************************************
365
366 \begin{code}
367 mkEmptyExportAvails :: ModuleName -> ExportAvails
368 mkEmptyExportAvails mod_name = (unitFM mod_name [], emptyNameEnv)
369
370 mkExportAvails :: ModuleName -> Bool -> GlobalRdrEnv -> [AvailInfo] -> [AvailInfo] -> ExportAvails
371 mkExportAvails mod_name unqual_imp gbl_env hides avails 
372   = (mod_avail_env, entity_avail_env)
373   where
374     mod_avail_env = unitFM mod_name unqual_avails 
375
376         -- unqual_avails is the Avails that are visible in *unqualfied* form
377         -- (1.4 Report, Section 5.1.1)
378         -- For example, in 
379         --      import T hiding( f )
380         -- we delete f from avails
381
382     unqual_avails | not unqual_imp = [] -- Short cut when no unqualified imports
383                   | otherwise      = mapMaybe prune avails
384
385     prune (Avail n) | unqual_in_scope n = Just (Avail n)
386                     | otherwise         = Nothing
387     prune (AvailTC n ns) | null uqs     = Nothing
388                          | otherwise    = Just (AvailTC n uqs)
389                          where
390                            uqs = filter unqual_in_scope ns
391
392     unqual_in_scope n = unQualInScope gbl_env n
393
394
395     entity_avail_env  = mkNameEnv ([ (availName avail,avail) | avail <- effective_avails ]  ++
396                                         -- sigh - need to have the method/field names in
397                                         -- the environment also, so that export lists
398                                         -- can be computed precisely (cf. exportsFromAvail)
399                                    [ (name,avail) | avail <- effective_avails,
400                                                     name  <- avNames avail ] )
401
402     avNames (Avail n) = [n]
403     avNames (AvailTC n ns) = filter (/=n) ns
404
405         -- remove 'hides' names from the avail list.
406     effective_avails = foldl wipeOut avails hides
407       where
408         wipeOut as (Avail n)       = mapMaybe (delName n) as
409         wipeOut as (AvailTC n ns)  = foldl wipeOut as (map Avail ns)
410
411         delName x a@(Avail n) 
412           | n == x    = Nothing
413           | otherwise = Just a
414         delName x (AvailTC n ns) 
415           = case (filter (/=x) ns) of
416               [] -> Nothing
417               xs -> Just (AvailTC n xs)
418
419 plusExportAvails ::  ExportAvails ->  ExportAvails ->  ExportAvails
420 plusExportAvails (m1, e1) (m2, e2)
421   = (plusFM_C (++) m1 m2, plusAvailEnv e1 e2)
422         -- ToDo: wasteful: we do this once for each constructor!
423 \end{code}
424
425
426 %************************************************************************
427 %*                                                                      *
428 \subsection{Export list processing}
429 %*                                                                      *
430 %************************************************************************
431
432 Processing the export list.
433
434 You might think that we should record things that appear in the export list
435 as ``occurrences'' (using @addOccurrenceName@), but you'd be wrong.
436 We do check (here) that they are in scope,
437 but there is no need to slurp in their actual declaration
438 (which is what @addOccurrenceName@ forces).
439
440 Indeed, doing so would big trouble when
441 compiling @PrelBase@, because it re-exports @GHC@, which includes @takeMVar#@,
442 whose type includes @ConcBase.StateAndSynchVar#@, and so on...
443
444 \begin{code}
445 type ExportAccum        -- The type of the accumulating parameter of
446                         -- the main worker function in exportsFromAvail
447      = ([ModuleName],           -- 'module M's seen so far
448         ExportOccMap,           -- Tracks exported occurrence names
449         AvailEnv)               -- The accumulated exported stuff, kept in an env
450                                 --   so we can common-up related AvailInfos
451
452 type ExportOccMap = FiniteMap OccName (Name, RdrNameIE)
453         -- Tracks what a particular exported OccName
454         --   in an export list refers to, and which item
455         --   it came from.  It's illegal to export two distinct things
456         --   that have the same occurrence name
457
458
459 exportsFromAvail :: ModuleName
460                  -> Maybe [RdrNameIE]   -- Export spec
461                  -> ExportAvails
462                  -> GlobalRdrEnv 
463                  -> RnMG Avails
464         -- Complains if two distinct exports have same OccName
465         -- Warns about identical exports.
466         -- Complains about exports items not in scope
467 exportsFromAvail this_mod Nothing export_avails global_name_env
468   = exportsFromAvail this_mod true_exports export_avails global_name_env
469   where
470     true_exports = Just $ if this_mod == mAIN_Name
471                           then [IEVar main_RDR_Unqual]
472                                -- export Main.main *only* unless otherwise specified,
473                           else [IEModuleContents this_mod]
474                                -- but for all other modules export everything.
475
476 exportsFromAvail this_mod (Just export_items) 
477                  (mod_avail_env, entity_avail_env)
478                  global_name_env
479   = doptRn Opt_WarnDuplicateExports             `thenRn` \ warn_dup_exports ->
480     foldlRn (exports_from_item warn_dup_exports)
481             ([], emptyFM, emptyAvailEnv) export_items
482                                                 `thenRn` \ (_, _, export_avail_map) ->
483     let
484         export_avails :: [AvailInfo]
485         export_avails   = nameEnvElts export_avail_map
486     in
487     returnRn export_avails
488
489   where
490     exports_from_item :: Bool -> ExportAccum -> RdrNameIE -> RnMG ExportAccum
491
492     exports_from_item warn_dups acc@(mods, occs, avails) ie@(IEModuleContents mod)
493         | mod `elem` mods       -- Duplicate export of M
494         = warnCheckRn warn_dups (dupModuleExport mod)   `thenRn_`
495           returnRn acc
496
497         | otherwise
498         = case lookupFM mod_avail_env mod of
499                 Nothing         -> failWithRn acc (modExportErr mod)
500                 Just mod_avails -> foldlRn (check_occs ie) occs mod_avails
501                                    `thenRn` \ occs' ->
502                                    let
503                                         avails' = foldl addAvail avails mod_avails
504                                    in
505                                    returnRn (mod:mods, occs', avails')
506
507     exports_from_item warn_dups acc@(mods, occs, avails) ie
508         = lookupSrcName global_name_env (ieName ie)     `thenRn` \ name -> 
509
510                 -- See what's available in the current environment
511           case lookupNameEnv entity_avail_env name of {
512             Nothing ->  -- Presumably this happens because lookupSrcName didn't find
513                         -- the name and returned an unboundName, which won't be in
514                         -- the entity_avail_env, of course
515                         WARN( not (isUnboundName name), ppr name )
516                         returnRn acc ;
517
518             Just avail ->
519
520                 -- Filter out the bits we want
521           case filterAvail ie avail of {
522             Nothing ->  -- Not enough availability
523                            failWithRn acc (exportItemErr ie) ;
524
525             Just export_avail ->        
526
527                 -- Phew!  It's OK!  Now to check the occurrence stuff!
528           warnCheckRn (ok_item ie avail) (dodgyExportWarn ie)   `thenRn_`
529           check_occs ie occs export_avail                       `thenRn` \ occs' ->
530           returnRn (mods, occs', addAvail avails export_avail)
531           }}
532
533
534
535 ok_item (IEThingAll _) (AvailTC _ [n]) = False
536   -- This occurs when you import T(..), but
537   -- only export T abstractly.  The single [n]
538   -- in the AvailTC is the type or class itself
539 ok_item _ _ = True
540
541 check_occs :: RdrNameIE -> ExportOccMap -> AvailInfo -> RnMG ExportOccMap
542 check_occs ie occs avail 
543   = doptRn Opt_WarnDuplicateExports     `thenRn` \ warn_dup_exports ->
544     foldlRn (check warn_dup_exports) occs (availNames avail)
545   where
546     check warn_dup occs name
547       = case lookupFM occs name_occ of
548           Nothing           -> returnRn (addToFM occs name_occ (name, ie))
549           Just (name', ie') 
550             | name == name' ->  -- Duplicate export
551                                 warnCheckRn warn_dup
552                                             (dupExportWarn name_occ ie ie')
553                                 `thenRn_` returnRn occs
554
555             | otherwise     ->  -- Same occ name but different names: an error
556                                 failWithRn occs (exportClashErr name_occ ie ie')
557       where
558         name_occ = nameOccName name
559 \end{code}
560
561 %************************************************************************
562 %*                                                                      *
563 \subsection{Errors}
564 %*                                                                      *
565 %************************************************************************
566
567 \begin{code}
568 badImportItemErr mod from ie
569   = sep [ptext SLIT("Module"), quotes (ppr mod), source_import,
570          ptext SLIT("does not export"), quotes (ppr ie)]
571   where
572     source_import = case from of
573                       ImportByUserSource -> ptext SLIT("(hi-boot interface)")
574                       other              -> empty
575
576 dodgyImportWarn mod item = dodgyMsg (ptext SLIT("import")) item
577 dodgyExportWarn     item = dodgyMsg (ptext SLIT("export")) item
578
579 dodgyMsg kind item@(IEThingAll tc)
580   = sep [ ptext SLIT("The") <+> kind <+> ptext SLIT("item") <+> quotes (ppr item),
581           ptext SLIT("suggests that") <+> quotes (ppr tc) <+> ptext SLIT("has constructor or class methods"),
582           ptext SLIT("but it has none; it is a type synonym or abstract type or class") ]
583           
584 modExportErr mod
585   = hsep [ ptext SLIT("Unknown module in export list: module"), quotes (ppr mod)]
586
587 exportItemErr export_item
588   = sep [ ptext SLIT("The export item") <+> quotes (ppr export_item),
589           ptext SLIT("attempts to export constructors or class methods that are not visible here") ]
590
591 exportClashErr occ_name ie1 ie2
592   = hsep [ptext SLIT("The export items"), quotes (ppr ie1)
593          ,ptext SLIT("and"), quotes (ppr ie2)
594          ,ptext SLIT("create conflicting exports for"), quotes (ppr occ_name)]
595
596 dupDeclErr (n:ns)
597   = vcat [ptext SLIT("Multiple declarations of") <+> quotes (ppr n),
598           nest 4 (vcat (map ppr sorted_locs))]
599   where
600     sorted_locs = sortLt occ'ed_before (map nameSrcLoc (n:ns))
601     occ'ed_before a b = LT == compare a b
602
603 dupExportWarn occ_name ie1 ie2
604   = hsep [quotes (ppr occ_name), 
605           ptext SLIT("is exported by"), quotes (ppr ie1),
606           ptext SLIT("and"),            quotes (ppr ie2)]
607
608 dupModuleExport mod
609   = hsep [ptext SLIT("Duplicate"),
610           quotes (ptext SLIT("Module") <+> ppr mod), 
611           ptext SLIT("in export list")]
612
613 moduleDeprec mod txt
614   = sep [ ptext SLIT("Module") <+> quotes (ppr mod) <+> ptext SLIT("is deprecated:"), 
615           nest 4 (ppr txt) ]      
616 \end{code}