ghc-tcplugin-api 0.19.0.0 → 0.20.1.0
raw patch · 5 files changed
Files
- changelog.md +21/−0
- ghc-tcplugin-api.cabal +8/−8
- src/GHC/Builtins.hs +130/−0
- src/GHC/TcPlugin/API.hs +14/−20
- src/GHC/TcPlugin/API/Internal.hs +45/−27
changelog.md view
@@ -1,4 +1,25 @@ +# Version 0.20.1.0 (2026-09-01) + +- Add `cTupleTyConName` and `isCTupleTyConName` to the export list of + `GHC.Builtins`. + +# Version 0.20.0.0 (2026-09-01) + +- Preliminary support for GHC 10.2 (with the known-entities refactor). + +- The re-exports of `GHC.Builtin.Names`, `GHC.Builtin.Types` and + `GHC.Builtin.Types.Prim` have been replaced by a single umbrella helper + module, `GHC.Builtins`. Remarks: + + - GHC 10.2 no longer defines static `Name`s for known-key entities. Instead, + these need to be resolved at runtime. Accordingly, `GHC.Builtins` + exports `KnownKey` uniques such as `errorMessageTypeErrorFamKey` on + GHC >= 10.2, instead of `Name`s such as `errorMessageTypeErrorFamName`. + + - The `MonadThings` class has been removed. Use `tcLookupTyCon`, + `tcLookupDataCon` etc instead. + # Version 0.19.0.0 (2026-05-12) - Starting from GHC 10.0, typechecker plugins are kept running during the
ghc-tcplugin-api.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ghc-tcplugin-api -version: 0.19.0.0 +version: 0.20.1.0 synopsis: An API for type-checker plugins. license: BSD-3-Clause build-type: Simple @@ -39,11 +39,11 @@ containers >= 0.6 && < 0.9, ghc - >= 8.8 && < 10.1, + >= 8.8 && < 10.3, transformers >= 0.5 && < 0.7, template-haskell - >= 2.15 && < 2.26, + >= 2.15 && < 3, default-language: Haskell2010 @@ -64,13 +64,12 @@ GHC.TcPlugin.API.Names, GHC.TcPlugin.API.TyConSubst, - GHC.TcPlugin.API.Internal + GHC.TcPlugin.API.Internal, + GHC.Builtins + reexported-modules: - GHC.Builtin.Names - , GHC.Builtin.Types - , GHC.Builtin.Types.Prim - , GHC.Core.Make + GHC.Core.Make , GHC.Plugins , GHC.Types.Unique.DFM , GHC.Types.Unique.FM @@ -100,6 +99,7 @@ , PrelNames as GHC.Builtin.Names , TysWiredIn as GHC.Builtin.Types + , TcTypeNats as GHC.Builtin.Types.Literals , TysPrim as GHC.Builtin.Types.Prim , CoreSyn as GHC.Core
+ src/GHC/Builtins.hs view
@@ -0,0 +1,130 @@+{-# LANGUAGE CPP #-} + +-- | Helper umbrella re-exports of various known entities to GHC: known-key +-- uniques, wired-in types. +module GHC.Builtins + ( -- * Known-key uniques + hasKey + , eqTyConKey, heqTyConKey, coercibleTyConKey + , eqPrimTyConKey, eqReprPrimTyConKey, eqPhantPrimTyConKey + + -- * Custom type errors (prefer using 'GHC.TcPlugin.API.mkTcPluginErrorTy') +#if MIN_VERSION_ghc(10,1,0) + , errorMessageTypeErrorFamKey + , typeErrorTextDataConKey, typeErrorShowTypeDataConKey + , typeErrorAppendDataConKey, typeErrorVAppendDataConKey +#else + , errorMessageTypeErrorFamName + , typeErrorTextDataConName, typeErrorShowTypeDataConName + , typeErrorAppendDataConName, typeErrorVAppendDataConName +#endif + + -- * Equality and coercions + , eqTyCon, heqTyCon, coercibleTyCon + , eqPrimTyCon, eqReprPrimTyCon, eqPhantPrimTyCon + , eqClass, heqClass, coercibleClass + , eqDataCon, heqDataCon, coercibleDataCon +#if MIN_VERSION_ghc(8,10,0) + , equalityTyCon +#endif + + -- * Kinds + , liftedTypeKind, constraintKind, typeSymbolKind + , unboxedTupleKind, unboxedSumKind + , liftedTypeKindTyCon, constraintKindTyCon, tYPETyCon + , anyTy, anyTyCon, anyTypeOfKind +#if MIN_VERSION_ghc(8,10,0) + , typeToTypeKind +#endif +#if MIN_VERSION_ghc(9,1,0) + , unliftedTypeKind +#endif +#if MIN_VERSION_ghc(9,3,0) + , zeroBitTypeKind +#endif +#if MIN_VERSION_ghc(9,5,0) + , tYPEKind, cONSTRAINTKind, cONSTRAINTTyCon, fUNTyCon +#endif + + -- * Runtime representations, levities and multiplicities + , runtimeRepTy, runtimeRepTyCon, liftedRepTy +#if MIN_VERSION_ghc(9,0,0) + , multiplicityTy, multiplicityTyCon + , manyDataCon, oneDataCon, manyDataConTy, oneDataConTy +#endif +#if MIN_VERSION_ghc(9,1,0) + , unliftedRepTy, boxedRepDataConTyCon, levityTyCon + , liftedDataConTy, unliftedDataConTy + , liftedDataConTyCon, unliftedDataConTyCon +#endif +#if MIN_VERSION_ghc(9,3,0) + , levityTy, zeroBitRepTy +#endif + + -- * Wired-in types + , unitTy, unitTyCon, unitDataCon, unitDataConId + , boolTy, boolTyCon, trueDataCon, falseDataCon + , promotedTrueDataCon, promotedFalseDataCon + , orderingTyCon, promotedLTDataCon, promotedEQDataCon, promotedGTDataCon + , charTy, charTyCon, charDataCon + , intTy, intTyCon, intDataCon + , wordTy, wordTyCon, wordDataCon + , floatTy, floatTyCon, doubleTy, doubleTyCon + , stringTy + , listTyCon, nilDataCon, consDataCon + , promotedNilDataCon, promotedConsDataCon + , maybeTyCon, justDataCon, nothingDataCon + , promotedJustDataCon, promotedNothingDataCon +#if MIN_VERSION_ghc(9,0,0) + , integerTy, integerTyCon, naturalTy, naturalTyCon +#endif +#if !MIN_VERSION_ghc(9,1,0) + , typeNatKind +#endif + + -- * Tuples and sums + , tupleTyCon, tupleDataCon, promotedTupleDataCon + , sumTyCon, sumDataCon + , cTupleTyConName, isCTupleTyConName + , mkTupleTy, mkBoxedTupleTy, mkSumTy + , mkListTy, mkPromotedListTy +#if MIN_VERSION_ghc(8,10,0) + , mkTupleTy1 +#endif +#if MIN_VERSION_ghc(9,1,0) + , cTupleTyCon, cTupleDataCon + , mkMaybeTy, mkPromotedMaybeTy, mkPromotedPairTy +#endif +#if MIN_VERSION_ghc(9,5,0) + , mkConstraintTupleTy +#endif + + -- * Type-level literals + , typeNatTyCons, typeNatCoAxiomRules + , typeNatAddTyCon, typeNatSubTyCon, typeNatMulTyCon, typeNatExpTyCon + , typeNatDivTyCon, typeNatModTyCon, typeNatLogTyCon, typeNatCmpTyCon + , typeSymbolCmpTyCon, typeSymbolAppendTyCon, typeSymbolKindCon +#if MIN_VERSION_ghc(9,1,0) + , typeConsSymbolTyCon, typeUnconsSymbolTyCon + , typeCharCmpTyCon, typeCharToNatTyCon, typeNatToCharTyCon +#endif + + -- * Primitive types + , intPrimTy, wordPrimTy, charPrimTy, floatPrimTy, doublePrimTy + , realWorldTy, realWorldTyCon, realWorldStatePrimTy + , mkStatePrimTy, mkProxyPrimTy, proxyPrimTyCon + ) + where + +-- ghc +#if MIN_VERSION_ghc(10,1,0) +import GHC.Builtin.KnownKeys +import GHC.Builtin.WiredIn.Prim +import GHC.Builtin.WiredIn.TypeLits +import GHC.Builtin.WiredIn.Types +#else +import GHC.Builtin.Names +import GHC.Builtin.Types +import GHC.Builtin.Types.Literals +import GHC.Builtin.Types.Prim +#endif
src/GHC/TcPlugin/API.hs view
@@ -511,7 +511,6 @@ -- | == Names , Name, OccName, TyThing, TcTyThing - , MonadThings(..) , Class(classTyCon), DataCon, TyCon, Id , FastString @@ -559,25 +558,6 @@ -- ghc import GHC ( TyThing(..) ) -import GHC.Builtin.Names - ( hasKey - , eqPrimTyConKey, eqReprPrimTyConKey - , heqTyConKey, eqTyConKey, coercibleTyConKey - ) -import GHC.Builtin.Types - ( typeSymbolKind, charTy -#if MIN_VERSION_ghc(9,1,0) - , naturalTy -#else - , typeNatKind -#endif - ) -#if !MIN_VERSION_ghc(9,0,0) -import GHC.Builtin.Types - ( intDataCon ) -import GHC.Builtin.Types.Prim - ( intPrimTy ) -#endif import GHC.Core ( CoreBndr, CoreExpr, Expr(..), mkTyApps, mkApps ) import GHC.Core.Class @@ -885,6 +865,20 @@ ( filterOut ) -- ghc-tcplugin-api +import GHC.Builtins + ( hasKey + , eqPrimTyConKey, eqReprPrimTyConKey + , heqTyConKey, eqTyConKey, coercibleTyConKey + , typeSymbolKind, charTy +#if MIN_VERSION_ghc(9,1,0) + , naturalTy +#else + , typeNatKind +#endif +#if !MIN_VERSION_ghc(9,0,0) + , intDataCon, intPrimTy +#endif + ) import GHC.TcPlugin.API.Internal #ifndef HAS_REWRITING import GHC.TcPlugin.API.Internal.Shim
src/GHC/TcPlugin/API/Internal.hs view
@@ -51,7 +51,6 @@ , TcPluginM(..) , TcPluginErrorMessage(..) , TcPluginRewriter - , MonadThings(..) , askRewriteEnv , askDeriveds , askEvBinds @@ -75,17 +74,6 @@ ( ReaderT(..) ) -- ghc -import qualified GHC.Builtin.Names - as GHC.TypeLits - ( errorMessageTypeErrorFamName - , typeErrorTextDataConName - , typeErrorAppendDataConName - , typeErrorVAppendDataConName - , typeErrorShowTypeDataConName - ) -import qualified GHC.Builtin.Types - as GHC - ( constraintKind ) import qualified GHC.Core.DataCon as GHC ( promoteDataCon ) @@ -104,6 +92,11 @@ import qualified GHC.Tc.Plugin as GHC ( tcLookupDataCon, tcLookupTyCon ) +#if MIN_VERSION_ghc(10,1,0) +import qualified GHC.Tc.Utils.Env + as GHC + ( rnLookupKnownKeyName ) +#endif import qualified GHC.Tc.Types as GHC ( TcM, TcPlugin(..), TcPluginM @@ -134,12 +127,7 @@ import qualified GHC.Types.Unique.FM as GHC ( UniqFM ) -#if MIN_VERSION_ghc(9,1,0) -import GHC.Types.TyThing - ( MonadThings(..) ) -#else -import GHC.Driver.Types - ( MonadThings(..) ) +#if !MIN_VERSION_ghc(9,1,0) import GHC.Tc.Types.Constraint ( ctEvidence, ctEvId, isDerived ) import GHC.Types.Var.Env @@ -150,6 +138,26 @@ #endif -- ghc-tcplugin-api +import qualified GHC.Builtins + as GHC + ( constraintKind ) +import qualified GHC.Builtins + as GHC.TypeError +#if MIN_VERSION_ghc(10,1,0) + ( errorMessageTypeErrorFamKey + , typeErrorTextDataConKey + , typeErrorAppendDataConKey + , typeErrorVAppendDataConKey + , typeErrorShowTypeDataConKey + ) +#else + ( errorMessageTypeErrorFamName + , typeErrorTextDataConName + , typeErrorAppendDataConName + , typeErrorVAppendDataConName + , typeErrorShowTypeDataConName + ) +#endif #ifndef HAS_REWRITING import GHC.TcPlugin.API.Internal.Shim ( TcPluginSolveResult, TcPluginRewriteResult(..) @@ -622,10 +630,6 @@ errorMsgTy = interpretErrorMessage builtinDefs msg pure $ GHC.mkTyConApp typeErrorTyCon [ GHC.constraintKind, errorMsgTy ] -instance ( Monad ( TcPluginM s ), MonadTcPlugin ( TcPluginM s ) ) - => MonadThings ( TcPluginM s ) where - lookupThing = unsafeLiftTcM . lookupThing - -------------------------------------------------------------------------------- -- Private types and functions. -- Not exposed at all, even from the internal module. @@ -647,11 +651,25 @@ initBuiltinDefs :: GHC.TcPluginM BuiltinDefs initBuiltinDefs = do - typeErrorTyCon <- GHC.tcLookupTyCon GHC.TypeLits.errorMessageTypeErrorFamName - textTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon GHC.TypeLits.typeErrorTextDataConName - showTypeTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon GHC.TypeLits.typeErrorShowTypeDataConName - concatTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon GHC.TypeLits.typeErrorAppendDataConName - vcatTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon GHC.TypeLits.typeErrorVAppendDataConName +#if MIN_VERSION_ghc(10,1,0) + let lookupBuiltin = GHC.unsafeTcPluginTcM . GHC.rnLookupKnownKeyName + typeErrorName <- lookupBuiltin GHC.TypeError.errorMessageTypeErrorFamKey + textName <- lookupBuiltin GHC.TypeError.typeErrorTextDataConKey + showTypeName <- lookupBuiltin GHC.TypeError.typeErrorShowTypeDataConKey + concatName <- lookupBuiltin GHC.TypeError.typeErrorAppendDataConKey + vcatName <- lookupBuiltin GHC.TypeError.typeErrorVAppendDataConKey +#else + let typeErrorName = GHC.TypeError.errorMessageTypeErrorFamName + textName = GHC.TypeError.typeErrorTextDataConName + showTypeName = GHC.TypeError.typeErrorShowTypeDataConName + concatName = GHC.TypeError.typeErrorAppendDataConName + vcatName = GHC.TypeError.typeErrorVAppendDataConName +#endif + typeErrorTyCon <- GHC.tcLookupTyCon typeErrorName + textTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon textName + showTypeTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon showTypeName + concatTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon concatName + vcatTyCon <- GHC.promoteDataCon <$> GHC.tcLookupDataCon vcatName pure ( BuiltinDefs { .. } ) interpretErrorMessage :: BuiltinDefs -> TcPluginErrorMessage -> GHC.PredType