-\begin{code}
-setNameProvenance :: Name -> Provenance -> Name
- -- setNameProvenance used to only change the provenance of
- -- Implicit-provenance things, but that gives bad error messages
- -- for names defined twice in the same module, so I changed it to
- -- set the provenance of *any* global (SLPJ Jun 97)
-setNameProvenance name prov = name {n_prov = prov}
-
-getNameProvenance :: Name -> Provenance
-getNameProvenance name = n_prov name
-
-setNameImportReason :: Name -> ImportReason -> Name
-setNameImportReason name reason
- = name { n_prov = new_prov }
- where
- -- It's important that we don't do the pattern matching
- -- in the top-level clause, else we get a black hole in
- -- the renamer. Rather a yukky constraint. There's only
- -- one call, in RnNames
- old_prov = n_prov name
- new_prov = case old_prov of
- NonLocalDef _ omit -> NonLocalDef reason omit
- other -> old_prov
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Provenance and export info}
-%* *
-%************************************************************************
-
-\begin{code}
-data Provenance
- = LocalDef -- Defined locally
- SrcLoc -- Defn site
- ExportFlag -- Whether it's exported
-
- | NonLocalDef -- Defined non-locally
- ImportReason
- PrintUnqualified
-
- | SystemProv -- Either (a) a system-generated local with
- -- a v short name OccName
- -- or (b) a known-key global which should have a proper
- -- provenance attached by the renamer
-\end{code}
-
-Sys-provs are only used internally. When the compiler generates (say)
-a fresh desguar variable it always calls it "ds", and of course it gets
-a fresh unique. But when printing -ddump-xx dumps, we must print it with
-its unique, because there'll be a lot of "ds" variables.
-
-Names with SystemProv differ in the following ways:
- a) locals have unique attached when printing dumps
- b) unifier eliminates sys tyvars in favour of user provs where possible
- c) renamer replaces SystemProv with a better one
-
-Before anything gets printed in interface files or output code, it's
-fed through a 'tidy' processor, which zaps the OccNames to have
-unique names; and converts all sys-locals to user locals
-If any desugarer sys-locals have survived that far, they get changed to
-"ds1", "ds2", etc.
-
-\begin{code}
-data ImportReason
- = UserImport Module SrcLoc Bool -- Imported from module M on line L
- -- Note the M may well not be the defining module
- -- for this thing!
- -- The Bool is true iff the thing was named *explicitly* in the import spec,
- -- rather than being imported as part of a group; e.g.
- -- import B
- -- import C( T(..) )
- -- Here, everything imported by B, and the constructors of T
- -- are not named explicitly; only T is named explicitly.
- -- This info is used when warning of unused names.
-
- | ImplicitImport -- Imported implicitly for some other reason
-
-
-type PrintUnqualified = Bool -- True <=> the unqualified name of this thing is
- -- in scope in this module, so print it
- -- unqualified in error messages
-
-data ExportFlag = Exported | NotExported
-\end{code}
-
-Something is "Exported" if it may be mentioned by another module without
-warning. The crucial thing about Exported things is that they must
-never be dropped as dead code, even if they aren't used in this module.
-Furthermore, being Exported means that we can't see all call sites of the thing.
-
-Exported things include:
-
- - explicitly exported Ids, including data constructors,
- class method selectors
-
- - dfuns from instance decls
-
-Being Exported is *not* the same as finally appearing in the .o file's
-symbol table. For example, a local Id may be mentioned in an Exported
-Id's unfolding in the interface file, in which case the local Id goes
-out too.
-
-
-\begin{code}
-systemProvenance :: Provenance
-systemProvenance = SystemProv
-
--- pprNameProvenance is used in error messages to say where a name came from
-pprNameProvenance :: Name -> SDoc
-pprNameProvenance name = pprProvenance (getNameProvenance name)
-
-pprProvenance :: Provenance -> SDoc
-pprProvenance SystemProv = ptext SLIT("System")
-pprProvenance (LocalDef loc _) = ptext SLIT("defined at") <+> ppr loc
-pprProvenance (NonLocalDef ImplicitImport _)
- = ptext SLIT("implicitly imported")
-pprProvenance (NonLocalDef (UserImport mod loc _) _)
- = ptext SLIT("imported from") <+> ppr mod <+> ptext SLIT("at") <+> ppr loc
-\end{code}
-