+\begin{code}
+mkLocalName :: Unique -> OccName -> SrcLoc -> Name
+mkLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ,
+ n_prov = LocalDef loc NotExported }
+ -- NB: You might worry that after lots of huffing and
+ -- puffing we might end up with two local names with distinct
+ -- uniques, but the same OccName. Indeed we can, but that's ok
+ -- * the insides of the compiler don't care: they use the Unique
+ -- * when printing for -ddump-xxx you can switch on -dppr-debug to get the
+ -- uniques if you get confused
+ -- * for interface files we tidyCore first, which puts the uniques
+ -- into the print name (see setNameVisibility below)
+
+mkImportedLocalName :: Unique -> OccName -> SrcLoc -> Name
+ -- Just the same as mkLocalName, except the provenance is different
+ -- Reason: this flags the name as one that came in from an interface file.
+ -- This is useful when trying to decide which of two type variables
+ -- should 'win' when unifying them.
+ -- NB: this is only for non-top-level names, so we use ImplicitImport
+mkImportedLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ,
+ n_prov = NonLocalDef ImplicitImport True }
+
+
+mkGlobalName :: Unique -> Module -> OccName -> Provenance -> Name
+mkGlobalName uniq mod occ prov = Name { n_uniq = uniq, n_sort = Global mod,
+ n_occ = occ, n_prov = prov }
+
+
+mkSysLocalName :: Unique -> FAST_STRING -> Name
+mkSysLocalName uniq fs = Name { n_uniq = uniq, n_sort = Local,
+ n_occ = mkSrcVarOcc fs, n_prov = SystemProv }
+
+mkTopName :: Unique -> Module -> FAST_STRING -> Name
+ -- Make a top-level name; make it Global if top-level
+ -- things should be externally visible; Local otherwise
+ -- This chap is only used *after* the tidyCore phase
+ -- Notably, it is used during STG lambda lifting
+ --
+ -- We have to make sure that the name is globally unique
+ -- and we don't have tidyCore to help us. So we append
+ -- the unique. Hack! Hack!
+mkTopName uniq mod fs
+ = Name { n_uniq = uniq,
+ n_sort = mk_top_sort mod,
+ n_occ = mkSrcVarOcc (_PK_ ((_UNPK_ fs) ++ show uniq)),
+ n_prov = LocalDef noSrcLoc NotExported }
+
+------------------------- Wired in names -------------------------
+
+mkWiredInIdName :: Unique -> Module -> OccName -> Id -> Name
+mkWiredInIdName uniq mod occ id = Name { n_uniq = uniq, n_sort = WiredInId mod id,
+ n_occ = occ, n_prov = SystemProv }
+
+-- mkWiredInTyConName takes a FAST_STRING instead of
+-- an OccName, which is a bit yukky but that's what the
+-- clients find easiest.
+mkWiredInTyConName :: Unique -> Module -> FAST_STRING -> TyCon -> Name
+mkWiredInTyConName uniq mod fs tycon
+ = Name { n_uniq = uniq, n_sort = WiredInTyCon mod tycon,
+ n_occ = mkSrcOccFS tcName fs, n_prov = SystemProv }
+
+
+---------------------------------------------------------------------
+mkDerivedName :: (OccName -> OccName)
+ -> Name -- Base name
+ -> Unique -- New unique
+ -> Name -- Result is always a value name
+
+mkDerivedName f name uniq = name {n_uniq = uniq, n_occ = f (n_occ name)}
+
+-- When we renumber/rename things, we need to be
+-- able to change a Name's Unique to match the cached
+-- one in the thing it's the name of. If you know what I mean.
+setNameUnique name uniq = name {n_uniq = uniq}
+
+setNameOcc :: Name -> OccName -> Name
+ -- Give the thing a new OccName, *and*
+ -- record that it's no longer a sys-local
+ -- This is used by the tidy-up pass
+setNameOcc name occ = name {n_occ = occ}
+
+setNameModule :: Name -> Module -> Name
+setNameModule name mod = name {n_sort = set (n_sort name)}
+ where
+ set (Global _) = Global mod
+ set (WiredInId _ id) = WiredInId mod id
+ set (WiredInTyCon _ tycon) = WiredInTyCon mod tycon
+\end{code}