ghc-tcplugin-api 0.6.1.0 → 0.7.0.0
raw patch · 4 files changed
+98/−18 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ GHC.TcPlugin.API: Boxed :: Boxity
+ GHC.TcPlugin.API: BoxedTuple :: TupleSort
+ GHC.TcPlugin.API: ConstraintTuple :: TupleSort
+ GHC.TcPlugin.API: IsPromoted :: PromotionFlag
+ GHC.TcPlugin.API: NotPromoted :: PromotionFlag
+ GHC.TcPlugin.API: Unboxed :: Boxity
+ GHC.TcPlugin.API: UnboxedTuple :: TupleSort
+ GHC.TcPlugin.API: class Monad m => MonadThings (m :: Type -> Type)
+ GHC.TcPlugin.API: data Boxity
+ GHC.TcPlugin.API: data PromotionFlag
+ GHC.TcPlugin.API: data TupleSort
+ GHC.TcPlugin.API: isNumLitTy :: Type -> Maybe Integer
+ GHC.TcPlugin.API: isPromoted :: PromotionFlag -> Bool
+ GHC.TcPlugin.API: isStrLitTy :: Type -> Maybe FastString
+ GHC.TcPlugin.API: lookupDataCon :: MonadThings m => Name -> m DataCon
+ GHC.TcPlugin.API: lookupId :: MonadThings m => Name -> m Id
+ GHC.TcPlugin.API: lookupThing :: MonadThings m => Name -> m TyThing
+ GHC.TcPlugin.API: lookupTyCon :: MonadThings m => Name -> m TyCon
+ GHC.TcPlugin.API: mkNumLitTy :: Integer -> Type
+ GHC.TcPlugin.API: mkStrLitTy :: FastString -> Type
+ GHC.TcPlugin.API: mkUncheckedIntExpr :: Integer -> CoreExpr
+ GHC.TcPlugin.API: mkVisFunTyMany :: Type -> Type -> Type
+ GHC.TcPlugin.API: mkVisFunTysMany :: [Type] -> Type -> Type
+ GHC.TcPlugin.API: splitAppTy_maybe :: Type -> Maybe (Type, Type)
+ GHC.TcPlugin.API: tyConAppTyConPicky_maybe :: Type -> Maybe TyCon
+ GHC.TcPlugin.API: tyConAppTyCon_maybe :: Type -> Maybe TyCon
+ GHC.TcPlugin.API: type Arity = Int
+ GHC.TcPlugin.API: type CoreExpr = Expr CoreBndr
+ GHC.TcPlugin.API.Internal: class Monad m => MonadThings (m :: Type -> Type)
+ GHC.TcPlugin.API.Internal: instance (GHC.Base.Monad (GHC.TcPlugin.API.Internal.TcPluginM s), GHC.TcPlugin.API.Internal.MonadTcPlugin (GHC.TcPlugin.API.Internal.TcPluginM s)) => HscTypes.MonadThings (GHC.TcPlugin.API.Internal.TcPluginM s)
+ GHC.TcPlugin.API.Internal: lookupDataCon :: MonadThings m => Name -> m DataCon
+ GHC.TcPlugin.API.Internal: lookupId :: MonadThings m => Name -> m Id
+ GHC.TcPlugin.API.Internal: lookupThing :: MonadThings m => Name -> m TyThing
+ GHC.TcPlugin.API.Internal: lookupTyCon :: MonadThings m => Name -> m TyCon
Files
- changelog.md +19/−3
- ghc-tcplugin-api.cabal +9/−3
- src/GHC/TcPlugin/API.hs +57/−12
- src/GHC/TcPlugin/API/Internal.hs +13/−0
changelog.md view
@@ -1,13 +1,29 @@ +# Version 0.7.0.0 (2021-12-31) + +- Re-export functions for dealing with type-level literals, + such as `mkNumLitTy` and `isStrLitTy`. + +- Re-export functions for splitting apart type applications, such as + `splitAppTy_maybe` and `tyConAppTyCon_maybe`. + +- Redefine and re-export `mkUncheckedIntExpr` for GHC versions prior to 9.0. + +- Re-export some basic types from `GHC.Types.Basic` such as `Arity`, + `PromotionFlag` and `Boxity`. + +- Re-export `GHC.Builtin.Names` and `GHC.Builin.Types.Prim`. + +- Provide `MonadThings` instances for `TcPluginM` monads. + # Version 0.6.1.0 (2021-12-13) - Re-export various useful types and functions to deal with type and coercion variables. - Re-export a few types and functions to deal with source locations. -- Remove some re-exports for constructing function types: only re-export `mkVisFunTyMany` - and `mkVisFunTysMany`, as these are the only functions that make sense across all - GHC versions. +- Remove some re-exports for constructing function types, as not all functions make sense + across all GHC versions supported by the library. - Re-export `panic` and `pprPanic`.
ghc-tcplugin-api.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ghc-tcplugin-api -version: 0.6.1.0 +version: 0.7.0.0 synopsis: An API for type-checker plugins. license: BSD-3-Clause build-type: Simple @@ -35,7 +35,7 @@ base >= 4.13.0 && < 4.18, ghc - >= 8.8 && < 9.5, + >= 8.8 && < 9.5, transformers >= 0.5 && < 0.6, @@ -59,7 +59,10 @@ GHC.TcPlugin.API.Internal reexported-modules: - GHC.Core.Make + GHC.Builtin.Names + , GHC.Builtin.Types + , GHC.Builtin.Types.Prim + , GHC.Core.Make , GHC.Plugins , GHC.Types.Unique.DFM , GHC.Types.Unique.FM @@ -84,6 +87,7 @@ , PrelNames as GHC.Builtin.Names , TysWiredIn as GHC.Builtin.Types + , TysPrim as GHC.Builtin.Types.Prim , CoreSyn as GHC.Core , CoAxiom as GHC.Core.Coercion.Axiom @@ -114,7 +118,9 @@ , TcType as GHC.Tc.Utils.TcType , TcMType as GHC.Tc.Utils.TcMType + , BasicTypes as GHC.Types.Basic , Id as GHC.Types.Id + , Literal as GHC.Types.Literal , Name as GHC.Types.Name , OccName as GHC.Types.Name.Occurrence , SrcLoc as GHC.Types.SrcLoc
src/GHC/TcPlugin/API.hs view
@@ -276,15 +276,17 @@ -- the values for the class methods. -- -- The class dictionary constructor can be obtained using 'classDataCon'. - -- Functions from "GHC.Core.Make", re-exported here, will be useful for - -- constructing the necessary terms. + -- Functions from "GHC.Core.Make", which is re-exported by this library, + -- will be useful for constructing the necessary terms -- -- For instance, we can apply the class data constructor using 'mkCoreConApps'. -- Remember that the type-level arguments (the typeclass variables) come first, -- before the actual evidence term (the class dictionary expression). , classDataCon - , module GHC.Core.Make +#if !MIN_VERSION_ghc(9,0,0) + , mkUncheckedIntExpr +#endif -- | ==== Class instances @@ -369,11 +371,18 @@ , isTyVarTy, getTyVar_maybe , TcType, TcTyVar, Unique, Kind + -- ** Type literals (natural numbers, type-level strings) + , mkNumLitTy, isNumLitTy + , mkStrLitTy, isStrLitTy + -- ** Creating and decomposing applications - , mkTyConTy, mkTyConApp, splitTyConApp_maybe - , mkAppTy, mkAppTys + , mkTyConTy, mkTyConApp, mkAppTy, mkAppTys + , splitTyConApp_maybe + , tyConAppTyConPicky_maybe, tyConAppTyCon_maybe + , splitAppTy_maybe -- ** Function types + , mkVisFunTyMany, mkVisFunTysMany , mkInvisFunTyMany, mkInvisFunTysMany , mkForAllTy, mkForAllTys , mkPiTy, mkPiTys @@ -417,7 +426,8 @@ -- -- This allows plugins to directly refer to e.g. the promoted data constructor -- 'True' without having to look up its name. - , module GHC.Builtin.Types + -- + -- Refer to "GHC.Builtin.Names", "GHC.Builtin.Types" and "GHC.Builtin.Types.Prim". -- * GHC types @@ -425,8 +435,13 @@ -- | = END OF API DOCUMENTATION, RE-EXPORTS FOLLOW + -- | == Some basic types + + , module GHC.Types.Basic + -- | == Names , Name, OccName, TyThing, TcTyThing + , MonadThings(..) , Class(classTyCon), DataCon, TyCon, Id , FastString @@ -441,7 +456,7 @@ , Coercion, Role(..), UnivCoProvenance , CoercionHole(..) , EvBind, EvTerm(EvExpr), EvVar, EvExpr, EvBindsVar - , Expr(Var, Type, Coercion), CoreBndr + , Expr(Var, Type, Coercion), CoreBndr, CoreExpr , TcEvDest(..) -- | == The type-checking environment @@ -460,9 +475,14 @@ -- ghc import GHC ( TyThing(..) ) +#if !MIN_VERSION_ghc(9,0,0) import GHC.Builtin.Types + ( intDataCon ) +import GHC.Builtin.Types.Prim + ( intPrimTy ) +#endif import GHC.Core - ( CoreBndr, Expr(..) ) + ( CoreBndr, CoreExpr, Expr(..) ) import GHC.Core.Class ( Class(..), FunDep ) import GHC.Core.Coercion @@ -482,7 +502,10 @@ ( FamInstEnv ) import GHC.Core.InstEnv ( InstEnvs(..) ) +#if !MIN_VERSION_ghc(9,0,0) import GHC.Core.Make + ( mkCoreConApps ) +#endif import GHC.Core.Predicate ( EqRel(..) #if MIN_VERSION_ghc(8,10,0) @@ -505,8 +528,10 @@ , UnivCoProvenance(..) #if MIN_VERSION_ghc(9,0,0) , Mult + , mkVisFunTyMany, mkVisFunTysMany , mkInvisFunTyMany, mkInvisFunTysMany #elif MIN_VERSION_ghc(8,10,0) + , mkVisFunTy, mkVisFunTys , mkInvisFunTy, mkInvisFunTys #else , mkFunTy, mkFunTys @@ -520,8 +545,11 @@ ) import GHC.Core.Type ( eqType, mkTyConTy, mkTyConApp, splitTyConApp_maybe + , splitAppTy_maybe + , tyConAppTyConPicky_maybe, tyConAppTyCon_maybe , mkAppTy, mkAppTys, isTyVarTy, getTyVar_maybe , mkCoercionTy, isCoercionTy, isCoercionTy_maybe + , mkNumLitTy, isNumLitTy, mkStrLitTy, isStrLitTy #if MIN_VERSION_ghc(9,0,0) , pattern One, pattern Many #endif @@ -562,8 +590,16 @@ ) import GHC.Tc.Utils.TcMType ( isFilledMetaTyVar_maybe, writeMetaTyVar ) +import GHC.Types.Basic + ( Arity, PromotionFlag(..), isPromoted + , Boxity(..), TupleSort(..) + ) import GHC.Types.Id ( Id, mkLocalId ) +#if !MIN_VERSION_ghc(9,0,0) +import GHC.Types.Literal + ( Literal(..), LitNumType(..) ) +#endif import GHC.Types.Name ( Name ) import GHC.Types.Name.Occurrence @@ -871,23 +907,32 @@ type UniqFM ty a = GHC.UniqFM a +mkUncheckedIntExpr :: Integer -> CoreExpr +mkUncheckedIntExpr i = mkCoreConApps intDataCon [Lit lit] + where + lit = LitNumber LitNumInt i intPrimTy + #if MIN_VERSION_ghc(8,10,0) -mkInvisFunTyMany :: Type -> Type -> Type +mkInvisFunTyMany, mkVisFunTyMany :: Type -> Type -> Type mkInvisFunTyMany = mkInvisFunTy +mkVisFunTyMany = mkVisFunTy -mkInvisFunTysMany :: [Type] -> Type -> Type +mkInvisFunTysMany, mkVisFunTysMany :: [Type] -> Type -> Type mkInvisFunTysMany = mkInvisFunTys +mkVisFunTysMany = mkVisFunTys #else type Pred = PredTree -mkInvisFunTyMany :: Type -> Type -> Type +mkInvisFunTyMany, mkVisFunTyMany :: Type -> Type -> Type mkInvisFunTyMany = mkFunTy +mkVisFunTyMany = mkFunTy -mkInvisFunTysMany :: [Type] -> Type -> Type +mkInvisFunTysMany, mkVisFunTysMany :: [Type] -> Type -> Type mkInvisFunTysMany = mkFunTys +mkVisFunTysMany = mkFunTys mkPiTy :: TyCoBinder -> Type -> Type mkPiTy bndr ty = mkPiTys [bndr] ty
src/GHC/TcPlugin/API/Internal.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingVia #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -50,6 +51,7 @@ , TcPluginM(..) , TcPluginErrorMessage(..) , TcPluginRewriter + , MonadThings(..) , askRewriteEnv , askDeriveds , askEvBinds @@ -127,6 +129,13 @@ 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(..) ) +#endif -- ghc-tcplugin-api #ifndef HAS_REWRITING @@ -528,6 +537,10 @@ errorMsgTy :: GHC.PredType 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.