diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2017-05-19 14:56:09 +0200 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2017-06-06 00:16:20 +0200 |
commit | 8e6ec0fa7431b0454b09c0011a615f0845df1198 (patch) | |
tree | d6b3604e0ceac3d81d0510669f7ccce9a2bf3ae2 /compiler/deSugar/DsUtils.hs | |
parent | c9eb4385aad248118650725b7b699bb97ee21c0d (diff) | |
download | haskell-8e6ec0fa7431b0454b09c0011a615f0845df1198.tar.gz |
Udate hsSyn AST to use Trees that Grow
Summary:
See https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow
This commit prepares the ground for a full extensible AST, by replacing the type
parameter for the hsSyn data types with a set of indices into type families,
data GhcPs -- ^ Index for GHC parser output
data GhcRn -- ^ Index for GHC renamer output
data GhcTc -- ^ Index for GHC typechecker output
These are now used instead of `RdrName`, `Name` and `Id`/`TcId`/`Var`
Where the original name type is required in a polymorphic context, this is
accessible via the IdP type family, defined as
type family IdP p
type instance IdP GhcPs = RdrName
type instance IdP GhcRn = Name
type instance IdP GhcTc = Id
These types are declared in the new 'hsSyn/HsExtension.hs' module.
To gain a better understanding of the extension mechanism, it has been applied
to `HsLit` only, also replacing the `SourceText` fields in them with extension
types.
To preserve extension generality, a type class is introduced to capture the
`SourceText` interface, which must be honoured by all of the extension points
which originally had a `SourceText`. The class is defined as
class HasSourceText a where
-- Provide setters to mimic existing constructors
noSourceText :: a
sourceText :: String -> a
setSourceText :: SourceText -> a
getSourceText :: a -> SourceText
And the constraint is captured in `SourceTextX`, which is a constraint type
listing all the extension points that make use of the class.
Updating Haddock submodule to match.
Test Plan: ./validate
Reviewers: simonpj, shayan-najd, goldfire, austin, bgamari
Subscribers: rwbarton, thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D3609
Diffstat (limited to 'compiler/deSugar/DsUtils.hs')
-rw-r--r-- | compiler/deSugar/DsUtils.hs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/compiler/deSugar/DsUtils.hs b/compiler/deSugar/DsUtils.hs index db757d6afe..4ef279faed 100644 --- a/compiler/deSugar/DsUtils.hs +++ b/compiler/deSugar/DsUtils.hs @@ -92,7 +92,7 @@ hand, which should indeed be bound to the pattern as a whole, then use it; otherwise, make one up. -} -selectSimpleMatchVarL :: LPat Id -> DsM Id +selectSimpleMatchVarL :: LPat GhcTc -> DsM Id selectSimpleMatchVarL pat = selectMatchVar (unLoc pat) -- (selectMatchVars ps tys) chooses variables of type tys @@ -111,10 +111,10 @@ selectSimpleMatchVarL pat = selectMatchVar (unLoc pat) -- Then we must not choose (x::Int) as the matching variable! -- And nowadays we won't, because the (x::Int) will be wrapped in a CoPat -selectMatchVars :: [Pat Id] -> DsM [Id] +selectMatchVars :: [Pat GhcTc] -> DsM [Id] selectMatchVars ps = mapM selectMatchVar ps -selectMatchVar :: Pat Id -> DsM Id +selectMatchVar :: Pat GhcTc -> DsM Id selectMatchVar (BangPat pat) = selectMatchVar (unLoc pat) selectMatchVar (LazyPat pat) = selectMatchVar (unLoc pat) selectMatchVar (ParPat pat) = selectMatchVar (unLoc pat) @@ -174,7 +174,7 @@ The ``equation info'' used by @match@ is relatively complicated and worthy of a type synonym and a few handy functions. -} -firstPat :: EquationInfo -> Pat Id +firstPat :: EquationInfo -> Pat GhcTc firstPat eqn = ASSERT( notNull (eqn_pats eqn) ) head (eqn_pats eqn) shiftEqns :: [EquationInfo] -> [EquationInfo] @@ -255,7 +255,7 @@ mkGuardedMatchResult pred_expr (MatchResult _ body_fn) = MatchResult CanFail (\fail -> do body <- body_fn fail return (mkIfThenElse pred_expr body fail)) -mkCoPrimCaseMatchResult :: Id -- Scrutinee +mkCoPrimCaseMatchResult :: Id -- Scrutinee -> Type -- Type of the case -> [(Literal, MatchResult)] -- Alternatives -> MatchResult -- Literals are all unlifted @@ -414,7 +414,8 @@ mkDataConCase var ty alts@(alt1:_) = MatchResult fail_flag mk_case -- parallel arrays, which are introduced by `tidy1' in the `PArrPat' -- case -- -mkPArrCase :: DynFlags -> Id -> Type -> [CaseAlt DataCon] -> CoreExpr -> DsM CoreExpr +mkPArrCase :: DynFlags -> Id -> Type -> [CaseAlt DataCon] -> CoreExpr + -> DsM CoreExpr mkPArrCase dflags var ty sorted_alts fail = do lengthP <- dsDPHBuiltin lengthPVar alt <- unboxAlt @@ -725,7 +726,7 @@ work out well: -} mkSelectorBinds :: [[Tickish Id]] -- ^ ticks to add, possibly - -> LPat Id -- ^ The pattern + -> LPat GhcTc -- ^ The pattern -> CoreExpr -- ^ Expression to which the pattern is bound -> DsM (Id,[(Id,CoreExpr)]) -- ^ Id the rhs is bound to, for desugaring strict @@ -814,31 +815,31 @@ is_triv_pat _ = False * * ********************************************************************* -} -mkLHsPatTup :: [LPat Id] -> LPat Id +mkLHsPatTup :: [LPat GhcTc] -> LPat GhcTc mkLHsPatTup [] = noLoc $ mkVanillaTuplePat [] Boxed mkLHsPatTup [lpat] = lpat mkLHsPatTup lpats = L (getLoc (head lpats)) $ mkVanillaTuplePat lpats Boxed -mkLHsVarPatTup :: [Id] -> LPat Id +mkLHsVarPatTup :: [Id] -> LPat GhcTc mkLHsVarPatTup bs = mkLHsPatTup (map nlVarPat bs) -mkVanillaTuplePat :: [OutPat Id] -> Boxity -> Pat Id +mkVanillaTuplePat :: [OutPat GhcTc] -> Boxity -> Pat GhcTc -- A vanilla tuple pattern simply gets its type from its sub-patterns mkVanillaTuplePat pats box = TuplePat pats box (map hsLPatType pats) -- The Big equivalents for the source tuple expressions -mkBigLHsVarTupId :: [Id] -> LHsExpr Id +mkBigLHsVarTupId :: [Id] -> LHsExpr GhcTc mkBigLHsVarTupId ids = mkBigLHsTupId (map nlHsVar ids) -mkBigLHsTupId :: [LHsExpr Id] -> LHsExpr Id +mkBigLHsTupId :: [LHsExpr GhcTc] -> LHsExpr GhcTc mkBigLHsTupId = mkChunkified mkLHsTupleExpr -- The Big equivalents for the source tuple patterns -mkBigLHsVarPatTupId :: [Id] -> LPat Id +mkBigLHsVarPatTupId :: [Id] -> LPat GhcTc mkBigLHsVarPatTupId bs = mkBigLHsPatTupId (map nlVarPat bs) -mkBigLHsPatTupId :: [LPat Id] -> LPat Id +mkBigLHsPatTupId :: [LPat GhcTc] -> LPat GhcTc mkBigLHsPatTupId = mkChunkified mkLHsPatTup {- |