d487b4691531dd3f34c8ed5bc10ed3a3ca36c6e8
[ghc-hetmet.git] / compiler / basicTypes / RdrName.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4
5 \section[RdrName]{@RdrName@}
6
7 \begin{code}
8 module RdrName (
9         RdrName(..),    -- Constructors exported only to BinIface
10
11         -- Construction
12         mkRdrUnqual, mkRdrQual, 
13         mkUnqual, mkVarUnqual, mkQual, mkOrig,
14         nameRdrName, getRdrName, 
15         mkDerivedRdrName, 
16
17         -- Destruction
18         rdrNameOcc, setRdrNameSpace,
19         isRdrDataCon, isRdrTyVar, isRdrTc, isQual, isQual_maybe, isUnqual, 
20         isOrig, isOrig_maybe, isExact, isExact_maybe, isSrcRdrName,
21
22         -- Printing;    instance Outputable RdrName
23
24         -- LocalRdrEnv
25         LocalRdrEnv, emptyLocalRdrEnv, extendLocalRdrEnv,
26         lookupLocalRdrEnv, elemLocalRdrEnv,
27
28         -- GlobalRdrEnv
29         GlobalRdrEnv, emptyGlobalRdrEnv, mkGlobalRdrEnv, plusGlobalRdrEnv, 
30         lookupGlobalRdrEnv, extendGlobalRdrEnv,
31         pprGlobalRdrEnv, globalRdrEnvElts,
32         lookupGRE_RdrName, lookupGRE_Name, hideSomeUnquals,
33
34         -- GlobalRdrElt, Provenance, ImportSpec
35         GlobalRdrElt(..), isLocalGRE, unQualOK, 
36         Provenance(..), pprNameProvenance,
37         ImportSpec(..), ImpDeclSpec(..), ImpItemSpec(..), 
38         importSpecLoc, importSpecModule
39   ) where 
40
41 #include "HsVersions.h"
42
43 import OccName
44 import Module   ( ModuleName, mkModuleNameFS, Module, moduleName )
45 import Name     ( Name, NamedThing(getName), nameModule, nameParent_maybe,
46                   nameOccName, isExternalName, nameSrcLoc )
47 import Maybes   ( mapCatMaybes )
48 import SrcLoc   ( isGoodSrcLoc, isGoodSrcSpan, srcLocSpan, SrcSpan )
49 import FastString ( FastString )
50 import Outputable
51 import Util     ( thenCmp )
52 \end{code}
53
54 %************************************************************************
55 %*                                                                      *
56 \subsection{The main data type}
57 %*                                                                      *
58 %************************************************************************
59
60 \begin{code}
61 data RdrName 
62   = Unqual OccName
63         -- Used for ordinary, unqualified occurrences 
64
65   | Qual ModuleName OccName
66         -- A qualified name written by the user in 
67         --  *source* code.  The module isn't necessarily 
68         -- the module where the thing is defined; 
69         -- just the one from which it is imported
70
71   | Orig Module OccName
72         -- An original name; the module is the *defining* module.
73         -- This is used when GHC generates code that will be fed
74         -- into the renamer (e.g. from deriving clauses), but where
75         -- we want to say "Use Prelude.map dammit".  
76  
77   | Exact Name
78         -- We know exactly the Name. This is used 
79         --  (a) when the parser parses built-in syntax like "[]" 
80         --      and "(,)", but wants a RdrName from it
81         --  (b) by Template Haskell, when TH has generated a unique name
82 \end{code}
83
84
85 %************************************************************************
86 %*                                                                      *
87 \subsection{Simple functions}
88 %*                                                                      *
89 %************************************************************************
90
91 \begin{code}
92 rdrNameOcc :: RdrName -> OccName
93 rdrNameOcc (Qual _ occ) = occ
94 rdrNameOcc (Unqual occ) = occ
95 rdrNameOcc (Orig _ occ) = occ
96 rdrNameOcc (Exact name) = nameOccName name
97
98 setRdrNameSpace :: RdrName -> NameSpace -> RdrName
99 -- This rather gruesome function is used mainly by the parser
100 -- When parsing         data T a = T | T1 Int
101 -- we parse the data constructors as *types* because of parser ambiguities,
102 -- so then we need to change the *type constr* to a *data constr*
103 --
104 -- The original-name case *can* occur when parsing
105 --              data [] a = [] | a : [a]
106 -- For the orig-name case we return an unqualified name.
107 setRdrNameSpace (Unqual occ) ns = Unqual (setOccNameSpace ns occ)
108 setRdrNameSpace (Qual m occ) ns = Qual m (setOccNameSpace ns occ)
109 setRdrNameSpace (Orig m occ) ns = Orig m (setOccNameSpace ns occ)
110 setRdrNameSpace (Exact n)    ns = Orig (nameModule n)
111                                        (setOccNameSpace ns (nameOccName n))
112 \end{code}
113
114 \begin{code}
115         -- These two are the basic constructors
116 mkRdrUnqual :: OccName -> RdrName
117 mkRdrUnqual occ = Unqual occ
118
119 mkRdrQual :: ModuleName -> OccName -> RdrName
120 mkRdrQual mod occ = Qual mod occ
121
122 mkOrig :: Module -> OccName -> RdrName
123 mkOrig mod occ = Orig mod occ
124
125 ---------------
126 mkDerivedRdrName :: Name -> (OccName -> OccName) -> (RdrName)
127 mkDerivedRdrName parent mk_occ
128   = mkOrig (nameModule parent) (mk_occ (nameOccName parent))
129
130 ---------------
131         -- These two are used when parsing source files
132         -- They do encode the module and occurrence names
133 mkUnqual :: NameSpace -> FastString -> RdrName
134 mkUnqual sp n = Unqual (mkOccNameFS sp n)
135
136 mkVarUnqual :: FastString -> RdrName
137 mkVarUnqual n = Unqual (mkVarOccFS n)
138
139 mkQual :: NameSpace -> (FastString, FastString) -> RdrName
140 mkQual sp (m, n) = Qual (mkModuleNameFS m) (mkOccNameFS sp n)
141
142 getRdrName :: NamedThing thing => thing -> RdrName
143 getRdrName name = nameRdrName (getName name)
144
145 nameRdrName :: Name -> RdrName
146 nameRdrName name = Exact name
147 -- Keep the Name even for Internal names, so that the
148 -- unique is still there for debug printing, particularly
149 -- of Types (which are converted to IfaceTypes before printing)
150
151 nukeExact :: Name -> RdrName
152 nukeExact n 
153   | isExternalName n = Orig (nameModule n) (nameOccName n)
154   | otherwise        = Unqual (nameOccName n)
155 \end{code}
156
157 \begin{code}
158 isRdrDataCon rn = isDataOcc (rdrNameOcc rn)
159 isRdrTyVar   rn = isTvOcc   (rdrNameOcc rn)
160 isRdrTc      rn = isTcOcc   (rdrNameOcc rn)
161
162 isSrcRdrName (Unqual _) = True
163 isSrcRdrName (Qual _ _) = True
164 isSrcRdrName _          = False
165
166 isUnqual (Unqual _) = True
167 isUnqual other      = False
168
169 isQual (Qual _ _) = True
170 isQual _          = False
171
172 isQual_maybe (Qual m n) = Just (m,n)
173 isQual_maybe _          = Nothing
174
175 isOrig (Orig _ _) = True
176 isOrig _          = False
177
178 isOrig_maybe (Orig m n) = Just (m,n)
179 isOrig_maybe _          = Nothing
180
181 isExact (Exact _) = True
182 isExact other   = False
183
184 isExact_maybe (Exact n) = Just n
185 isExact_maybe other     = Nothing
186 \end{code}
187
188
189 %************************************************************************
190 %*                                                                      *
191 \subsection{Instances}
192 %*                                                                      *
193 %************************************************************************
194
195 \begin{code}
196 instance Outputable RdrName where
197     ppr (Exact name)   = ppr name
198     ppr (Unqual occ)   = ppr occ
199     ppr (Qual mod occ) = ppr mod <> dot <> ppr occ
200     ppr (Orig mod occ) = ppr mod <> dot <> ppr occ
201
202 instance OutputableBndr RdrName where
203     pprBndr _ n 
204         | isTvOcc (rdrNameOcc n) = char '@' <+> ppr n
205         | otherwise              = ppr n
206
207 instance Eq RdrName where
208     (Exact n1)    == (Exact n2)    = n1==n2
209         -- Convert exact to orig
210     (Exact n1)    == r2@(Orig _ _) = nukeExact n1 == r2
211     r1@(Orig _ _) == (Exact n2)    = r1 == nukeExact n2
212
213     (Orig m1 o1)  == (Orig m2 o2)  = m1==m2 && o1==o2
214     (Qual m1 o1)  == (Qual m2 o2)  = m1==m2 && o1==o2
215     (Unqual o1)   == (Unqual o2)   = o1==o2
216     r1 == r2 = False
217
218 instance Ord RdrName where
219     a <= b = case (a `compare` b) of { LT -> True;  EQ -> True;  GT -> False }
220     a <  b = case (a `compare` b) of { LT -> True;  EQ -> False; GT -> False }
221     a >= b = case (a `compare` b) of { LT -> False; EQ -> True;  GT -> True  }
222     a >  b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True  }
223
224         -- Exact < Unqual < Qual < Orig
225         -- [Note: Apr 2004] We used to use nukeExact to convert Exact to Orig 
226         --      before comparing so that Prelude.map == the exact Prelude.map, but 
227         --      that meant that we reported duplicates when renaming bindings 
228         --      generated by Template Haskell; e.g 
229         --      do { n1 <- newName "foo"; n2 <- newName "foo"; 
230         --           <decl involving n1,n2> }
231         --      I think we can do without this conversion
232     compare (Exact n1) (Exact n2) = n1 `compare` n2
233     compare (Exact n1) n2         = LT
234
235     compare (Unqual _)   (Exact _)    = GT
236     compare (Unqual o1)  (Unqual  o2) = o1 `compare` o2
237     compare (Unqual _)   _            = LT
238
239     compare (Qual _ _)   (Exact _)    = GT
240     compare (Qual _ _)   (Unqual _)   = GT
241     compare (Qual m1 o1) (Qual m2 o2) = (o1 `compare` o2) `thenCmp` (m1 `compare` m2) 
242     compare (Qual _ _)   (Orig _ _)   = LT
243
244     compare (Orig m1 o1) (Orig m2 o2) = (o1 `compare` o2) `thenCmp` (m1 `compare` m2) 
245     compare (Orig _ _)   _            = GT
246 \end{code}
247
248
249
250 %************************************************************************
251 %*                                                                      *
252                         LocalRdrEnv
253 %*                                                                      *
254 %************************************************************************
255
256 A LocalRdrEnv is used for local bindings (let, where, lambda, case)
257 It is keyed by OccName, because we never use it for qualified names.
258
259 \begin{code}
260 type LocalRdrEnv = OccEnv Name
261
262 emptyLocalRdrEnv = emptyOccEnv
263
264 extendLocalRdrEnv :: LocalRdrEnv -> [Name] -> LocalRdrEnv
265 extendLocalRdrEnv env names
266   = extendOccEnvList env [(nameOccName n, n) | n <- names]
267
268 lookupLocalRdrEnv :: LocalRdrEnv -> RdrName -> Maybe Name
269 lookupLocalRdrEnv env (Exact name) = Just name
270 lookupLocalRdrEnv env (Unqual occ) = lookupOccEnv env occ
271 lookupLocalRdrEnv env other        = Nothing
272
273 elemLocalRdrEnv :: RdrName -> LocalRdrEnv -> Bool
274 elemLocalRdrEnv rdr_name env 
275   | isUnqual rdr_name = rdrNameOcc rdr_name `elemOccEnv` env
276   | otherwise         = False
277 \end{code}
278
279
280 %************************************************************************
281 %*                                                                      *
282                         GlobalRdrEnv
283 %*                                                                      *
284 %************************************************************************
285
286 \begin{code}
287 type GlobalRdrEnv = OccEnv [GlobalRdrElt]
288         -- Keyed by OccName; when looking up a qualified name
289         -- we look up the OccName part, and then check the Provenance
290         -- to see if the appropriate qualification is valid.  This
291         -- saves routinely doubling the size of the env by adding both
292         -- qualified and unqualified names to the domain.
293         --
294         -- The list in the range is reqd because there may be name clashes
295         -- These only get reported on lookup, not on construction
296
297         -- INVARIANT: All the members of the list have distinct 
298         --            gre_name fields; that is, no duplicate Names
299
300 emptyGlobalRdrEnv = emptyOccEnv
301
302 globalRdrEnvElts :: GlobalRdrEnv -> [GlobalRdrElt]
303 globalRdrEnvElts env = foldOccEnv (++) [] env
304
305 data GlobalRdrElt 
306   = GRE { gre_name   :: Name,
307           gre_prov   :: Provenance      -- Why it's in scope
308     }
309
310 instance Outputable GlobalRdrElt where
311   ppr gre = ppr name <+> pp_parent (nameParent_maybe name)
312                 <+> parens (pprNameProvenance gre)
313           where
314             name = gre_name gre
315             pp_parent (Just p) = brackets (text "parent:" <+> ppr p)
316             pp_parent Nothing  = empty
317
318 pprGlobalRdrEnv :: GlobalRdrEnv -> SDoc
319 pprGlobalRdrEnv env
320   = vcat (map pp (occEnvElts env))
321   where
322     pp gres = ppr (nameOccName (gre_name (head gres))) <> colon <+> 
323               vcat [ ppr (gre_name gre) <+> pprNameProvenance gre
324                    | gre <- gres]
325 \end{code}
326
327 \begin{code}
328 lookupGlobalRdrEnv :: GlobalRdrEnv -> OccName -> [GlobalRdrElt]
329 lookupGlobalRdrEnv env rdr_name = case lookupOccEnv env rdr_name of
330                                         Nothing   -> []
331                                         Just gres -> gres
332
333 extendGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrElt -> GlobalRdrEnv
334 extendGlobalRdrEnv env gre = extendOccEnv_C add env occ [gre]
335   where
336     occ = nameOccName (gre_name gre)
337     add gres _ = gre:gres
338
339 lookupGRE_RdrName :: RdrName -> GlobalRdrEnv -> [GlobalRdrElt]
340 lookupGRE_RdrName rdr_name env
341   = case lookupOccEnv env (rdrNameOcc rdr_name) of
342         Nothing   -> []
343         Just gres -> pickGREs rdr_name gres
344
345 lookupGRE_Name :: GlobalRdrEnv -> Name -> [GlobalRdrElt]
346 lookupGRE_Name env name
347   = [ gre | gre <- lookupGlobalRdrEnv env (nameOccName name),
348             gre_name gre == name ]
349
350
351 pickGREs :: RdrName -> [GlobalRdrElt] -> [GlobalRdrElt]
352 -- Take a list of GREs which have the right OccName
353 -- Pick those GREs that are suitable for this RdrName
354 -- And for those, keep only only the Provenances that are suitable
355 -- 
356 -- Consider
357 --       module A ( f ) where
358 --       import qualified Foo( f )
359 --       import Baz( f )
360 --       f = undefined
361 -- Let's suppose that Foo.f and Baz.f are the same entity really.
362 -- The export of f is ambiguous because it's in scope from the local def
363 -- and the import.  The lookup of (Unqual f) should return a GRE for
364 -- the locally-defined f, and a GRE for the imported f, with a *single* 
365 -- provenance, namely the one for Baz(f).
366 pickGREs rdr_name gres
367   = mapCatMaybes pick gres
368   where
369     rdr_is_unqual = isUnqual rdr_name
370     rdr_is_qual   = isQual_maybe rdr_name
371
372     pick :: GlobalRdrElt -> Maybe GlobalRdrElt
373     pick gre@(GRE {gre_prov = LocalDef, gre_name = n})  -- Local def
374         | rdr_is_unqual                         = Just gre
375         | Just (mod,_) <- rdr_is_qual, 
376           mod == moduleName (nameModule n)      = Just gre
377         | otherwise                             = Nothing
378     pick gre@(GRE {gre_prov = Imported [is]})   -- Single import (efficiency)
379         | rdr_is_unqual,
380           not (is_qual (is_decl is))            = Just gre
381         | Just (mod,_) <- rdr_is_qual, 
382           mod == is_as (is_decl is)             = Just gre
383         | otherwise                             = Nothing
384     pick gre@(GRE {gre_prov = Imported is})     -- Multiple import
385         | null filtered_is = Nothing
386         | otherwise        = Just (gre {gre_prov = Imported filtered_is})
387         where
388           filtered_is | rdr_is_unqual
389                       = filter (not . is_qual    . is_decl) is
390                       | Just (mod,_) <- rdr_is_qual 
391                       = filter ((== mod) . is_as . is_decl) is
392                       | otherwise
393                       = []
394
395 isLocalGRE :: GlobalRdrElt -> Bool
396 isLocalGRE (GRE {gre_prov = LocalDef}) = True
397 isLocalGRE other                       = False
398
399 unQualOK :: GlobalRdrElt -> Bool
400 -- An unqualifed version of this thing is in scope
401 unQualOK (GRE {gre_prov = LocalDef})    = True
402 unQualOK (GRE {gre_prov = Imported is}) = not (all (is_qual . is_decl) is)
403
404 plusGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv
405 plusGlobalRdrEnv env1 env2 = plusOccEnv_C (foldr insertGRE) env1 env2
406
407 mkGlobalRdrEnv :: [GlobalRdrElt] -> GlobalRdrEnv
408 mkGlobalRdrEnv gres
409   = foldr add emptyGlobalRdrEnv gres
410   where
411     add gre env = extendOccEnv_C (foldr insertGRE) env 
412                                  (nameOccName (gre_name gre)) 
413                                  [gre]
414
415 insertGRE :: GlobalRdrElt -> [GlobalRdrElt] -> [GlobalRdrElt]
416 insertGRE new_g [] = [new_g]
417 insertGRE new_g (old_g : old_gs)
418         | gre_name new_g == gre_name old_g
419         = new_g `plusGRE` old_g : old_gs
420         | otherwise
421         = old_g : insertGRE new_g old_gs
422
423 plusGRE :: GlobalRdrElt -> GlobalRdrElt -> GlobalRdrElt
424 -- Used when the gre_name fields match
425 plusGRE g1 g2
426   = GRE { gre_name = gre_name g1,
427           gre_prov = gre_prov g1 `plusProv` gre_prov g2 }
428
429 hideSomeUnquals :: GlobalRdrEnv -> [OccName] -> GlobalRdrEnv
430 -- Hide any unqualified bindings for the specified OccNames
431 -- This is used in TH, when renaming a declaration bracket
432 --      [d| foo = ... |]
433 -- We want unqualified 'foo' in "..." to mean this foo, not
434 -- the one from the enclosing module.  But the *qualified* name
435 -- from the enclosing moudule must certainly still be avaialable
436 --      Seems like 5 times as much work as it deserves!
437 hideSomeUnquals rdr_env occs
438   = foldr hide rdr_env occs
439   where
440     hide occ env 
441         | Just gres <- lookupOccEnv env occ = extendOccEnv env occ (map qual_gre gres)
442         | otherwise                         = env
443     qual_gre gre@(GRE { gre_name = name, gre_prov = LocalDef })
444         = GRE { gre_name = name, gre_prov = Imported [imp_spec] }
445         where   -- Local defs get transfomed to (fake) imported things
446           mod = moduleName (nameModule name)
447           imp_spec = ImpSpec { is_item = ImpAll, is_decl = decl_spec }
448           decl_spec = ImpDeclSpec { is_mod = mod, is_as = mod, 
449                                     is_qual = True, 
450                                     is_dloc = srcLocSpan (nameSrcLoc name) }
451
452     qual_gre gre@(GRE { gre_prov = Imported specs })
453         = gre { gre_prov = Imported (map qual_spec specs) }
454
455     qual_spec spec@(ImpSpec { is_decl = decl_spec })
456         = spec { is_decl = decl_spec { is_qual = True } }
457 \end{code}
458
459
460 %************************************************************************
461 %*                                                                      *
462                         Provenance
463 %*                                                                      *
464 %************************************************************************
465
466 The "provenance" of something says how it came to be in scope.
467 It's quite elaborate so that we can give accurate unused-name warnings.
468
469 \begin{code}
470 data Provenance
471   = LocalDef            -- Defined locally
472   | Imported            -- Imported
473         [ImportSpec]    -- INVARIANT: non-empty
474
475 data ImportSpec = ImpSpec { is_decl :: ImpDeclSpec,
476                             is_item ::  ImpItemSpec }
477                 deriving( Eq, Ord )
478
479 data ImpDeclSpec        -- Describes a particular import declaration
480                         -- Shared among all the Provenaces for that decl
481   = ImpDeclSpec {
482         is_mod      :: ModuleName, -- 'import Muggle'
483                                 -- Note the Muggle may well not be 
484                                 -- the defining module for this thing!
485                                 -- TODO: either should be Module, or there
486                                 -- should be a Maybe PackageId here too.
487         is_as       :: ModuleName, -- 'as M' (or 'Muggle' if there is no 'as' clause)
488         is_qual     :: Bool,    -- True <=> qualified (only)
489         is_dloc     :: SrcSpan  -- Location of import declaration
490     }
491
492 data ImpItemSpec  -- Describes import info a particular Name
493   = ImpAll              -- The import had no import list, 
494                         -- or  had a hiding list
495
496   | ImpSome {           -- The import had an import list
497         is_explicit :: Bool,
498         is_iloc     :: SrcSpan  -- Location of the import item
499     }
500         -- The is_explicit field is True iff the thing was named 
501         -- *explicitly* in the import specs rather 
502         -- than being imported as part of a "..." group 
503         -- e.g.         import C( T(..) )
504         -- Here the constructors of T are not named explicitly; 
505         -- only T is named explicitly.
506
507 importSpecLoc :: ImportSpec -> SrcSpan
508 importSpecLoc (ImpSpec decl ImpAll) = is_dloc decl
509 importSpecLoc (ImpSpec _    item)   = is_iloc item
510
511 importSpecModule :: ImportSpec -> ModuleName
512 importSpecModule is = is_mod (is_decl is)
513
514 -- Note [Comparing provenance]
515 -- Comparison of provenance is just used for grouping 
516 -- error messages (in RnEnv.warnUnusedBinds)
517 instance Eq Provenance where
518   p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
519
520 instance Eq ImpDeclSpec where
521   p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
522
523 instance Eq ImpItemSpec where
524   p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
525
526 instance Ord Provenance where
527    compare LocalDef      LocalDef        = EQ
528    compare LocalDef      (Imported _)    = LT
529    compare (Imported _ ) LocalDef        = GT
530    compare (Imported is1) (Imported is2) = compare (head is1) 
531         {- See Note [Comparing provenance] -}      (head is2)
532
533 instance Ord ImpDeclSpec where
534    compare is1 is2 = (is_mod is1 `compare` is_mod is2) `thenCmp` 
535                      (is_dloc is1 `compare` is_dloc is2)
536
537 instance Ord ImpItemSpec where
538    compare is1 is2 = is_iloc is1 `compare` is_iloc is2
539 \end{code}
540
541 \begin{code}
542 plusProv :: Provenance -> Provenance -> Provenance
543 -- Choose LocalDef over Imported
544 -- There is an obscure bug lurking here; in the presence
545 -- of recursive modules, something can be imported *and* locally
546 -- defined, and one might refer to it with a qualified name from
547 -- the import -- but I'm going to ignore that because it makes
548 -- the isLocalGRE predicate so much nicer this way
549 plusProv LocalDef        LocalDef        = panic "plusProv"
550 plusProv LocalDef        p2              = LocalDef
551 plusProv p1              LocalDef        = LocalDef
552 plusProv (Imported is1)  (Imported is2)  = Imported (is1++is2)
553
554 pprNameProvenance :: GlobalRdrElt -> SDoc
555 -- Print out the place where the name was imported
556 pprNameProvenance (GRE {gre_name = name, gre_prov = LocalDef})
557   = ptext SLIT("defined at") <+> ppr (nameSrcLoc name)
558 pprNameProvenance (GRE {gre_name = name, gre_prov = Imported whys})
559   = case whys of
560         (why:whys) -> sep [ppr why, nest 2 (ppr_defn (nameSrcLoc name))]
561         [] -> panic "pprNameProvenance"
562
563 -- If we know the exact definition point (which we may do with GHCi)
564 -- then show that too.  But not if it's just "imported from X".
565 ppr_defn loc | isGoodSrcLoc loc = parens (ptext SLIT("defined at") <+> ppr loc)
566              | otherwise        = empty
567
568 instance Outputable ImportSpec where
569    ppr imp_spec
570      = ptext SLIT("imported from") <+> ppr (importSpecModule imp_spec) 
571         <+> if isGoodSrcSpan loc then ptext SLIT("at") <+> ppr loc
572                                  else empty
573      where
574        loc = importSpecLoc imp_spec
575 \end{code}