- set (Global _) = Global mod
- set (WiredInId _ id) = WiredInId mod id
- set (WiredInTyCon _ tycon) = WiredInTyCon mod tycon
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Setting provenance and visibility
-%* *
-%************************************************************************
-
-tidyTopName is applied to top-level names in the final program
-
-For top-level things, it globalises Local names
- (if all top-level things should be visible)
- and localises non-exported Global names
- (if only exported things should be visible)
-
-In all cases except an exported global, it gives it a new occurrence name.
-
-The "visibility" here concerns whether the .o file's symbol table
-mentions the thing; if so, it needs a module name in its symbol.
-The Global things are "visible" and the Local ones are not
-
-Why should things be "visible"? Certainly they must be if they
-are exported. But also:
-
-(a) In certain (prelude only) modules we split up the .hc file into
- lots of separate little files, which are separately compiled by the C
- compiler. That gives lots of little .o files. The idea is that if
- you happen to mention one of them you don't necessarily pull them all
- in. (Pulling in a piece you don't need can be v bad, because it may
- mention other pieces you don't need either, and so on.)
-
- Sadly, splitting up .hc files means that local names (like s234) are
- now globally visible, which can lead to clashes between two .hc
- files. So unlocaliseWhatnot goes through making all the local things
- into global things, essentially by giving them full names so when they
- are printed they'll have their module name too. Pretty revolting
- really.
-
-(b) When optimisation is on we want to make all the internal
- top-level defns externally visible
-
-\begin{code}
-tidyTopName :: Module -> TidyOccEnv -> Name -> (TidyOccEnv, Name)
-tidyTopName mod env name
- = (env', name')
- where
- (env', occ') = tidyOccName env (n_occ name)
-
- name' = Name { n_uniq = n_uniq name, n_sort = mk_top_sort mod,
- n_occ = occ', n_prov = LocalDef noSrcLoc NotExported }
-
-mk_top_sort mod | all_toplev_ids_visible = Global mod
- | otherwise = Local
-
-all_toplev_ids_visible =
- not opt_OmitInterfacePragmas || -- Pragmas can make them visible
- opt_EnsureSplittableC -- Splitting requires visiblilty
-\end{code}
-
-
-\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