{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE UndecidableInstances #-}
#if !MIN_VERSION_ghc(8,11,0)
{-# OPTIONS_GHC -Wno-orphans #-}
#endif
module GHC.TcPlugin.API
(
TcPlugin(..)
, mkTcPlugin
, TcPluginStage(..), MonadTcPlugin
, TcPluginM
, MonadTcPluginWork
, TcPluginErrorMessage(..)
, mkTcPluginErrorTy
, lookupTHName
, 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, nonDetCmpType
, ctLoc, ctEvidence, ctFlavour, ctEqRel, ctOrigin
, ctEvPred, ctEvId, ctEvExpr, ctEvLoc
, isGiven, isWanted
, isEqPred, isEqClassPred
, className, tyConName
, mkPluginUnivCo
, newCoercionHole
, mkReflCo, mkSymCo, mkTransCo, mkUnivCo
, mkCoercionTy, isCoercionTy, isCoercionTy_maybe
, ctEvCoercion
, mkPluginUnivEvTerm
, evDFunApp, evDataConApp
, newEvVar, setEvBind
, evId, evCoercion, evCast
, askEvBinds, lookupEvBind, eb_lhs, eb_rhs
, newName, mkLocalId, mkTyVar
, 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
, natKind, symbolKind, charKind
, mkTyConTy, mkTyConApp, mkAppTy, mkAppTys
, splitTyConApp_maybe
, tyConAppTyConPicky_maybe, tyConAppTyCon_maybe
, splitAppTy_maybe, splitAppTys
, isNewTyCon, dataConTyCon
, tyConDataCons, tyConSingleDataCon_maybe, tyConSingleDataCon
, isNewDataCon
, mkVisFunTyMany, mkVisFunTysMany
, mkInvisFunTy, mkInvisFunTys
, mkForAllTy, mkForAllTys
, mkPiTy, mkPiTys
, typeKind
#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 Prelude
hiding ( cos )
#if !MIN_VERSION_ghc(8,11,0)
import Data.List.NonEmpty
( NonEmpty(..) )
#endif
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
( Class(..), FunDep )
import GHC.Core.Coercion
( mkReflCo, mkSymCo, mkTransCo
, mkUnivCo, isReflCo
#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, dataConWrapId
, dataConTyCon
#if MIN_VERSION_ghc(9,1,0)
, isNewDataCon
#endif
)
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(..), tyConClass_maybe
, tyConDataCons, tyConSingleDataCon_maybe, tyConSingleDataCon
, isNewTyCon
)
#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
, typeKind
#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 )
#if MIN_VERSION_ghc(9,5,0)
import GHC.Plugins
( thNameToGhcNameIO )
#else
import Data.Maybe
( listToMaybe )
#if MIN_VERSION_ghc(9,3,0)
import GHC.Iface.Env
( lookupNameCache )
#else
import GHC.Iface.Env
( lookupOrigIO )
#endif
import GHC.ThToHs
( thRdrNameGuesses )
import GHC.Types.Name
( isExternalName )
import GHC.Types.Name.Reader
( isExact_maybe, isOrig_maybe )
import GHC.Utils.Monad
( mapMaybeM )
#endif
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 )
#else
import GHC.Tc.Types.Constraint
( CtLoc(..), bumpCtLocDepth )
#endif
#if MIN_VERSION_ghc(9,13,0)
import GHC.Tc.Types.Constraint
( GivenCtEvidence(..) )
#endif
import GHC.Tc.Types.Constraint
( Ct(..), CtEvidence(..), CtFlavour(..)
, QCInst(..), TcEvDest(..)
, ctPred, ctLoc, ctEvidence, ctEvExpr
, ctEvCoercion
, ctFlavour, ctEqRel, ctOrigin
, ctEvFlavour, ctEvPred, ctEvLoc
, mkNonCanonical, ctEvId
)
import GHC.Tc.Types.Evidence
( EvBind(..), EvTerm(..), EvExpr, EvBindsVar(..)
, evCoercion, lookupEvBind
, mkGivenEvBind, evId
)
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
, nonDetCmpType
)
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,1,0)
import GHC.Driver.Env.Types
( HscEnv )
#else
import GHC.Driver.Types
( HscEnv )
#endif
#if MIN_VERSION_ghc(9,3,0)
import GHC.Driver.Env.Types
( hsc_unit_env, hsc_NC )
import GHC.Types.PkgQual
( PkgQual(..) )
import GHC.Rename.Names
( renamePkgQual )
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, DFunId
)
import GHC.Utils.Outputable
( Outputable(..), SDoc, text )
#if MIN_VERSION_ghc(9,2,0)
import GHC.Utils.Panic
( panic, pprPanic )
#else
import GHC.Utils.Outputable
( 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 GHC.TcPlugin.API.Internal
#ifndef HAS_REWRITING
import GHC.TcPlugin.API.Internal.Shim
#endif
import qualified Language.Haskell.TH as TH
import Control.Monad.IO.Class
( MonadIO ( 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
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
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
isGiven :: CtEvidence -> Bool
isGiven :: CtEvidence -> Bool
isGiven CtEvidence
ev = case CtEvidence -> CtFlavour
ctEvFlavour CtEvidence
ev of
Given {} -> Bool
True
CtFlavour
_ -> Bool
False
isWanted :: CtEvidence -> Bool
isWanted :: CtEvidence -> Bool
isWanted CtEvidence
ev = case CtEvidence -> CtFlavour
ctEvFlavour CtEvidence
ev of
Wanted {} -> Bool
True
CtFlavour
_ -> Bool
False
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 -> EvTerm -> TcPluginM Solve CtEvidence
newGiven :: CtLoc -> TcType -> EvTerm -> TcPluginM 'Solve CtEvidence
newGiven CtLoc
loc TcType
pty EvTerm
evtm = do
Id
new_ev <- TcType -> TcPluginM 'Solve Id
newEvVar TcType
pty
EvBind -> TcPluginM 'Solve ()
setEvBind (EvBind -> TcPluginM 'Solve ()) -> EvBind -> TcPluginM 'Solve ()
forall a b. (a -> b) -> a -> b
$ Id -> EvTerm -> EvBind
mkGivenEvBind Id
new_ev EvTerm
evtm
CtEvidence -> TcPluginM 'Solve CtEvidence
forall a. a -> TcPluginM 'Solve a
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> TcPluginM 'Solve CtEvidence)
-> CtEvidence -> TcPluginM 'Solve CtEvidence
forall a b. (a -> b) -> a -> b
$
CtGiven
#if MIN_VERSION_ghc(9,13,0)
$ GivenCt
#endif
{ ctev_pred :: TcType
ctev_pred = TcType
pty
, ctev_evar :: Id
ctev_evar = Id
new_ev
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc
}
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,1,0)
isNewDataCon :: DataCon -> Bool
isNewDataCon dc = isNewTyCon (dataConTyCon dc)
#endif
#if !MIN_VERSION_ghc(8,11,0)
instance Outputable a => Outputable (NonEmpty a) where
ppr (x :| xs) = ppr (x : xs)
#endif
#if MIN_VERSION_ghc(9,8,0)
setInertSet :: InertSet -> TcS ()
setInertSet :: InertSet -> TcS ()
setInertSet InertSet
inerts = (InertSet -> InertSet) -> TcS ()
updInertSet ( InertSet -> InertSet -> InertSet
forall a b. a -> b -> a
const InertSet
inerts )
#elif !MIN_VERSION_ghc(9,8,0)
getInertSet :: TcS InertSet
getInertSet = getTcSInerts
setInertSet :: InertSet -> TcS ()
setInertSet = setTcSInerts
#endif
lookupTHName :: ( Monad (TcPluginM s), MonadTcPlugin (TcPluginM s) )
=> TH.Name -> TcPluginM s Name
lookupTHName :: forall (s :: TcPluginStage).
(Monad (TcPluginM s), MonadTcPlugin (TcPluginM s)) =>
Name -> TcPluginM s Name
lookupTHName Name
thNm = do
HscEnv
hscEnv <- TcPluginM s HscEnv
forall (m :: * -> *). MonadTcPlugin m => m HscEnv
getTopEnv
Maybe Name
mbNm <-
IO (Maybe Name) -> TcPluginM s (Maybe Name)
forall a. IO a -> TcPluginM s a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Name) -> TcPluginM s (Maybe Name))
-> IO (Maybe Name) -> TcPluginM s (Maybe Name)
forall a b. (a -> b) -> a -> b
$
NameCache -> Name -> IO (Maybe Name)
thNameToGhcNameIO
#if MIN_VERSION_ghc(9,6,0)
(HscEnv -> NameCache
hsc_NC HscEnv
hscEnv)
#else
hscEnv
#endif
Name
thNm
case Maybe Name
mbNm of
Just Name
nm ->
Name -> TcPluginM s Name
forall a. a -> TcPluginM s a
forall (m :: * -> *) a. Monad m => a -> m a
return Name
nm
Maybe Name
Nothing ->
String -> SDoc -> TcPluginM s Name
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"lookupTHName: lookup failed" (String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
thNm)
evDFunApp :: DFunId -> [Type] -> [EvExpr] -> EvExpr
evDFunApp :: Id -> [TcType] -> [EvExpr] -> EvExpr
evDFunApp Id
df [TcType]
tys [EvExpr]
ets = Id -> EvExpr
forall b. Id -> Expr b
Var Id
df EvExpr -> [TcType] -> EvExpr
forall b. Expr b -> [TcType] -> Expr b
`mkTyApps` [TcType]
tys EvExpr -> [EvExpr] -> EvExpr
forall b. Expr b -> [Expr b] -> Expr b
`mkApps` [EvExpr]
ets
evDataConApp :: DataCon -> [Type] -> [EvExpr] -> EvExpr
evDataConApp :: DataCon -> [TcType] -> [EvExpr] -> EvExpr
evDataConApp DataCon
dc [TcType]
tys [EvExpr]
ets = Id -> [TcType] -> [EvExpr] -> EvExpr
evDFunApp (DataCon -> Id
dataConWrapId DataCon
dc) [TcType]
tys [EvExpr]
ets
evCast :: EvExpr -> Coercion -> EvExpr
evCast :: EvExpr -> Coercion -> EvExpr
evCast EvExpr
et Coercion
co | Coercion -> Bool
isReflCo Coercion
co = EvExpr
et
| Bool
otherwise = EvExpr -> Coercion -> EvExpr
forall b. Expr b -> Coercion -> Expr b
Cast EvExpr
et Coercion
co
natKind, symbolKind, charKind :: Type
natKind :: TcType
natKind =
#if MIN_VERSION_ghc(9,1,0)
TcType
naturalTy
#else
typeNatKind
#endif
symbolKind :: TcType
symbolKind = TcType
typeSymbolKind
charKind :: TcType
charKind = TcType
charTy
isEqPred :: PredType -> Bool
isEqPred :: TcType -> Bool
isEqPred TcType
pty
| Just TyCon
tc <- TcType -> Maybe TyCon
tyConAppTyCon_maybe TcType
pty
= TyCon
tc TyCon -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
eqPrimTyConKey Bool -> Bool -> Bool
|| TyCon
tc TyCon -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
eqReprPrimTyConKey
| Bool
otherwise
= Bool
False
isEqClassPred :: PredType -> Bool
isEqClassPred :: TcType -> Bool
isEqClassPred TcType
pty
| Just TyCon
tc <- TcType -> Maybe TyCon
tyConAppTyCon_maybe TcType
pty
, Just Class
cls <- TyCon -> Maybe Class
tyConClass_maybe TyCon
tc
= Class
cls Class -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
heqTyConKey
Bool -> Bool -> Bool
|| Class
cls Class -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
eqTyConKey
Bool -> Bool -> Bool
|| Class
cls Class -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
coercibleTyConKey
| Bool
otherwise
= Bool
False
#if !MIN_VERSION_ghc(9,6,0)
thNameToGhcNameIO :: HscEnv -> TH.Name -> IO (Maybe Name)
thNameToGhcNameIO hscEnv th_name
= do { names <- mapMaybeM do_lookup (thRdrNameGuesses th_name)
; return (listToMaybe names) }
where
do_lookup rdr_name
| Just n <- isExact_maybe rdr_name
= return $ if isExternalName n then Just n else Nothing
| Just (rdr_mod, rdr_occ) <- isOrig_maybe rdr_name
#if MIN_VERSION_ghc(9,3,0)
= Just <$> lookupNameCache (hsc_NC hscEnv) rdr_mod rdr_occ
#else
= Just <$> lookupOrigIO hscEnv rdr_mod rdr_occ
#endif
| otherwise
= return Nothing
#endif