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