packages feed

ghc-tcplugin-api 0.11.0.0 → 0.12.0.0

raw patch · 3 files changed

+71/−21 lines, 3 filesdep ~basedep ~ghcPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, ghc

API changes (from Hackage documentation)

- GHC.TcPlugin.API: instance GHC.Classes.Eq GHC.TcPlugin.API.PkgQual
- GHC.TcPlugin.API: instance GHC.Classes.Ord GHC.TcPlugin.API.PkgQual
- GHC.TcPlugin.API: instance GHC.Utils.Outputable.Outputable GHC.TcPlugin.API.PkgQual
- GHC.TcPlugin.API: type FamInstEnv = UniqDFM TyCon FamilyInstEnv
- GHC.TcPlugin.API.Names: Generically1 :: f a -> Generically1 (f :: k -> Type) (a :: k)
- GHC.TcPlugin.API.Names: instance (GHC.Generics.Generic (f 'GHC.TcPlugin.API.Names.Named), GHC.Generics.Generic (f 'GHC.TcPlugin.API.Names.Resolved), GHC.TcPlugin.API.Names.GTraversableC GHC.TcPlugin.API.Names.ResolveName (GHC.Generics.Rep (f 'GHC.TcPlugin.API.Names.Named)) (GHC.Generics.Rep (f 'GHC.TcPlugin.API.Names.Resolved))) => GHC.TcPlugin.API.Names.ResolveNames (GHC.TcPlugin.API.Names.Generically1 f)
+ GHC.TcPlugin.API: TcPluginSolveResult :: [Ct] -> [(EvTerm, Ct)] -> [Ct] -> TcPluginSolveResult
+ GHC.TcPlugin.API: [tcPluginInsolubleCts] :: TcPluginSolveResult -> [Ct]
+ GHC.TcPlugin.API: [tcPluginNewCts] :: TcPluginSolveResult -> [Ct]
+ GHC.TcPlugin.API: [tcPluginSolvedCts] :: TcPluginSolveResult -> [(EvTerm, Ct)]
+ GHC.TcPlugin.API: ctEvId :: HasDebugCallStack => Ct -> EvVar
+ GHC.TcPlugin.API: data () => FamInstEnv
+ GHC.TcPlugin.API: emptyDVarSet :: DVarSet
+ GHC.TcPlugin.API: extendDVarSet :: DVarSet -> Var -> DVarSet
+ GHC.TcPlugin.API: mkDVarSet :: [Var] -> DVarSet
+ GHC.TcPlugin.API: type DVarSet = UniqDSet Var
+ GHC.TcPlugin.API: unionDVarSet :: DVarSet -> DVarSet -> DVarSet
+ GHC.TcPlugin.API: unitDVarSet :: Var -> DVarSet
+ GHC.TcPlugin.API.Names: [Generically1] :: forall {k} (f :: k -> Type) (a :: k). f a -> Generically1 f a
+ GHC.TcPlugin.API.Names: instance (GHC.Generics.Generic (f 'GHC.TcPlugin.API.Names.Named), GHC.Generics.Generic (f 'GHC.TcPlugin.API.Names.Resolved), GHC.TcPlugin.API.Names.GTraversableC GHC.TcPlugin.API.Names.ResolveName (GHC.Generics.Rep (f 'GHC.TcPlugin.API.Names.Named)) (GHC.Generics.Rep (f 'GHC.TcPlugin.API.Names.Resolved))) => GHC.TcPlugin.API.Names.ResolveNames (GHC.Generics.Generically1 f)
- GHC.TcPlugin.API: class Outputable a
+ GHC.TcPlugin.API: class () => Outputable a
- GHC.TcPlugin.API: ctEvExpr :: CtEvidence -> EvExpr
+ GHC.TcPlugin.API: ctEvExpr :: HasDebugCallStack => CtEvidence -> EvExpr
- GHC.TcPlugin.API: data Boxity
+ GHC.TcPlugin.API: data () => Boxity
- GHC.TcPlugin.API: data Class
+ GHC.TcPlugin.API: data () => Class
- GHC.TcPlugin.API: data Coercion
+ GHC.TcPlugin.API: data () => Coercion
- GHC.TcPlugin.API: data CoercionHole
+ GHC.TcPlugin.API: data () => CoercionHole
- GHC.TcPlugin.API: data Ct
+ GHC.TcPlugin.API: data () => Ct
- GHC.TcPlugin.API: data CtEvidence
+ GHC.TcPlugin.API: data () => CtEvidence
- GHC.TcPlugin.API: data CtFlavour
+ GHC.TcPlugin.API: data () => CtFlavour
- GHC.TcPlugin.API: data CtLoc
+ GHC.TcPlugin.API: data () => CtLoc
- GHC.TcPlugin.API: data CtOrigin
+ GHC.TcPlugin.API: data () => CtOrigin
- GHC.TcPlugin.API: data DataCon
+ GHC.TcPlugin.API: data () => DataCon
- GHC.TcPlugin.API: data EqRel
+ GHC.TcPlugin.API: data () => EqRel
- GHC.TcPlugin.API: data EvBind
+ GHC.TcPlugin.API: data () => EvBind
- GHC.TcPlugin.API: data EvBindsVar
+ GHC.TcPlugin.API: data () => EvBindsVar
- GHC.TcPlugin.API: data EvTerm
+ GHC.TcPlugin.API: data () => EvTerm
- GHC.TcPlugin.API: data Expr b
+ GHC.TcPlugin.API: data () => Expr b
- GHC.TcPlugin.API: data FastString
+ GHC.TcPlugin.API: data () => FastString
- GHC.TcPlugin.API: data FindResult
+ GHC.TcPlugin.API: data () => FindResult
- GHC.TcPlugin.API: data GenLocated l e
+ GHC.TcPlugin.API: data () => GenLocated l e
- GHC.TcPlugin.API: data InertSet
+ GHC.TcPlugin.API: data () => InertSet
- GHC.TcPlugin.API: data InstEnvs
+ GHC.TcPlugin.API: data () => InstEnvs
- GHC.TcPlugin.API: data MetaDetails
+ GHC.TcPlugin.API: data () => MetaDetails
- GHC.TcPlugin.API: data MetaInfo
+ GHC.TcPlugin.API: data () => MetaInfo
- GHC.TcPlugin.API: data ModuleName
+ GHC.TcPlugin.API: data () => ModuleName
- GHC.TcPlugin.API: data Name
+ GHC.TcPlugin.API: data () => Name
- GHC.TcPlugin.API: data OccName
+ GHC.TcPlugin.API: data () => OccName
- GHC.TcPlugin.API: data PkgQual
+ GHC.TcPlugin.API: data () => PkgQual
- GHC.TcPlugin.API: data Pred
+ GHC.TcPlugin.API: data () => Pred
- GHC.TcPlugin.API: data PromotionFlag
+ GHC.TcPlugin.API: data () => PromotionFlag
- GHC.TcPlugin.API: data QCInst
+ GHC.TcPlugin.API: data () => QCInst
- GHC.TcPlugin.API: data Reduction
+ GHC.TcPlugin.API: data () => Reduction
- GHC.TcPlugin.API: data RewriteEnv
+ GHC.TcPlugin.API: data () => RewriteEnv
- GHC.TcPlugin.API: data Role
+ GHC.TcPlugin.API: data () => Role
- GHC.TcPlugin.API: data SDoc
+ GHC.TcPlugin.API: data () => SDoc
- GHC.TcPlugin.API: data TcEvDest
+ GHC.TcPlugin.API: data () => TcEvDest
- GHC.TcPlugin.API: data TcGblEnv
+ GHC.TcPlugin.API: data () => TcGblEnv
- GHC.TcPlugin.API: data TcLclEnv
+ GHC.TcPlugin.API: data () => TcLclEnv
- GHC.TcPlugin.API: data TcLevel
+ GHC.TcPlugin.API: data () => TcLevel
- GHC.TcPlugin.API: data TcPluginRewriteResult
+ GHC.TcPlugin.API: data () => TcPluginRewriteResult
- GHC.TcPlugin.API: data TcPluginSolveResult
+ GHC.TcPlugin.API: data () => TcPluginSolveResult
- GHC.TcPlugin.API: data TcS a
+ GHC.TcPlugin.API: data () => TcS a
- GHC.TcPlugin.API: data TcTyThing
+ GHC.TcPlugin.API: data () => TcTyThing
- GHC.TcPlugin.API: data TupleSort
+ GHC.TcPlugin.API: data () => TupleSort
- GHC.TcPlugin.API: data TyCon
+ GHC.TcPlugin.API: data () => TyCon
- GHC.TcPlugin.API: data TyThing
+ GHC.TcPlugin.API: data () => TyThing
- GHC.TcPlugin.API: data Type
+ GHC.TcPlugin.API: data () => Type
- GHC.TcPlugin.API: data UniqDFM key ele
+ GHC.TcPlugin.API: data () => UniqDFM key ele
- GHC.TcPlugin.API: data UniqFM key ele
+ GHC.TcPlugin.API: data () => UniqFM key ele
- GHC.TcPlugin.API: data Unique
+ GHC.TcPlugin.API: data () => Unique
- GHC.TcPlugin.API: data UnitId
+ GHC.TcPlugin.API: data () => UnitId
- GHC.TcPlugin.API: data UnivCoProvenance
+ GHC.TcPlugin.API: data () => UnivCoProvenance
- GHC.TcPlugin.API: infixr 3 `mkVisFunTyMany`
+ GHC.TcPlugin.API: infixr 3 `mkInvisFunTy`
- GHC.TcPlugin.API: mkForAllTy :: TyCoVar -> ArgFlag -> Type -> Type
+ GHC.TcPlugin.API: mkForAllTy :: ForAllTyBinder -> Type -> Type
- GHC.TcPlugin.API: mkForAllTys :: [TyCoVarBinder] -> Type -> Type
+ GHC.TcPlugin.API: mkForAllTys :: [ForAllTyBinder] -> Type -> Type
- GHC.TcPlugin.API: mkPiTy :: TyCoBinder -> Type -> Type
+ GHC.TcPlugin.API: mkPiTy :: PiTyBinder -> Type -> Type
- GHC.TcPlugin.API: mkPiTys :: [TyCoBinder] -> Type -> Type
+ GHC.TcPlugin.API: mkPiTys :: [PiTyBinder] -> Type -> Type
- GHC.TcPlugin.API: mkPluginUnivCo :: String -> Role -> TcType -> TcType -> Coercion
+ GHC.TcPlugin.API: mkPluginUnivCo :: String -> Role -> DVarSet -> TcType -> TcType -> Coercion
- GHC.TcPlugin.API: mkPluginUnivEvTerm :: String -> Role -> TcType -> TcType -> EvTerm
+ GHC.TcPlugin.API: mkPluginUnivEvTerm :: String -> Role -> DVarSet -> TcType -> TcType -> EvTerm
- GHC.TcPlugin.API: mkTyFamAppReduction :: String -> Role -> TyCon -> [TcType] -> TcType -> Reduction
+ GHC.TcPlugin.API: mkTyFamAppReduction :: String -> Role -> DVarSet -> TyCon -> [TcType] -> TcType -> Reduction
- GHC.TcPlugin.API: mkVisFunTyMany :: Type -> Type -> Type
+ GHC.TcPlugin.API: mkVisFunTyMany :: HasDebugCallStack => Type -> Type -> Type
- GHC.TcPlugin.API: panic :: String -> a
+ GHC.TcPlugin.API: panic :: HasCallStack => String -> a
- GHC.TcPlugin.API: type TcPluginRewriter = [Ct] " Givens" -> [Type] " Type family arguments (saturated)" -> TcPluginM Rewrite TcPluginRewriteResult
+ GHC.TcPlugin.API: type TcPluginRewriter = -- | Givens [Ct] -> -- | Type family arguments (saturated) [Type] -> TcPluginM Rewrite TcPluginRewriteResult
- GHC.TcPlugin.API: type TcPluginSolver = [Ct] " Givens" -> [Ct] " Wanteds" -> TcPluginM Solve TcPluginSolveResult
+ GHC.TcPlugin.API: type TcPluginSolver = -- | Givens [Ct] -> -- | Wanteds [Ct] -> TcPluginM Solve TcPluginSolveResult
- GHC.TcPlugin.API: writeMetaTyVar :: TcTyVar -> TcType -> TcM ()
+ GHC.TcPlugin.API: writeMetaTyVar :: HasDebugCallStack => TcTyVar -> TcType -> TcM ()
- GHC.TcPlugin.API.Internal: type TcPluginRewriter = [Ct] " Givens" -> [Type] " Type family arguments (saturated)" -> TcPluginM Rewrite TcPluginRewriteResult
+ GHC.TcPlugin.API.Internal: type TcPluginRewriter = -- | Givens [Ct] -> -- | Type family arguments (saturated) [Type] -> TcPluginM Rewrite TcPluginRewriteResult
- GHC.TcPlugin.API.Internal: type TcPluginSolver = [Ct] " Givens" -> [Ct] " Wanteds" -> TcPluginM Solve TcPluginSolveResult
+ GHC.TcPlugin.API.Internal: type TcPluginSolver = -- | Givens [Ct] -> -- | Wanteds [Ct] -> TcPluginM Solve TcPluginSolveResult
- GHC.TcPlugin.API.Names: newtype Generically1 (f :: k -> Type) (a :: k)
+ GHC.TcPlugin.API.Names: newtype () => Generically1 (f :: k -> Type) (a :: k)

Files

changelog.md view
@@ -1,3 +1,18 @@+# Version 0.12.0.0 (2024-22-10)
+
+- Add support for GHC 9.12.
+
+- `mkPluginUnivCo`, `mkPluginUnivEvTerm` and `mkTyFamAppReduction` now all take
+  an additional `DVarSet` argument which allows specifying evidence that we
+  depend on. This stops evidence terms being floated out past used enclosing
+  Givens (see [GHC issue #23923](https://gitlab.haskell.org/ghc/ghc/-/issues/23923)).
+
+- Re-export `DVarSet`, `emptyDVarSet`, `extendDVarSet`, `unionDVarSet`,
+  `unitDVarSet`, and `mkDVarSet`, as well as `ctEvId`, in order to facilitate
+  construction and manipulation of `DVarSet`s.
+
+- Re-export `GHC.Types.Unique.Set`, `GHC.Types.Unique.DSet`.
+
 # Version 0.11.0.0 (2023-08-29)
 
 - Add support for GHC 9.8.
ghc-tcplugin-api.cabal view
@@ -1,12 +1,12 @@ cabal-version:  3.0
 name:           ghc-tcplugin-api
-version:        0.11.0.0
+version:        0.12.0.0
 synopsis:       An API for type-checker plugins.
 license:        BSD-3-Clause
 build-type:     Simple
 author:         Sam Derbyshire
 maintainer:     Sam Derbyshire
-copyright:      2021-2023 Sam Derbyshire
+copyright:      2021-2024 Sam Derbyshire
 homepage:       https://github.com/sheaf/ghc-tcplugin-api
 category:       Type System, GHC, Plugin
 description:
@@ -33,11 +33,11 @@ 
   build-depends:
     base
-      >= 4.13.0 && < 4.20,
+      >= 4.13.0 && < 4.22,
     containers
-      >= 0.6    && < 0.7,
+      >= 0.6    && < 0.8,
     ghc
-      >= 8.8    && < 9.9,
+      >= 8.8    && < 9.13,
     transformers
       >= 0.5    && < 0.7,
 
@@ -68,6 +68,8 @@     , GHC.Plugins
     , GHC.Types.Unique.DFM
     , GHC.Types.Unique.FM
+    , GHC.Types.Unique.Set
+    , GHC.Types.Unique.DSet
     , GHC.Utils.Outputable
 
   if impl(ghc >= 9.3.0)
@@ -126,7 +128,9 @@         , SrcLoc     as GHC.Types.SrcLoc
         , Unique     as GHC.Types.Unique
         , UniqDFM    as GHC.Types.Unique.DFM
+        , UniqDSet   as GHC.Types.Unique.DSet
         , UniqFM     as GHC.Types.Unique.FM
+        , UniqSet    as GHC.Types.Unique.Set
         , Var        as GHC.Types.Var
         , VarEnv     as GHC.Types.Var.Env
         , VarSet     as GHC.Types.Var.Set
src/GHC/TcPlugin/API.hs view
@@ -246,6 +246,7 @@     -- | == Some further functions for inspecting constraints
   , eqType
   , ctLoc, ctEvidence, ctFlavour, ctEqRel, ctOrigin
+  , ctEvId
 
     -- ** Constraint evidence
 
@@ -259,6 +260,20 @@   , mkReflCo, mkSymCo, mkTransCo, mkUnivCo
   , mkCoercionTy, isCoercionTy, isCoercionTy_maybe
 
+    -- *** Depending on outer Givens
+
+    -- | When a plugin returns a coercion that depends on outer Given constraints,
+    -- it should declare this dependency using the 'DVarSet' argument to
+    -- functions such as 'mkPluginUnivCo', 'mkPluginUnivEvTerm' and 'mkTyFamAppReduction'
+    -- in order to avoid this coercion getting floated out past such enclosing
+    -- Givens.
+    --
+    -- You can use 'ctEvId' to obtain the evidence variable corresponding to
+    -- a Given constraint, and functions such as 'emptyDVarSet', 'unitDVarSet',
+    -- 'unionDVarSet' and 'extendDVarSet' to construct the appropriate 'DVarSet's.
+  , DVarSet
+  , emptyDVarSet, unitDVarSet, unionDVarSet, extendDVarSet, mkDVarSet
+
     -- *** Evidence terms
 
     -- | Typeclass constraints have a different notion of evidence: evidence terms.
@@ -611,7 +626,7 @@ import GHC.Tc.Types.Constraint
   ( Ct(..), CtLoc(..), CtEvidence(..), CtFlavour(..)
   , QCInst(..), TcEvDest(..)
-  , ctPred, ctLoc, ctEvidence, ctEvExpr
+  , ctPred, ctLoc, ctEvidence, ctEvId, ctEvExpr
   , ctFlavour, ctEqRel, ctOrigin
   , bumpCtLocDepth
   , mkNonCanonical
@@ -649,6 +664,11 @@   ( OccName(..)
   , mkVarOcc, mkDataOcc, mkTyVarOcc, mkTcOcc, mkClsOcc
   )
+import GHC.Types.Var.Set
+  ( mkDVarSet, emptyDVarSet, extendDVarSet
+  , unitDVarSet, extendDVarSet, unionDVarSet
+  , DVarSet
+  )
 #if MIN_VERSION_ghc(9,3,0)
 import GHC
   ( HscEnv )
@@ -1007,12 +1027,20 @@ -- The plugin is responsible for not emitting any unsound coercions,
 -- such as a coercion between 'Int' and 'Float'.
 mkPluginUnivCo
-  :: String -- ^ Name of equality (for the plugin's internal use, or for debugging)
+  :: String  -- ^ Name of equality (for the plugin's internal use, or for debugging)
   -> Role
-  -> TcType -- ^ LHS
-  -> TcType -- ^ RHS
+  -> DVarSet -- ^ Evidence that this proof term depends on (use e.g. 'ctEvId' for a Given)
+  -> TcType  -- ^ LHS
+  -> TcType  -- ^ RHS
   -> Coercion
-mkPluginUnivCo str role lhs rhs = mkUnivCo ( PluginProv str ) role lhs rhs
+mkPluginUnivCo str role _deps lhs rhs =
+  let prov =
+        PluginProv
+          str
+#if MIN_VERSION_ghc(9,11,0)
+          _deps
+#endif
+  in mkUnivCo prov role lhs rhs
 
 -- | Conjure up an evidence term for an equality between two types
 -- at the given 'Role' ('Nominal' or 'Representational').
@@ -1022,12 +1050,14 @@ -- The plugin is responsible for not emitting any unsound equalities,
 -- such as an equality between 'Int' and 'Float'.
 mkPluginUnivEvTerm
-  :: String -- ^ Name of equality (for the plugin's internal use, or for debugging)
+  :: String  -- ^ Name of equality (for the plugin's internal use, or for debugging)
   -> Role
-  -> TcType -- ^ LHS
-  -> TcType -- ^ RHS
+  -> DVarSet -- ^ Evidence that this proof term depends on (use e.g. 'ctEvId' for a Given)
+  -> TcType  -- ^ LHS
+  -> TcType  -- ^ RHS
   -> EvTerm
-mkPluginUnivEvTerm str role lhs rhs = evCoercion $ mkPluginUnivCo str role lhs rhs
+mkPluginUnivEvTerm str role deps lhs rhs =
+  evCoercion $ mkPluginUnivCo str role deps lhs rhs
 
 -- | Provide a rewriting of a saturated type family application
 -- at the given 'Role' ('Nominal' or 'Representational').
@@ -1035,14 +1065,15 @@ -- The result can be passed to 'TcPluginRewriteTo' to specify the outcome
 -- of rewriting a type family application.
 mkTyFamAppReduction
-  :: String   -- ^ Name of reduction (for debugging)
-  -> Role     -- ^ Role of reduction ('Nominal' or 'Representational')
-  -> TyCon    -- ^ Type family 'TyCon'
-  -> [TcType] -- ^ Type family arguments
-  -> TcType   -- ^ The type that the type family application reduces to
+  :: String    -- ^ Name of reduction (for debugging)
+  -> Role      -- ^ Role of reduction ('Nominal' or 'Representational')
+  -> DVarSet   -- ^ Evidence that this reduction depends on (use e.g. 'ctEvId' for a Given)
+  -> TyCon     -- ^ Type family 'TyCon'
+  -> [TcType]  -- ^ Type family arguments
+  -> TcType    -- ^ The type that the type family application reduces to
   -> Reduction
-mkTyFamAppReduction str role tc args ty =
-  Reduction ( mkPluginUnivCo str role ( mkTyConApp tc args ) ty ) ty
+mkTyFamAppReduction str role deps tc args ty =
+  Reduction ( mkPluginUnivCo str role deps ( mkTyConApp tc args ) ty ) ty
 
 --------------------------------------------------------------------------------