Commit e0df569f authored by alexbiehl's avatar alexbiehl Committed by Ben Gamari
Browse files

Use proper Unique for Name

I noticed this while tinkering in haddock. This might be a relict from
ancient times where newtypes wouldn't optimize well.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D4146
parent b0b80e90
...@@ -109,7 +109,7 @@ import Data.Data ...@@ -109,7 +109,7 @@ import Data.Data
data Name = Name { data Name = Name {
n_sort :: NameSort, -- What sort of name it is n_sort :: NameSort, -- What sort of name it is
n_occ :: !OccName, -- Its occurrence name n_occ :: !OccName, -- Its occurrence name
n_uniq :: {-# UNPACK #-} !Int, n_uniq :: {-# UNPACK #-} !Unique,
n_loc :: !SrcSpan -- Definition site n_loc :: !SrcSpan -- Definition site
} }
...@@ -198,7 +198,7 @@ nameModule :: Name -> Module ...@@ -198,7 +198,7 @@ nameModule :: Name -> Module
nameSrcLoc :: Name -> SrcLoc nameSrcLoc :: Name -> SrcLoc
nameSrcSpan :: Name -> SrcSpan nameSrcSpan :: Name -> SrcSpan
nameUnique name = mkUniqueGrimily (n_uniq name) nameUnique name = n_uniq name
nameOccName name = n_occ name nameOccName name = n_occ name
nameSrcLoc name = srcSpanStart (n_loc name) nameSrcLoc name = srcSpanStart (n_loc name)
nameSrcSpan name = n_loc name nameSrcSpan name = n_loc name
...@@ -334,7 +334,7 @@ isSystemName _ = False ...@@ -334,7 +334,7 @@ isSystemName _ = False
-- | Create a name which is (for now at least) local to the current module and hence -- | Create a name which is (for now at least) local to the current module and hence
-- does not need a 'Module' to disambiguate it from other 'Name's -- does not need a 'Module' to disambiguate it from other 'Name's
mkInternalName :: Unique -> OccName -> SrcSpan -> Name mkInternalName :: Unique -> OccName -> SrcSpan -> Name
mkInternalName uniq occ loc = Name { n_uniq = getKey uniq mkInternalName uniq occ loc = Name { n_uniq = uniq
, n_sort = Internal , n_sort = Internal
, n_occ = occ , n_occ = occ
, n_loc = loc } , n_loc = loc }
...@@ -349,12 +349,12 @@ mkInternalName uniq occ loc = Name { n_uniq = getKey uniq ...@@ -349,12 +349,12 @@ mkInternalName uniq occ loc = Name { n_uniq = getKey uniq
mkClonedInternalName :: Unique -> Name -> Name mkClonedInternalName :: Unique -> Name -> Name
mkClonedInternalName uniq (Name { n_occ = occ, n_loc = loc }) mkClonedInternalName uniq (Name { n_occ = occ, n_loc = loc })
= Name { n_uniq = getKey uniq, n_sort = Internal = Name { n_uniq = uniq, n_sort = Internal
, n_occ = occ, n_loc = loc } , n_occ = occ, n_loc = loc }
mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name
mkDerivedInternalName derive_occ uniq (Name { n_occ = occ, n_loc = loc }) mkDerivedInternalName derive_occ uniq (Name { n_occ = occ, n_loc = loc })
= Name { n_uniq = getKey uniq, n_sort = Internal = Name { n_uniq = uniq, n_sort = Internal
, n_occ = derive_occ occ, n_loc = loc } , n_occ = derive_occ occ, n_loc = loc }
-- | Create a name which definitely originates in the given module -- | Create a name which definitely originates in the given module
...@@ -363,13 +363,13 @@ mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name ...@@ -363,13 +363,13 @@ mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name
-- (see Note [The Name Cache] in IfaceEnv), so don't just call mkExternalName -- (see Note [The Name Cache] in IfaceEnv), so don't just call mkExternalName
-- with some fresh unique without populating the Name Cache -- with some fresh unique without populating the Name Cache
mkExternalName uniq mod occ loc mkExternalName uniq mod occ loc
= Name { n_uniq = getKey uniq, n_sort = External mod, = Name { n_uniq = uniq, n_sort = External mod,
n_occ = occ, n_loc = loc } n_occ = occ, n_loc = loc }
-- | Create a name which is actually defined by the compiler itself -- | Create a name which is actually defined by the compiler itself
mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
mkWiredInName mod occ uniq thing built_in mkWiredInName mod occ uniq thing built_in
= Name { n_uniq = getKey uniq, = Name { n_uniq = uniq,
n_sort = WiredIn mod thing built_in, n_sort = WiredIn mod thing built_in,
n_occ = occ, n_loc = wiredInSrcSpan } n_occ = occ, n_loc = wiredInSrcSpan }
...@@ -378,7 +378,7 @@ mkSystemName :: Unique -> OccName -> Name ...@@ -378,7 +378,7 @@ mkSystemName :: Unique -> OccName -> Name
mkSystemName uniq occ = mkSystemNameAt uniq occ noSrcSpan mkSystemName uniq occ = mkSystemNameAt uniq occ noSrcSpan
mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
mkSystemNameAt uniq occ loc = Name { n_uniq = getKey uniq, n_sort = System mkSystemNameAt uniq occ loc = Name { n_uniq = uniq, n_sort = System
, n_occ = occ, n_loc = loc } , n_occ = occ, n_loc = loc }
mkSystemVarName :: Unique -> FastString -> Name mkSystemVarName :: Unique -> FastString -> Name
...@@ -396,7 +396,7 @@ mkFCallName uniq str = mkInternalName uniq (mkVarOcc str) noSrcSpan ...@@ -396,7 +396,7 @@ mkFCallName uniq str = mkInternalName uniq (mkVarOcc str) noSrcSpan
-- able to change a Name's Unique to match the cached -- 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. -- one in the thing it's the name of. If you know what I mean.
setNameUnique :: Name -> Unique -> Name setNameUnique :: Name -> Unique -> Name
setNameUnique name uniq = name {n_uniq = getKey uniq} setNameUnique name uniq = name {n_uniq = uniq}
-- This is used for hsigs: we want to use the name of the originally exported -- This is used for hsigs: we want to use the name of the originally exported
-- entity, but edit the location to refer to the reexport site -- entity, but edit the location to refer to the reexport site
...@@ -435,7 +435,7 @@ mkLocalisedOccName this_mod mk_occ name = mk_occ origin (nameOccName name) ...@@ -435,7 +435,7 @@ mkLocalisedOccName this_mod mk_occ name = mk_occ origin (nameOccName name)
-} -}
cmpName :: Name -> Name -> Ordering cmpName :: Name -> Name -> Ordering
cmpName n1 n2 = n_uniq n1 `compare` n_uniq n2 cmpName n1 n2 = n_uniq n1 `nonDetCmpUnique` n_uniq n2
-- | Compare Names lexicographically -- | Compare Names lexicographically
-- This only works for Names that originate in the source code or have been -- This only works for Names that originate in the source code or have been
...@@ -527,14 +527,13 @@ instance OutputableBndr Name where ...@@ -527,14 +527,13 @@ instance OutputableBndr Name where
pprPrefixOcc = pprPrefixName pprPrefixOcc = pprPrefixName
pprName :: Name -> SDoc pprName :: Name -> SDoc
pprName (Name {n_sort = sort, n_uniq = u, n_occ = occ}) pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ})
= getPprStyle $ \ sty -> = getPprStyle $ \ sty ->
case sort of case sort of
WiredIn mod _ builtin -> pprExternal sty uniq mod occ True builtin WiredIn mod _ builtin -> pprExternal sty uniq mod occ True builtin
External mod -> pprExternal sty uniq mod occ False UserSyntax External mod -> pprExternal sty uniq mod occ False UserSyntax
System -> pprSystem sty uniq occ System -> pprSystem sty uniq occ
Internal -> pprInternal sty uniq occ Internal -> pprInternal sty uniq occ
where uniq = mkUniqueGrimily u
pprExternal :: PprStyle -> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc pprExternal :: PprStyle -> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal sty uniq mod occ is_wired is_builtin pprExternal sty uniq mod occ is_wired is_builtin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment