2 % (c) The University of Glasgow, 2000
4 \section[HscTypes]{Types for the per-module compiler}
10 ModuleLocation(..), showModMsg,
12 ModDetails(..), ModIface(..),
13 HomeSymbolTable, emptySymbolTable,
15 HomeIfaceTable, PackageIfaceTable, emptyIfaceTable,
16 lookupIface, lookupIfaceByModName,
19 InteractiveContext(..),
21 IfaceDecls, mkIfaceDecls, dcl_tycl, dcl_rules, dcl_insts,
23 VersionInfo(..), initialVersionInfo, lookupVersion,
24 FixityEnv, lookupFixity,
26 TyThing(..), isTyClThing, implicitTyThingIds,
28 TypeEnv, lookupType, mkTypeEnv, emptyTypeEnv,
29 extendTypeEnvList, extendTypeEnvWithIds,
30 typeEnvElts, typeEnvClasses, typeEnvTyCons, typeEnvIds,
32 ImportedModuleInfo, WhetherHasOrphans, ImportVersion, WhatsImported(..),
33 PersistentRenamerState(..), IsBootInterface, DeclsMap,
34 IfaceInsts, IfaceRules, GatedDecl, GatedDecls, GateFn, IsExported,
35 NameSupply(..), OrigNameCache, OrigIParamCache,
36 Avails, AvailEnv, emptyAvailEnv,
37 GenAvailInfo(..), AvailInfo, RdrAvailInfo,
38 PersistentCompilerState(..),
40 Deprecations(..), lookupDeprec,
42 InstEnv, ClsInstEnv, DFunId,
43 PackageInstEnv, PackageRuleBase,
45 GlobalRdrEnv, GlobalRdrElt(..), pprGlobalRdrEnv,
46 LocalRdrEnv, extendLocalRdrEnv,
50 Provenance(..), ImportReason(..),
51 pprNameProvenance, hasBetterProv
55 #include "HsVersions.h"
57 import RdrName ( RdrName, RdrNameEnv, addListToRdrEnv,
58 mkRdrUnqual, rdrEnvToList )
59 import Name ( Name, NamedThing, getName, nameOccName, nameModule, nameSrcLoc )
61 import OccName ( OccName )
63 import InstEnv ( InstEnv, ClsInstEnv, DFunId )
64 import Rules ( RuleBase )
65 import CoreSyn ( CoreBind )
67 import Class ( Class, classSelIds )
68 import TyCon ( TyCon, isNewTyCon, tyConGenIds, tyConSelIds, tyConDataConsIfAvailable )
69 import DataCon ( dataConId, dataConWrapId )
71 import BasicTypes ( Version, initialVersion, Fixity, defaultFixity, IPName )
73 import HsSyn ( DeprecTxt, tyClDeclName, ifaceRuleDeclName )
74 import RdrHsSyn ( RdrNameInstDecl, RdrNameRuleDecl, RdrNameTyClDecl )
75 import RnHsSyn ( RenamedTyClDecl, RenamedRuleDecl, RenamedInstDecl )
77 import CoreSyn ( IdCoreRule )
79 import FiniteMap ( FiniteMap )
81 import Maybes ( seqMaybe, orElse )
83 import SrcLoc ( SrcLoc, isGoodSrcLoc )
84 import Util ( thenCmp, sortLt, unJust )
85 import UniqSupply ( UniqSupply )
88 %************************************************************************
90 \subsection{Which mode we're in
92 %************************************************************************
95 data GhciMode = Batch | Interactive | OneShot
100 %************************************************************************
102 \subsection{Module locations}
104 %************************************************************************
109 ml_hs_file :: Maybe FilePath,
110 ml_hspp_file :: Maybe FilePath, -- path of preprocessed source
111 ml_hi_file :: FilePath,
112 ml_obj_file :: Maybe FilePath
116 instance Outputable ModuleLocation where
119 -- Probably doesn't really belong here, but used in HscMain and InteractiveUI.
121 showModMsg :: Bool -> Module -> ModuleLocation -> String
122 showModMsg use_object mod location =
123 mod_str ++ replicate (max 0 (16 - length mod_str)) ' '
124 ++" ( " ++ unJust "showModMsg" (ml_hs_file location) ++ ", "
126 then unJust "showModMsg" (ml_obj_file location)
129 where mod_str = moduleUserString mod
132 For a module in another package, the hs_file and obj_file
133 components of ModuleLocation are undefined.
135 The locations specified by a ModuleLocation may or may not
136 correspond to actual files yet: for example, even if the object
137 file doesn't exist, the ModuleLocation still contains the path to
138 where the object file will reside if/when it is created.
141 %************************************************************************
143 \subsection{Symbol tables and Module details}
145 %************************************************************************
147 A @ModIface@ plus a @ModDetails@ summarises everything we know
148 about a compiled module. The @ModIface@ is the stuff *before* linking,
149 and can be written out to an interface file. (The @ModDetails@ is after
150 linking; it is the "linked" form of the mi_decls field.)
152 When we *read* an interface file, we also construct a @ModIface@ from it,
153 except that the mi_decls part is empty; when reading we consolidate
154 the declarations into a single indexed map in the @PersistentRenamerState@.
159 mi_module :: !Module,
160 mi_package :: !PackageName, -- Which package the module comes from
161 mi_version :: !VersionInfo, -- Module version number
163 mi_orphan :: WhetherHasOrphans, -- Whether this module has orphans
164 -- NOT STRICT! we fill this field with _|_ sometimes
166 mi_boot :: !IsBootInterface, -- read from an hi-boot file?
168 mi_usages :: ![ImportVersion Name],
169 -- Usages; kept sorted so that it's easy to decide
170 -- whether to write a new iface file (changing usages
171 -- doesn't affect the version of this module)
173 mi_exports :: ![(ModuleName,Avails)],
174 -- What it exports Kept sorted by (mod,occ), to make
175 -- version comparisons easier
177 mi_globals :: !(Maybe GlobalRdrEnv),
178 -- Its top level environment or Nothing if we read this
179 -- interface from a file.
181 mi_fixities :: !FixityEnv, -- Fixities
182 mi_deprecs :: !Deprecations, -- Deprecations
184 mi_decls :: IfaceDecls -- The RnDecls form of ModDetails
185 -- NOT STRICT! we fill this field with _|_ sometimes
188 data IfaceDecls = IfaceDecls { dcl_tycl :: [RenamedTyClDecl], -- Sorted
189 dcl_rules :: [RenamedRuleDecl], -- Sorted
190 dcl_insts :: [RenamedInstDecl] } -- Unsorted
192 mkIfaceDecls :: [RenamedTyClDecl] -> [RenamedRuleDecl] -> [RenamedInstDecl] -> IfaceDecls
193 mkIfaceDecls tycls rules insts
194 = IfaceDecls { dcl_tycl = sortLt lt_tycl tycls,
195 dcl_rules = sortLt lt_rule rules,
198 d1 `lt_tycl` d2 = tyClDeclName d1 < tyClDeclName d2
199 r1 `lt_rule` r2 = ifaceRuleDeclName r1 < ifaceRuleDeclName r2
202 -- typechecker should only look at this, not ModIface
203 -- Should be able to construct ModDetails from mi_decls in ModIface
206 -- The next three fields are created by the typechecker
207 md_types :: !TypeEnv,
208 md_insts :: ![DFunId], -- Dfun-ids for the instances in this module
209 md_rules :: ![IdCoreRule], -- Domain may include Ids from other modules
210 md_binds :: ![CoreBind]
213 -- The ModDetails takes on several slightly different forms:
215 -- After typecheck + desugar
216 -- md_types Contains TyCons, Classes, and implicit Ids
217 -- md_insts All instances from this module (incl derived ones)
218 -- md_rules All rules from this module
219 -- md_binds Desugared bindings
221 -- After simplification
222 -- md_types Same as after typecheck
224 -- md_rules Orphan rules only (local ones now attached to binds)
225 -- md_binds With rules attached
228 -- md_types Now contains Ids as well, replete with final IdInfo
229 -- The Ids are only the ones that are visible from
230 -- importing modules. Without -O that means only
231 -- exported Ids, but with -O importing modules may
232 -- see ids mentioned in unfoldings of exported Ids
234 -- md_insts Same DFunIds as before, but with final IdInfo,
235 -- and the unique might have changed; remember that
236 -- CoreTidy links up the uniques of old and new versions
238 -- md_rules All rules for exported things, substituted with final Ids
242 -- Passed back to compilation manager
243 -- Just as after CoreTidy, but with md_binds nuked
248 emptyModIface :: Module -> ModIface
250 = ModIface { mi_module = mod,
251 mi_package = preludePackage, -- XXX fully bogus
252 mi_version = initialVersionInfo,
257 mi_fixities = emptyNameEnv,
258 mi_globals = Nothing,
259 mi_deprecs = NoDeprecs,
260 mi_decls = panic "emptyModIface: decls"
264 Symbol tables map modules to ModDetails:
267 type SymbolTable = ModuleEnv ModDetails
268 type IfaceTable = ModuleEnv ModIface
270 type HomeIfaceTable = IfaceTable
271 type PackageIfaceTable = IfaceTable
273 type HomeSymbolTable = SymbolTable -- Domain = modules in the home package
275 emptySymbolTable :: SymbolTable
276 emptySymbolTable = emptyModuleEnv
278 emptyIfaceTable :: IfaceTable
279 emptyIfaceTable = emptyModuleEnv
282 Simple lookups in the symbol table.
285 lookupIface :: HomeIfaceTable -> PackageIfaceTable -> Name -> Maybe ModIface
286 -- We often have two IfaceTables, and want to do a lookup
287 lookupIface hit pit name
288 = lookupModuleEnv hit mod `seqMaybe` lookupModuleEnv pit mod
290 mod = nameModule name
292 lookupIfaceByModName :: HomeIfaceTable -> PackageIfaceTable -> ModuleName -> Maybe ModIface
293 -- We often have two IfaceTables, and want to do a lookup
294 lookupIfaceByModName hit pit mod
295 = lookupModuleEnvByName hit mod `seqMaybe` lookupModuleEnvByName pit mod
299 %************************************************************************
301 \subsection{The interactive context}
303 %************************************************************************
306 data InteractiveContext
307 = InteractiveContext {
308 ic_toplev_scope :: [Module], -- Include the "top-level" scope of
311 ic_exports :: [Module], -- Include just the exports of these
314 ic_rn_gbl_env :: GlobalRdrEnv, -- The cached GlobalRdrEnv, built from
315 -- ic_toplev_scope and ic_exports
317 ic_print_unqual :: PrintUnqualified,
318 -- cached PrintUnqualified, as above
320 ic_rn_local_env :: LocalRdrEnv, -- Lexical context for variables bound
321 -- during interaction
323 ic_type_env :: TypeEnv -- Ditto for types
328 %************************************************************************
330 \subsection{Type environment stuff}
332 %************************************************************************
335 data TyThing = AnId Id
339 isTyClThing :: TyThing -> Bool
340 isTyClThing (ATyCon _) = True
341 isTyClThing (AClass _) = True
342 isTyClThing (AnId _) = False
344 instance NamedThing TyThing where
345 getName (AnId id) = getName id
346 getName (ATyCon tc) = getName tc
347 getName (AClass cl) = getName cl
349 instance Outputable TyThing where
350 ppr (AnId id) = ptext SLIT("AnId") <+> ppr id
351 ppr (ATyCon tc) = ptext SLIT("ATyCon") <+> ppr tc
352 ppr (AClass cl) = ptext SLIT("AClass") <+> ppr cl
355 typeEnvElts :: TypeEnv -> [TyThing]
356 typeEnvClasses :: TypeEnv -> [Class]
357 typeEnvTyCons :: TypeEnv -> [TyCon]
358 typeEnvIds :: TypeEnv -> [Id]
360 typeEnvElts env = nameEnvElts env
361 typeEnvClasses env = [cl | AClass cl <- typeEnvElts env]
362 typeEnvTyCons env = [tc | ATyCon tc <- typeEnvElts env]
363 typeEnvIds env = [id | AnId id <- typeEnvElts env]
365 implicitTyThingIds :: [TyThing] -> [Id]
366 -- Add the implicit data cons and selectors etc
367 implicitTyThingIds things
368 = concat (map go things)
371 go (AClass cl) = classSelIds cl
372 go (ATyCon tc) = tyConGenIds tc ++
374 [ n | dc <- tyConDataConsIfAvailable tc,
375 n <- implicitConIds tc dc]
376 -- Synonyms return empty list of constructors and selectors
378 implicitConIds tc dc -- Newtypes have a constructor wrapper,
380 | isNewTyCon tc = [dataConWrapId dc]
381 | otherwise = [dataConId dc, dataConWrapId dc]
386 type TypeEnv = NameEnv TyThing
388 emptyTypeEnv = emptyNameEnv
390 mkTypeEnv :: [TyThing] -> TypeEnv
391 mkTypeEnv things = extendTypeEnvList emptyTypeEnv things
393 extendTypeEnvList :: TypeEnv -> [TyThing] -> TypeEnv
394 extendTypeEnvList env things
395 = extendNameEnvList env [(getName thing, thing) | thing <- things]
397 extendTypeEnvWithIds :: TypeEnv -> [Id] -> TypeEnv
398 extendTypeEnvWithIds env ids
399 = extendNameEnvList env [(getName id, AnId id) | id <- ids]
403 lookupType :: HomeSymbolTable -> PackageTypeEnv -> Name -> Maybe TyThing
404 lookupType hst pte name
405 = case lookupModuleEnv hst (nameModule name) of
406 Just details -> lookupNameEnv (md_types details) name
407 Nothing -> lookupNameEnv pte name
410 %************************************************************************
412 \subsection{Auxiliary types}
414 %************************************************************************
416 These types are defined here because they are mentioned in ModDetails,
417 but they are mostly elaborated elsewhere
422 vers_module :: Version, -- Changes when anything changes
423 vers_exports :: Version, -- Changes when export list changes
424 vers_rules :: Version, -- Changes when any rule changes
425 vers_decls :: NameEnv Version
426 -- Versions for "big" names only (not data constructors, class ops)
427 -- The version of an Id changes if its fixity changes
428 -- Ditto data constructors, class operations, except that the version of
429 -- the parent class/tycon changes
431 -- If a name isn't in the map, it means 'initialVersion'
434 initialVersionInfo :: VersionInfo
435 initialVersionInfo = VersionInfo { vers_module = initialVersion,
436 vers_exports = initialVersion,
437 vers_rules = initialVersion,
438 vers_decls = emptyNameEnv
441 lookupVersion :: NameEnv Version -> Name -> Version
442 lookupVersion env name = lookupNameEnv env name `orElse` initialVersion
444 data Deprecations = NoDeprecs
445 | DeprecAll DeprecTxt -- Whole module deprecated
446 | DeprecSome (NameEnv (Name,DeprecTxt)) -- Some things deprecated
448 -- We keep the Name in the range, so we can print them out
450 lookupDeprec :: Deprecations -> Name -> Maybe DeprecTxt
451 lookupDeprec NoDeprecs name = Nothing
452 lookupDeprec (DeprecAll txt) name = Just txt
453 lookupDeprec (DeprecSome env) name = case lookupNameEnv env name of
454 Just (_, txt) -> Just txt
457 instance Eq Deprecations where
458 -- Used when checking whether we need write a new interface
459 NoDeprecs == NoDeprecs = True
460 (DeprecAll t1) == (DeprecAll t2) = t1 == t2
461 (DeprecSome e1) == (DeprecSome e2) = nameEnvElts e1 == nameEnvElts e2
467 type Avails = [AvailInfo]
468 type AvailInfo = GenAvailInfo Name
469 type RdrAvailInfo = GenAvailInfo OccName
471 data GenAvailInfo name = Avail name -- An ordinary identifier
472 | AvailTC name -- The name of the type or class
473 [name] -- The available pieces of type/class.
474 -- NB: If the type or class is itself
475 -- to be in scope, it must be in this list.
476 -- Thus, typically: AvailTC Eq [Eq, ==, /=]
478 -- Equality used when deciding if the interface has changed
480 type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
482 emptyAvailEnv :: AvailEnv
483 emptyAvailEnv = emptyNameEnv
485 instance Outputable n => Outputable (GenAvailInfo n) where
488 pprAvail :: Outputable n => GenAvailInfo n -> SDoc
489 pprAvail (AvailTC n ns) = ppr n <> case {- filter (/= n) -} ns of
491 ns' -> braces (hsep (punctuate comma (map ppr ns')))
493 pprAvail (Avail n) = ppr n
497 type FixityEnv = NameEnv Fixity
499 lookupFixity :: FixityEnv -> Name -> Fixity
500 lookupFixity env n = lookupNameEnv env n `orElse` defaultFixity
504 %************************************************************************
506 \subsection{ModIface}
508 %************************************************************************
511 type WhetherHasOrphans = Bool
513 -- * an instance decl in a module other than the defn module for
514 -- one of the tycons or classes in the instance head
515 -- * a transformation rule in a module other than the one defining
516 -- the function in the head of the rule.
518 type IsBootInterface = Bool
520 type ImportVersion name = (ModuleName, WhetherHasOrphans, IsBootInterface, WhatsImported name)
522 data WhatsImported name = NothingAtAll -- The module is below us in the
523 -- hierarchy, but we import nothing
525 | Everything Version -- Used for modules from other packages;
526 -- we record only the module's version number
529 Version -- Module version
530 (Maybe Version) -- Export-list version, if we depend on it
531 [(name,Version)] -- List guaranteed non-empty
532 Version -- Rules version
535 -- 'Specifically' doesn't let you say "I imported f but none of the rules in
536 -- the module". If you use anything in the module you get its rule version
537 -- So if the rules change, you'll recompile, even if you don't use them.
538 -- This is easy to implement, and it's safer: you might not have used the rules last
539 -- time round, but if someone has added a new rule you might need it this time
541 -- The export list field is (Just v) if we depend on the export list:
542 -- we imported the module without saying exactly what we imported
543 -- We need to recompile if the module exports changes, because we might
544 -- now have a name clash in the importing module.
546 type IsExported = Name -> Bool -- True for names that are exported from this module
550 %************************************************************************
552 \subsection{The persistent compiler state}
554 %************************************************************************
556 The @PersistentCompilerState@ persists across successive calls to the
559 * A ModIface for each non-home-package module
561 * An accumulated TypeEnv from all the modules in imported packages
563 * An accumulated InstEnv from all the modules in imported packages
564 The point is that we don't want to keep recreating it whenever
565 we compile a new module. The InstEnv component of pcPST is empty.
566 (This means we might "see" instances that we shouldn't "really" see;
567 but the Haskell Report is vague on what is meant to be visible,
568 so we just take the easy road here.)
572 * The persistent renamer state
575 data PersistentCompilerState
577 pcs_PIT :: !PackageIfaceTable, -- Domain = non-home-package modules
578 -- the mi_decls component is empty
580 pcs_PTE :: !PackageTypeEnv, -- Domain = non-home-package modules
581 -- except that the InstEnv components is empty
583 pcs_insts :: !PackageInstEnv, -- The total InstEnv accumulated from all
584 -- the non-home-package modules
586 pcs_rules :: !PackageRuleBase, -- Ditto RuleEnv
588 pcs_PRS :: !PersistentRenamerState
593 The persistent renamer state contains:
595 * A name supply, which deals with allocating unique names to
596 (Module,OccName) original names,
598 * A "holding pen" for declarations that have been read out of
599 interface files but not yet sucked in, renamed, and typechecked
602 type PackageTypeEnv = TypeEnv
603 type PackageRuleBase = RuleBase
604 type PackageInstEnv = InstEnv
606 data PersistentRenamerState
607 = PRS { prsOrig :: !NameSupply,
608 prsImpMods :: !ImportedModuleInfo,
610 -- Holding pens for stuff that has been read in
611 -- but not yet slurped into the renamer
612 prsDecls :: !DeclsMap,
613 prsInsts :: !IfaceInsts,
614 prsRules :: !IfaceRules
618 The NameSupply makes sure that there is just one Unique assigned for
619 each original name; i.e. (module-name, occ-name) pair. The Name is
620 always stored as a Global, and has the SrcLoc of its binding location.
621 Actually that's not quite right. When we first encounter the original
622 name, we might not be at its binding site (e.g. we are reading an
623 interface file); so we give it 'noSrcLoc' then. Later, when we find
624 its binding site, we fix it up.
626 Exactly the same is true of the Module stored in the Name. When we first
627 encounter the occurrence, we may not know the details of the module, so
628 we just store junk. Then when we find the binding site, we fix it up.
632 = NameSupply { nsUniqs :: UniqSupply,
634 nsNames :: OrigNameCache,
635 -- Ensures that one original name gets one unique
636 nsIPs :: OrigIParamCache
637 -- Ensures that one implicit parameter name gets one unique
640 type OrigNameCache = FiniteMap (ModuleName,OccName) Name
641 type OrigIParamCache = FiniteMap (IPName RdrName) (IPName Name)
644 @ImportedModuleInfo@ contains info ONLY about modules that have not yet
645 been loaded into the iPIT. These modules are mentioned in interfaces we've
646 already read, so we know a tiny bit about them, but we havn't yet looked
647 at the interface file for the module itself. It needs to persist across
648 invocations of the renamer, at least from Rename.checkOldIface to Rename.renameSource.
649 And there's no harm in it persisting across multiple compilations.
652 type ImportedModuleInfo = FiniteMap ModuleName (WhetherHasOrphans, IsBootInterface)
655 A DeclsMap contains a binding for each Name in the declaration
656 including the constructors of a type decl etc. The Bool is True just
660 type DeclsMap = (NameEnv (AvailInfo, Bool, (Module, RdrNameTyClDecl)), Int)
661 -- The Int says how many have been sucked in
663 type IfaceInsts = GatedDecls RdrNameInstDecl
664 type IfaceRules = GatedDecls RdrNameRuleDecl
666 type GatedDecls d = (Bag (GatedDecl d), Int) -- The Int says how many have been sucked in
667 type GatedDecl d = (GateFn, (Module, d))
668 type GateFn = (Name -> Bool) -> Bool -- Returns True <=> gate is open
669 -- The (Name -> Bool) fn returns True for visible Names
670 -- For example, suppose this is in an interface file
671 -- instance C T where ...
672 -- We want to slurp this decl if both C and T are "visible" in
673 -- the importing module. See "The gating story" in RnIfaces for details.
677 %************************************************************************
679 \subsection{Provenance and export info}
681 %************************************************************************
683 A LocalRdrEnv is used for local bindings (let, where, lambda, case)
686 type LocalRdrEnv = RdrNameEnv Name
688 extendLocalRdrEnv :: LocalRdrEnv -> [Name] -> LocalRdrEnv
689 extendLocalRdrEnv env names
690 = addListToRdrEnv env [(mkRdrUnqual (nameOccName n), n) | n <- names]
693 The GlobalRdrEnv gives maps RdrNames to Names. There is a separate
694 one for each module, corresponding to that module's top-level scope.
697 type GlobalRdrEnv = RdrNameEnv [GlobalRdrElt]
698 -- The list is because there may be name clashes
699 -- These only get reported on lookup, not on construction
701 data GlobalRdrElt = GRE Name Provenance (Maybe DeprecTxt)
702 -- The Maybe DeprecTxt tells whether this name is deprecated
705 = vcat (map pp (rdrEnvToList env))
707 pp (rn, nps) = ppr rn <> colon <+>
708 vcat [ppr n <+> pprNameProvenance n p | (GRE n p _) <- nps]
711 The "provenance" of something says how it came to be in scope.
715 = LocalDef -- Defined locally
717 | NonLocalDef -- Defined non-locally
720 -- Just used for grouping error messages (in RnEnv.warnUnusedBinds)
721 instance Eq Provenance where
722 p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
724 instance Eq ImportReason where
725 p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False
727 instance Ord Provenance where
728 compare LocalDef LocalDef = EQ
729 compare LocalDef (NonLocalDef _) = LT
730 compare (NonLocalDef _) LocalDef = GT
732 compare (NonLocalDef reason1) (NonLocalDef reason2)
733 = compare reason1 reason2
735 instance Ord ImportReason where
736 compare ImplicitImport ImplicitImport = EQ
737 compare ImplicitImport (UserImport _ _ _) = LT
738 compare (UserImport _ _ _) ImplicitImport = GT
739 compare (UserImport m1 loc1 _) (UserImport m2 loc2 _)
740 = (m1 `compare` m2) `thenCmp` (loc1 `compare` loc2)
744 = UserImport Module SrcLoc Bool -- Imported from module M on line L
745 -- Note the M may well not be the defining module
747 -- The Bool is true iff the thing was named *explicitly* in the import spec,
748 -- rather than being imported as part of a group; e.g.
751 -- Here, everything imported by B, and the constructors of T
752 -- are not named explicitly; only T is named explicitly.
753 -- This info is used when warning of unused names.
755 | ImplicitImport -- Imported implicitly for some other reason
759 hasBetterProv :: Provenance -> Provenance -> Bool
761 -- a local thing over an imported thing
762 -- a user-imported thing over a non-user-imported thing
763 -- an explicitly-imported thing over an implicitly imported thing
764 hasBetterProv LocalDef _ = True
765 hasBetterProv (NonLocalDef (UserImport _ _ _ )) (NonLocalDef ImplicitImport) = True
766 hasBetterProv _ _ = False
768 pprNameProvenance :: Name -> Provenance -> SDoc
769 pprNameProvenance name LocalDef = ptext SLIT("defined at") <+> ppr (nameSrcLoc name)
770 pprNameProvenance name (NonLocalDef why) = sep [ppr_reason why,
771 nest 2 (ppr_defn (nameSrcLoc name))]
773 ppr_reason ImplicitImport = ptext SLIT("implicitly imported")
774 ppr_reason (UserImport mod loc _) = ptext SLIT("imported from") <+> ppr mod <+> ptext SLIT("at") <+> ppr loc
776 ppr_defn loc | isGoodSrcLoc loc = parens (ptext SLIT("at") <+> ppr loc)