From b056adc8062b4fe015450a21eb70e32dcf7023f5 Mon Sep 17 00:00:00 2001 From: romes Date: Sat, 12 Mar 2022 01:08:00 +0000 Subject: TTG: Make HsQuote GhcTc isomorphic to NoExtField An untyped bracket `HsQuote p` can never be constructed with `p ~ GhcTc`. This is because we don't typecheck `HsQuote` at all. That's OK, because we also never use `HsQuote GhcTc`. To enforce this at the type level we make `HsQuote GhcTc` isomorphic to `NoExtField` and impossible to construct otherwise, by using TTG field extensions to make all constructors, except for `XQuote` (which takes `NoExtField`), unconstructable, with `DataConCantHappen` This is explained more in detail in Note [The life cycle of a TH quotation] Related discussion: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4782 --- compiler/GHC/Tc/Gen/Splice.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'compiler/GHC/Tc/Gen/Splice.hs') diff --git a/compiler/GHC/Tc/Gen/Splice.hs b/compiler/GHC/Tc/Gen/Splice.hs index bed8e14161..48464f5ca5 100644 --- a/compiler/GHC/Tc/Gen/Splice.hs +++ b/compiler/GHC/Tc/Gen/Splice.hs @@ -199,13 +199,7 @@ tcTypedBracket rn_expr expr res_ty -- Bundle them together so they can be used in GHC.HsToCore.Quote for desugaring -- brackets. ; let wrapper = QuoteWrapper ev_var m_var - -- Typecheck expr to make sure it is valid, - -- - -- romes TODO: The following is not actually that true: ppr_expr in - -- GHC.Hs.Expr uses this (and for untyped brackets the supposedly not - -- used type is also used). - -- If it isn't to be used, should the types enforce that? - -- + -- Typecheck expr to make sure it is valid. -- The typechecked expression won't be used, but we return it with its type. -- (See Note [The life cycle of a TH quotation] in GHC.Hs.Expr) -- We'll typecheck it again when we splice it in somewhere @@ -249,7 +243,7 @@ tcUntypedBracket rn_expr brack ps res_ty -- Unify the overall type of the bracket with the expected result -- type ; tcWrapResultO BracketOrigin rn_expr - (HsUntypedBracket (HsBracketTc brack expected_type brack_info ps') (XQuote brack)) + (HsUntypedBracket (HsBracketTc brack expected_type brack_info ps') (XQuote noExtField)) expected_type res_ty } -- cgit v1.2.1