summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2023-03-27 20:55:15 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-12 12:32:57 -0400
commitebd8918b7c50ae51921664e24fac0de4376ffcf9 (patch)
tree39f7112ed74735163f2208abe7e491bdbdaad757 /compiler
parentecf22da3c6d992d76fbb8e970b4ffbabb445d38a (diff)
downloadhaskell-ebd8918b7c50ae51921664e24fac0de4376ffcf9.tar.gz
Allow generation of TTH syntax with TH
In other words allow generation of typed splices and brackets with Untyped Template Haskell. That is useful in cases where a library is build with TTH in mind, but we still want to generate some auxiliary declarations, where TTH cannot help us, but untyped TH can. Such example is e.g. `staged-sop` which works with TTH, but we would like to derive `Generic` declarations with TH. An alternative approach is to use `unsafeCodeCoerce`, but then the derived `Generic` instances would be type-checked only at use sites, i.e. much later. Also `-ddump-splices` output is quite ugly: user-written instances would use TTH brackets, not `unsafeCodeCoerce`. This commit doesn't allow generating of untyped template splices and brackets with untyped TH, as I don't know why one would want to do that (instead of merging the splices, e.g.)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/ThToHs.hs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs
index 724f15f602..39da7e0c51 100644
--- a/compiler/GHC/ThToHs.hs
+++ b/compiler/GHC/ThToHs.hs
@@ -1157,6 +1157,10 @@ cvtl e = wrapLA (cvt e)
(L noSrcSpanA (DotFieldOcc noAnn (L noSrcSpanA (FieldLabelString (fsLit f))))) }
cvt (ProjectionE xs) = return $ HsProjection noAnn $ fmap
(L noSrcSpanA . DotFieldOcc noAnn . L noSrcSpanA . FieldLabelString . fsLit) xs
+ cvt (TypedSpliceE e) = do { e' <- parenthesizeHsExpr appPrec <$> cvtl e
+ ; return $ HsTypedSplice (noAnn, noAnn) e' }
+ cvt (TypedBracketE e) = do { e' <- cvtl e
+ ; return $ HsTypedBracket noAnn e' }
{- | #16895 Ensure an infix expression's operator is a variable/constructor.
Consider this example: