[Git][ghc/ghc][wip/az/ghc-9.10-backports-1] EPA: Avoid duplicated comments in splice decls
Alan Zimmerman (@alanz)
gitlab at gitlab.haskell.org
Sun Apr 21 13:26:39 UTC 2024
Alan Zimmerman pushed to branch wip/az/ghc-9.10-backports-1 at Glasgow Haskell Compiler / GHC
Commits:
898fcbd2 by Alan Zimmerman at 2024-04-21T13:49:41+01:00
EPA: Avoid duplicated comments in splice decls
Contributes to #24669
(cherry picked from commit 2f8e3a254a20f4573aec26fc85ab74b51d661472)
- - - - -
2 changed files:
- compiler/GHC/Parser.y
- compiler/GHC/Parser/PostProcess.hs
Changes:
=====================================
compiler/GHC/Parser.y
=====================================
@@ -1257,8 +1257,7 @@ topdecl :: { LHsDecl GhcPs }
-- but we treat an arbitrary expression just as if
-- it had a $(..) wrapped around it
| infixexp {% runPV (unECP $1) >>= \ $1 ->
- do { d <- mkSpliceDecl $1
- ; commentsPA d }}
+ commentsPA $ mkSpliceDecl $1 }
-- Type classes
--
@@ -2603,7 +2602,7 @@ decl :: { LHsDecl GhcPs }
-- Why do we only allow naked declaration splices in top-level
-- declarations and not here? Short answer: because readFail009
-- fails terribly with a panic in cvBindsAndSigs otherwise.
- | splice_exp {% mkSpliceDecl $1 }
+ | splice_exp { mkSpliceDecl $1 }
rhs :: { Located (GRHSs GhcPs (LHsExpr GhcPs)) }
: '=' exp wherebinds {% runPV (unECP $2) >>= \ $2 ->
=====================================
compiler/GHC/Parser/PostProcess.hs
=====================================
@@ -386,7 +386,7 @@ mkFamDecl loc info topLevel lhs ksig injAnn annsIn
OpenTypeFamily -> empty
ClosedTypeFamily {} -> whereDots
-mkSpliceDecl :: LHsExpr GhcPs -> P (LHsDecl GhcPs)
+mkSpliceDecl :: LHsExpr GhcPs -> (LHsDecl GhcPs)
-- If the user wrote
-- [pads| ... ] then return a QuasiQuoteD
-- $(e) then return a SpliceD
@@ -397,18 +397,15 @@ mkSpliceDecl :: LHsExpr GhcPs -> P (LHsDecl GhcPs)
-- Typed splices are not allowed at the top level, thus we do not represent them
-- as spliced declaration. See #10945
mkSpliceDecl lexpr@(L loc expr)
- | HsUntypedSplice _ splice@(HsUntypedSpliceExpr {}) <- expr = do
- !cs <- getCommentsFor (locA loc)
- return $ L (addCommentsToEpAnn loc cs) $ SpliceD noExtField (SpliceDecl noExtField (L loc splice) DollarSplice)
-
- | HsUntypedSplice _ splice@(HsQuasiQuote {}) <- expr = do
- cs <- getCommentsFor (locA loc)
- return $ L (addCommentsToEpAnn loc cs) $ SpliceD noExtField (SpliceDecl noExtField (L loc splice) DollarSplice)
-
- | otherwise = do
- !cs <- getCommentsFor (locA loc)
- return $ L (addCommentsToEpAnn loc cs) $ SpliceD noExtField (SpliceDecl noExtField
- (L loc (HsUntypedSpliceExpr noAnn lexpr))
+ | HsUntypedSplice _ splice@(HsUntypedSpliceExpr {}) <- expr
+ = L loc $ SpliceD noExtField (SpliceDecl noExtField (L (l2l loc) splice) DollarSplice)
+
+ | HsUntypedSplice _ splice@(HsQuasiQuote {}) <- expr
+ = L loc $ SpliceD noExtField (SpliceDecl noExtField (L (l2l loc) splice) DollarSplice)
+
+ | otherwise
+ = L loc $ SpliceD noExtField (SpliceDecl noExtField
+ (L (l2l loc) (HsUntypedSpliceExpr noAnn (la2la lexpr)))
BareSplice)
mkRoleAnnotDecl :: SrcSpan
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/898fcbd20a7ec5164bb37c33f1c909430200ea06
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/898fcbd20a7ec5164bb37c33f1c909430200ea06
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240421/f1384603/attachment-0001.html>
More information about the ghc-commits
mailing list