From a77e48d291b35a92731f106d79ea75117ec380e1 Mon Sep 17 00:00:00 2001 From: Sebastian Graf Date: Mon, 7 Sep 2020 17:08:27 +0200 Subject: Extract definition of DsM into GHC.HsToCore.Types `DsM` was previously defined in `GHC.Tc.Types`, along with `TcM`. But `GHC.Tc.Types` is in the set of transitive dependencies of `GHC.Parser`, a set which we aim to minimise. Test case `CountParserDeps` checks for that. Having `DsM` in that set means the parser also depends on the innards of the pattern-match checker in `GHC.HsToCore.PmCheck.Types`, which is the reason we have that module in the first place. In the previous commit, we represented the `TyState` by an `InertSet`, but that pulls the constraint solver as well as 250 more modules into the set of dependencies, triggering failure of `CountParserDeps`. Clearly, we want to evolve the pattern-match checker (and the desugarer) without being concerned by this test, so this patch includes a small refactor that puts `DsM` into its own module. --- compiler/GHC/Tc/Utils/Monad.hs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'compiler/GHC/Tc/Utils/Monad.hs') diff --git a/compiler/GHC/Tc/Utils/Monad.hs b/compiler/GHC/Tc/Utils/Monad.hs index b2c987794b..96bff3d261 100644 --- a/compiler/GHC/Tc/Utils/Monad.hs +++ b/compiler/GHC/Tc/Utils/Monad.hs @@ -138,7 +138,7 @@ module GHC.Tc.Utils.Monad( withException, -- * Stuff for cost centres. - ContainsCostCentreState(..), getCCIndexM, + getCCIndexM, getCCIndexTcM, -- * Types etc. module GHC.Tc.Types, @@ -2081,23 +2081,16 @@ discussion). We don't currently know a general solution to this problem, but we can use uninterruptibleMask_ to avoid the situation. -} --- | Environments which track 'CostCentreState' -class ContainsCostCentreState e where - extractCostCentreState :: e -> TcRef CostCentreState - -instance ContainsCostCentreState TcGblEnv where - extractCostCentreState = tcg_cc_st - -instance ContainsCostCentreState DsGblEnv where - extractCostCentreState = ds_cc_st - -- | Get the next cost centre index associated with a given name. -getCCIndexM :: (ContainsCostCentreState gbl) - => FastString -> TcRnIf gbl lcl CostCentreIndex -getCCIndexM nm = do +getCCIndexM :: (gbl -> TcRef CostCentreState) -> FastString -> TcRnIf gbl lcl CostCentreIndex +getCCIndexM get_ccs nm = do env <- getGblEnv - let cc_st_ref = extractCostCentreState env + let cc_st_ref = get_ccs env cc_st <- readTcRef cc_st_ref let (idx, cc_st') = getCCIndex nm cc_st writeTcRef cc_st_ref cc_st' return idx + +-- | See 'getCCIndexM'. +getCCIndexTcM :: FastString -> TcM CostCentreIndex +getCCIndexTcM = getCCIndexM tcg_cc_st -- cgit v1.2.1