{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE UndecidableInstances #-}
module GHC.TcPlugin.API
(
TcPlugin(..)
, mkTcPlugin
, TcPluginStage(..), MonadTcPlugin
, TcPluginM
, tcPluginIO
, MonadTcPluginWork
, TcPluginErrorMessage(..)
, mkTcPluginErrorTy
, findImportedModule, resolveImport, fsLit, unpackFS, mkModuleName
, unitIdFS, stringToUnitId, pkgQualToPkgName
, Module, ModuleName, FindResult(..), UnitId, PkgQual
, mkVarOcc, mkDataOcc, mkTyVarOcc, mkTcOcc, mkClsOcc
, lookupOrig
, tcLookupTyCon
, tcLookupDataCon
, tcLookupClass
, tcLookupGlobal
, tcLookup
, tcLookupId
, promoteDataCon
, TcPluginSolver
#if HAS_REWRITING
, TcPluginSolveResult(..)
#else
, TcPluginSolveResult
, pattern TcPluginContradiction, pattern TcPluginOk
#endif
, tcPluginTrace
, mkNonCanonical
, Pred
, pattern ClassPred, pattern EqPred, pattern IrredPred, pattern ForAllPred
, classifyPredType, ctPred
, TyVar, CoVar
, MetaDetails, MetaInfo
, isSkolemTyVar
, isMetaTyVar, isFilledMetaTyVar_maybe
, writeMetaTyVar
, readTcRef, writeTcRef
, eqType
, ctLoc, ctEvidence, ctFlavour, ctEqRel, ctOrigin
, mkPluginUnivCo
, newCoercionHole
, mkReflCo, mkSymCo, mkTransCo, mkUnivCo
, mkCoercionTy, isCoercionTy, isCoercionTy_maybe
, ctEvCoercion
, mkPluginUnivEvTerm
, evDataConApp
, newEvVar, setEvBind
, evCoercion, evCast
, ctEvExpr
, askEvBinds, lookupEvBind, eb_lhs, eb_rhs
, newName, mkLocalId, mkTyVar
, ctev_pred, ctev_evar, ctev_loc, ctev_dest
, classDataCon
#if !MIN_VERSION_ghc(9,0,0)
, mkUncheckedIntExpr
#endif
, getInstEnvs
, newWanted, newGiven
, mkClassPred, mkEqPredRole
, askDeriveds
, setCtLocM
, setCtLocRewriteM
, bumpCtLocDepth
, TcPluginRewriter, TcPluginRewriteResult(..)
, matchFam
, getFamInstEnvs
, FamInstEnv
, askRewriteEnv, rewriteEnvCtLoc, RewriteEnv
, mkTyFamAppReduction, Reduction(..)
, newUnique
, newFlexiTyVar
, isTouchableTcPluginM
, mkTyVarTy, mkTyVarTys
, isTyVarTy, getTyVar_maybe
, TcType, TcTyVar, Unique, Kind
, mkNumLitTy, isNumLitTy
, mkStrLitTy, isStrLitTy
, mkTyConTy, mkTyConApp, mkAppTy, mkAppTys
, splitTyConApp_maybe
, tyConAppTyConPicky_maybe, tyConAppTyCon_maybe
, splitAppTy_maybe, splitAppTys
, mkVisFunTyMany, mkVisFunTysMany
, mkInvisFunTy, mkInvisFunTys
, mkForAllTy, mkForAllTys
, mkPiTy, mkPiTys
#if MIN_VERSION_ghc(9,0,0)
, Mult
, pattern OneTy, pattern ManyTy
#endif
, zonkTcType
, zonkCt
, panic, pprPanic
, UniqDFM
, lookupUDFM, lookupUDFM_Directly, elemUDFM
, UniqFM
, emptyUFM, listToUFM
, getEnvs
, TcS
, InertSet, getInertSet, setInertSet
, getTcEvBindsMap, setTcEvBindsMap
, module GHC.Types.Basic
, Name, OccName, TyThing, TcTyThing
, MonadThings(..)
, Class(classTyCon), DataCon, TyCon, Id
, FastString
, EqRel(..), FunDep, CtFlavour
, Ct, CtLoc, CtEvidence, CtOrigin
, QCInst
, Type, PredType
, InstEnvs, TcLevel
, Coercion, Role(..), UnivCoProvenance
, CoercionHole(..)
, EvBind, EvTerm(EvExpr), EvVar, EvExpr, EvBindsVar
, Expr(Var, Type, Coercion), CoreBndr, CoreExpr
, TcEvDest(..)
, TcGblEnv, TcLclEnv
, GenLocated(..), Located, RealLocated
, unLoc, getLoc
, SDoc, Outputable(..)
)
where
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, CoreExpr, Expr(..) )
import GHC.Core.Class
( Class(..), FunDep )
import GHC.Core.Coercion
( mkReflCo, mkSymCo, mkTransCo
, mkUnivCo
#if !MIN_VERSION_ghc(9,13,0) && MIN_VERSION_ghc(8,10,0)
, mkPrimEqPredRole
#endif
)
import GHC.Core.Coercion.Axiom
( Role(..) )
import GHC.Core.DataCon
( DataCon
, classDataCon, promoteDataCon
)
import GHC.Core.FamInstEnv
( 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(9,13,0)
, mkEqPredRole
#endif
#if MIN_VERSION_ghc(8,10,0)
, Pred(..)
#else
, PredTree(..), TyCoBinder
, mkPrimEqPred, mkReprPrimEqPred
#endif
, classifyPredType, mkClassPred
)
#if HAS_REWRITING
import GHC.Core.Reduction
( Reduction(..) )
#endif
import GHC.Core.TyCon
( TyCon(..) )
#if MIN_VERSION_ghc(9,6,0)
import GHC.Core.TyCo.Compare
( eqType )
#endif
import GHC.Core.TyCo.Rep
( Type, PredType, Kind
, Coercion(..), CoercionHole(..)
, UnivCoProvenance(..)
#if MIN_VERSION_ghc(9,0,0)
, Mult
, mkVisFunTyMany, mkVisFunTysMany
#if MIN_VERSION_ghc(9,6,0)
, mkInvisFunTy, mkInvisFunTys
#else
, mkInvisFunTyMany, mkInvisFunTysMany
#endif
#elif MIN_VERSION_ghc(8,10,0)
, mkVisFunTy, mkVisFunTys
, mkInvisFunTy, mkInvisFunTys
#else
, mkFunTy, mkFunTys
#endif
#if MIN_VERSION_ghc(8,10,0)
, mkPiTy
#endif
, mkPiTys
, mkTyVarTy, mkTyVarTys
, mkForAllTy, mkForAllTys
)
import GHC.Core.Type
( mkTyConTy, mkTyConApp, splitTyConApp_maybe
, splitAppTy_maybe, splitAppTys
, tyConAppTyConPicky_maybe, tyConAppTyCon_maybe
, mkAppTy, mkAppTys, isTyVarTy, getTyVar_maybe
, mkCoercionTy, isCoercionTy, isCoercionTy_maybe
, mkNumLitTy, isNumLitTy, mkStrLitTy, isStrLitTy
#if !MIN_VERSION_ghc(9,6,0)
, eqType
#endif
#if MIN_VERSION_ghc(9,6,0)
, pattern OneTy, pattern ManyTy
#elif MIN_VERSION_ghc(9,0,0)
, pattern One, pattern Many
#endif
)
import GHC.Data.FastString
( FastString, fsLit, unpackFS )
import qualified GHC.Tc.Plugin
as GHC
#if MIN_VERSION_ghc(9,4,0)
import GHC.Tc.Solver.InertSet
( InertSet )
#endif
import GHC.Tc.Solver.Monad
( TcS
#if !MIN_VERSION_ghc(9,4,0)
, InertSet
#endif
#if MIN_VERSION_ghc(9,8,0)
, getInertSet, updInertSet
#else
, getTcSInerts, setTcSInerts
#endif
, getTcEvBindsMap, setTcEvBindsMap
)
import GHC.Tc.Types
( TcTyThing(..), TcGblEnv(..), TcLclEnv(..)
#if HAS_REWRITING
, TcPluginSolveResult(..), TcPluginRewriteResult(..)
, RewriteEnv(..)
#endif
)
#if MIN_VERSION_ghc(9,11,0)
import GHC.Tc.Types.CtLoc
( CtLoc(..), bumpCtLocDepth )
#endif
import GHC.Tc.Types.Constraint
( Ct(..), CtEvidence(..), CtFlavour(..)
, QCInst(..), TcEvDest(..)
, ctPred, ctLoc, ctEvidence, ctEvExpr
, ctEvCoercion
, ctFlavour, ctEqRel, ctOrigin
, mkNonCanonical
#if !MIN_VERSION_ghc(9,11,0)
, CtLoc(..), bumpCtLocDepth
#endif
)
import GHC.Tc.Types.Evidence
( EvBind(..), EvTerm(..), EvExpr, EvBindsVar(..)
, evCoercion, evCast, lookupEvBind, evDataConApp
)
import GHC.Tc.Types.Origin
( CtOrigin(..) )
import GHC.Tc.Utils.Monad
( newName, readTcRef, writeTcRef )
import qualified GHC.Tc.Utils.Monad
as GHC
( traceTc, setCtLocM )
import GHC.Tc.Utils.TcType
( TcType, TcLevel, MetaDetails, MetaInfo
, isSkolemTyVar, isMetaTyVar
)
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
( OccName(..)
, mkVarOcc, mkDataOcc, mkTyVarOcc, mkTcOcc, mkClsOcc
)
#if MIN_VERSION_ghc(9,3,0)
import GHC
( HscEnv )
import GHC.Types.PkgQual
( PkgQual(..) )
import GHC.Rename.Names
( renamePkgQual )
import GHC.Driver.Env
( hsc_unit_env )
import GHC.Unit.Module
( unitIdString )
#elif MIN_VERSION_ghc(9,1,0)
import GHC.Data.FastString
( NonDetFastString(NonDetFastString) )
#endif
import GHC.Types.SrcLoc
( GenLocated(..), Located, RealLocated
, unLoc, getLoc
)
import GHC.Types.Unique
( Unique )
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.Unique.FM as UniqFM
( UniqFM, emptyUFM, listToUFM )
#else
import qualified GHC.Types.Unique.FM as GHC
( UniqFM )
import GHC.Types.Unique.FM as UniqFM
( emptyUFM, listToUFM )
#endif
import GHC.Types.Unique.DFM
( UniqDFM, lookupUDFM, lookupUDFM_Directly, elemUDFM )
import GHC.Types.Var
( TyVar, CoVar, TcTyVar, EvVar
, mkTyVar
)
import GHC.Utils.Outputable
( Outputable(..), SDoc
#if !MIN_VERSION_ghc(9,2,0)
, panic, pprPanic
#endif
)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Utils.Panic
( panic, pprPanic )
#endif
#if MIN_VERSION_ghc(9,2,0)
import GHC.Unit.Finder
( FindResult(..) )
#else
import GHC.Driver.Finder
( FindResult(..) )
#endif
import GHC.Unit.Module
( UnitId, unitIdFS, stringToUnitId, mkModuleName )
#if MIN_VERSION_ghc(9,5,0)
import Language.Haskell.Syntax.Module.Name
( ModuleName )
#else
import GHC.Unit.Module.Name
( ModuleName )
#endif
import GHC.Unit.Types
( Module )
#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,5,0)
import GHC.Utils.Misc
( HasDebugCallStack )
#endif
import Control.Monad.IO.Class
( MonadIO ( liftIO ) )
import GHC.TcPlugin.API.Internal
#ifndef HAS_REWRITING
import GHC.TcPlugin.API.Internal.Shim
#endif
tcPluginIO :: MonadTcPlugin m => IO a -> m a
tcPluginIO :: forall (m :: * -> *) a. MonadTcPlugin m => IO a -> m a
tcPluginIO = TcM a -> m a
forall a. TcM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcM a -> m a
unsafeLiftTcM (TcM a -> m a) -> (IO a -> TcM a) -> IO a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> TcM a
forall a. IO a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
tcPluginTrace :: MonadTcPlugin m
=> String
-> SDoc
-> m ()
tcPluginTrace :: forall (m :: * -> *). MonadTcPlugin m => String -> SDoc -> m ()
tcPluginTrace String
a SDoc
b = TcM () -> m ()
forall a. TcM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcM a -> m a
unsafeLiftTcM (TcM () -> m ()) -> TcM () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> SDoc -> TcM ()
GHC.traceTc String
a SDoc
b
#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,5,0)
pattern OneTy, ManyTy :: Mult
pattern OneTy = One
pattern ManyTy = Many
mkInvisFunTy :: HasDebugCallStack => Type -> Type -> Type
mkInvisFunTy = mkInvisFunTyMany
mkInvisFunTys :: HasDebugCallStack => [Type] -> Type -> Type
mkInvisFunTys = mkInvisFunTysMany
#endif
#if MIN_VERSION_ghc(9,3,0)
#elif MIN_VERSION_ghc(9,1,0)
newtype PkgQual = PkgQual (Maybe NonDetFastString)
deriving stock ( Eq, Ord )
deriving newtype ( Outputable )
getPkgQual :: PkgQual -> Maybe FastString
getPkgQual (PkgQual Nothing) = Nothing
getPkgQual (PkgQual (Just (NonDetFastString pkg))) = Just pkg
#else
newtype PkgQual = PkgQual (Maybe FastString)
deriving stock ( Eq, Ord )
deriving newtype ( Outputable )
getPkgQual :: PkgQual -> Maybe FastString
getPkgQual (PkgQual mPkg) = mPkg
#endif
pkgQualToPkgName :: PkgQual -> Maybe String
#if MIN_VERSION_ghc(9,3,0)
pkgQualToPkgName :: PkgQual -> Maybe String
pkgQualToPkgName PkgQual
NoPkgQual = Maybe String
forall a. Maybe a
Nothing
pkgQualToPkgName (ThisPkg UnitId
unit) = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ UnitId -> String
unitIdString UnitId
unit
pkgQualToPkgName (OtherPkg UnitId
unit) = String -> Maybe String
forall a. a -> Maybe a
Just (String -> Maybe String) -> String -> Maybe String
forall a b. (a -> b) -> a -> b
$ UnitId -> String
unitIdString UnitId
unit
#else
pkgQualToPkgName = fmap unpackFS . getPkgQual
#endif
resolveImport :: MonadTcPlugin m
=> ModuleName
-> Maybe FastString
-> m PkgQual
#if MIN_VERSION_ghc(9,3,0)
resolveImport :: forall (m :: * -> *).
MonadTcPlugin m =>
ModuleName -> Maybe FastString -> m PkgQual
resolveImport ModuleName
mod_name Maybe FastString
mPkg = do
HscEnv
hscEnv <- m HscEnv
forall (m :: * -> *). MonadTcPlugin m => m HscEnv
getTopEnv
PkgQual -> m PkgQual
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (PkgQual -> m PkgQual) -> PkgQual -> m PkgQual
forall a b. (a -> b) -> a -> b
$ UnitEnv -> ModuleName -> Maybe FastString -> PkgQual
renamePkgQual (HscEnv -> UnitEnv
hsc_unit_env HscEnv
hscEnv) ModuleName
mod_name Maybe FastString
mPkg
#elif MIN_VERSION_ghc(9,1,0)
resolveImport _mod_name mPkg = do
return $ PkgQual (NonDetFastString <$> mPkg)
#else
resolveImport _mod_name mPkg = do
return $ PkgQual mPkg
#endif
findImportedModule :: MonadTcPlugin m
=> ModuleName
-> PkgQual
-> m FindResult
#if MIN_VERSION_ghc(9,3,0)
findImportedModule :: forall (m :: * -> *).
MonadTcPlugin m =>
ModuleName -> PkgQual -> m FindResult
findImportedModule ModuleName
mod_name PkgQual
pkg = TcPluginM FindResult -> m FindResult
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM FindResult -> m FindResult)
-> TcPluginM FindResult -> m FindResult
forall a b. (a -> b) -> a -> b
$
ModuleName -> PkgQual -> TcPluginM FindResult
GHC.findImportedModule ModuleName
mod_name PkgQual
pkg
#else
findImportedModule mod_name pkg = liftTcPluginM $
GHC.findImportedModule mod_name (getPkgQual pkg)
#endif
lookupOrig :: MonadTcPlugin m => Module -> OccName -> m Name
lookupOrig :: forall (m :: * -> *).
MonadTcPlugin m =>
Module -> OccName -> m Name
lookupOrig Module
md = TcPluginM Name -> m Name
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Name -> m Name)
-> (OccName -> TcPluginM Name) -> OccName -> m Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> OccName -> TcPluginM Name
GHC.lookupOrig Module
md
tcLookupTyCon :: MonadTcPlugin m => Name -> m TyCon
tcLookupTyCon :: forall (m :: * -> *). MonadTcPlugin m => Name -> m TyCon
tcLookupTyCon = TcPluginM TyCon -> m TyCon
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM TyCon -> m TyCon)
-> (Name -> TcPluginM TyCon) -> Name -> m TyCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM TyCon
GHC.tcLookupTyCon
tcLookupDataCon :: MonadTcPlugin m => Name -> m DataCon
tcLookupDataCon :: forall (m :: * -> *). MonadTcPlugin m => Name -> m DataCon
tcLookupDataCon = TcPluginM DataCon -> m DataCon
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM DataCon -> m DataCon)
-> (Name -> TcPluginM DataCon) -> Name -> m DataCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM DataCon
GHC.tcLookupDataCon
tcLookupClass :: MonadTcPlugin m => Name -> m Class
tcLookupClass :: forall (m :: * -> *). MonadTcPlugin m => Name -> m Class
tcLookupClass = TcPluginM Class -> m Class
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Class -> m Class)
-> (Name -> TcPluginM Class) -> Name -> m Class
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM Class
GHC.tcLookupClass
tcLookupGlobal :: MonadTcPlugin m => Name -> m TyThing
tcLookupGlobal :: forall (m :: * -> *). MonadTcPlugin m => Name -> m TyThing
tcLookupGlobal = TcPluginM TyThing -> m TyThing
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM TyThing -> m TyThing)
-> (Name -> TcPluginM TyThing) -> Name -> m TyThing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM TyThing
GHC.tcLookupGlobal
tcLookup :: MonadTcPlugin m => Name -> m TcTyThing
tcLookup :: forall (m :: * -> *). MonadTcPlugin m => Name -> m TcTyThing
tcLookup = TcPluginM TcTyThing -> m TcTyThing
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM TcTyThing -> m TcTyThing)
-> (Name -> TcPluginM TcTyThing) -> Name -> m TcTyThing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM TcTyThing
GHC.tcLookup
tcLookupId :: MonadTcPlugin m => Name -> m Id
tcLookupId :: forall (m :: * -> *). MonadTcPlugin m => Name -> m Id
tcLookupId = TcPluginM Id -> m Id
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Id -> m Id) -> (Name -> TcPluginM Id) -> Name -> m Id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> TcPluginM Id
GHC.tcLookupId
#if MIN_VERSION_ghc(9,3,0)
getTopEnv :: MonadTcPlugin m => m HscEnv
getTopEnv :: forall (m :: * -> *). MonadTcPlugin m => m HscEnv
getTopEnv = TcPluginM HscEnv -> m HscEnv
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM TcPluginM HscEnv
GHC.getTopEnv
#endif
getEnvs :: MonadTcPlugin m => m ( TcGblEnv, TcLclEnv )
getEnvs :: forall (m :: * -> *). MonadTcPlugin m => m (TcGblEnv, TcLclEnv)
getEnvs = TcPluginM (TcGblEnv, TcLclEnv) -> m (TcGblEnv, TcLclEnv)
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM TcPluginM (TcGblEnv, TcLclEnv)
GHC.getEnvs
getInstEnvs :: MonadTcPlugin m => m InstEnvs
getInstEnvs :: forall (m :: * -> *). MonadTcPlugin m => m InstEnvs
getInstEnvs = TcPluginM InstEnvs -> m InstEnvs
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM TcPluginM InstEnvs
GHC.getInstEnvs
getFamInstEnvs :: MonadTcPlugin m => m ( FamInstEnv, FamInstEnv )
getFamInstEnvs :: forall (m :: * -> *). MonadTcPlugin m => m (FamInstEnv, FamInstEnv)
getFamInstEnvs = TcPluginM (FamInstEnv, FamInstEnv) -> m (FamInstEnv, FamInstEnv)
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM TcPluginM (FamInstEnv, FamInstEnv)
GHC.getFamInstEnvs
matchFam :: MonadTcPlugin m
=> TyCon -> [ TcType ]
-> m ( Maybe Reduction )
matchFam :: forall (m :: * -> *).
MonadTcPlugin m =>
TyCon -> [TcType] -> m (Maybe Reduction)
matchFam TyCon
tycon [TcType]
args =
#ifndef HAS_REWRITING
fmap ( \ (co,ty) -> mkReduction (mkSymCo co) ty ) <$>
#endif
( TcPluginM (Maybe Reduction) -> m (Maybe Reduction)
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM (Maybe Reduction) -> m (Maybe Reduction))
-> TcPluginM (Maybe Reduction) -> m (Maybe Reduction)
forall a b. (a -> b) -> a -> b
$ TyCon -> [TcType] -> TcPluginM (Maybe Reduction)
GHC.matchFam TyCon
tycon [TcType]
args )
newUnique :: MonadTcPlugin m => m Unique
newUnique :: forall (m :: * -> *). MonadTcPlugin m => m Unique
newUnique = TcPluginM Unique -> m Unique
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM TcPluginM Unique
GHC.newUnique
newFlexiTyVar :: MonadTcPlugin m => Kind -> m TcTyVar
newFlexiTyVar :: forall (m :: * -> *). MonadTcPlugin m => TcType -> m Id
newFlexiTyVar = TcPluginM Id -> m Id
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Id -> m Id)
-> (TcType -> TcPluginM Id) -> TcType -> m Id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> TcPluginM Id
GHC.newFlexiTyVar
isTouchableTcPluginM :: MonadTcPlugin m => TcTyVar -> m Bool
isTouchableTcPluginM :: forall (m :: * -> *). MonadTcPlugin m => Id -> m Bool
isTouchableTcPluginM = TcPluginM Bool -> m Bool
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Bool -> m Bool)
-> (Id -> TcPluginM Bool) -> Id -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> TcPluginM Bool
GHC.isTouchableTcPluginM
zonkTcType :: MonadTcPluginWork m => TcType -> m TcType
zonkTcType :: forall (m :: * -> *). MonadTcPluginWork m => TcType -> m TcType
zonkTcType = TcPluginM TcType -> m TcType
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM TcType -> m TcType)
-> (TcType -> TcPluginM TcType) -> TcType -> m TcType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> TcPluginM TcType
GHC.zonkTcType
zonkCt :: MonadTcPluginWork m => Ct -> m Ct
zonkCt :: forall (m :: * -> *). MonadTcPluginWork m => Ct -> m Ct
zonkCt = TcPluginM Ct -> m Ct
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Ct -> m Ct) -> (Ct -> TcPluginM Ct) -> Ct -> m Ct
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ct -> TcPluginM Ct
GHC.zonkCt
newWanted :: MonadTcPluginWork m => CtLoc -> PredType -> m CtEvidence
newWanted :: forall (m :: * -> *).
MonadTcPluginWork m =>
CtLoc -> TcType -> m CtEvidence
newWanted CtLoc
loc TcType
pty =
#if !HAS_REWRITING
setCtLocM loc $
#endif
TcPluginM CtEvidence -> m CtEvidence
forall a. TcPluginM a -> m a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM CtEvidence -> m CtEvidence)
-> TcPluginM CtEvidence -> m CtEvidence
forall a b. (a -> b) -> a -> b
$ CtLoc -> TcType -> TcPluginM CtEvidence
GHC.newWanted CtLoc
loc TcType
pty
newGiven :: CtLoc -> PredType -> EvExpr -> TcPluginM Solve CtEvidence
newGiven :: CtLoc -> TcType -> EvExpr -> TcPluginM 'Solve CtEvidence
newGiven CtLoc
loc TcType
pty EvExpr
evtm = do
#if HAS_REWRITING
EvBindsVar
tc_evbinds <- TcPluginM 'Solve EvBindsVar
askEvBinds
TcPluginM CtEvidence -> TcPluginM 'Solve CtEvidence
forall a. TcPluginM a -> TcPluginM 'Solve a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM CtEvidence -> TcPluginM 'Solve CtEvidence)
-> TcPluginM CtEvidence -> TcPluginM 'Solve CtEvidence
forall a b. (a -> b) -> a -> b
$ EvBindsVar -> CtLoc -> TcType -> EvExpr -> TcPluginM CtEvidence
GHC.newGiven EvBindsVar
tc_evbinds CtLoc
loc TcType
pty EvExpr
evtm
#else
liftTcPluginM $ GHC.newGiven loc pty evtm
#endif
rewriteEnvCtLoc :: RewriteEnv -> CtLoc
rewriteEnvCtLoc :: RewriteEnv -> CtLoc
rewriteEnvCtLoc =
#if MIN_VERSION_ghc(9,3,0)
RewriteEnv -> CtLoc
re_loc
#else
fe_loc
#endif
setCtLocM :: MonadTcPluginWork m => CtLoc -> m a -> m a
setCtLocM :: forall (m :: * -> *) a. MonadTcPluginWork m => CtLoc -> m a -> m a
setCtLocM CtLoc
loc = (TcM a -> TcM a) -> m a -> m a
forall (m :: * -> *) a b.
MonadTcPlugin m =>
(TcM a -> TcM b) -> m a -> m b
unsafeLiftThroughTcM ( CtLoc -> TcM a -> TcM a
forall a. CtLoc -> TcM a -> TcM a
GHC.setCtLocM CtLoc
loc )
setCtLocRewriteM :: TcPluginM Rewrite a -> TcPluginM Rewrite a
setCtLocRewriteM :: forall a. TcPluginM 'Rewrite a -> TcPluginM 'Rewrite a
setCtLocRewriteM TcPluginM 'Rewrite a
ma = do
CtLoc
rewriteCtLoc <- RewriteEnv -> CtLoc
rewriteEnvCtLoc (RewriteEnv -> CtLoc)
-> TcPluginM 'Rewrite RewriteEnv -> TcPluginM 'Rewrite CtLoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcPluginM 'Rewrite RewriteEnv
askRewriteEnv
CtLoc -> TcPluginM 'Rewrite a -> TcPluginM 'Rewrite a
forall (m :: * -> *) a. MonadTcPluginWork m => CtLoc -> m a -> m a
setCtLocM CtLoc
rewriteCtLoc TcPluginM 'Rewrite a
ma
newEvVar :: PredType -> TcPluginM Solve EvVar
newEvVar :: TcType -> TcPluginM 'Solve Id
newEvVar = TcPluginM Id -> TcPluginM 'Solve Id
forall a. TcPluginM a -> TcPluginM 'Solve a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM Id -> TcPluginM 'Solve Id)
-> (TcType -> TcPluginM Id) -> TcType -> TcPluginM 'Solve Id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> TcPluginM Id
GHC.newEvVar
newCoercionHole :: PredType -> TcPluginM Solve CoercionHole
newCoercionHole :: TcType -> TcPluginM 'Solve CoercionHole
newCoercionHole = TcPluginM CoercionHole -> TcPluginM 'Solve CoercionHole
forall a. TcPluginM a -> TcPluginM 'Solve a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM CoercionHole -> TcPluginM 'Solve CoercionHole)
-> (TcType -> TcPluginM CoercionHole)
-> TcType
-> TcPluginM 'Solve CoercionHole
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> TcPluginM CoercionHole
GHC.newCoercionHole
setEvBind :: EvBind -> TcPluginM Solve ()
setEvBind :: EvBind -> TcPluginM 'Solve ()
setEvBind EvBind
ev_bind = do
#if HAS_REWRITING
EvBindsVar
tc_evbinds <- TcPluginM 'Solve EvBindsVar
askEvBinds
TcPluginM () -> TcPluginM 'Solve ()
forall a. TcPluginM a -> TcPluginM 'Solve a
forall (m :: * -> *) a. MonadTcPlugin m => TcPluginM a -> m a
liftTcPluginM (TcPluginM () -> TcPluginM 'Solve ())
-> TcPluginM () -> TcPluginM 'Solve ()
forall a b. (a -> b) -> a -> b
$ EvBindsVar -> EvBind -> TcPluginM ()
GHC.setEvBind EvBindsVar
tc_evbinds EvBind
ev_bind
#else
liftTcPluginM $ GHC.setEvBind ev_bind
#endif
mkPluginUnivCo
:: String
-> Role
-> [Coercion]
-> TcType
-> TcType
-> Coercion
mkPluginUnivCo :: String -> Role -> [Coercion] -> TcType -> TcType -> Coercion
mkPluginUnivCo String
str Role
role [Coercion]
_deps TcType
lhs TcType
rhs =
UnivCoProvenance -> Role -> TcType -> TcType -> Coercion
mkUnivCo
( String -> UnivCoProvenance
PluginProv String
str )
#if MIN_VERSION_ghc(9,12,0)
_deps
#endif
Role
role
TcType
lhs
TcType
rhs
mkPluginUnivEvTerm
:: String
-> Role
-> [Coercion]
-> TcType
-> TcType
-> EvTerm
mkPluginUnivEvTerm :: String -> Role -> [Coercion] -> TcType -> TcType -> EvTerm
mkPluginUnivEvTerm String
str Role
role [Coercion]
deps TcType
lhs TcType
rhs =
Coercion -> EvTerm
evCoercion (Coercion -> EvTerm) -> Coercion -> EvTerm
forall a b. (a -> b) -> a -> b
$ String -> Role -> [Coercion] -> TcType -> TcType -> Coercion
mkPluginUnivCo String
str Role
role [Coercion]
deps TcType
lhs TcType
rhs
mkTyFamAppReduction
:: String
-> Role
-> [Coercion]
-> TyCon
-> [TcType]
-> TcType
-> Reduction
mkTyFamAppReduction :: String
-> Role -> [Coercion] -> TyCon -> [TcType] -> TcType -> Reduction
mkTyFamAppReduction String
str Role
role [Coercion]
deps TyCon
tc [TcType]
args TcType
ty =
Coercion -> TcType -> Reduction
Reduction ( String -> Role -> [Coercion] -> TcType -> TcType -> Coercion
mkPluginUnivCo String
str Role
role [Coercion]
deps ( TyCon -> [TcType] -> TcType
mkTyConApp TyCon
tc [TcType]
args ) TcType
ty ) TcType
ty
#if !MIN_VERSION_ghc(9,0,0)
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)
mkVisFunTyMany :: Type -> Type -> Type
mkVisFunTyMany = mkVisFunTy
mkVisFunTysMany :: [Type] -> Type -> Type
mkVisFunTysMany = mkVisFunTys
#else
type Pred = PredTree
mkInvisFunTy, mkVisFunTyMany :: Type -> Type -> Type
mkInvisFunTy = mkFunTy
mkVisFunTyMany = mkFunTy
mkInvisFunTys, mkVisFunTysMany :: [Type] -> Type -> Type
mkInvisFunTys = mkFunTys
mkVisFunTysMany = mkFunTys
mkPiTy :: TyCoBinder -> Type -> Type
mkPiTy bndr ty = mkPiTys [bndr] ty
#endif
#endif
#if !MIN_VERSION_ghc(9,13,0)
mkEqPredRole :: Role -> Type -> Type -> PredType
#if MIN_VERSION_ghc(8,10,0)
mkEqPredRole :: Role -> TcType -> TcType -> TcType
mkEqPredRole = Role -> TcType -> TcType -> TcType
mkPrimEqPredRole
#else
mkEqPredRole Nominal = mkPrimEqPred
mkEqPredRole Representational = mkReprPrimEqPred
mkEqPredRole Phantom = panic "mkPrimEqPredRole phantom"
#endif
#endif
#if MIN_VERSION_ghc(9,8,0)
setInertSet :: InertSet -> TcS ()
setInertSet inerts = updInertSet ( const inerts )
#elif !MIN_VERSION_ghc(9,8,0)
getInertSet :: TcS InertSet
getInertSet :: TcS InertSet
getInertSet = TcS InertSet
getTcSInerts
setInertSet :: InertSet -> TcS ()
setInertSet :: InertSet -> TcS ()
setInertSet = InertSet -> TcS ()
setTcSInerts
#endif