[Git][ghc/ghc][wip/T22010] Rename mask to tag
Jaro Reinders (@Noughtmare)
gitlab at gitlab.haskell.org
Wed Jun 28 15:47:41 UTC 2023
Jaro Reinders pushed to branch wip/T22010 at Glasgow Haskell Compiler / GHC
Commits:
64e13a3b by Jaro Reinders at 2023-06-28T17:47:30+02:00
Rename mask to tag
- - - - -
12 changed files:
- compiler/GHC/Builtin/Uniques.hs
- compiler/GHC/CmmToLlvm/Base.hs
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify/Monad.hs
- compiler/GHC/Stg/Pipeline.hs
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Types/Name/Cache.hs
- compiler/GHC/Types/Unique.hs
- compiler/GHC/Types/Unique/Supply.hs
Changes:
=====================================
compiler/GHC/Builtin/Uniques.hs
=====================================
@@ -305,7 +305,7 @@ getTupleDataConName boxity n =
_ -> panic "getTupleDataConName: impossible"
{-
-Note [Uniques for wired-in prelude things and known masks]
+Note [Uniques for wired-in prelude things and known tags]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allocation of unique supply characters:
v,u: for renumbering value-, and usage- vars.
=====================================
compiler/GHC/CmmToLlvm/Base.hs
=====================================
@@ -260,7 +260,7 @@ data LlvmEnv = LlvmEnv
, envConfig :: !LlvmCgConfig -- ^ Configuration for LLVM code gen
, envLogger :: !Logger -- ^ Logger
, envOutput :: BufHandle -- ^ Output buffer
- , envMask :: !Char -- ^ Mask for creating unique values
+ , envTag :: !Char -- ^ Tag for creating unique values
, envFreshMeta :: MetaId -- ^ Supply of fresh metadata IDs
, envUniqMeta :: UniqFM Unique MetaId -- ^ Global metadata nodes
, envFunMap :: LlvmEnvMap -- ^ Global functions so far, with type
@@ -292,12 +292,12 @@ getConfig = LlvmM $ \env -> return (envConfig env, env)
instance MonadUnique LlvmM where
getUniqueSupplyM = do
- mask <- getEnv envMask
- liftIO $! mkSplitUniqSupply mask
+ tag <- getEnv envTag
+ liftIO $! mkSplitUniqSupply tag
getUniqueM = do
- mask <- getEnv envMask
- liftIO $! uniqFromMask mask
+ tag <- getEnv envTag
+ liftIO $! uniqFromTag tag
-- | Lifting of IO actions. Not exported, as we want to encapsulate IO.
liftIO :: IO a -> LlvmM a
@@ -318,7 +318,7 @@ runLlvm logger cfg ver out m = do
, envConfig = cfg
, envLogger = logger
, envOutput = out
- , envMask = 'n'
+ , envTag = 'n'
, envFreshMeta = MetaId 0
, envUniqMeta = emptyUFM
}
=====================================
compiler/GHC/Core/Opt/Monad.hs
=====================================
@@ -20,7 +20,7 @@ module GHC.Core.Opt.Monad (
initRuleEnv, getExternalRuleBase,
getDynFlags, getPackageFamInstEnv,
getInteractiveContext,
- getUniqMask,
+ getUniqTag,
getNamePprCtx, getSrcSpanM,
-- ** Writing to the monad
@@ -117,7 +117,7 @@ data CoreReader = CoreReader {
cr_name_ppr_ctx :: NamePprCtx,
cr_loc :: SrcSpan, -- Use this for log/error messages so they
-- are at least tagged with the right source file
- cr_uniq_mask :: !Char -- Mask for creating unique values
+ cr_uniq_tag :: !Char -- Tag for creating unique values
}
-- Note: CoreWriter used to be defined with data, rather than newtype. If it
@@ -167,12 +167,12 @@ instance MonadPlus CoreM
instance MonadUnique CoreM where
getUniqueSupplyM = do
- mask <- read cr_uniq_mask
- liftIO $! mkSplitUniqSupply mask
+ tag <- read cr_uniq_tag
+ liftIO $! mkSplitUniqSupply tag
getUniqueM = do
- mask <- read cr_uniq_mask
- liftIO $! uniqFromMask mask
+ tag <- read cr_uniq_tag
+ liftIO $! uniqFromTag tag
runCoreM :: HscEnv
-> RuleBase
@@ -182,7 +182,7 @@ runCoreM :: HscEnv
-> SrcSpan
-> CoreM a
-> IO (a, SimplCount)
-runCoreM hsc_env rule_base mask mod name_ppr_ctx loc m
+runCoreM hsc_env rule_base tag mod name_ppr_ctx loc m
= liftM extract $ runIOEnv reader $ unCoreM m
where
reader = CoreReader {
@@ -191,7 +191,7 @@ runCoreM hsc_env rule_base mask mod name_ppr_ctx loc m
cr_module = mod,
cr_name_ppr_ctx = name_ppr_ctx,
cr_loc = loc,
- cr_uniq_mask = mask
+ cr_uniq_tag = tag
}
extract :: (a, CoreWriter) -> (a, SimplCount)
@@ -261,8 +261,8 @@ getSrcSpanM = read cr_loc
addSimplCount :: SimplCount -> CoreM ()
addSimplCount count = write (CoreWriter { cw_simpl_count = count })
-getUniqMask :: CoreM Char
-getUniqMask = read cr_uniq_mask
+getUniqTag :: CoreM Char
+getUniqTag = read cr_uniq_tag
-- Convenience accessors for useful fields of HscEnv
=====================================
compiler/GHC/Core/Opt/Pipeline.hs
=====================================
@@ -77,9 +77,9 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
, mg_loc = loc
, mg_rdr_env = rdr_env })
= do { let builtin_passes = getCoreToDo dflags hpt_rule_base extra_vars
- uniq_mask = 's'
+ uniq_tag = 's'
- ; (guts2, stats) <- runCoreM hsc_env hpt_rule_base uniq_mask mod
+ ; (guts2, stats) <- runCoreM hsc_env hpt_rule_base uniq_tag mod
name_ppr_ctx loc $
do { hsc_env' <- getHscEnv
; all_passes <- withPlugins (hsc_plugins hsc_env')
=====================================
compiler/GHC/Core/Opt/Simplify/Monad.hs
=====================================
@@ -180,13 +180,13 @@ traceSmpl herald doc
************************************************************************
-}
--- See Note [Uniques for wired-in prelude things and known masks] in GHC.Builtin.Uniques
-simplMask :: Char
-simplMask = 's'
+-- See Note [Uniques for wired-in prelude things and known tags] in GHC.Builtin.Uniques
+simplTag :: Char
+simplTag = 's'
instance MonadUnique SimplM where
- getUniqueSupplyM = liftIO $ mkSplitUniqSupply simplMask
- getUniqueM = liftIO $ uniqFromMask simplMask
+ getUniqueSupplyM = liftIO $ mkSplitUniqSupply simplTag
+ getUniqueM = liftIO $ uniqFromTag simplTag
instance HasLogger SimplM where
getLogger = gets st_logger
=====================================
compiler/GHC/Stg/Pipeline.hs
=====================================
@@ -57,10 +57,10 @@ newtype StgM a = StgM { _unStgM :: ReaderT Char IO a }
deriving (Functor, Applicative, Monad, MonadIO)
instance MonadUnique StgM where
- getUniqueSupplyM = StgM $ do { mask <- ask
- ; liftIO $! mkSplitUniqSupply mask}
- getUniqueM = StgM $ do { mask <- ask
- ; liftIO $! uniqFromMask mask}
+ getUniqueSupplyM = StgM $ do { tag <- ask
+ ; liftIO $! mkSplitUniqSupply tag}
+ getUniqueM = StgM $ do { tag <- ask
+ ; liftIO $! uniqFromTag tag}
runStgM :: Char -> StgM a -> IO a
runStgM mask (StgM m) = runReaderT m mask
=====================================
compiler/GHC/Tc/Types.hs
=====================================
@@ -250,7 +250,7 @@ data Env gbl lcl
-- Includes all info about imported things
-- BangPattern is to fix leak, see #15111
- env_um :: {-# UNPACK #-} !Char, -- Mask for Uniques
+ env_ut :: {-# UNPACK #-} !Char, -- Tag for Uniques
env_gbl :: gbl, -- Info about things defined at the top level
-- of the module being compiled
=====================================
compiler/GHC/Tc/Types/Origin.hs
=====================================
@@ -322,7 +322,7 @@ unkSkolAnon = UnkSkol callStack
-- shares a certain 'Unique'.
mkSkolemInfo :: MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo sk_anon = do
- u <- liftIO $! uniqFromMask 's'
+ u <- liftIO $! uniqFromTag 's'
return (SkolemInfo u sk_anon)
getSkolemInfo :: SkolemInfo -> SkolemInfoAnon
=====================================
compiler/GHC/Tc/Utils/Monad.hs
=====================================
@@ -450,14 +450,14 @@ an actual crash (attempting to look up the Integer type).
************************************************************************
-}
-initTcRnIf :: Char -- ^ Mask for unique supply
+initTcRnIf :: Char -- ^ Tag for unique supply
-> HscEnv
-> gbl -> lcl
-> TcRnIf gbl lcl a
-> IO a
-initTcRnIf uniq_mask hsc_env gbl_env lcl_env thing_inside
+initTcRnIf uniq_tag hsc_env gbl_env lcl_env thing_inside
= do { let { env = Env { env_top = hsc_env,
- env_um = uniq_mask,
+ env_ut = uniq_tag,
env_gbl = gbl_env,
env_lcl = lcl_env} }
@@ -710,14 +710,14 @@ escapeArrowScope
newUnique :: TcRnIf gbl lcl Unique
newUnique
= do { env <- getEnv
- ; let mask = env_um env
- ; liftIO $! uniqFromMask mask }
+ ; let tag = env_ut env
+ ; liftIO $! uniqFromTag tag }
newUniqueSupply :: TcRnIf gbl lcl UniqSupply
newUniqueSupply
= do { env <- getEnv
- ; let mask = env_um env
- ; liftIO $! mkSplitUniqSupply mask }
+ ; let tag = env_ut env
+ ; liftIO $! mkSplitUniqSupply tag }
cloneLocalName :: Name -> TcM Name
-- Make a fresh Internal name with the same OccName and SrcSpan
=====================================
compiler/GHC/Types/Name/Cache.hs
=====================================
@@ -100,7 +100,7 @@ data NameCache = NameCache
type OrigNameCache = ModuleEnv (OccEnv Name)
takeUniqFromNameCache :: NameCache -> IO Unique
-takeUniqFromNameCache (NameCache c _) = uniqFromMask c
+takeUniqFromNameCache (NameCache c _) = uniqFromTag c
lookupOrigNameCache :: OrigNameCache -> Module -> OccName -> Maybe Name
lookupOrigNameCache nc mod occ
=====================================
compiler/GHC/Types/Unique.hs
=====================================
@@ -72,16 +72,16 @@ import Language.Haskell.Syntax.Module.Name
* *
************************************************************************
-Note [Uniques and masks]
+Note [Uniques and tags]
~~~~~~~~~~~~~~~~~~~~~~~~
A `Unique` in GHC is a 64 bit value composed of two pieces:
-* A "mask", of width `UNIQUE_TAG_BITS`, in the high order bits
+* A "tag", of width `UNIQUE_TAG_BITS`, in the high order bits
* A number, of width `uNIQUE_BITS`, which fills up the remainder of the Word64
-The mask is typically an ASCII character. It is typically used to make it easier
+The tag is typically an ASCII character. It is typically used to make it easier
to distinguish uniques constructed by different parts of the compiler.
-There is a (potentially incomplete) list of unique masks used given in
-GHC.Builtin.Uniques. See Note [Uniques for wired-in prelude things and known masks]
+There is a (potentially incomplete) list of unique tags used given in
+GHC.Builtin.Uniques. See Note [Uniques for wired-in prelude things and known tags]
`mkUnique` constructs a `Unique` from its pieces
mkUnique :: Char -> Word64 -> Unique
@@ -135,8 +135,7 @@ maxLocalUnique = mkLocalUnique uniqueMask
-- newTagUnique changes the "domain" of a unique to a different char
newTagUnique u c = mkUnique c i where (_,i) = unpkUnique u
--- | How many bits are devoted to the unique index (as opposed to the class
--- character).
+-- | Bitmask that has zeros for the tag bits and ones for the rest.
uniqueMask :: Word64
uniqueMask = (1 `shiftL` uNIQUE_BITS) - 1
=====================================
compiler/GHC/Types/Unique/Supply.hs
=====================================
@@ -15,7 +15,7 @@ module GHC.Types.Unique.Supply (
-- ** Operations on supplies
uniqFromSupply, uniqsFromSupply, -- basic ops
- takeUniqFromSupply, uniqFromMask,
+ takeUniqFromSupply, uniqFromTag,
mkSplitUniqSupply,
splitUniqSupply, listSplitUniqSupply,
@@ -90,24 +90,24 @@ The general design (used throughout GHC) is to:
* For creating new uniques either a UniqSupply is used and threaded through
or for monadic code a MonadUnique instance might conjure up uniques using
- `uniqFromMask`.
+ `uniqFromTag`.
* Different parts of the compiler will use a UniqSupply or MonadUnique instance
- with a specific mask. This way the different parts of the compiler will
- generate uniques with different masks.
+ with a specific tag. This way the different parts of the compiler will
+ generate uniques with different tags.
-If different code shares the same mask then care has to be taken that all uniques
+If different code shares the same tag then care has to be taken that all uniques
still get distinct numbers. Usually this is done by relying on genSym which
has *one* counter per GHC invocation that is relied on by all calls to it.
But using something like the address for pinned objects works as well and in fact is done
for fast strings.
This is important for example in the simplifier. Most passes of the simplifier use
-the same mask 's'. However in some places we create a unique supply using `mkSplitUniqSupply`
+the same tag 's'. However in some places we create a unique supply using `mkSplitUniqSupply`
and thread it through the code, while in GHC.Core.Opt.Simplify.Monad we use the
`instance MonadUnique SimplM`, which uses `mkSplitUniqSupply` in getUniqueSupplyM
-and `uniqFromMask` in getUniqueM.
+and `uniqFromTag` in getUniqueM.
-Ultimately all these boil down to each new unique consisting of the mask and the result from
+Ultimately all these boil down to each new unique consisting of the tag and the result from
a call to `genSym`. The latter producing a distinct number for each invocation ensuring
uniques are distinct.
@@ -120,7 +120,7 @@ The inner loop of mkSplitUniqSupply is a function closure
case unIO genSym s1 of { (# s2, u #) ->
case unIO (unsafeDupableInterleaveIO (IO mk_supply)) s2 of { (# s3, x #) ->
case unIO (unsafeDupableInterleaveIO (IO mk_supply)) s3 of { (# s4, y #) ->
- (# s4, MkSplitUniqSupply (mask .|. u) x y #)
+ (# s4, MkSplitUniqSupply (tag .|. u) x y #)
}}}}
It's a classic example of an IO action that is captured and then called
@@ -134,7 +134,7 @@ We used to write it as:
genSym >>= \ u ->
mk_supply >>= \ s1 ->
mk_supply >>= \ s2 ->
- return (MkSplitUniqSupply (mask .|. u) s1 s2)
+ return (MkSplitUniqSupply (tag .|. u) s1 s2)
and to rely on -fno-state-hack, full laziness and inlining to get the same
result. It was very brittle and required enabling -fno-state-hack globally. So
@@ -153,29 +153,29 @@ The code for this is about as optimized as it gets, but we can't
get around the need to allocate one `UniqSupply` for each Unique
we need.
-For code in IO we can improve on this by threading only the *mask*
-we are going to use for Uniques. Using `uniqFromMask` to
+For code in IO we can improve on this by threading only the *tag*
+we are going to use for Uniques. Using `uniqFromTag` to
generate uniques as needed. This gets rid of the overhead of
allocating a new UniqSupply for each unique generated. It also avoids
-frequent state updates when the Unique/Mask is part of the state in a
+frequent state updates when the Unique/Tag is part of the state in a
state monad.
-For monadic code in IO which always uses the same mask we can go further
-and hardcode the mask into the MonadUnique instance. On top of all the
-benefits of threading the mask this *also* has the benefit of avoiding
-the mask getting captured in thunks, or being passed around at runtime.
-It does however come at the cost of having to use a fixed Mask for all
-code run in this Monad. But remember, the Mask is purely cosmetic:
-See Note [Uniques and masks].
+For monadic code in IO which always uses the same tag we can go further
+and hardcode the tag into the MonadUnique instance. On top of all the
+benefits of threading the tag this *also* has the benefit of avoiding
+the tag getting captured in thunks, or being passed around at runtime.
+It does however come at the cost of having to use a fixed tag for all
+code run in this Monad. But remember, the tag is purely cosmetic:
+See Note [Uniques and tags].
NB: It's *not* an optimization to pass around the UniqSupply inside an
-IORef instead of the mask. While this would avoid frequent state updates
+IORef instead of the tag. While this would avoid frequent state updates
it still requires allocating one UniqSupply per Unique. On top of some
overhead for reading/writing to/from the IORef.
All of this hinges on the assumption that UniqSupply and
-uniqFromMask use the same source of distinct numbers (`genSym`) which
-allows both to be used at the same time, with the same mask, while still
+uniqFromTag use the same source of distinct numbers (`genSym`) which
+allows both to be used at the same time, with the same tag, while still
ensuring distinct uniques.
One might consider this fact to be an "accident". But GHC worked like this
as far back as source control history goes. It also allows the later two
@@ -197,12 +197,12 @@ data UniqSupply
mkSplitUniqSupply :: Char -> IO UniqSupply
-- ^ Create a unique supply out of thin air.
--- The "mask" (Char) supplied is purely cosmetic, making it easier
+-- The "tag" (Char) supplied is purely cosmetic, making it easier
-- to figure out where a Unique was born. See
--- Note [Uniques and masks].
+-- Note [Uniques and tags].
--
-- The payload part of the Uniques allocated from this UniqSupply are
--- guaranteed distinct wrt all other supplies, regardless of their "mask".
+-- guaranteed distinct wrt all other supplies, regardless of their "tag".
-- This is achieved by allocating the payload part from
-- a single source of Uniques, namely `genSym`, shared across
-- all UniqSupply's.
@@ -213,7 +213,7 @@ mkSplitUniqSupply c
= unsafeDupableInterleaveIO (IO mk_supply)
where
- !mask = mkTag c
+ !tag = mkTag c
-- Here comes THE MAGIC: see Note [How the unique supply works]
-- This is one of the most hammered bits in the whole compiler
@@ -225,7 +225,7 @@ mkSplitUniqSupply c
-- deferred IO computations
case unIO (unsafeDupableInterleaveIO (IO mk_supply)) s2 of { (# s3, x #) ->
case unIO (unsafeDupableInterleaveIO (IO mk_supply)) s3 of { (# s4, y #) ->
- (# s4, MkSplitUniqSupply (mask .|. u) x y #)
+ (# s4, MkSplitUniqSupply (tag .|. u) x y #)
}}}}
#if !MIN_VERSION_GLASGOW_HASKELL(9,1,0,0) || WORD_SIZE_IN_BITS != 64
@@ -261,11 +261,11 @@ initUniqSupply counter inc = do
poke ghc_unique_counter64 counter
poke ghc_unique_inc inc
-uniqFromMask :: Char -> IO Unique
-uniqFromMask !mask
+uniqFromTag :: Char -> IO Unique
+uniqFromTag !tag
= do { uqNum <- genSym
- ; return $! mkUnique mask uqNum }
-{-# NOINLINE uniqFromMask #-} -- We'll unbox everything, but we don't want to inline it
+ ; return $! mkUnique tag uqNum }
+{-# NOINLINE uniqFromTag #-} -- We'll unbox everything, but we don't want to inline it
splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply)
-- ^ Build two 'UniqSupply' from a single one, each of which
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/64e13a3b24f2b370b9b44ae3a5072c79a6dce645
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/64e13a3b24f2b370b9b44ae3a5072c79a6dce645
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230628/0719d858/attachment-0001.html>
More information about the ghc-commits
mailing list