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