{-# LANGUAGE CPP, FlexibleInstances, PatternGuards, PatternSynonyms #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances, ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module GHC.TypeLits.Presburger.Compat (module GHC.TypeLits.Presburger.Compat) where
import Data.Function (on)
import GHC.TcPluginM.Extra as GHC.TypeLits.Presburger.Compat (evByFiat, lookupModule, lookupName,
tracePlugin)
import Data.Generics.Twins
#if MIN_VERSION_ghc(9,0,0)
import GHC.Builtin.Names as GHC.TypeLits.Presburger.Compat (gHC_TYPENATS)
#if MIN_VERSION_ghc(9,4,1)
import GHC.Tc.Types as GHC.TypeLits.Presburger.Compat (TcPlugin (..), TcPluginSolveResult (..))
import GHC.Builtin.Types as GHC.TypeLits.Presburger.Compat (cTupleTyCon, cTupleDataCon)
import GHC.Tc.Types.Evidence as GHC.TypeLits.Presburger.Compat (evCast)
import GHC.Plugins as GHC.TypeLits.Presburger.Compat (mkUnivCo)
import GHC.Core.TyCo.Rep as GHC.TypeLits.Presburger.Compat (UnivCoProvenance(..))
import GHC.Core.DataCon as GHC.TypeLits.Presburger.Compat (dataConWrapId)
#else
import GHC.Tc.Types as GHC.TypeLits.Presburger.Compat (TcPlugin (..), TcPluginResult (..))
#endif
#if MIN_VERSION_ghc(9,4,1)
import GHC.Builtin.Names as GHC.TypeLits.Presburger.Compat (mkBaseModule, gHC_TYPEERROR)
import GHC.Core.Reduction (reductionReducedType)
#else
import GHC.Builtin.Names as GHC.TypeLits.Presburger.Compat (dATA_TYPE_EQUALITY)
import qualified GHC.Builtin.Names as Old
#endif
import GHC.Hs as GHC.TypeLits.Presburger.Compat (HsModule(..), NoExtField(..))
import GHC.Hs.ImpExp as GHC.TypeLits.Presburger.Compat (ImportDecl(..), ImportDeclQualifiedStyle(..))
import GHC.Hs.Extension as GHC.TypeLits.Presburger.Compat (GhcPs)
import GHC.Builtin.Types as GHC.TypeLits.Presburger.Compat
( boolTyCon,
eqTyConName,
promotedEQDataCon,
promotedGTDataCon,
promotedLTDataCon,
)
import qualified GHC.Builtin.Types as TysWiredIn
import GHC.Builtin.Types.Literals as GHC.TypeLits.Presburger.Compat
import GHC.Core.Class as GHC.TypeLits.Presburger.Compat (className, classTyCon)
import GHC.Core.FamInstEnv as GHC.TypeLits.Presburger.Compat
import GHC.Core.Predicate as GHC.TypeLits.Presburger.Compat (EqRel (..), Pred (..), isEqPred, mkPrimEqPredRole)
import qualified GHC.Core.Predicate as Old (classifyPredType)
import GHC.Core.TyCo.Rep as GHC.TypeLits.Presburger.Compat (TyLit (NumTyLit), Type (..))
import GHC.Core.TyCon as GHC.TypeLits.Presburger.Compat
import qualified GHC.Core.Type as Old
import GHC.Core.Unify as Old (tcUnifyTy)
import GHC.Unit.Types (Module, UnitId, toUnitId)
import GHC.Unit.Types as GHC.TypeLits.Presburger.Compat (mkModule)
import GHC.Data.FastString as GHC.TypeLits.Presburger.Compat (FastString, fsLit, unpackFS)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Driver.Env.Types as GHC.TypeLits.Presburger.Compat (HscEnv (hsc_dflags))
#else
import GHC.Driver.Types as GHC.TypeLits.Presburger.Compat (HscEnv (hsc_dflags))
import GHC.Driver.Session (unitState)
#endif
import GHC.Plugins (InScopeSet, Outputable, emptyUFM, moduleUnit, Unit, Name)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Hs as GHC.TypeLits.Presburger.Compat (HsParsedModule(..))
import GHC.Types.TyThing as GHC.TypeLits.Presburger.Compat (lookupTyCon)
import GHC.Builtin.Types (naturalTy)
#else
import GHC.Plugins as GHC.TypeLits.Presburger.Compat
( HsParsedModule(..),
lookupTyCon,
typeNatKind
)
#endif
import GHC.Plugins as GHC.TypeLits.Presburger.Compat
( PackageName (..),isStrLitTy, isNumLitTy,
nilDataCon, consDataCon,
Hsc,
Plugin (..),
TCvSubst (..),
TvSubstEnv,
TyVar,
defaultPlugin,
emptyTCvSubst,
eqType,
mkTcOcc,
mkTyConTy,
mkTyVarTy,
ppr,
promotedFalseDataCon,
promotedTrueDataCon,
purePlugin,
splitTyConApp,
splitTyConApp_maybe,
text,
tyConAppTyCon_maybe,
typeKind,
unionTCvSubst,
)
import GHC.Tc.Plugin (lookupOrig)
import GHC.Core.InstEnv as GHC.TypeLits.Presburger.Compat (classInstances)
#if MIN_VERSION_ghc(9,2,0)
import GHC.Tc.Plugin (unsafeTcPluginTcM)
import GHC.Utils.Logger (getLogger)
import Data.Functor ((<&>))
import GHC.Unit.Types as GHC.TypeLits.Presburger.Compat (IsBootInterface(..))
#else
import GHC.Driver.Types as GHC.TypeLits.Presburger.Compat (IsBootInterface(..))
#endif
import GHC.Tc.Plugin as GHC.TypeLits.Presburger.Compat
( TcPluginM,
getInstEnvs,
newFlexiTyVar,
getTopEnv,
lookupOrig,
newFlexiTyVar,
newWanted,
matchFam,
tcLookupClass,
tcLookupTyCon,
tcPluginIO,
tcPluginTrace,
)
import GHC.Tc.Types as GHC.TypeLits.Presburger.Compat (TcPlugin (..))
import GHC.Tc.Types.Constraint as GHC.TypeLits.Presburger.Compat
( Ct,
CtEvidence,
ctEvPred,
ctEvidence,
isWanted,
)
import GHC.Tc.Types.Evidence as GHC.TypeLits.Presburger.Compat (EvTerm)
import GHC.Tc.Utils.TcType (TcTyVar, TcType)
import GHC.Tc.Utils.TcType as GHC.TypeLits.Presburger.Compat (tcTyFamInsts)
import qualified GHC.TcPluginM.Extra as Extra
import GHC.Types.Name.Occurrence as GHC.TypeLits.Presburger.Compat (emptyOccSet, mkInstTyTcOcc)
import GHC.Types.Unique as GHC.TypeLits.Presburger.Compat (getKey, getUnique)
import GHC.Unit.Module as GHC.TypeLits.Presburger.Compat (ModuleName, mkModuleName)
import GHC.Unit.State as GHC.TypeLits.Presburger.Compat (lookupPackageName)
import GHC.Unit.State (initUnits, UnitState (preloadUnits))
import GHC.Unit.Types (UnitId(..), fsToUnit, toUnitId)
import GHC.Utils.Outputable as GHC.TypeLits.Presburger.Compat (showSDocUnsafe)
#else
import Class as GHC.TypeLits.Presburger.Compat (classTyCon, className)
import FastString as GHC.TypeLits.Presburger.Compat (FastString, fsLit, unpackFS)
import GhcPlugins (InScopeSet, Outputable, emptyUFM, InstalledUnitId(..), initPackages, Name)
import GhcPlugins as GHC.TypeLits.Presburger.Compat (PackageName (..), fsToUnitId, lookupPackageName, lookupTyCon, mkTcOcc, mkTyConTy, ppr, promotedFalseDataCon, promotedTrueDataCon, text, tyConAppTyCon_maybe, typeKind, typeNatKind)
import HscTypes as GHC.TypeLits.Presburger.Compat (HscEnv (hsc_dflags))
import Module as GHC.TypeLits.Presburger.Compat (ModuleName, mkModuleName, mkModule)
import Module (Module, UnitId)
import OccName as GHC.TypeLits.Presburger.Compat (emptyOccSet, mkInstTyTcOcc)
import Outputable as GHC.TypeLits.Presburger.Compat (showSDocUnsafe)
import Plugins as GHC.TypeLits.Presburger.Compat (Plugin (..), defaultPlugin)
import PrelNames as GHC.TypeLits.Presburger.Compat (gHC_TYPENATS, dATA_TYPE_EQUALITY)
import qualified PrelNames as Old
import TcEvidence as GHC.TypeLits.Presburger.Compat (EvTerm)
import TcHsType as GHC.TypeLits.Presburger.Compat (tcInferApps)
import TcPluginM as GHC.TypeLits.Presburger.Compat
( TcPluginM,
getTopEnv,
lookupOrig,
matchFam,
newFlexiTyVar,
newWanted,
tcLookupClass,
tcLookupTyCon,
tcPluginIO,
tcPluginTrace,
)
import TcRnMonad as GHC.TypeLits.Presburger.Compat (TcPluginResult (..))
import TcRnTypes as GHC.TypeLits.Presburger.Compat (TcPlugin (..))
import TcType as GHC.TypeLits.Presburger.Compat (tcTyFamInsts)
import TcTypeNats as GHC.TypeLits.Presburger.Compat
import TyCoRep ()
import TyCoRep as GHC.TypeLits.Presburger.Compat (TyLit (NumTyLit), Type (..))
import TyCon as GHC.TypeLits.Presburger.Compat
import Type as GHC.TypeLits.Presburger.Compat (TCvSubst (..), TvSubstEnv, emptyTCvSubst, eqType, mkTyVarTy, splitTyConApp, splitTyConApp_maybe, unionTCvSubst)
import qualified Type as Old
import TysWiredIn as GHC.TypeLits.Presburger.Compat
( boolTyCon,
promotedEQDataCon,
promotedGTDataCon,
promotedLTDataCon,
)
import Unify as Old (tcUnifyTy)
import Unique as GHC.TypeLits.Presburger.Compat (getKey, getUnique)
import Var as GHC.TypeLits.Presburger.Compat (TyVar)
#if MIN_VERSION_ghc(8,4,1)
import TcType (TcTyVar, TcType)
import qualified GHC.TcPluginM.Extra as Extra
import qualified GHC
#else
import Data.Maybe
import TcPluginM (zonkCt)
import TcRnTypes (cc_ev, ctev_pred)
#endif
#if MIN_VERSION_ghc(8,6,0)
import Plugins as GHC.TypeLits.Presburger.Compat (purePlugin)
#endif
#if MIN_VERSION_ghc(8,8,1)
import Name
import TysWiredIn as GHC.TypeLits.Presburger.Compat (eqTyConName)
import qualified TysWiredIn
#else
import PrelNames as GHC.TypeLits.Presburger.Compat (eqTyConName)
#endif
#if MIN_VERSION_ghc(8,10,1)
import Predicate as GHC.TypeLits.Presburger.Compat (EqRel (..), Pred(..))
import Predicate as GHC.TypeLits.Presburger.Compat (isEqPred)
import GHC (NoExtField(..))
import qualified Predicate as Old (classifyPredType)
import Predicate as GHC.TypeLits.Presburger.Compat (mkPrimEqPredRole)
import Constraint as GHC.TypeLits.Presburger.Compat
(Ct, ctEvidence, CtEvidence, ctEvPred, isWanted)
#else
import GHC (NoExt(..))
import GhcPlugins as GHC.TypeLits.Presburger.Compat (EqRel (..), PredTree (..))
import GhcPlugins as GHC.TypeLits.Presburger.Compat (isEqPred)
import qualified GhcPlugins as Old (classifyPredType)
import TcRnMonad as GHC.TypeLits.Presburger.Compat (Ct, isWanted)
import Type as GHC.TypeLits.Presburger.Compat (mkPrimEqPredRole)
import TcRnTypes as GHC.TypeLits.Presburger.Compat (ctEvPred, ctEvidence)
#endif
#endif
#if !MIN_VERSION_ghc(9,4,1)
type TcPluginSolveResult = TcPluginResult
#endif
#if MIN_VERSION_ghc(9,4,1)
dATA_TYPE_EQUALITY :: Module
dATA_TYPE_EQUALITY = mkBaseModule "Data.Type.Equality"
#endif
#if MIN_VERSION_ghc(8,10,1)
type PredTree = Pred
#endif
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 800
data TvSubst = TvSubst InScopeSet TvSubstEnv
instance Outputable TvSubst where
ppr :: TvSubst -> SDoc
ppr = forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. TvSubst -> TCvSubst
toTCv
emptyTvSubst :: TvSubst
emptyTvSubst :: TvSubst
emptyTvSubst = case TCvSubst
emptyTCvSubst of
TCvSubst InScopeSet
set TvSubstEnv
tvsenv CvSubstEnv
_ -> InScopeSet -> TvSubstEnv -> TvSubst
TvSubst InScopeSet
set TvSubstEnv
tvsenv
toTCv :: TvSubst -> TCvSubst
toTCv :: TvSubst -> TCvSubst
toTCv (TvSubst InScopeSet
set TvSubstEnv
tvenv) = InScopeSet -> TvSubstEnv -> CvSubstEnv -> TCvSubst
TCvSubst InScopeSet
set TvSubstEnv
tvenv forall key elt. UniqFM key elt
emptyUFM
substTy :: TvSubst -> Type -> Type
substTy :: TvSubst -> Type -> Type
substTy TvSubst
tvs = HasCallStack => TCvSubst -> Type -> Type
Old.substTy (TvSubst -> TCvSubst
toTCv TvSubst
tvs)
unionTvSubst :: TvSubst -> TvSubst -> TvSubst
unionTvSubst :: TvSubst -> TvSubst -> TvSubst
unionTvSubst TvSubst
s1 TvSubst
s2 =
TCvSubst -> TvSubst
fromTCv forall a b. (a -> b) -> a -> b
$ TCvSubst -> TCvSubst -> TCvSubst
unionTCvSubst (TvSubst -> TCvSubst
toTCv TvSubst
s1) (TvSubst -> TCvSubst
toTCv TvSubst
s2)
fromTCv :: TCvSubst -> TvSubst
fromTCv :: TCvSubst -> TvSubst
fromTCv (TCvSubst InScopeSet
set TvSubstEnv
tvsenv CvSubstEnv
_) = InScopeSet -> TvSubstEnv -> TvSubst
TvSubst InScopeSet
set TvSubstEnv
tvsenv
promotedBoolTyCon :: TyCon
promotedBoolTyCon :: TyCon
promotedBoolTyCon = TyCon
boolTyCon
viewFunTy :: Type -> Maybe (Type, Type)
viewFunTy :: Type -> Maybe (Type, Type)
viewFunTy t :: Type
t@(TyConApp TyCon
_ [Type
t1, Type
t2])
| Type -> Bool
Old.isFunTy Type
t = forall a. a -> Maybe a
Just (Type
t1, Type
t2)
viewFunTy Type
_ = forall a. Maybe a
Nothing
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 802
#else
pattern FunTy :: Type -> Type -> Type
pattern FunTy t1 t2 <- (viewFunTy -> Just (t1, t2)) where
FunTy t1 t2 = Old.mkFunTy t1 t2
#endif
tcUnifyTy :: Type -> Type -> Maybe TvSubst
tcUnifyTy :: Type -> Type -> Maybe TvSubst
tcUnifyTy Type
t1 Type
t2 = TCvSubst -> TvSubst
fromTCv forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> Type -> Maybe TCvSubst
Old.tcUnifyTy Type
t1 Type
t2
getEqTyCon :: TcPluginM TyCon
getEqTyCon :: TcPluginM TyCon
getEqTyCon =
#if MIN_VERSION_ghc(8,8,1)
forall (m :: * -> *) a. Monad m => a -> m a
return TyCon
TysWiredIn.eqTyCon
#else
tcLookupTyCon Old.eqTyConName
#endif
#else
eqType :: Type -> Type -> Bool
eqType = (==)
getEqTyCon :: TcPluginM TyCon
getEqTyCon = return Old.eqTyCon
#endif
getEqWitnessTyCon :: TcPluginM TyCon
getEqWitnessTyCon :: TcPluginM TyCon
getEqWitnessTyCon = do
Module
md <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Equality") (String -> FastString
fsLit String
"base")
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
md (String -> OccName
mkTcOcc String
":~:")
decompFunTy :: Type -> [Type]
#if MIN_VERSION_ghc(9,0,0)
decompFunTy :: Type -> [Type]
decompFunTy (FunTy AnonArgFlag
_ Type
_ Type
t1 Type
t2) = Type
t1 forall a. a -> [a] -> [a]
: Type -> [Type]
decompFunTy Type
t2
#else
#if MIN_VERSION_ghc(8,10,1)
decompFunTy (FunTy _ t1 t2) = t1 : decompFunTy t2
#else
decompFunTy (FunTy t1 t2) = t1 : decompFunTy t2
#endif
#endif
decompFunTy Type
t = [Type
t]
newtype TypeEq = TypeEq { TypeEq -> Type
runTypeEq :: Type }
instance Eq TypeEq where
== :: TypeEq -> TypeEq -> Bool
(==) = forall a. Data a => a -> a -> Bool
geq forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` TypeEq -> Type
runTypeEq
instance Ord TypeEq where
compare :: TypeEq -> TypeEq -> Ordering
compare = forall a. Data a => a -> a -> Ordering
gcompare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` TypeEq -> Type
runTypeEq
isTrivial :: Old.PredType -> Bool
isTrivial :: Type -> Bool
isTrivial Type
ty =
case Type -> PredTree
classifyPredType Type
ty of
EqPred EqRel
_ Type
l Type
r -> Type
l Type -> Type -> Bool
`eqType` Type
r
PredTree
_ -> Bool
False
normaliseGivens
:: [Ct] -> TcPluginM [Ct]
normaliseGivens :: [Ct] -> TcPluginM [Ct]
normaliseGivens =
#if MIN_VERSION_ghc(8,4,1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> Bool
isTrivial forall b c a. (b -> c) -> (a -> b) -> a -> c
. CtEvidence -> Type
ctEvPred forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ct -> CtEvidence
ctEvidence))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a] -> [a]
(++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. a -> a
id forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Ct] -> [Ct]
Extra.flattenGivens
#else
mapM zonkCt
#endif
#if MIN_VERSION_ghc(8,4,1)
type Substitution = [(TcTyVar, TcType)]
#else
type Substitution = TvSubst
#endif
subsCt :: Substitution -> Ct -> Ct
subsCt :: Substitution -> Ct -> Ct
subsCt =
#if MIN_VERSION_ghc(8,4,1)
Substitution -> Ct -> Ct
Extra.substCt
#else
\subst ct ->
ct { cc_ev = (cc_ev ct) {ctev_pred = substTy subst (ctev_pred (cc_ev ct))}
}
#endif
subsType :: Substitution -> Type -> Type
subsType :: Substitution -> Type -> Type
subsType =
#if MIN_VERSION_ghc(8,4,1)
Substitution -> Type -> Type
Extra.substType
#else
substTy
#endif
mkSubstitution :: [Ct] -> Substitution
mkSubstitution :: [Ct] -> Substitution
mkSubstitution =
#if MIN_VERSION_ghc(8,4,1)
forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Ct] -> [((TcTyVar, Type), Ct)]
Extra.mkSubst'
#else
foldr (unionTvSubst . genSubst) emptyTvSubst
#endif
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 804
genSubst :: Ct -> TvSubst
genSubst ct = case classifyPredType (ctEvPred . ctEvidence $ ct) of
EqPred NomEq t u -> fromMaybe emptyTvSubst $ GHC.TypeLits.Presburger.Compat.tcUnifyTy t u
_ -> emptyTvSubst
#endif
classifyPredType :: Type -> PredTree
classifyPredType :: Type -> PredTree
classifyPredType Type
ty = case Type -> PredTree
Old.classifyPredType Type
ty of
e :: PredTree
e@EqPred{} -> PredTree
e
ClassPred Class
cls [Type
_,Type
t1,Type
t2]
| Class -> Name
className Class
cls forall a. Eq a => a -> a -> Bool
== Name
eqTyConName
-> EqRel -> Type -> Type -> PredTree
EqPred EqRel
NomEq Type
t1 Type
t2
PredTree
e -> PredTree
e
#if MIN_VERSION_ghc(9,0,0)
fsToUnitId :: FastString -> UnitId
fsToUnitId :: FastString -> UnitId
fsToUnitId = Unit -> UnitId
toUnitId forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> Unit
fsToUnit
#endif
type RawUnitId = FastString
preloadedUnitsM :: TcPluginM [FastString]
#if MIN_VERSION_ghc(9,4,0)
preloadedUnitsM = do
logger <- unsafeTcPluginTcM getLogger
dflags <- hsc_dflags <$> getTopEnv
packs <- tcPluginIO $ initUnits logger dflags Nothing mempty <&>
\(_, us, _, _ ) -> preloadUnits us
let packNames = map (\(UnitId p) -> p) packs
tcPluginTrace "pres: packs" $ ppr packNames
pure packNames
#elif MIN_VERSION_ghc(9,2,0)
preloadedUnitsM :: TcPluginM [FastString]
preloadedUnitsM = do
Logger
logger <- forall a. TcM a -> TcPluginM a
unsafeTcPluginTcM forall (m :: * -> *). HasLogger m => m Logger
getLogger
DynFlags
dflags <- HscEnv -> DynFlags
hsc_dflags forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcPluginM HscEnv
getTopEnv
[UnitId]
packs <- forall a. IO a -> TcPluginM a
tcPluginIO forall a b. (a -> b) -> a -> b
$ Logger
-> DynFlags
-> Maybe [UnitDatabase UnitId]
-> IO
([UnitDatabase UnitId], UnitState, HomeUnit,
Maybe PlatformConstants)
initUnits Logger
logger DynFlags
dflags forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\([UnitDatabase UnitId]
_, UnitState
us, HomeUnit
_, Maybe PlatformConstants
_ ) -> UnitState -> [UnitId]
preloadUnits UnitState
us
let packNames :: [FastString]
packNames = forall a b. (a -> b) -> [a] -> [b]
map (\(UnitId FastString
p) -> FastString
p) [UnitId]
packs
String -> SDoc -> TcPluginM ()
tcPluginTrace String
"pres: packs" forall a b. (a -> b) -> a -> b
$ forall a. Outputable a => a -> SDoc
ppr [FastString]
packNames
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FastString]
packNames
#elif MIN_VERSION_ghc(9,0,0)
preloadedUnitsM = do
dflags <- hsc_dflags <$> getTopEnv
packs <- tcPluginIO $ preloadUnits . unitState <$> initUnits dflags
let packNames = map (\(UnitId p) -> p) packs
tcPluginTrace "pres: packs" $ ppr packNames
pure packNames
#else
preloadedUnitsM = do
dflags <- hsc_dflags <$> getTopEnv
(_, packs) <- tcPluginIO $ initPackages dflags
let packNames = map (\(InstalledUnitId p) -> p) packs
tcPluginTrace "pres: packs" $ ppr packNames
pure packNames
#endif
#if MIN_VERSION_ghc(9,0,0)
type ModuleUnit = Unit
moduleUnit' :: Module -> ModuleUnit
moduleUnit' :: Module -> Unit
moduleUnit' = forall unit. GenModule unit -> unit
moduleUnit
#else
type ModuleUnit = UnitId
moduleUnit' :: Module -> ModuleUnit
moduleUnit' = GHC.moduleUnitId
#endif
#if !MIN_VERSION_ghc(8,10,1)
type NoExtField = NoExt
#endif
noExtField :: NoExtField
#if MIN_VERSION_ghc(8,10,1)
noExtField :: NoExtField
noExtField = NoExtField
NoExtField
#else
noExtField = NoExt
#endif
#if MIN_VERSION_ghc(9,0,1)
type HsModule' = HsModule
#else
type HsModule' = GHC.HsModule GHC.GhcPs
#endif
#if !MIN_VERSION_ghc(9,0,1)
type IsBootInterface = Bool
pattern NotBoot :: IsBootInterface
pattern NotBoot = False
pattern IsBoot :: IsBootInterface
pattern IsBoot = True
{-# COMPLETE NotBoot, IsBoot #-}
#endif
#if MIN_VERSION_ghc(9,2,0)
typeNatKind :: TcType
typeNatKind :: Type
typeNatKind = Type
naturalTy
#endif
mtypeNatLeqTyCon :: Maybe TyCon
#if MIN_VERSION_ghc(9,2,0)
mtypeNatLeqTyCon :: Maybe TyCon
mtypeNatLeqTyCon = forall a. Maybe a
Nothing
#else
mtypeNatLeqTyCon = Just typeNatLeqTyCon
#endif
lookupTyNatPredLeq :: TcPluginM Name
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatPredLeq :: TcPluginM Name
lookupTyNatPredLeq = do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"<=")
#else
lookupTyNatPredLeq =
lookupOrig gHC_TYPENATS (mkTcOcc "<=")
#endif
lookupTyNatBoolLeq :: TcPluginM TyCon
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatBoolLeq :: TcPluginM TyCon
lookupTyNatBoolLeq = do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"<=?")
#else
lookupTyNatBoolLeq =
pure typeNatLeqTyCon
#endif
lookupAssertTyCon :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_base(4,17,0)
lookupAssertTyCon =
fmap Just . tcLookupTyCon =<< lookupOrig gHC_TYPEERROR (mkTcOcc "Assert")
#else
lookupAssertTyCon :: TcPluginM (Maybe TyCon)
lookupAssertTyCon = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing
#endif
lookupTyNatPredLt :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,2)
lookupTyNatPredLt :: TcPluginM (Maybe TyCon)
lookupTyNatPredLt = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"<")
#else
lookupTyNatPredLt = pure Nothing
#endif
lookupTyNatBoolLt :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatBoolLt :: TcPluginM (Maybe TyCon)
lookupTyNatBoolLt = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"<?")
#else
lookupTyNatBoolLt = pure Nothing
#endif
lookupTyNatPredGt :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatPredGt :: TcPluginM (Maybe TyCon)
lookupTyNatPredGt = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
">")
#else
lookupTyNatPredGt = pure Nothing
#endif
lookupTyNatBoolGt :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatBoolGt :: TcPluginM (Maybe TyCon)
lookupTyNatBoolGt = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
">?")
#else
lookupTyNatBoolGt = pure Nothing
#endif
lookupTyNatPredGeq :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatPredGeq :: TcPluginM (Maybe TyCon)
lookupTyNatPredGeq = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
">=")
#else
lookupTyNatPredGeq = pure Nothing
#endif
lookupTyNatBoolGeq :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyNatBoolGeq :: TcPluginM (Maybe TyCon)
lookupTyNatBoolGeq = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
">=?")
#else
lookupTyNatBoolGeq = pure Nothing
#endif
mOrdCondTyCon :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
mOrdCondTyCon :: TcPluginM (Maybe TyCon)
mOrdCondTyCon = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"OrdCond")
#else
mOrdCondTyCon = pure Nothing
#endif
lookupTyGenericCompare :: TcPluginM (Maybe TyCon)
#if MIN_VERSION_ghc(9,2,0)
lookupTyGenericCompare :: TcPluginM (Maybe TyCon)
lookupTyGenericCompare = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Module
tyOrd <- ModuleName -> FastString -> TcPluginM Module
lookupModule (String -> ModuleName
mkModuleName String
"Data.Type.Ord") FastString
"base"
Name -> TcPluginM TyCon
tcLookupTyCon forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Module -> OccName -> TcPluginM Name
lookupOrig Module
tyOrd (String -> OccName
mkTcOcc String
"Compare")
#else
lookupTyGenericCompare = pure Nothing
#endif
lookupBool47 :: String -> TcPluginM (Maybe TyCon)
#if MIN_VERSION_base(4,17,0)
lookupBool47 nam = Just <$> do
tcLookupTyCon =<< lookupOrig (mkBaseModule "Data.Type.Bool") (mkTcOcc nam)
#else
lookupBool47 :: String -> TcPluginM (Maybe TyCon)
lookupBool47 = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing
#endif
lookupTyNot, lookupTyIf, lookupTyAnd, lookupTyOr :: TcPluginM (Maybe TyCon)
lookupTyNot :: TcPluginM (Maybe TyCon)
lookupTyNot = String -> TcPluginM (Maybe TyCon)
lookupBool47 String
"Not"
lookupTyIf :: TcPluginM (Maybe TyCon)
lookupTyIf = String -> TcPluginM (Maybe TyCon)
lookupBool47 String
"If"
lookupTyAnd :: TcPluginM (Maybe TyCon)
lookupTyAnd = String -> TcPluginM (Maybe TyCon)
lookupBool47 String
"&&"
lookupTyOr :: TcPluginM (Maybe TyCon)
lookupTyOr = String -> TcPluginM (Maybe TyCon)
lookupBool47 String
"||"
matchFam' :: TyCon -> [Type] -> TcPluginM (Maybe Type)
#if MIN_VERSION_ghc(9,4,1)
matchFam' con args = fmap reductionReducedType <$> matchFam con args
#else
matchFam' :: TyCon -> [Type] -> TcPluginM (Maybe Type)
matchFam' TyCon
con [Type]
args = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyCon -> [Type] -> TcPluginM (Maybe (TcCoercion, Type))
matchFam TyCon
con [Type]
args
#endif