Zubin pushed to branch wip/26264 at Glasgow Haskell Compiler / GHC
Commits:
-
51ec3159
by Zubin Duggal at 2025-08-12T18:00:59+05:30
22 changed files:
- compiler/GHC/Builtin/Uniques.hs
- compiler/GHC/Cmm/Pipeline.hs
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify/Monad.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Iface/Rename.hs
- compiler/GHC/JS/JStg/Monad.hs
- compiler/GHC/Platform/Reg.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Stg/EnforceEpt.hs
- compiler/GHC/Stg/Pipeline.hs
- compiler/GHC/StgToCmm/Monad.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/DSM.hs
- compiler/GHC/Types/Unique/Supply.hs
Changes:
... | ... | @@ -121,7 +121,7 @@ mkSumTyConUnique arity = |
121 | 121 | assertPpr (arity <= 0x3f) (ppr arity) $
|
122 | 122 | -- 0x3f since we only have 6 bits to encode the
|
123 | 123 | -- alternative
|
124 | - mkUniqueInt 'z' (arity `shiftL` 8 .|. 0xfc)
|
|
124 | + mkUniqueInt SumTag (arity `shiftL` 8 .|. 0xfc)
|
|
125 | 125 | |
126 | 126 | -- | Inverse of 'mkSumTyConUnique'
|
127 | 127 | isSumTyConUnique :: Unique -> Maybe Arity
|
... | ... | @@ -137,7 +137,7 @@ mkSumDataConUnique alt arity |
137 | 137 | | alt >= arity
|
138 | 138 | = panic ("mkSumDataConUnique: " ++ show alt ++ " >= " ++ show arity)
|
139 | 139 | | otherwise
|
140 | - = mkUniqueInt 'z' (arity `shiftL` 8 + alt `shiftL` 2) {- skip the tycon -}
|
|
140 | + = mkUniqueInt SumTag (arity `shiftL` 8 + alt `shiftL` 2) {- skip the tycon -}
|
|
141 | 141 | |
142 | 142 | getUnboxedSumName :: Int -> Name
|
143 | 143 | getUnboxedSumName n
|
... | ... | @@ -224,17 +224,17 @@ selector Uniques takes inspiration from the encoding for unboxed sum Uniques. |
224 | 224 | -}
|
225 | 225 | |
226 | 226 | mkCTupleTyConUnique :: Arity -> Unique
|
227 | -mkCTupleTyConUnique a = mkUniqueInt 'k' (2*a)
|
|
227 | +mkCTupleTyConUnique a = mkUniqueInt CTupleTag (2*a)
|
|
228 | 228 | |
229 | 229 | mkCTupleDataConUnique :: Arity -> Unique
|
230 | -mkCTupleDataConUnique a = mkUniqueInt 'm' (3*a)
|
|
230 | +mkCTupleDataConUnique a = mkUniqueInt CTupleDataTag (3*a)
|
|
231 | 231 | |
232 | 232 | mkCTupleSelIdUnique :: ConTagZ -> Arity -> Unique
|
233 | 233 | mkCTupleSelIdUnique sc_pos arity
|
234 | 234 | | sc_pos >= arity
|
235 | 235 | = panic ("mkCTupleSelIdUnique: " ++ show sc_pos ++ " >= " ++ show arity)
|
236 | 236 | | otherwise
|
237 | - = mkUniqueInt 'j' (arity `shiftL` cTupleSelIdArityBits + sc_pos)
|
|
237 | + = mkUniqueInt CTupleSelTag (arity `shiftL` cTupleSelIdArityBits + sc_pos)
|
|
238 | 238 | |
239 | 239 | -- | Inverse of 'mkCTupleTyConUnique'
|
240 | 240 | isCTupleTyConUnique :: Unique -> Maybe Arity
|
... | ... | @@ -288,12 +288,12 @@ cTupleSelIdPosBitmask = 0xff |
288 | 288 | -- Normal tuples
|
289 | 289 | |
290 | 290 | mkTupleDataConUnique :: Boxity -> Arity -> Unique
|
291 | -mkTupleDataConUnique Boxed a = mkUniqueInt '7' (3*a) -- may be used in C labels
|
|
292 | -mkTupleDataConUnique Unboxed a = mkUniqueInt '8' (3*a)
|
|
291 | +mkTupleDataConUnique Boxed a = mkUniqueInt BoxedTupleDataTag (3*a) -- may be used in C labels
|
|
292 | +mkTupleDataConUnique Unboxed a = mkUniqueInt UnboxedTupleDataTag (3*a)
|
|
293 | 293 | |
294 | 294 | mkTupleTyConUnique :: Boxity -> Arity -> Unique
|
295 | -mkTupleTyConUnique Boxed a = mkUniqueInt '4' (2*a)
|
|
296 | -mkTupleTyConUnique Unboxed a = mkUniqueInt '5' (2*a)
|
|
295 | +mkTupleTyConUnique Boxed a = mkUniqueInt BoxedTupleTyConTag (2*a)
|
|
296 | +mkTupleTyConUnique Unboxed a = mkUniqueInt UnboxedTupleTyConTag (2*a)
|
|
297 | 297 | |
298 | 298 | -- | Inverse of 'mkTupleTyConUnique'
|
299 | 299 | isTupleTyConUnique :: Unique -> Maybe (Boxity, Arity)
|
... | ... | @@ -397,50 +397,50 @@ mkPrimOpIdUnique :: Int -> Unique |
397 | 397 | mkPrimOpWrapperUnique :: Int -> Unique
|
398 | 398 | mkPreludeMiscIdUnique :: Int -> Unique
|
399 | 399 | |
400 | -mkAlphaTyVarUnique i = mkUniqueInt '1' i
|
|
401 | -mkPreludeClassUnique i = mkUniqueInt '2' i
|
|
400 | +mkAlphaTyVarUnique i = mkUniqueInt AlphaTyVarTag i
|
|
401 | +mkPreludeClassUnique i = mkUniqueInt PreludeClassTag i
|
|
402 | 402 | |
403 | 403 | --------------------------------------------------
|
404 | -mkPrimOpIdUnique op = mkUniqueInt '9' (2*op)
|
|
405 | -mkPrimOpWrapperUnique op = mkUniqueInt '9' (2*op+1)
|
|
406 | -mkPreludeMiscIdUnique i = mkUniqueInt '0' i
|
|
404 | +mkPrimOpIdUnique op = mkUniqueInt PrimOpTag (2*op)
|
|
405 | +mkPrimOpWrapperUnique op = mkUniqueInt PrimOpTag (2*op+1)
|
|
406 | +mkPreludeMiscIdUnique i = mkUniqueInt PreludeMiscIdTag i
|
|
407 | 407 | |
408 | 408 | mkPseudoUniqueE, mkBuiltinUnique :: Int -> Unique
|
409 | 409 | |
410 | -mkBuiltinUnique i = mkUniqueInt 'B' i
|
|
411 | -mkPseudoUniqueE i = mkUniqueInt 'E' i -- used in NCG spiller to create spill VirtualRegs
|
|
410 | +mkBuiltinUnique i = mkUniqueInt BuiltinTag i
|
|
411 | +mkPseudoUniqueE i = mkUniqueInt PseudoTag i -- used in NCG spiller to create spill VirtualRegs
|
|
412 | 412 | |
413 | 413 | mkRegSingleUnique, mkRegPairUnique, mkRegSubUnique, mkRegClassUnique :: Int -> Unique
|
414 | -mkRegSingleUnique = mkUniqueInt 'R'
|
|
415 | -mkRegSubUnique = mkUniqueInt 'S'
|
|
416 | -mkRegPairUnique = mkUniqueInt 'P'
|
|
417 | -mkRegClassUnique = mkUniqueInt 'L'
|
|
414 | +mkRegSingleUnique = mkUniqueInt RegSingleTag
|
|
415 | +mkRegSubUnique = mkUniqueInt RegSubTag
|
|
416 | +mkRegPairUnique = mkUniqueInt RegPairTag
|
|
417 | +mkRegClassUnique = mkUniqueInt RegClassTag
|
|
418 | 418 | |
419 | 419 | mkCostCentreUnique :: Int -> Unique
|
420 | -mkCostCentreUnique = mkUniqueInt 'C'
|
|
420 | +mkCostCentreUnique = mkUniqueInt CostCentreTag
|
|
421 | 421 | |
422 | 422 | varNSUnique, dataNSUnique, tvNSUnique, tcNSUnique :: Unique
|
423 | -varNSUnique = mkUnique 'i' 0
|
|
424 | -dataNSUnique = mkUnique 'd' 0
|
|
425 | -tvNSUnique = mkUnique 'v' 0
|
|
426 | -tcNSUnique = mkUnique 'c' 0
|
|
423 | +varNSUnique = mkUnique VarNSTag 0
|
|
424 | +dataNSUnique = mkUnique DataNSTag 0
|
|
425 | +tvNSUnique = mkUnique TvNSTag 0
|
|
426 | +tcNSUnique = mkUnique TcNSTag 0
|
|
427 | 427 | |
428 | 428 | mkFldNSUnique :: FastString -> Unique
|
429 | -mkFldNSUnique fs = mkUniqueInt 'f' (uniqueOfFS fs)
|
|
429 | +mkFldNSUnique fs = mkUniqueInt FldNSTag (uniqueOfFS fs)
|
|
430 | 430 | |
431 | 431 | isFldNSUnique :: Unique -> Bool
|
432 | 432 | isFldNSUnique uniq = case unpkUnique uniq of
|
433 | 433 | (tag, _) -> tag == 'f'
|
434 | 434 | |
435 | 435 | initExitJoinUnique :: Unique
|
436 | -initExitJoinUnique = mkUnique 's' 0
|
|
436 | +initExitJoinUnique = mkUnique SimplTag 0
|
|
437 | 437 | |
438 | 438 | --------------------------------------------------
|
439 | 439 | -- Wired-in type constructor keys occupy *two* slots:
|
440 | 440 | -- See Note [Related uniques for wired-in things]
|
441 | 441 | |
442 | 442 | mkPreludeTyConUnique :: Int -> Unique
|
443 | -mkPreludeTyConUnique i = mkUniqueInt '3' (2*i)
|
|
443 | +mkPreludeTyConUnique i = mkUniqueInt PreludeTyConTag (2*i)
|
|
444 | 444 | |
445 | 445 | tyConRepNameUnique :: Unique -> Unique
|
446 | 446 | tyConRepNameUnique u = incrUnique u
|
... | ... | @@ -450,7 +450,7 @@ tyConRepNameUnique u = incrUnique u |
450 | 450 | -- See Note [Related uniques for wired-in things]
|
451 | 451 | |
452 | 452 | mkPreludeDataConUnique :: Int -> Unique
|
453 | -mkPreludeDataConUnique i = mkUniqueInt '6' (3*i) -- Must be alphabetic
|
|
453 | +mkPreludeDataConUnique i = mkUniqueInt PreludeDataConTag (3*i) -- Must be alphabetic
|
|
454 | 454 | |
455 | 455 | dataConTyRepNameUnique, dataConWorkerUnique :: Unique -> Unique
|
456 | 456 | dataConWorkerUnique u = incrUnique u
|
... | ... | @@ -476,7 +476,7 @@ dataConTyRepNameUnique u = stepUnique u 2 |
476 | 476 | -- A little delicate!
|
477 | 477 | |
478 | 478 | mkBoxingTyConUnique :: Int -> Unique
|
479 | -mkBoxingTyConUnique i = mkUniqueInt 'b' (5*i)
|
|
479 | +mkBoxingTyConUnique i = mkUniqueInt BoxingTyConTag (5*i)
|
|
480 | 480 | |
481 | 481 | boxingDataConUnique :: Unique -> Unique
|
482 | 482 | boxingDataConUnique u = stepUnique u 2 |
... | ... | @@ -107,7 +107,7 @@ cpsTop logger platform cfg dus proc = |
107 | 107 | -- TODO(#25273): Use the deterministic UniqDSM (ie `runUniqueDSM`) instead
|
108 | 108 | -- of UniqSM (see `initUs_`) to guarantee deterministic objects
|
109 | 109 | -- when doing thread sanitization.
|
110 | - us <- mkSplitUniqSupply 'u'
|
|
110 | + us <- mkSplitUniqSupply TsanTag
|
|
111 | 111 | return $ initUs_ us $
|
112 | 112 | annotateTSAN platform g
|
113 | 113 | else return g
|
... | ... | @@ -123,7 +123,7 @@ data CoreReader = CoreReader { |
123 | 123 | cr_name_ppr_ctx :: NamePprCtx,
|
124 | 124 | cr_loc :: SrcSpan, -- Use this for log/error messages so they
|
125 | 125 | -- are at least tagged with the right source file
|
126 | - cr_uniq_tag :: !Char -- Tag for creating unique values
|
|
126 | + cr_uniq_tag :: !UniqueTag -- Tag for creating unique values
|
|
127 | 127 | }
|
128 | 128 | |
129 | 129 | -- Note: CoreWriter used to be defined with data, rather than newtype. If it
|
... | ... | @@ -182,7 +182,7 @@ instance MonadUnique CoreM where |
182 | 182 | |
183 | 183 | runCoreM :: HscEnv
|
184 | 184 | -> RuleBase
|
185 | - -> Char -- ^ Mask
|
|
185 | + -> UniqueTag -- ^ Mask
|
|
186 | 186 | -> Module
|
187 | 187 | -> NamePprCtx
|
188 | 188 | -> SrcSpan
|
... | ... | @@ -267,7 +267,7 @@ getSrcSpanM = read cr_loc |
267 | 267 | addSimplCount :: SimplCount -> CoreM ()
|
268 | 268 | addSimplCount count = write (CoreWriter { cw_simpl_count = count })
|
269 | 269 | |
270 | -getUniqTag :: CoreM Char
|
|
270 | +getUniqTag :: CoreM UniqueTag
|
|
271 | 271 | getUniqTag = read cr_uniq_tag
|
272 | 272 | |
273 | 273 | -- Convenience accessors for useful fields of HscEnv
|
... | ... | @@ -59,6 +59,7 @@ import GHC.Types.Basic |
59 | 59 | import GHC.Types.Demand ( zapDmdEnvSig )
|
60 | 60 | import GHC.Types.Name.Ppr
|
61 | 61 | import GHC.Types.Var ( Var )
|
62 | +import GHC.Types.Unique.Supply ( UniqueTag(..) )
|
|
62 | 63 | |
63 | 64 | import Control.Monad
|
64 | 65 | import qualified GHC.LanguageExtensions as LangExt
|
... | ... | @@ -78,7 +79,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod |
78 | 79 | , mg_rdr_env = rdr_env })
|
79 | 80 | = do { hpt_rule_base <- home_pkg_rules
|
80 | 81 | ; let builtin_passes = getCoreToDo dflags hpt_rule_base extra_vars
|
81 | - uniq_tag = 's'
|
|
82 | + uniq_tag = SimplTag
|
|
82 | 83 | |
83 | 84 | ; (guts2, stats) <- runCoreM hsc_env hpt_rule_base uniq_tag mod
|
84 | 85 | name_ppr_ctx loc $
|
... | ... | @@ -180,13 +180,9 @@ traceSmpl herald doc |
180 | 180 | ************************************************************************
|
181 | 181 | -}
|
182 | 182 | |
183 | --- See Note [Uniques for wired-in prelude things and known tags] in GHC.Builtin.Uniques
|
|
184 | -simplTag :: Char
|
|
185 | -simplTag = 's'
|
|
186 | - |
|
187 | 183 | instance MonadUnique SimplM where
|
188 | - getUniqueSupplyM = liftIO $ mkSplitUniqSupply simplTag
|
|
189 | - getUniqueM = liftIO $ uniqFromTag simplTag
|
|
184 | + getUniqueSupplyM = liftIO $ mkSplitUniqSupply SimplTag
|
|
185 | + getUniqueM = liftIO $ uniqFromTag SimplTag
|
|
190 | 186 | |
191 | 187 | instance HasLogger SimplM where
|
192 | 188 | getLogger = gets st_logger
|
... | ... | @@ -251,7 +251,7 @@ corePrepPgm logger cp_cfg pgm_cfg |
251 | 251 | (\a -> a `seqList` ()) $ do
|
252 | 252 | let initialCorePrepEnv = mkInitialCorePrepEnv cp_cfg
|
253 | 253 | |
254 | - us <- mkSplitUniqSupply 's'
|
|
254 | + us <- mkSplitUniqSupply StgTag
|
|
255 | 255 | |
256 | 256 | let implicit_binds = mkDataConWorkers
|
257 | 257 | (cpPgm_generateDebugInfo pgm_cfg)
|
... | ... | @@ -271,7 +271,7 @@ corePrepPgm logger cp_cfg pgm_cfg |
271 | 271 | corePrepExpr :: Logger -> CorePrepConfig -> CoreExpr -> IO CoreExpr
|
272 | 272 | corePrepExpr logger config expr = do
|
273 | 273 | withTiming logger (text "CorePrep [expr]") (\e -> e `seq` ()) $ do
|
274 | - us <- mkSplitUniqSupply 's'
|
|
274 | + us <- mkSplitUniqSupply StgTag
|
|
275 | 275 | let initialCorePrepEnv = mkInitialCorePrepEnv config
|
276 | 276 | let new_expr = initUs_ us (cpeBodyNF initialCorePrepEnv expr)
|
277 | 277 | putDumpFileMaybe logger Opt_D_dump_prep "CorePrep" FormatCore (ppr new_expr)
|
... | ... | @@ -249,7 +249,7 @@ import GHC.Types.Name.Cache ( newNameCache ) |
249 | 249 | import GHC.Types.Name.Reader
|
250 | 250 | import GHC.Types.Name.Ppr
|
251 | 251 | import GHC.Types.TyThing
|
252 | -import GHC.Types.Unique.Supply (uniqFromTag)
|
|
252 | +import GHC.Types.Unique.Supply ( uniqFromTag, UniqueTag(BcoTag) )
|
|
253 | 253 | import GHC.Types.Unique.Set
|
254 | 254 | |
255 | 255 | import GHC.Utils.Fingerprint ( Fingerprint )
|
... | ... | @@ -2728,7 +2728,7 @@ hscCompileCoreExpr' hsc_env srcspan ds_expr = do |
2728 | 2728 | --
|
2729 | 2729 | -- The id has to be exported for the JS backend. This isn't required for the
|
2730 | 2730 | -- byte-code interpreter but it does no harm to always do it.
|
2731 | - u <- uniqFromTag 'I'
|
|
2731 | + u <- uniqFromTag BcoTag
|
|
2732 | 2732 | let binding_name = mkSystemVarName u (fsLit ("BCO_toplevel"))
|
2733 | 2733 | let binding_id = mkExportedVanillaId binding_name (exprType simpl_expr)
|
2734 | 2734 |
... | ... | @@ -308,7 +308,7 @@ lookupCompleteMatch type_env hsc_env (CompleteMatch { cmConLikes = nms, cmResult |
308 | 308 | |
309 | 309 | runDs :: HscEnv -> (DsGblEnv, DsLclEnv) -> DsM a -> IO (Messages DsMessage, Maybe a)
|
310 | 310 | runDs hsc_env (ds_gbl, ds_lcl) thing_inside
|
311 | - = do { res <- initTcRnIf 'd' hsc_env ds_gbl ds_lcl
|
|
311 | + = do { res <- initTcRnIf DsTag hsc_env ds_gbl ds_lcl
|
|
312 | 312 | (tryM thing_inside)
|
313 | 313 | ; msgs <- readIORef (ds_msgs ds_gbl)
|
314 | 314 | ; let final_res
|
... | ... | @@ -34,6 +34,7 @@ import GHC.Types.Var |
34 | 34 | import GHC.Types.Basic
|
35 | 35 | import GHC.Types.Name
|
36 | 36 | import GHC.Types.Name.Shape
|
37 | +import GHC.Types.Unique.Supply
|
|
37 | 38 | |
38 | 39 | import GHC.Utils.Outputable
|
39 | 40 | import GHC.Utils.Misc
|
... | ... | @@ -194,7 +195,7 @@ initRnIface hsc_env iface insts nsubst do_this = do |
194 | 195 | sh_if_errs = errs_var
|
195 | 196 | }
|
196 | 197 | -- Modeled off of 'initTc'
|
197 | - res <- initTcRnIf 'c' hsc_env env () $ tryM do_this
|
|
198 | + res <- initTcRnIf RnIfaceTag hsc_env env () $ tryM do_this
|
|
198 | 199 | msgs <- readIORef errs_var
|
199 | 200 | case res of
|
200 | 201 | Left _ -> return (Left msgs)
|
... | ... | @@ -76,7 +76,7 @@ initJSMState tag supply = JEnv { prefix = tag |
76 | 76 | , ids = supply
|
77 | 77 | }
|
78 | 78 | initJSM :: IO JEnv
|
79 | -initJSM = do supply <- mkSplitUniqSupply 'j'
|
|
79 | +initJSM = do supply <- mkSplitUniqSupply JsTag
|
|
80 | 80 | return (initJSMState "js" supply)
|
81 | 81 | |
82 | 82 | update_stream :: UniqSupply -> JSM ()
|
... | ... | @@ -130,7 +130,7 @@ getHiVirtualRegFromLo :: VirtualReg -> VirtualReg |
130 | 130 | getHiVirtualRegFromLo reg
|
131 | 131 | = case reg of
|
132 | 132 | -- makes a pseudo-unique with tag 'H'
|
133 | - VirtualRegI u -> VirtualRegHi (newTagUnique u 'H')
|
|
133 | + VirtualRegI u -> VirtualRegHi (newTagUnique u VirtualRegTag)
|
|
134 | 134 | _ -> panic "Reg.getHiVirtualRegFromLo"
|
135 | 135 | |
136 | 136 | getHiVRegFromLo :: Reg -> Reg
|
... | ... | @@ -613,7 +613,7 @@ bindLocalsAtBreakpoint hsc_env apStack_fhv span (Just ibi) = do |
613 | 613 | debugTraceMsg (hsc_logger hsc_env) 1 $
|
614 | 614 | text "Warning: _result has been evaluated, some bindings have been lost"
|
615 | 615 | |
616 | - us <- mkSplitUniqSupply 'I' -- Dodgy; will give the same uniques every time
|
|
616 | + us <- mkSplitUniqSupply BcoTag -- Dodgy; will give the same uniques every time
|
|
617 | 617 | let tv_subst = newTyVars us free_tvs
|
618 | 618 | (filtered_ids, occs'') = unzip -- again, sync the occ-names
|
619 | 619 | [ (id, occ) | (id, Just _hv, occ) <- zip3 ids mb_hValues occs' ]
|
... | ... | @@ -17,7 +17,7 @@ import GHC.Types.Name |
17 | 17 | import GHC.Stg.Syntax
|
18 | 18 | import GHC.Types.Basic ( CbvMark (..) )
|
19 | 19 | import GHC.Types.Demand (isDeadEndAppSig)
|
20 | -import GHC.Types.Unique.Supply (mkSplitUniqSupply)
|
|
20 | +import GHC.Types.Unique.Supply (mkSplitUniqSupply, UniqueTag(StgTag))
|
|
21 | 21 | import GHC.Types.RepType (dataConRuntimeRepStrictness)
|
22 | 22 | import GHC.Core (AltCon(..))
|
23 | 23 | import Data.List (mapAccumL)
|
... | ... | @@ -326,7 +326,7 @@ enforceEpt ppr_opts !for_bytecode logger this_mod stg_binds = do |
326 | 326 | let export_tag_info = collectExportInfo stg_binds_w_tags
|
327 | 327 | |
328 | 328 | -- Rewrite STG to uphold the strict field invariant
|
329 | - us_t <- mkSplitUniqSupply 't'
|
|
329 | + us_t <- mkSplitUniqSupply StgTag
|
|
330 | 330 | let rewritten_binds = {-# SCC "StgEptRewrite" #-} rewriteTopBinds this_mod us_t stg_binds_w_tags :: [TgStgTopBinding]
|
331 | 331 | |
332 | 332 | return (rewritten_binds,export_tag_info)
|
... | ... | @@ -62,7 +62,7 @@ data StgPipelineOpts = StgPipelineOpts |
62 | 62 | -- -fexternal-dynamic-refs flag. See GHC.Stg.Utils.allowTopLevelConApp.
|
63 | 63 | }
|
64 | 64 | |
65 | -newtype StgM a = StgM { _unStgM :: ReaderT Char IO a }
|
|
65 | +newtype StgM a = StgM { _unStgM :: ReaderT UniqueTag IO a }
|
|
66 | 66 | deriving (Functor, Applicative, Monad, MonadIO)
|
67 | 67 | |
68 | 68 | instance MonadUnique StgM where
|
... | ... | @@ -71,7 +71,7 @@ instance MonadUnique StgM where |
71 | 71 | getUniqueM = StgM $ do { tag <- ask
|
72 | 72 | ; liftIO $! uniqFromTag tag}
|
73 | 73 | |
74 | -runStgM :: Char -> StgM a -> IO a
|
|
74 | +runStgM :: UniqueTag -> StgM a -> IO a
|
|
75 | 75 | runStgM mask (StgM m) = runReaderT m mask
|
76 | 76 | |
77 | 77 | stg2stg :: Logger
|
... | ... | @@ -85,7 +85,7 @@ stg2stg logger extra_vars opts this_mod binds |
85 | 85 | ; stg_linter False "StgFromCore" binds
|
86 | 86 | ; showPass logger "Stg2Stg"
|
87 | 87 | -- Do the main business!
|
88 | - ; binds' <- runStgM 'g' $
|
|
88 | + ; binds' <- runStgM StgPTag $
|
|
89 | 89 | foldM (do_stg_pass this_mod) binds (stgPipeline_phases opts)
|
90 | 90 | |
91 | 91 | -- Dependency sort the program as last thing. The program needs to be
|
... | ... | @@ -174,7 +174,7 @@ instance DSM.MonadGetUnique FCode where |
174 | 174 | getUniqueM = GHC.Types.Unique.Supply.getUniqueM
|
175 | 175 | |
176 | 176 | initC :: IO CgState
|
177 | -initC = do { uniqs <- mkSplitUniqSupply 'c'
|
|
177 | +initC = do { uniqs <- mkSplitUniqSupply CmmTag
|
|
178 | 178 | ; return (initCgState uniqs) }
|
179 | 179 | |
180 | 180 | runC :: StgToCmmConfig -> FCodeState -> CgState -> FCode a -> (a, CgState)
|
... | ... | @@ -158,6 +158,7 @@ import GHC.Types.TypeEnv |
158 | 158 | import GHC.Types.SourceFile
|
159 | 159 | import GHC.Types.SrcLoc
|
160 | 160 | import GHC.Types.Unique.FM
|
161 | +import GHC.Types.Unique.Supply ( UniqueTag )
|
|
161 | 162 | import GHC.Types.Basic
|
162 | 163 | import GHC.Types.CostCentre.State
|
163 | 164 | |
... | ... | @@ -285,7 +286,7 @@ data Env gbl lcl |
285 | 286 | -- Includes all info about imported things
|
286 | 287 | -- BangPattern is to fix leak, see #15111
|
287 | 288 | |
288 | - env_ut :: {-# UNPACK #-} !Char, -- Tag for Uniques
|
|
289 | + env_ut :: {-# UNPACK #-} !UniqueTag, -- Tag for Uniques
|
|
289 | 290 | |
290 | 291 | env_gbl :: gbl, -- Info about things defined at the top level
|
291 | 292 | -- of the module being compiled
|
... | ... | @@ -347,7 +347,7 @@ unkSkolAnon = UnkSkol callStack |
347 | 347 | -- shares a certain 'Unique'.
|
348 | 348 | mkSkolemInfo :: MonadIO m => SkolemInfoAnon -> m SkolemInfo
|
349 | 349 | mkSkolemInfo sk_anon = do
|
350 | - u <- liftIO $! uniqFromTag 's'
|
|
350 | + u <- liftIO $! uniqFromTag SkolemTag
|
|
351 | 351 | return (SkolemInfo u sk_anon)
|
352 | 352 | |
353 | 353 | getSkolemInfo :: SkolemInfo -> SkolemInfoAnon
|
... | ... | @@ -413,7 +413,7 @@ initTcWithGbl hsc_env gbl_env loc do_this |
413 | 413 | tcl_errs = errs_var
|
414 | 414 | }
|
415 | 415 | |
416 | - ; maybe_res <- initTcRnIf 'a' hsc_env gbl_env lcl_env $
|
|
416 | + ; maybe_res <- initTcRnIf TcTag hsc_env gbl_env lcl_env $
|
|
417 | 417 | do { r <- tryM do_this
|
418 | 418 | ; case r of
|
419 | 419 | Right res -> return (Just res)
|
... | ... | @@ -447,7 +447,7 @@ initTcInteractive hsc_env thing_inside |
447 | 447 | where
|
448 | 448 | interactive_src_loc = mkRealSrcLoc (fsLit "<interactive>") 1 1
|
449 | 449 | |
450 | -initTcRnIf :: Char -- ^ Tag for unique supply
|
|
450 | +initTcRnIf :: UniqueTag -- ^ Tag for unique supply
|
|
451 | 451 | -> HscEnv
|
452 | 452 | -> gbl -> lcl
|
453 | 453 | -> TcRnIf gbl lcl a
|
... | ... | @@ -2297,7 +2297,7 @@ initIfaceLoad hsc_env do_this |
2297 | 2297 | if_doc = text "initIfaceLoad",
|
2298 | 2298 | if_rec_types = emptyKnotVars
|
2299 | 2299 | }
|
2300 | - initTcRnIf 'i' (hsc_env { hsc_type_env_vars = emptyKnotVars }) gbl_env () do_this
|
|
2300 | + initTcRnIf IfaceTag (hsc_env { hsc_type_env_vars = emptyKnotVars }) gbl_env () do_this
|
|
2301 | 2301 | |
2302 | 2302 | -- | This is used when we are doing to call 'typecheckModule' on an 'ModIface',
|
2303 | 2303 | -- if it's part of a loop with some other modules then we need to use their
|
... | ... | @@ -2308,7 +2308,7 @@ initIfaceLoadModule hsc_env this_mod do_this |
2308 | 2308 | if_doc = text "initIfaceLoadModule",
|
2309 | 2309 | if_rec_types = readTcRef <$> knotVarsWithout this_mod (hsc_type_env_vars hsc_env)
|
2310 | 2310 | }
|
2311 | - initTcRnIf 'i' hsc_env gbl_env () do_this
|
|
2311 | + initTcRnIf IfaceTag hsc_env gbl_env () do_this
|
|
2312 | 2312 | |
2313 | 2313 | initIfaceCheck :: SDoc -> HscEnv -> IfG a -> IO a
|
2314 | 2314 | -- Used when checking the up-to-date-ness of the old Iface
|
... | ... | @@ -2318,7 +2318,7 @@ initIfaceCheck doc hsc_env do_this |
2318 | 2318 | if_doc = text "initIfaceCheck" <+> doc,
|
2319 | 2319 | if_rec_types = readTcRef <$> hsc_type_env_vars hsc_env
|
2320 | 2320 | }
|
2321 | - initTcRnIf 'i' hsc_env gbl_env () do_this
|
|
2321 | + initTcRnIf IfaceTag hsc_env gbl_env () do_this
|
|
2322 | 2322 | |
2323 | 2323 | initIfaceLcl :: Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
|
2324 | 2324 | initIfaceLcl mod loc_doc hi_boot_file thing_inside
|
... | ... | @@ -110,7 +110,7 @@ there, hyperlinks won't work as expected. Test case: haddockHtmlTest (Bug923.hs) |
110 | 110 | -- each original name; i.e. (module-name, occ-name) pair and provides
|
111 | 111 | -- something of a lookup mechanism for those names.
|
112 | 112 | data NameCache = NameCache
|
113 | - { nsUniqChar :: {-# UNPACK #-} !Char
|
|
113 | + { nsUniqChar :: {-# UNPACK #-} !UniqueTag
|
|
114 | 114 | , nsNames :: {-# UNPACK #-} !(MVar OrigNameCache)
|
115 | 115 | }
|
116 | 116 | |
... | ... | @@ -143,7 +143,7 @@ extendOrigNameCache nc mod occ name |
143 | 143 | |
144 | 144 | -- | Initialize a new name cache
|
145 | 145 | newNameCache :: IO NameCache
|
146 | -newNameCache = newNameCacheWith 'r' knownKeysOrigNameCache
|
|
146 | +newNameCache = newNameCacheWith HscTag knownKeysOrigNameCache
|
|
147 | 147 | |
148 | 148 | -- | This is a version of `newNameCache` that lets you supply your
|
149 | 149 | -- own unique tag and set of known key names. This can go wrong if the tag
|
... | ... | @@ -151,8 +151,8 @@ newNameCache = newNameCacheWith 'r' knownKeysOrigNameCache |
151 | 151 | -- an example.
|
152 | 152 | --
|
153 | 153 | -- Use `newNameCache` when possible.
|
154 | -newNameCacheWith :: Char -> OrigNameCache -> IO NameCache
|
|
155 | -newNameCacheWith c nc = NameCache c <$> newMVar nc
|
|
154 | +newNameCacheWith :: UniqueTag -> OrigNameCache -> IO NameCache
|
|
155 | +newNameCacheWith ut nc = NameCache ut <$> newMVar nc
|
|
156 | 156 | |
157 | 157 | -- | This takes a tag for uniques to be generated and the list of knownKeyNames
|
158 | 158 | -- These must be initialized properly to ensure that names generated from this
|
... | ... | @@ -160,7 +160,7 @@ newNameCacheWith c nc = NameCache c <$> newMVar nc |
160 | 160 | --
|
161 | 161 | -- Use `newNameCache` or `newNameCacheWith` instead
|
162 | 162 | {-# DEPRECATED initNameCache "Use newNameCache or newNameCacheWith instead" #-}
|
163 | -initNameCache :: Char -> [Name] -> IO NameCache
|
|
163 | +initNameCache :: UniqueTag -> [Name] -> IO NameCache
|
|
164 | 164 | initNameCache c names = newNameCacheWith c (initOrigNames names)
|
165 | 165 | |
166 | 166 | initOrigNames :: [Name] -> OrigNameCache
|
... | ... | @@ -23,6 +23,7 @@ Haskell). |
23 | 23 | module GHC.Types.Unique (
|
24 | 24 | -- * Main data types
|
25 | 25 | Unique, Uniquable(..),
|
26 | + UniqueTag(..), uniqueTag,
|
|
26 | 27 | uNIQUE_BITS,
|
27 | 28 | |
28 | 29 | -- ** Constructors, destructors and operations on 'Unique's
|
... | ... | @@ -97,6 +98,100 @@ GHC.Builtin.Uniques. See Note [Uniques for wired-in prelude things and known tag |
97 | 98 | -- These are sometimes also referred to as \"keys\" in comments in GHC.
|
98 | 99 | newtype Unique = MkUnique Word64
|
99 | 100 | |
101 | +data UniqueTag = PluginTag
|
|
102 | + | SkolemTag
|
|
103 | + | JsTag
|
|
104 | + | SimplTag
|
|
105 | + | StgTag
|
|
106 | + | CmmTag
|
|
107 | + | HscTag
|
|
108 | + | TsanTag
|
|
109 | + | TcTag
|
|
110 | + | IfaceTag
|
|
111 | + | RnIfaceTag
|
|
112 | + | DsTag
|
|
113 | + | StgPTag
|
|
114 | + | BcoTag
|
|
115 | + | LocalTag
|
|
116 | + | SumTag
|
|
117 | + | TupleTag
|
|
118 | + | CTupleTag
|
|
119 | + | CTupleDataTag
|
|
120 | + | CTupleSelTag
|
|
121 | + | BoxedTupleDataTag
|
|
122 | + | UnboxedTupleDataTag
|
|
123 | + | BoxedTupleTyConTag
|
|
124 | + | UnboxedTupleTyConTag
|
|
125 | + | AlphaTyVarTag
|
|
126 | + | PreludeClassTag
|
|
127 | + | PrimOpTag
|
|
128 | + | PreludeMiscIdTag
|
|
129 | + | BuiltinTag
|
|
130 | + | PseudoTag
|
|
131 | + | RegSingleTag
|
|
132 | + | RegSubTag
|
|
133 | + | RegPairTag
|
|
134 | + | RegClassTag
|
|
135 | + | CostCentreTag
|
|
136 | + | VarNSTag
|
|
137 | + | DataNSTag
|
|
138 | + | TvNSTag
|
|
139 | + | TcNSTag
|
|
140 | + | FldNSTag
|
|
141 | + | PreludeTyConTag
|
|
142 | + | PreludeDataConTag
|
|
143 | + | BoxingTyConTag
|
|
144 | + | VirtualRegTag
|
|
145 | + |
|
146 | +uniqueTag :: UniqueTag -> Char
|
|
147 | +uniqueTag PluginTag = 'p'
|
|
148 | +uniqueTag JsTag = 'j'
|
|
149 | +uniqueTag SkolemTag = 's' -- TODO: conflicts with SimplTag
|
|
150 | +uniqueTag SimplTag = 's' -- TODO: conflicts with SkolemTag
|
|
151 | +uniqueTag StgTag = 't'
|
|
152 | +uniqueTag CmmTag = 'c' -- TODO: conflicts with RnIfaceTag and TcNSTag
|
|
153 | +uniqueTag HscTag = 'r'
|
|
154 | +uniqueTag TsanTag = 'u'
|
|
155 | +uniqueTag TcTag = 'a'
|
|
156 | +uniqueTag IfaceTag = 'i' -- TODO: conflicts with VarNSTag
|
|
157 | +uniqueTag RnIfaceTag = 'c' -- TODO: conflicts with CmmTag and TcNSTag
|
|
158 | +uniqueTag DsTag = 'd' -- TODO: conflicts with DataNSTag
|
|
159 | +uniqueTag StgPTag = 'g'
|
|
160 | +uniqueTag BcoTag = 'I'
|
|
161 | +uniqueTag LocalTag = 'X'
|
|
162 | +uniqueTag SumTag = 'z'
|
|
163 | +uniqueTag TupleTag = 'k' -- TODO: conflicts with CTupleTag
|
|
164 | +uniqueTag CTupleTag = 'k' -- TODO: conflicts with TupleTag
|
|
165 | +uniqueTag CTupleDataTag = 'm'
|
|
166 | +uniqueTag CTupleSelTag = 'j'
|
|
167 | +uniqueTag BoxedTupleDataTag = '7'
|
|
168 | +uniqueTag UnboxedTupleDataTag = '8'
|
|
169 | +uniqueTag BoxedTupleTyConTag = '4'
|
|
170 | +uniqueTag UnboxedTupleTyConTag = '5'
|
|
171 | +uniqueTag AlphaTyVarTag = '1'
|
|
172 | +uniqueTag PreludeClassTag = '2'
|
|
173 | +uniqueTag PrimOpTag = '9'
|
|
174 | +uniqueTag PreludeMiscIdTag = '0'
|
|
175 | +uniqueTag BuiltinTag = 'B'
|
|
176 | +uniqueTag PseudoTag = 'E'
|
|
177 | +uniqueTag RegSingleTag = 'R'
|
|
178 | +uniqueTag RegSubTag = 'S'
|
|
179 | +uniqueTag RegPairTag = 'P'
|
|
180 | +uniqueTag RegClassTag = 'L'
|
|
181 | +uniqueTag CostCentreTag = 'C'
|
|
182 | +uniqueTag VarNSTag = 'i' -- TODO: conflicts with IfaceTag
|
|
183 | +uniqueTag DataNSTag = 'd' -- TODO: conflicts with DsTag
|
|
184 | +uniqueTag TvNSTag = 'v'
|
|
185 | +uniqueTag TcNSTag = 'c' -- TODO: conflicts with CmmTag and RnIfaceTag
|
|
186 | +uniqueTag FldNSTag = 'f'
|
|
187 | +uniqueTag PreludeTyConTag = '3'
|
|
188 | +uniqueTag PreludeDataConTag = '6'
|
|
189 | +uniqueTag BoxingTyConTag = 'b'
|
|
190 | +uniqueTag VirtualRegTag = 'H'
|
|
191 | + |
|
192 | +{-# INLINE uniqueTag #-}
|
|
193 | + |
|
194 | + |
|
100 | 195 | {-# INLINE uNIQUE_BITS #-}
|
101 | 196 | uNIQUE_BITS :: Int
|
102 | 197 | uNIQUE_BITS = 64 - UNIQUE_TAG_BITS
|
... | ... | @@ -113,7 +208,7 @@ getKey :: Unique -> Word64 -- for Var |
113 | 208 | |
114 | 209 | incrUnique :: Unique -> Unique
|
115 | 210 | stepUnique :: Unique -> Word64 -> Unique
|
116 | -newTagUnique :: Unique -> Char -> Unique
|
|
211 | +newTagUnique :: Unique -> UniqueTag -> Unique
|
|
117 | 212 | |
118 | 213 | mkUniqueGrimily = MkUnique
|
119 | 214 | |
... | ... | @@ -124,7 +219,7 @@ incrUnique (MkUnique i) = MkUnique (i + 1) |
124 | 219 | stepUnique (MkUnique i) n = MkUnique (i + n)
|
125 | 220 | |
126 | 221 | mkLocalUnique :: Word64 -> Unique
|
127 | -mkLocalUnique i = mkUnique 'X' i
|
|
222 | +mkLocalUnique i = mkUnique LocalTag i
|
|
128 | 223 | |
129 | 224 | minLocalUnique :: Unique
|
130 | 225 | minLocalUnique = mkLocalUnique 0
|
... | ... | @@ -152,15 +247,15 @@ mkTag c = intToWord64 (ord c) `shiftL` uNIQUE_BITS |
152 | 247 | |
153 | 248 | -- and as long as the Char fits in 8 bits, which we assume anyway!
|
154 | 249 | |
155 | -mkUnique :: Char -> Word64 -> Unique -- Builds a unique from pieces
|
|
250 | +mkUnique :: UniqueTag -> Word64 -> Unique -- Builds a unique from pieces
|
|
156 | 251 | -- EXPORTED and used only in GHC.Builtin.Uniques
|
157 | 252 | mkUnique c i
|
158 | 253 | = MkUnique (tag .|. bits)
|
159 | 254 | where
|
160 | - tag = mkTag c
|
|
255 | + tag = mkTag $ uniqueTag c
|
|
161 | 256 | bits = i .&. uniqueMask
|
162 | 257 | |
163 | -mkUniqueInt :: Char -> Int -> Unique
|
|
258 | +mkUniqueInt :: UniqueTag -> Int -> Unique
|
|
164 | 259 | mkUniqueInt c i = mkUnique c (intToWord64 i)
|
165 | 260 | |
166 | 261 | mkUniqueIntGrimily :: Int -> Unique
|
... | ... | @@ -134,12 +134,13 @@ runUniqueDSM ds (UDSM f) = |
134 | 134 | DUniqResult uq us -> (uq, us)
|
135 | 135 | |
136 | 136 | -- | Set the tag of uniques generated from this deterministic unique supply
|
137 | -newTagDUniqSupply :: Char -> DUniqSupply -> DUniqSupply
|
|
137 | +newTagDUniqSupply :: UniqueTag -> DUniqSupply -> DUniqSupply
|
|
138 | 138 | newTagDUniqSupply c (DUS w) = DUS $ getKey $ newTagUnique (mkUniqueGrimily w) c
|
139 | 139 | |
140 | 140 | -- | Get the tag uniques generated from this deterministic unique supply would have
|
141 | -getTagDUniqSupply :: DUniqSupply -> Char
|
|
142 | -getTagDUniqSupply (DUS w) = fst $ unpkUnique (mkUniqueGrimily w)
|
|
141 | +getTagDUniqSupply :: DUniqSupply -> UniqueTag -- TODO
|
|
142 | +getTagDUniqSupply (DUS w) = fst $ undefined -- unpkUnique (mkUniqueGrimily w)
|
|
143 | + |
|
143 | 144 | |
144 | 145 | -- | Get a unique from a monad that can access a unique supply.
|
145 | 146 | --
|
... | ... | @@ -201,7 +202,7 @@ instance Monad m => MonadGetUnique (UniqDSMT m) where |
201 | 202 | -- | Set the tag of the running @UniqDSMT@ supply to the given tag and run an action with it.
|
202 | 203 | -- All uniques produced in the given action will use this tag, until the tag is changed
|
203 | 204 | -- again.
|
204 | -setTagUDSMT :: Monad m => Char {-^ Tag -} -> UniqDSMT m a -> UniqDSMT m a
|
|
205 | +setTagUDSMT :: Monad m => UniqueTag {-^ Tag -} -> UniqDSMT m a -> UniqDSMT m a
|
|
205 | 206 | setTagUDSMT tag (UDSMT act) = UDSMT $ \us -> do
|
206 | 207 | let origtag = getTagDUniqSupply us
|
207 | 208 | new_us = newTagDUniqSupply tag us
|
... | ... | @@ -15,7 +15,8 @@ module GHC.Types.Unique.Supply ( |
15 | 15 | |
16 | 16 | -- ** Operations on supplies
|
17 | 17 | uniqFromSupply, uniqsFromSupply, -- basic ops
|
18 | - takeUniqFromSupply, uniqFromTag,
|
|
18 | + takeUniqFromSupply,
|
|
19 | + uniqFromTag, UniqueTag(..),
|
|
19 | 20 | |
20 | 21 | mkSplitUniqSupply,
|
21 | 22 | splitUniqSupply, listSplitUniqSupply,
|
... | ... | @@ -200,7 +201,7 @@ data UniqSupply |
200 | 201 | UniqSupply UniqSupply
|
201 | 202 | -- when split => these two supplies
|
202 | 203 | |
203 | -mkSplitUniqSupply :: Char -> IO UniqSupply
|
|
204 | +mkSplitUniqSupply :: UniqueTag -> IO UniqSupply
|
|
204 | 205 | -- ^ Create a unique supply out of thin air.
|
205 | 206 | -- The "tag" (Char) supplied is mostly cosmetic, making it easier
|
206 | 207 | -- to figure out where a Unique was born. See Note [Uniques and tags].
|
... | ... | @@ -213,11 +214,11 @@ mkSplitUniqSupply :: Char -> IO UniqSupply |
213 | 214 | |
214 | 215 | -- See Note [How the unique supply works]
|
215 | 216 | -- See Note [Optimising the unique supply]
|
216 | -mkSplitUniqSupply c
|
|
217 | +mkSplitUniqSupply ut
|
|
217 | 218 | = unsafeDupableInterleaveIO (IO mk_supply)
|
218 | 219 | |
219 | 220 | where
|
220 | - !tag = mkTag c
|
|
221 | + !tag = mkTag $ uniqueTag ut
|
|
221 | 222 | |
222 | 223 | -- Here comes THE MAGIC: see Note [How the unique supply works]
|
223 | 224 | -- This is one of the most hammered bits in the whole compiler
|
... | ... | @@ -279,11 +280,11 @@ initUniqSupply counter inc = do |
279 | 280 | poke ghc_unique_counter64 counter
|
280 | 281 | poke ghc_unique_inc inc
|
281 | 282 | |
282 | -uniqFromTag :: Char -> IO Unique
|
|
283 | +uniqFromTag :: UniqueTag -> IO Unique
|
|
283 | 284 | uniqFromTag !tag
|
284 | 285 | = do { uqNum <- genSym
|
285 | 286 | ; return $! mkUnique tag uqNum }
|
286 | -{-# NOINLINE uniqFromTag #-} -- We'll unbox everything, but we don't want to inline it
|
|
287 | +{-# INLINE uniqFromTag #-} -- We'll unbox everything, but we don't want to inline it
|
|
287 | 288 | |
288 | 289 | splitUniqSupply :: UniqSupply -> (UniqSupply, UniqSupply)
|
289 | 290 | -- ^ Build two 'UniqSupply' from a single one, each of which
|