diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2020-09-07 17:08:27 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-12 21:27:40 -0400 |
commit | a77e48d291b35a92731f106d79ea75117ec380e1 (patch) | |
tree | 334a8d173c4ffba8be4b8b0f89bbb2d3f1635595 /compiler/GHC/HsToCore/Types.hs | |
parent | 69ea2fee35b4bcfd9253ee608f7135024186aeed (diff) | |
download | haskell-a77e48d291b35a92731f106d79ea75117ec380e1.tar.gz |
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.
Diffstat (limited to 'compiler/GHC/HsToCore/Types.hs')
-rw-r--r-- | compiler/GHC/HsToCore/Types.hs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/compiler/GHC/HsToCore/Types.hs b/compiler/GHC/HsToCore/Types.hs new file mode 100644 index 0000000000..26f6a6af79 --- /dev/null +++ b/compiler/GHC/HsToCore/Types.hs @@ -0,0 +1,77 @@ +-- | Various types used during desugaring. +module GHC.HsToCore.Types ( + DsM, DsLclEnv(..), DsGblEnv(..), + DsMetaEnv, DsMetaVal(..), CompleteMatches + ) where + +import Data.IORef + +import GHC.Types.CostCentre.State +import GHC.Types.Name.Env +import GHC.Types.SrcLoc +import GHC.Types.Var +import GHC.Hs (HsExpr, GhcTc) +import GHC.Tc.Types (TcRnIf, IfGblEnv, IfLclEnv, CompleteMatches) +import {-# SOURCE #-} GHC.HsToCore.PmCheck.Types (Nablas) +import GHC.Core.FamInstEnv +import GHC.Utils.Error +import GHC.Utils.Outputable as Outputable +import GHC.Unit.Module + +{- +************************************************************************ +* * + Desugarer monad +* * +************************************************************************ + +Now the mondo monad magic (yes, @DsM@ is a silly name)---carry around +a @UniqueSupply@ and some annotations, which +presumably include source-file location information: +-} + +-- | Global read-only context and state of the desugarer. +-- The statefulness is implemented through 'IORef's. +data DsGblEnv + = DsGblEnv + { ds_mod :: Module -- For SCC profiling + , ds_fam_inst_env :: FamInstEnv -- Like tcg_fam_inst_env + , ds_unqual :: PrintUnqualified + , ds_msgs :: IORef Messages -- Warning messages + , ds_if_env :: (IfGblEnv, IfLclEnv) -- Used for looking up global, + -- possibly-imported things + , ds_complete_matches :: CompleteMatches + -- Additional complete pattern matches + , ds_cc_st :: IORef CostCentreState + -- Tracking indices for cost centre annotations + } + +instance ContainsModule DsGblEnv where + extractModule = ds_mod + +-- | Local state of the desugarer, extended as we lexically descend +data DsLclEnv + = DsLclEnv + { dsl_meta :: DsMetaEnv -- ^ Template Haskell bindings + , dsl_loc :: RealSrcSpan -- ^ To put in pattern-matching error msgs + , dsl_nablas :: Nablas + -- ^ See Note [Note [Long-distance information] in "GHC.HsToCore.PmCheck". + -- The set of reaching values Nablas is augmented as we walk inwards, refined + -- through each pattern match in turn + } + +-- Inside [| |] brackets, the desugarer looks +-- up variables in the DsMetaEnv +type DsMetaEnv = NameEnv DsMetaVal + +data DsMetaVal + = DsBound Id -- Bound by a pattern inside the [| |]. + -- Will be dynamically alpha renamed. + -- The Id has type THSyntax.Var + + | DsSplice (HsExpr GhcTc) -- These bindings are introduced by + -- the PendingSplices on a HsBracketOut + +-- | Desugaring monad. See also 'TcM'. +type DsM = TcRnIf DsGblEnv DsLclEnv + |