module GHC.Types.CostCentre.State
( CostCentreState
, newCostCentreState
, CostCentreIndex
, unCostCentreIndex
, getCCIndex
)
where
import GHC.Prelude
import GHC.Data.FastString
import GHC.Data.FastString.Env
import Data.Data
import GHC.Utils.Binary
newtype CostCentreState = CostCentreState (FastStringEnv Int)
newCostCentreState :: CostCentreState
newCostCentreState = CostCentreState emptyFsEnv
newtype CostCentreIndex = CostCentreIndex { unCostCentreIndex :: Int }
deriving (Eq, Ord, Data, Binary)
getCCIndex :: FastString
-> CostCentreState
-> (CostCentreIndex, CostCentreState)
getCCIndex nm (CostCentreState m) =
(CostCentreIndex idx, CostCentreState m')
where
m_idx = lookupFsEnv m nm
idx = maybe 0 id m_idx
m' = extendFsEnv m nm (idx + 1)