diff options
author | romes <rodrigo.m.mesquita@gmail.com> | 2022-03-11 16:51:09 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-03-18 05:10:58 -0400 |
commit | 4a2567f5641a4807584c90015dfc40a791f241b4 (patch) | |
tree | 632cd30d5a1d5be5536d4f30cadeaa347ce81382 /compiler/GHC/Rename | |
parent | 310890a51372937afa69e1edac1179eba67ac046 (diff) | |
download | haskell-4a2567f5641a4807584c90015dfc40a791f241b4.tar.gz |
TTG: Refactor bracket for desugaring during tc
When desugaring a bracket we want to desugar /renamed/ rather than
/typechecked/ code; So in (HsExpr GhcTc) tree, we must
have a (HsExpr GhcRn) for the quotation itself.
This commit reworks the TTG refactor on typed and untyped brackets by
storing the /renamed/ code in the bracket field extension rather than in
the constructor extension in `HsQuote` (previously called
`HsUntypedBracket`)
See Note [The life cycle of a TH quotation] and https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4782
Diffstat (limited to 'compiler/GHC/Rename')
-rw-r--r-- | compiler/GHC/Rename/Splice.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/GHC/Rename/Splice.hs b/compiler/GHC/Rename/Splice.hs index 8993442711..bf46b89cc9 100644 --- a/compiler/GHC/Rename/Splice.hs +++ b/compiler/GHC/Rename/Splice.hs @@ -73,8 +73,8 @@ import qualified GHC.LanguageExtensions as LangExt ************************************************************************ -} -rnTypedBracket :: HsExpr GhcPs -> HsTypedBracket GhcPs -> RnM (HsExpr GhcRn, FreeVars) -rnTypedBracket e (TExpBr ext br_body) +rnTypedBracket :: HsExpr GhcPs -> LHsExpr GhcPs -> RnM (HsExpr GhcRn, FreeVars) +rnTypedBracket e br_body = addErrCtxt (typedQuotationCtxtDoc br_body) $ do { -- Check that -XTemplateHaskellQuotes is enabled and available thQuotesEnabled <- xoptM LangExt.TemplateHaskellQuotes @@ -103,11 +103,11 @@ rnTypedBracket e (TExpBr ext br_body) ; traceRn "Renaming typed TH bracket" empty ; (body', fvs_e) <- setStage (Brack cur_stage RnPendingTyped) $ rnLExpr br_body - ; return (HsTypedBracket noAnn (TExpBr ext body'), fvs_e) + ; return (HsTypedBracket noAnn body', fvs_e) } -rnUntypedBracket :: HsExpr GhcPs -> HsUntypedBracket GhcPs -> RnM (HsExpr GhcRn, FreeVars) +rnUntypedBracket :: HsExpr GhcPs -> HsQuote GhcPs -> RnM (HsExpr GhcRn, FreeVars) rnUntypedBracket e br_body = addErrCtxt (untypedQuotationCtxtDoc br_body) $ do { -- Check that -XTemplateHaskellQuotes is enabled and available @@ -146,7 +146,7 @@ rnUntypedBracket e br_body } -rn_utbracket :: ThStage -> HsUntypedBracket GhcPs -> RnM (HsUntypedBracket GhcRn, FreeVars) +rn_utbracket :: ThStage -> HsQuote GhcPs -> RnM (HsQuote GhcRn, FreeVars) rn_utbracket outer_stage br@(VarBr x flg rdr_name) = do { name <- lookupOccRn (unLoc rdr_name) ; check_namespace flg name @@ -224,7 +224,7 @@ typedQuotationCtxtDoc br_body = hang (text "In the Template Haskell typed quotation") 2 (thTyBrackets . ppr $ br_body) -untypedQuotationCtxtDoc :: HsUntypedBracket GhcPs -> SDoc +untypedQuotationCtxtDoc :: HsQuote GhcPs -> SDoc untypedQuotationCtxtDoc br_body = hang (text "In the Template Haskell quotation") 2 (ppr br_body) @@ -242,7 +242,7 @@ illegalUntypedBracket :: TcRnMessage illegalUntypedBracket = TcRnUnknownMessage $ mkPlainError noHints $ text "Untyped brackets may only appear in untyped splices." -quotedNameStageErr :: HsUntypedBracket GhcPs -> TcRnMessage +quotedNameStageErr :: HsQuote GhcPs -> TcRnMessage quotedNameStageErr br = TcRnUnknownMessage $ mkPlainError noHints $ sep [ text "Stage error: the non-top-level quoted name" <+> ppr br |