diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-09-13 08:58:40 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-15 15:21:43 -0400 |
commit | 4283feaa9e0826211f7a71d543054c989ea32965 (patch) | |
tree | 93f96b0599ed403b0180b0416c13f14a193bb1e4 /compiler/GHC/ThToHs.hs | |
parent | b3143f5a0827b640840ef241a30933dc23b69d91 (diff) | |
download | haskell-4283feaa9e0826211f7a71d543054c989ea32965.tar.gz |
Introduce and use DerivClauseTys (#18662)
This switches `deriv_clause_tys` so that instead of using a list of
`LHsSigType`s to represent the types in a `deriving` clause, it now
uses a sum type. `DctSingle` represents a `deriving` clause with no
enclosing parentheses, while `DctMulti` represents a clause with
enclosing parentheses. This makes pretty-printing easier and avoids
confusion between `HsParTy` and the enclosing parentheses in
`deriving` clauses, which are different semantically.
Fixes #18662.
Diffstat (limited to 'compiler/GHC/ThToHs.hs')
-rw-r--r-- | compiler/GHC/ThToHs.hs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs index d6ecba4149..bdc0203c90 100644 --- a/compiler/GHC/ThToHs.hs +++ b/compiler/GHC/ThToHs.hs @@ -1393,12 +1393,25 @@ cvtContext p tys = do { preds' <- mapM cvtPred tys cvtPred :: TH.Pred -> CvtM (LHsType GhcPs) cvtPred = cvtType +cvtDerivClauseTys :: TH.Cxt -> CvtM (LDerivClauseTys GhcPs) +cvtDerivClauseTys tys + = do { tys' <- mapM cvtType tys + -- Since TH.Cxt doesn't indicate the presence or absence of + -- parentheses in a deriving clause, we have to choose between + -- DctSingle and DctMulti somewhat arbitrarily. We opt to use DctMulti + -- unless the TH.Cxt is a singleton list whose type is a bare type + -- constructor with no arguments. + ; case tys' of + [ty'@(L l (HsTyVar _ NotPromoted _))] + -> return $ L l $ DctSingle noExtField $ mkLHsSigType ty' + _ -> returnL $ DctMulti noExtField (map mkLHsSigType tys') } + cvtDerivClause :: TH.DerivClause -> CvtM (LHsDerivingClause GhcPs) -cvtDerivClause (TH.DerivClause ds ctxt) - = do { ctxt' <- fmap (map mkLHsSigType) <$> cvtContext appPrec ctxt - ; ds' <- traverse cvtDerivStrategy ds - ; returnL $ HsDerivingClause noExtField ds' ctxt' } +cvtDerivClause (TH.DerivClause ds tys) + = do { tys' <- cvtDerivClauseTys tys + ; ds' <- traverse cvtDerivStrategy ds + ; returnL $ HsDerivingClause noExtField ds' tys' } cvtDerivStrategy :: TH.DerivStrategy -> CvtM (Hs.LDerivStrategy GhcPs) cvtDerivStrategy TH.StockStrategy = returnL Hs.StockStrategy |