[Git][ghc/ghc][master] Back-compat for TH SpecialiseP data-con of Pragma

Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 27206c5e by sheaf at 2025-08-29T17:28:14-04:00 Back-compat for TH SpecialiseP data-con of Pragma This commit improves the backwards-compatibility story for the SpecialiseP constructor of the Template Haskell 'Pragma' datatype. Instead of keeping the constructor but deprecating it, this commit makes it into a bundled pattern synonym of the Pragma datatype. We no longer deprecate it; it's useful for handling old-form specialise pragmas. - - - - - 7 changed files: - compiler/GHC/ThToHs.hs - libraries/ghc-boot-th/GHC/Boot/TH/Ppr.hs - libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs - libraries/template-haskell/Language/Haskell/TH/Lib.hs - libraries/template-haskell/Language/Haskell/TH/Syntax.hs - libraries/template-haskell/changelog.md - testsuite/tests/interface-stability/template-haskell-exports.stdout Changes: ===================================== compiler/GHC/ThToHs.hs ===================================== @@ -915,12 +915,6 @@ cvtPragmaD (OpaqueP nm) srcTxt = SourceText $ fsLit "{-# OPAQUE" ; returnJustLA $ Hs.SigD noExtField $ InlineSig noAnn nm' ip } -cvtPragmaD (SpecialiseP nm ty inline phases) - = do { nm' <- vNameN nm - ; ty' <- cvtSigType ty - ; let ip = cvtInlinePhases inline phases - ; returnJustLA $ Hs.SigD noExtField $ SpecSig noAnn nm' [ty'] ip } - cvtPragmaD (SpecialiseInstP ty) = do { ty' <- cvtSigType ty ; returnJustLA $ Hs.SigD noExtField $ ===================================== libraries/ghc-boot-th/GHC/Boot/TH/Ppr.hs ===================================== @@ -646,13 +646,6 @@ instance Ppr Pragma where <+> text "#-}" ppr (OpaqueP n) = text "{-# OPAQUE" <+> pprName' Applied n <+> text "#-}" - ppr (SpecialiseP n ty inline phases) - = text "{-# SPECIALISE" - <+> maybe empty ppr inline - <+> ppr phases - <+> sep [ pprName' Applied n <+> dcolon - , nest 2 $ ppr ty ] - <+> text "#-}" ppr (SpecialiseEP ty_bndrs tm_bndrs spec_e inline phases) = sep [ text "{-# SPECIALISE" <+> maybe empty ppr inline ===================================== libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs ===================================== @@ -2115,12 +2115,8 @@ data Pragma = InlineP Name Inline RuleMatch Phases -- 'Inline' and 'RuleMatch'. | OpaqueP Name -- ^ @{ {\-\# OPAQUE T #-} }@ - | SpecialiseP Name Type (Maybe Inline) Phases - -- ^ @{ {\-\# SPECIALISE [INLINE] [phases] nm :: ty #-} }@ - -- - -- NB: this constructor is deprecated and will be removed in GHC 9.18 | SpecialiseEP (Maybe [TyVarBndr ()]) [RuleBndr] Exp (Maybe Inline) Phases - -- ^ @{ {\-\# SPECIALISE [INLINE] [phases] exp #-} }@ + -- ^ @{ {\-\# SPECIALISE [forall t_1 ... t_i]. [forall b_1 ... b_j] [INLINE] [phases] exp #-} }@ | SpecialiseInstP Type -- ^ @{ {\-\# SPECIALISE instance I #-} }@ | RuleP String (Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases ===================================== libraries/template-haskell/Language/Haskell/TH/Lib.hs ===================================== @@ -443,16 +443,14 @@ varStrictType :: Quote m => Name -> m StrictType -> m VarStrictType varStrictType = varBangType -------------------------------------------------------------------------------- --- * Specialisation pragmas (deprecated) +-- * Specialisation pragmas (backwards compatibility) -{-# DEPRECATED pragSpecD "Please use 'pragSpecED' instead. 'pragSpecD' will be removed in GHC 9.18." #-} pragSpecD :: Quote m => Name -> m Type -> Phases -> m Dec pragSpecD n ty phases = do ty1 <- ty pure $ PragmaD $ SpecialiseP n ty1 Nothing phases -{-# DEPRECATED pragSpecInlD "Please use 'pragSpecInlED' instead. 'pragSpecInlD' will be removed in GHC 9.18." #-} pragSpecInlD :: Quote m => Name -> m Type -> Inline -> Phases -> m Dec pragSpecInlD n ty inline phases = do ===================================== libraries/template-haskell/Language/Haskell/TH/Syntax.hs ===================================== @@ -1,4 +1,5 @@ {-# LANGUAGE MagicHash #-} +{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskellQuotes #-} @@ -157,7 +158,7 @@ module Language.Haskell.TH.Syntax ( PatSynType, Phases (..), PkgName (..), - Pragma (..), + Pragma (SpecialiseP, ..), Quasi (..), Range (..), Role (..), @@ -457,3 +458,12 @@ reassociate the tree as necessary. 'InfixT', 'PromotedInfixT, 'ParensE', 'ParensP', or 'ParensT' constructors. -} + +-------------------------------------------------------------------------------- +-- Back-compat for Specialise pragmas + +-- | Old-form specialise pragma @{ {\-\# SPECIALISE [INLINE] [phases] (var :: ty) #-} }@. +-- +-- Subsumed by the more general 'SpecialiseEP' constructor. +pattern SpecialiseP :: Name -> Type -> (Maybe Inline) -> Phases -> Pragma +pattern SpecialiseP nm ty inl phases = SpecialiseEP Nothing [] (SigE (VarE nm) ty) inl phases ===================================== libraries/template-haskell/changelog.md ===================================== @@ -7,16 +7,9 @@ * Introduce `dataToCodeQ` and `liftDataTyped`, typed variants of `dataToExpQ` and `liftData` respectively. - * As part of the implementation of [GHC proposal 493](https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0493-sp...), - the ``SpecialiseP`` constructor of `Pragma`, as well as the helper functions - `pragSpecD` and `pragSpecInlD`, have been deprecated. - - They are replaced, respectively, by `SpecialiseEP`, `pragSpecED` and - `pragSpecInlED`. - * Remove the `Language.Haskell.TH.Lib.Internal` module. This module has long been deprecated, and exposes compiler internals. Users should use `Language.Haskell.TH.Lib` instead, which exposes a more stable version of this API. - + * Remove `addrToByteArrayName` and `addrToByteArray` from `Language.Haskell.TH.Syntax`. These were part of the implementation of the `Lift ByteArray` instance and were accidentally exported because this module lacked an explicit export list. They have no usages on Hackage. ## 2.23.0.0 ===================================== testsuite/tests/interface-stability/template-haskell-exports.stdout ===================================== @@ -347,7 +347,7 @@ module Language.Haskell.TH where ppr_list :: [a] -> GHC.Boot.TH.PprLib.Doc {-# MINIMAL ppr #-} type Pragma :: * - data Pragma = InlineP Name Inline RuleMatch Phases | OpaqueP Name | SpecialiseP Name Type (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseEP (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseInstP Type | RuleP GHC.Internal.Base.String (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases | AnnP AnnTarget Exp | LineP GHC.Internal.Types.Int GHC.Internal.Base.String | CompleteP [Name] (GHC.Internal.Maybe.Maybe Name) | SCCP Name (GHC.Internal.Maybe.Maybe GHC.Internal.Base.String) + data Pragma = InlineP Name Inline RuleMatch Phases | OpaqueP Name | SpecialiseEP (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseInstP Type | RuleP GHC.Internal.Base.String (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases | AnnP AnnTarget Exp | LineP GHC.Internal.Types.Int GHC.Internal.Base.String | CompleteP [Name] (GHC.Internal.Maybe.Maybe Name) | SCCP Name (GHC.Internal.Maybe.Maybe GHC.Internal.Base.String) type Pred :: * type Pred = Type type PredQ :: * @@ -381,6 +381,7 @@ module Language.Haskell.TH where data SourceUnpackedness = NoSourceUnpackedness | SourceNoUnpack | SourceUnpack type SourceUnpackednessQ :: * type SourceUnpackednessQ = Q SourceUnpackedness + pattern SpecialiseP :: Name -> Type -> GHC.Internal.Maybe.Maybe Inline -> Phases -> Pragma type Specificity :: * data Specificity = SpecifiedSpec | InferredSpec type Stmt :: * @@ -1693,7 +1694,7 @@ module Language.Haskell.TH.Syntax where type PkgName :: * newtype PkgName = PkgName GHC.Internal.Base.String type Pragma :: * - data Pragma = InlineP Name Inline RuleMatch Phases | OpaqueP Name | SpecialiseP Name Type (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseEP (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseInstP Type | RuleP GHC.Internal.Base.String (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases | AnnP AnnTarget Exp | LineP GHC.Internal.Types.Int GHC.Internal.Base.String | CompleteP [Name] (GHC.Internal.Maybe.Maybe Name) | SCCP Name (GHC.Internal.Maybe.Maybe GHC.Internal.Base.String) + data Pragma = InlineP Name Inline RuleMatch Phases | OpaqueP Name | SpecialiseEP (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp (GHC.Internal.Maybe.Maybe Inline) Phases | SpecialiseInstP Type | RuleP GHC.Internal.Base.String (GHC.Internal.Maybe.Maybe [TyVarBndr ()]) [RuleBndr] Exp Exp Phases | AnnP AnnTarget Exp | LineP GHC.Internal.Types.Int GHC.Internal.Base.String | CompleteP [Name] (GHC.Internal.Maybe.Maybe Name) | SCCP Name (GHC.Internal.Maybe.Maybe GHC.Internal.Base.String) type Pred :: * type Pred = Type type role Q nominal @@ -1748,6 +1749,7 @@ module Language.Haskell.TH.Syntax where data SourceStrictness = NoSourceStrictness | SourceLazy | SourceStrict type SourceUnpackedness :: * data SourceUnpackedness = NoSourceUnpackedness | SourceNoUnpack | SourceUnpack + pattern SpecialiseP :: Name -> Type -> GHC.Internal.Maybe.Maybe Inline -> Phases -> Pragma type Specificity :: * data Specificity = SpecifiedSpec | InferredSpec type Stmt :: * View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/27206c5e3c8e6f878f509d6a8f648a21... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/27206c5e3c8e6f878f509d6a8f648a21... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)