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