summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorromes <rodrigo.m.mesquita@gmail.com>2022-03-19 17:42:46 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-06-01 07:44:44 -0400
commit7975202ba9010c581918413808ee06fbab9ac85f (patch)
treeffebdbd9d9fcef2300b1a6d3950bb5dd3f8435c4 /utils
parent392ce3fca5d33688add52309a05914efa163e6f6 (diff)
downloadhaskell-7975202ba9010c581918413808ee06fbab9ac85f.tar.gz
TTG: Rework and improve splices
This commit redefines the structure of Splices in the AST. We get rid of `HsSplice` which used to represent typed and untyped splices, quasi quotes, and the result of splicing either an expression, a type or a pattern. Instead we have `HsUntypedSplice` which models an untyped splice or a quasi quoter, which works in practice just like untyped splices. The `HsExpr` constructor `HsSpliceE` which used to be constructed with an `HsSplice` is split into `HsTypedSplice` and `HsUntypedSplice`. The former is directly constructed with an `HsExpr` and the latter now takes an `HsUntypedSplice`. Both `HsType` and `Pat` constructors `HsSpliceTy` and `SplicePat` now take an `HsUntypedSplice` instead of a `HsSplice` (remember only /untyped splices/ can be spliced as types or patterns). The result of splicing an expression, type, or pattern is now comfortably stored in the extension fields `XSpliceTy`, `XSplicePat`, `XUntypedSplice` as, respectively, `HsUntypedSpliceResult (HsType GhcRn)`, `HsUntypedSpliceResult (Pat GhcRn)`, and `HsUntypedSpliceResult (HsExpr GhcRn)` Overall the TTG extension points are now better used to make invalid states unrepresentable and model the progression between stages better. See Note [Lifecycle of an untyped splice, and PendingRnSplice] and Note [Lifecycle of an typed splice, and PendingTcSplice] for more details. Updates haddock submodule Fixes #21263 ------------------------- Metric Decrease: hard_hole_fits -------------------------
Diffstat (limited to 'utils')
-rw-r--r--utils/check-exact/ExactPrint.hs39
m---------utils/haddock0
2 files changed, 12 insertions, 27 deletions
diff --git a/utils/check-exact/ExactPrint.hs b/utils/check-exact/ExactPrint.hs
index b52aa18de9..05c6a1e792 100644
--- a/utils/check-exact/ExactPrint.hs
+++ b/utils/check-exact/ExactPrint.hs
@@ -1859,7 +1859,8 @@ instance ExactPrint (HsExpr GhcPs) where
getAnnotationEntry (ArithSeq an _ _) = fromAnn an
getAnnotationEntry (HsTypedBracket an _) = fromAnn an
getAnnotationEntry (HsUntypedBracket an _) = fromAnn an
- getAnnotationEntry (HsSpliceE an _) = fromAnn an
+ getAnnotationEntry (HsTypedSplice (_, an) _) = fromAnn an
+ getAnnotationEntry (HsUntypedSplice an _) = fromAnn an
getAnnotationEntry (HsProc an _ _) = fromAnn an
getAnnotationEntry (HsStatic an _) = fromAnn an
getAnnotationEntry (HsPragE{}) = NoEntryVal
@@ -2082,8 +2083,10 @@ instance ExactPrint (HsExpr GhcPs) where
markEpAnn an AnnThTyQuote
markAnnotated e
-
- exact (HsSpliceE _ sp) = markAnnotated sp
+ exact (HsTypedSplice (_, an) e) = do
+ markEpAnn an AnnDollarDollar
+ markAnnotated e
+ exact (HsUntypedSplice _ sp) = markAnnotated sp
exact (HsProc an p c) = do
debugM $ "HsProc start"
@@ -2161,29 +2164,15 @@ instance ExactPrint (HsPragE GhcPs) where
-- ---------------------------------------------------------------------
-instance ExactPrint (HsSplice GhcPs) where
- getAnnotationEntry (HsTypedSplice an _ _ _) = fromAnn an
- getAnnotationEntry (HsUntypedSplice an _ _ _) = fromAnn an
- getAnnotationEntry (HsQuasiQuote _ _ _ _ _) = NoEntryVal
- getAnnotationEntry (HsSpliced _ _ _) = NoEntryVal
-
- exact (HsTypedSplice an DollarSplice _n e) = do
- markEpAnn an AnnDollarDollar
- markAnnotated e
+instance ExactPrint (HsUntypedSplice GhcPs) where
+ getAnnotationEntry (HsUntypedSpliceExpr an _) = fromAnn an
+ getAnnotationEntry (HsQuasiQuote _ _ _) = NoEntryVal
- -- = ppr_splice (text "$$") n e empty
- -- exact (HsTypedSplice _ BareSplice _ _ )
- -- = panic "Bare typed splice" -- impossible
- exact (HsUntypedSplice an decoration _n b) = do
- when (decoration == DollarSplice) $ markEpAnn an AnnDollar
+ exact (HsUntypedSpliceExpr an b) = do
+ markEpAnn an AnnDollar
markAnnotated b
- -- exact (HsUntypedSplice _ DollarSplice n e)
- -- = ppr_splice (text "$") n e empty
- -- exact (HsUntypedSplice _ BareSplice n e)
- -- = ppr_splice empty n e empty
-
- exact (HsQuasiQuote _ _ q ss fs) = do
+ exact (HsQuasiQuote _ q (L (SrcSpanAnn _ ss) fs)) = do
-- The quasiquote string does not honour layout offsets. Store
-- the colOffset for now.
-- TODO: use local?
@@ -2196,10 +2185,6 @@ instance ExactPrint (HsSplice GhcPs) where
p <- getPosP
debugM $ "HsQuasiQuote:after:(p,ss)=" ++ show (p,ss2range ss)
- -- exact (HsSpliced _ _ thing) = ppr thing
- -- exact (XSplice x) = case ghcPass @p of
- exact x = error $ "exact HsSplice for:" ++ showAst x
-
-- ---------------------------------------------------------------------
-- TODO:AZ: combine these instances
diff --git a/utils/haddock b/utils/haddock
-Subproject 4dd5c93bded622a6e2e011dc7e2c8976454b53c
+Subproject 89afef9daeb6da6624d42d32813d86c1f9b9f0c