[project @ 1997-06-18 23:52:36 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnEnv.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[RnEnv]{Environment manipulation for the renamer monad}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module RnEnv where              -- Export everything
10
11 IMPORT_1_3(List (nub))
12 IMP_Ubiq()
13
14 import CmdLineOpts      ( opt_WarnNameShadowing )
15 import HsSyn
16 import RdrHsSyn         ( RdrName(..), SYN_IE(RdrNameIE),
17                           rdrNameOcc, ieOcc, isQual, qual
18                         )
19 import HsTypes          ( getTyVarName, replaceTyVarName )
20 import BasicTypes       ( Fixity(..), FixityDirection(..) )
21 import RnMonad
22 import Name             ( Name, OccName(..), Provenance(..), DefnInfo(..), ExportFlag(..), NamedThing(..),
23                           occNameString, occNameFlavour,
24                           SYN_IE(NameSet), emptyNameSet, addListToNameSet,
25                           mkLocalName, mkGlobalName, modAndOcc, isLocallyDefinedName,
26                           isWiredInName, nameOccName, setNameProvenance, isVarOcc, getNameProvenance,
27                           pprProvenance, pprOccName, pprModule, pprNameProvenance
28                         )
29 import TyCon            ( TyCon )
30 import TysWiredIn       ( tupleTyCon, listTyCon, charTyCon, intTyCon )
31 import FiniteMap
32 import Outputable
33 import Unique           ( Unique, unboundKey )
34 import UniqFM           ( Uniquable(..), listToUFM, plusUFM_C )
35 import Maybes           ( maybeToBool )
36 import UniqSupply
37 import SrcLoc           ( SrcLoc, noSrcLoc )
38 import Pretty
39 import Outputable       ( PprStyle(..) )
40 import Util             --( panic, removeDups, pprTrace, assertPanic )
41
42 \end{code}
43
44
45
46 %*********************************************************
47 %*                                                      *
48 \subsection{Making new names}
49 %*                                                      *
50 %*********************************************************
51
52 \begin{code}
53 newGlobalName :: Module -> OccName -> RnM s d Name
54 newGlobalName mod occ
55   =     -- First check the cache
56     getNameSupplyRn             `thenRn` \ (us, inst_ns, cache) ->
57     let key = (mod,occ)         in
58     case lookupFM cache key of
59
60         -- A hit in the cache!  Return it, but change the src loc
61         -- of the thing we've found if this is a second definition site
62         -- (that is, if loc /= NoSrcLoc)
63         Just name ->  returnRn name
64
65         -- Miss in the cache, so build a new original name,
66         -- and put it in the cache
67         Nothing        -> 
68             let
69                 (us', us1) = splitUniqSupply us
70                 uniq       = getUnique us1
71                 name       = mkGlobalName uniq mod occ VanillaDefn Implicit
72                 cache'     = addToFM cache key name
73             in
74             setNameSupplyRn (us', inst_ns, cache')              `thenRn_`
75             returnRn name
76
77 newLocallyDefinedGlobalName :: Module -> OccName 
78                             -> (Name -> ExportFlag) -> SrcLoc
79                             -> RnM s d Name
80 newLocallyDefinedGlobalName mod occ rec_exp_fn loc
81   =     -- First check the cache
82     getNameSupplyRn             `thenRn` \ (us, inst_ns, cache) ->
83
84         -- We are at the binding site for a locally-defined thing, so
85         -- you might think it can't be in the cache, but it can if it's a
86         -- wired in thing. In that case we need to use the correct unique etc...
87         -- so all we do is replace its provenance.  
88         -- If it's not in the cache we put it there with the correct provenance.
89         -- The idea is that, after all this, the cache
90         -- will contain a Name with the correct Provenance (i.e. Local)
91
92         -- OLD (now wrong) COMMENT:
93         --   "Actually, there's a catch.  If this is the *second* binding for something
94         --    we want to allocate a *fresh* unique, rather than using the same Name as before.
95         --    Otherwise we don't detect conflicting definitions of the same top-level name!
96         --    So the only time we re-use a Name already in the cache is when it's one of
97         --    the Implicit magic-unique ones mentioned in the previous para"
98
99         -- This (incorrect) patch doesn't work for record decls, when we have
100         -- the same field declared in multiple constructors.   With the above patch,
101         -- each occurrence got a new Name --- aargh!
102         --
103         -- So I reverted to the simple caching method (no "second-binding" thing)
104         -- The multiple-local-binding case is now handled by improving the conflict
105         -- detection in plusNameEnv.
106     let
107         provenance = LocalDef (rec_exp_fn new_name) loc
108         (us', us1) = splitUniqSupply us
109         uniq       = getUnique us1
110         key        = (mod,occ)
111         new_name   = case lookupFM cache key of
112                          Just name -> setNameProvenance name provenance
113                          other     -> mkGlobalName uniq mod occ VanillaDefn provenance
114         new_cache  = addToFM cache key new_name
115     in
116     setNameSupplyRn (us', inst_ns, new_cache)           `thenRn_`
117     returnRn new_name
118
119 -- newSysName is used to create the names for
120 --      a) default methods
121 -- These are never mentioned explicitly in source code (hence no point in looking
122 -- them up in the NameEnv), but when reading an interface file
123 -- we may want to slurp in their pragma info.  In the source file itself we
124 -- need to create these names too so that we export them into the inferface file for this module.
125
126 newSysName :: OccName -> ExportFlag -> SrcLoc -> RnMS s Name
127 newSysName occ export_flag loc
128   = getModeRn   `thenRn` \ mode ->
129     getModuleRn `thenRn` \ mod_name ->
130     case mode of 
131         SourceMode -> newLocallyDefinedGlobalName 
132                                 mod_name occ
133                                 (\_ -> export_flag)
134                                 loc
135         InterfaceMode _ -> newGlobalName mod_name occ
136
137 -- newDfunName is a variant, specially for dfuns.  
138 -- When renaming derived definitions we are in *interface* mode (because we can trip
139 -- over original names), but we still want to make the Dfun locally-defined.
140 -- So we can't use whether or not we're in source mode to decide the locally-defined question.
141 newDfunName :: Maybe RdrName -> SrcLoc -> RnMS s Name
142 newDfunName Nothing src_loc                     -- Local instance decls have a "Nothing"
143   = getModuleRn         `thenRn` \ mod_name ->
144     newInstUniq         `thenRn` \ inst_uniq ->
145     let
146         dfun_occ = VarOcc (_PK_ ("$d" ++ show inst_uniq))
147     in
148     newLocallyDefinedGlobalName mod_name dfun_occ 
149                                 (\_ -> Exported) src_loc
150
151 newDfunName (Just n) src_loc                    -- Imported ones have "Just n"
152   = getModuleRn         `thenRn` \ mod_name ->
153     newGlobalName mod_name (rdrNameOcc n)
154
155
156 newLocalNames :: [(RdrName,SrcLoc)] -> RnM s d [Name]
157 newLocalNames rdr_names
158   = getNameSupplyRn             `thenRn` \ (us, inst_ns, cache) ->
159     let
160         n          = length rdr_names
161         (us', us1) = splitUniqSupply us
162         uniqs      = getUniques n us1
163         locals     = [ mkLocalName uniq (rdrNameOcc rdr_name) loc
164                      | ((rdr_name,loc), uniq) <- rdr_names `zip` uniqs
165                      ]
166     in
167     setNameSupplyRn (us', inst_ns, cache)       `thenRn_`
168     returnRn locals
169
170 -- mkUnboundName makes a place-holder Name; it shouldn't be looked at except possibly
171 -- during compiler debugging.
172 mkUnboundName :: RdrName -> Name
173 mkUnboundName rdr_name = mkLocalName unboundKey (rdrNameOcc rdr_name) noSrcLoc
174
175 isUnboundName :: Name -> Bool
176 isUnboundName name = uniqueOf name == unboundKey
177 \end{code}
178
179 \begin{code}
180 bindLocatedLocalsRn :: (PprStyle -> Doc)                -- Documentation string for error message
181                     -> [(RdrName,SrcLoc)]
182                     -> ([Name] -> RnMS s a)
183                     -> RnMS s a
184 bindLocatedLocalsRn doc_str rdr_names_w_loc enclosed_scope
185   = checkDupOrQualNames doc_str rdr_names_w_loc `thenRn_`
186
187     getNameEnv                  `thenRn` \ name_env ->
188     (if opt_WarnNameShadowing
189      then
190         mapRn (check_shadow name_env) rdr_names_w_loc
191      else
192         returnRn []
193     )                                   `thenRn_`
194         
195     newLocalNames rdr_names_w_loc       `thenRn` \ names ->
196     let
197         new_name_env = addListToFM name_env (map fst rdr_names_w_loc `zip` names)
198     in
199     setNameEnv new_name_env (enclosed_scope names)
200   where
201     check_shadow name_env (rdr_name,loc)
202         = case lookupFM name_env rdr_name of
203                 Nothing   -> returnRn ()
204                 Just name -> pushSrcLocRn loc $
205                              addWarnRn (shadowedNameWarn rdr_name)
206
207 bindLocalsRn doc_str rdr_names enclosed_scope
208   = getSrcLocRn         `thenRn` \ loc ->
209     bindLocatedLocalsRn (\_ -> text doc_str)
210                         (rdr_names `zip` repeat loc)
211                         enclosed_scope
212
213 bindTyVarsRn doc_str tyvar_names enclosed_scope
214   = getSrcLocRn                                 `thenRn` \ loc ->
215     let
216         located_tyvars = [(getTyVarName tv, loc) | tv <- tyvar_names] 
217     in
218     bindLocatedLocalsRn doc_str located_tyvars  $ \ names ->
219     enclosed_scope (zipWith replaceTyVarName tyvar_names names)
220
221         -- Works in any variant of the renamer monad
222 checkDupOrQualNames, checkDupNames :: (PprStyle -> Doc)
223                                    -> [(RdrName, SrcLoc)]
224                                    -> RnM s d ()
225
226 checkDupOrQualNames doc_str rdr_names_w_loc
227   =     -- Check for use of qualified names
228     mapRn (qualNameErr doc_str) quals   `thenRn_`
229     checkDupNames doc_str rdr_names_w_loc
230   where
231     quals = filter (isQual.fst) rdr_names_w_loc
232     
233 checkDupNames doc_str rdr_names_w_loc
234   =     -- Check for dupicated names in a binding group
235     mapRn (dupNamesErr doc_str) dups    `thenRn_`
236     returnRn ()
237   where
238     (_, dups) = removeDups (\(n1,l1) (n2,l2) -> n1 `cmp` n2) rdr_names_w_loc
239 \end{code}
240
241
242 %*********************************************************
243 %*                                                      *
244 \subsection{Looking up names}
245 %*                                                      *
246 %*********************************************************
247
248 Looking up a name in the RnEnv.
249
250 \begin{code}
251 lookupRn :: NameEnv -> RdrName -> RnMS s Name
252 lookupRn name_env rdr_name
253   = case lookupFM name_env rdr_name of
254
255         -- Found it!
256         Just name -> returnRn name
257
258         -- Not found
259         Nothing -> getModeRn    `thenRn` \ mode ->
260                    case mode of 
261                         -- Not found when processing source code; so fail
262                         SourceMode    -> failWithRn (mkUnboundName rdr_name)
263                                                     (unknownNameErr rdr_name)
264                 
265                         -- Not found when processing an imported declaration,
266                         -- so we create a new name for the purpose
267                         InterfaceMode _ -> 
268                             case rdr_name of
269
270                                 Qual mod_name occ -> newGlobalName mod_name occ
271
272                                 -- An Unqual is allowed; interface files contain 
273                                 -- unqualified names for locally-defined things, such as
274                                 -- constructors of a data type.
275                                 Unqual occ -> getModuleRn       `thenRn ` \ mod_name ->
276                                               newGlobalName mod_name occ
277
278
279 lookupBndrRn rdr_name
280   = getNameEnv                  `thenRn` \ name_env ->
281     lookupRn name_env rdr_name
282
283 -- Just like lookupRn except that we record the occurrence too
284 -- Perhaps surprisingly, even wired-in names are recorded.
285 -- Why?  So that we know which wired-in names are referred to when
286 -- deciding which instance declarations to import.
287 lookupOccRn :: RdrName -> RnMS s Name
288 lookupOccRn rdr_name
289   = getNameEnv                  `thenRn` \ name_env ->
290     lookupRn name_env rdr_name  `thenRn` \ name ->
291     addOccurrenceName name
292
293 -- lookupGlobalOccRn is like lookupOccRn, except that it looks in the global 
294 -- environment.  It's used for record field names only.
295 lookupGlobalOccRn :: RdrName -> RnMS s Name
296 lookupGlobalOccRn rdr_name
297   = getGlobalNameEnv            `thenRn` \ name_env ->
298     lookupRn name_env rdr_name  `thenRn` \ name ->
299     addOccurrenceName name
300
301    
302
303 -- lookupImplicitOccRn takes an RdrName representing an *original* name, and
304 -- adds it to the occurrence pool so that it'll be loaded later.  This is
305 -- used when language constructs (such as monad comprehensions, overloaded literals,
306 -- or deriving clauses) require some stuff to be loaded that isn't explicitly
307 -- mentioned in the code.
308 --
309 -- This doesn't apply in interface mode, where everything is explicit, but
310 -- we don't check for this case: it does no harm to record an "extra" occurrence
311 -- and lookupImplicitOccRn isn't used much in interface mode (it's only the
312 -- Nothing clause of rnDerivs that calls it at all I think).
313 --
314 -- For List and Tuple types it's important to get the correct
315 -- isLocallyDefined flag, which is used in turn when deciding
316 -- whether there are any instance decls in this module are "special".
317 -- The name cache should have the correct provenance, though.
318
319 lookupImplicitOccRn :: RdrName -> RnMS s Name 
320 lookupImplicitOccRn (Qual mod occ)
321  = newGlobalName mod occ                `thenRn` \ name ->
322    addOccurrenceName name
323
324 addImplicitOccRn :: Name -> RnMS s Name
325 addImplicitOccRn name = addOccurrenceName name
326
327 addImplicitOccsRn :: [Name] -> RnMS s ()
328 addImplicitOccsRn names = addOccurrenceNames names
329
330 listType_RDR    = qual (modAndOcc listType_name)
331 tupleType_RDR n = qual (modAndOcc (tupleType_name n))
332
333 charType_name    = getName charTyCon
334 listType_name    = getName listTyCon
335 tupleType_name n = getName (tupleTyCon n)
336 \end{code}
337
338 \begin{code}
339 lookupFixity :: RdrName -> RnMS s Fixity
340 lookupFixity rdr_name
341   = getFixityEnv        `thenRn` \ fixity_env ->
342     returnRn (lookupFixityEnv fixity_env rdr_name)
343 \end{code}
344
345
346
347 %************************************************************************
348 %*                                                                      *
349 \subsection{Envt utility functions}
350 %*                                                                      *
351 %************************************************************************
352
353 ===============  RnEnv  ================
354 \begin{code}
355 plusRnEnv (RnEnv n1 f1) (RnEnv n2 f2) 
356   = plusNameEnvRn n1 n2         `thenRn` \ n ->
357     plusFixityEnvRn f1 f2       `thenRn` \ f -> 
358     returnRn (RnEnv n f)
359 \end{code}
360
361 ===============  NameEnv  ================
362 \begin{code}
363 plusNameEnvRn :: NameEnv -> NameEnv -> RnM s d NameEnv
364 plusNameEnvRn env1 env2
365   = mapRn (addErrRn.nameClashErr) (conflictsFM conflicting_name env1 env2)              `thenRn_`
366     returnRn (env1 `plusFM` env2)
367
368 addOneToNameEnv :: NameEnv -> RdrName -> Name -> RnM s d NameEnv
369 addOneToNameEnv env rdr_name name
370  = case lookupFM env rdr_name of
371         Just name2 | conflicting_name name name2
372                    -> addErrRn (nameClashErr (rdr_name, (name, name2))) `thenRn_`
373                       returnRn env
374
375         Nothing    -> returnRn (addToFM env rdr_name name)
376
377 conflicting_name n1 n2 = (n1 /= n2) || (isLocallyDefinedName n1 && isLocallyDefinedName n2)
378         -- We complain of a conflict if one RdrName maps to two different Names,
379         -- OR if one RdrName maps to the same *locally-defined* Name.  The latter
380         -- case is to catch two separate, local definitions of the same thing.
381         --
382         -- If a module imports itself then there might be a local defn and an imported
383         -- defn of the same name; in this case the names will compare as equal, but
384         -- will still have different provenances.
385
386 lookupNameEnv :: NameEnv -> RdrName -> Maybe Name
387 lookupNameEnv = lookupFM
388
389 delOneFromNameEnv :: NameEnv -> RdrName -> NameEnv 
390 delOneFromNameEnv env rdr_name = delFromFM env rdr_name
391 \end{code}
392
393 ===============  FixityEnv  ================
394 \begin{code}
395 plusFixityEnvRn f1 f2
396   = mapRn (addErrRn.fixityClashErr) (conflictsFM bad_fix f1 f2)         `thenRn_`
397     returnRn (f1 `plusFM` f2)
398
399 addOneToFixityEnv env rdr_name fixity = addToFM env rdr_name fixity
400
401 lookupFixityEnv env rdr_name 
402   = case lookupFM env rdr_name of
403         Just (fixity,_) -> fixity
404         Nothing         -> Fixity 9 InfixL              -- Default case
405
406 bad_fix :: (Fixity, Provenance) -> (Fixity, Provenance) -> Bool
407 bad_fix (f1,_) (f2,_) = f1 /= f2
408
409 pprFixityProvenance :: PprStyle -> (Fixity,Provenance) -> Doc
410 pprFixityProvenance sty (fixity, prov) = pprProvenance sty prov
411 \end{code}
412
413
414
415 ===============  Avails  ================
416 \begin{code}
417 mkExportAvails :: Bool -> Module -> [AvailInfo] -> ExportAvails
418 mkExportAvails unqualified_import mod_name avails
419   = (mod_avail_env, entity_avail_env)
420   where
421         -- The "module M" syntax only applies to *unqualified* imports (1.4 Report, Section 5.1.1)
422     mod_avail_env | unqualified_import = unitFM mod_name avails 
423                   | otherwise          = emptyFM
424    
425     entity_avail_env = listToUFM [ (name,avail) | avail <- avails, 
426                                                   name  <- availEntityNames avail]
427
428 plusExportAvails ::  ExportAvails ->  ExportAvails ->  ExportAvails
429 plusExportAvails (m1, e1) (m2, e2)
430   = (plusFM_C (++) m1 m2, plusUFM_C plusAvail e1 e2)
431 \end{code}
432
433
434 ===============  AvailInfo  ================
435 \begin{code}
436 plusAvail (Avail n1)       (Avail n2)       = Avail n1
437 plusAvail (AvailTC n1 ns1) (AvailTC n2 ns2) = AvailTC n1 (nub (ns1 ++ ns2))
438 plusAvail a NotAvailable = a
439 plusAvail NotAvailable a = a
440 -- Added SOF 4/97
441 #ifdef DEBUG
442 plusAvail a1 a2 = panic ("RnEnv.plusAvail " ++ (show (hsep [pprAvail PprDebug a1,pprAvail PprDebug a2])))
443 #endif
444
445 addAvailToNameSet :: NameSet -> AvailInfo -> NameSet
446 addAvailToNameSet names avail = addListToNameSet names (availNames avail)
447
448 availsToNameSet :: [AvailInfo] -> NameSet
449 availsToNameSet avails = foldl addAvailToNameSet emptyNameSet avails
450
451 availName :: AvailInfo -> Name
452 availName (Avail n)     = n
453 availName (AvailTC n _) = n
454
455 availNames :: AvailInfo -> [Name]
456 availNames NotAvailable   = []
457 availNames (Avail n)      = [n]
458 availNames (AvailTC n ns) = ns
459
460 -- availEntityNames is used to extract the names that can appear on their own in
461 -- an export or import list.  For class decls, class methods can appear on their
462 -- own, thus    import A( op )
463 -- but constructors cannot; thus
464 --              import B( T )
465 -- means import type T from B, not constructor T.
466
467 availEntityNames :: AvailInfo -> [Name]
468 availEntityNames NotAvailable   = []
469 availEntityNames (Avail n)      = [n]
470 availEntityNames (AvailTC n ns) = n : filter (isVarOcc . nameOccName) ns
471
472 filterAvail :: RdrNameIE        -- Wanted
473             -> AvailInfo        -- Available
474             -> AvailInfo        -- Resulting available; 
475                                 -- NotAvailable if wanted stuff isn't there
476
477 filterAvail ie@(IEThingWith want wants) avail@(AvailTC n ns)
478   | sub_names_ok = AvailTC n (filter is_wanted ns)
479   | otherwise    = pprTrace "filterAvail" (hsep [ppr PprDebug ie, pprAvail PprDebug avail]) $
480                    NotAvailable
481   where
482     is_wanted name = nameOccName name `elem` wanted_occs
483     sub_names_ok   = all (`elem` avail_occs) wanted_occs
484     avail_occs     = map nameOccName ns
485     wanted_occs    = map rdrNameOcc (want:wants)
486
487 filterAvail (IEThingAbs _) (AvailTC n ns)      
488   | n `elem` ns = AvailTC n [n]
489
490 filterAvail (IEThingAbs _) avail@(Avail n)      = avail         -- Type synonyms
491
492 filterAvail (IEVar _)      avail@(Avail n)      = avail
493 filterAvail (IEVar v)      avail@(AvailTC n ns) = AvailTC n (filter wanted ns)
494                                                 where
495                                                   wanted n = nameOccName n == occ
496                                                   occ      = rdrNameOcc v
497         -- The second equation happens if we import a class op, thus
498         --      import A( op ) 
499         -- where op is a class operation
500
501 filterAvail (IEThingAll _) avail@(AvailTC _ _)  = avail
502
503 filterAvail ie avail = NotAvailable 
504
505
506 -- In interfaces, pprAvail gets given the OccName of the "host" thing
507 pprAvail PprInterface avail = ppr_avail (pprOccName PprInterface . nameOccName) avail
508 pprAvail sty          avail = ppr_avail (ppr sty) avail
509
510 ppr_avail pp_name NotAvailable = ptext SLIT("NotAvailable")
511 ppr_avail pp_name (AvailTC n ns) = hsep [
512                                      pp_name n,
513                                      parens  $ hsep $ punctuate comma $
514                                      map pp_name ns
515                                    ]
516 ppr_avail pp_name (Avail n) = pp_name n
517 \end{code}
518
519
520
521
522 %************************************************************************
523 %*                                                                      *
524 \subsection{Finite map utilities}
525 %*                                                                      *
526 %************************************************************************
527
528
529 Generally useful function on finite maps to check for overlap.
530
531 \begin{code}
532 conflictsFM :: Ord a 
533             => (b->b->Bool)             -- False <=> no conflict; you can pick either
534             -> FiniteMap a b -> FiniteMap a b
535             -> [(a,(b,b))]
536 conflictsFM bad fm1 fm2 
537   = filter (\(a,(b1,b2)) -> bad b1 b2)
538            (fmToList (intersectFM_C (\b1 b2 -> (b1,b2)) fm1 fm2))
539
540 conflictFM :: Ord a 
541            => (b->b->Bool)
542            -> FiniteMap a b -> a -> b
543            -> [(a,(b,b))]
544 conflictFM bad fm key elt
545   = case lookupFM fm key of
546         Just elt' | bad elt elt' -> [(key,(elt,elt'))]
547         other                    -> []
548 \end{code}
549
550
551 %************************************************************************
552 %*                                                                      *
553 \subsection{Envt utility functions}
554 %*                                                                      *
555 %************************************************************************
556
557
558 \begin{code}
559 nameClashErr (rdr_name, (name1,name2)) sty
560   = hang (hsep [ptext SLIT("Conflicting definitions for:"), ppr sty rdr_name])
561         4 (vcat [pprNameProvenance sty name1,
562                  pprNameProvenance sty name2])
563
564 fixityClashErr (rdr_name, (fp1,fp2)) sty
565   = hang (hsep [ptext SLIT("Conflicting fixities for:"), ppr sty rdr_name])
566         4 (vcat [pprFixityProvenance sty fp1,
567                  pprFixityProvenance sty fp2])
568
569 shadowedNameWarn shadow sty
570   = hcat [ptext SLIT("This binding for"), 
571                ppr sty shadow,
572                ptext SLIT("shadows an existing binding")]
573
574 unknownNameErr name sty
575   = sep [text flavour, ptext SLIT("not in scope:"), ppr sty name]
576   where
577     flavour = occNameFlavour (rdrNameOcc name)
578
579 qualNameErr descriptor (name,loc)
580   = pushSrcLocRn loc $
581     addErrRn (\sty -> hsep [ ptext SLIT("Invalid use of qualified name"), 
582                              ppr sty name,
583                              ptext SLIT("in"),
584                              descriptor sty])
585
586 dupNamesErr descriptor ((name,loc) : dup_things)
587   = pushSrcLocRn loc $
588     addErrRn (\sty -> hsep [ptext SLIT("Conflicting definitions for"), 
589                             ppr sty name, 
590                             ptext SLIT("in"), descriptor sty])
591 \end{code}
592