module GHC.Core.TyCo.FVs
( shallowTyCoVarsOfType, shallowTyCoVarsOfTypes,
tyCoVarsOfType, tyCoVarsOfTypes,
tyCoVarsOfTypeDSet, tyCoVarsOfTypesDSet,
tyCoFVsBndr, tyCoFVsVarBndr, tyCoFVsVarBndrs,
tyCoFVsOfType, tyCoVarsOfTypeList,
tyCoFVsOfTypes, tyCoVarsOfTypesList,
deepTcvFolder,
shallowTyCoVarsOfTyVarEnv, shallowTyCoVarsOfCoVarEnv,
shallowTyCoVarsOfCo, shallowTyCoVarsOfCos,
tyCoVarsOfCo, tyCoVarsOfCos, tyCoVarsOfMCo,
coVarsOfType, coVarsOfTypes,
coVarsOfCo, coVarsOfCos,
tyCoVarsOfCoDSet,
tyCoFVsOfCo, tyCoFVsOfCos,
tyCoVarsOfCoList,
almostDevoidCoVarOfCo,
injectiveVarsOfType, injectiveVarsOfTypes,
invisibleVarsOfType, invisibleVarsOfTypes,
anyFreeVarsOfType, anyFreeVarsOfTypes, anyFreeVarsOfCo,
noFreeVarsOfType, noFreeVarsOfTypes, noFreeVarsOfCo,
tyConsOfType, tyConsOfTypes,
visVarsOfTypes, visVarsOfType,
occCheckExpand,
scopedSort, tyCoVarsOfTypeWellScoped,
tyCoVarsOfTypesWellScoped,
closeOverKindsDSet, closeOverKindsList,
closeOverKinds,
Endo(..), runTyCoVars
) where
import GHC.Prelude
import {-# SOURCE #-} GHC.Core.Type( partitionInvisibleTypes, coreView )
import {-# SOURCE #-} GHC.Core.Coercion( coercionLKind )
import GHC.Builtin.Types.Prim( funTyFlagTyCon )
import Data.Monoid as DM ( Endo(..), Any(..) )
import GHC.Core.TyCo.Rep
import GHC.Core.TyCon
import GHC.Core.Coercion.Axiom( coAxiomTyCon )
import GHC.Utils.FV
import GHC.Types.Var
import GHC.Types.Unique.FM
import GHC.Types.Unique.Set
import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Utils.Misc
import GHC.Utils.Panic
import GHC.Data.Pair
runTyCoVars :: Endo TyCoVarSet -> TyCoVarSet
{-# INLINE runTyCoVars #-}
runTyCoVars :: Endo VarSet -> VarSet
runTyCoVars Endo VarSet
f = forall a. Endo a -> a -> a
appEndo Endo VarSet
f VarSet
emptyVarSet
tyCoVarsOfType :: Type -> TyCoVarSet
tyCoVarsOfType :: Type -> VarSet
tyCoVarsOfType Type
ty = Endo VarSet -> VarSet
runTyCoVars (Type -> Endo VarSet
deep_ty Type
ty)
tyCoVarsOfTypes :: [Type] -> TyCoVarSet
tyCoVarsOfTypes :: [Type] -> VarSet
tyCoVarsOfTypes [Type]
tys = Endo VarSet -> VarSet
runTyCoVars ([Type] -> Endo VarSet
deep_tys [Type]
tys)
tyCoVarsOfCo :: Coercion -> TyCoVarSet
tyCoVarsOfCo :: Coercion -> VarSet
tyCoVarsOfCo Coercion
co = Endo VarSet -> VarSet
runTyCoVars (Coercion -> Endo VarSet
deep_co Coercion
co)
tyCoVarsOfMCo :: MCoercion -> TyCoVarSet
tyCoVarsOfMCo :: MCoercion -> VarSet
tyCoVarsOfMCo MCoercion
MRefl = VarSet
emptyVarSet
tyCoVarsOfMCo (MCo Coercion
co) = Coercion -> VarSet
tyCoVarsOfCo Coercion
co
tyCoVarsOfCos :: [Coercion] -> TyCoVarSet
tyCoVarsOfCos :: [Coercion] -> VarSet
tyCoVarsOfCos [Coercion]
cos = Endo VarSet -> VarSet
runTyCoVars ([Coercion] -> Endo VarSet
deep_cos [Coercion]
cos)
deep_ty :: Type -> Endo TyCoVarSet
deep_tys :: [Type] -> Endo TyCoVarSet
deep_co :: Coercion -> Endo TyCoVarSet
deep_cos :: [Coercion] -> Endo TyCoVarSet
(Type -> Endo VarSet
deep_ty, [Type] -> Endo VarSet
deep_tys, Coercion -> Endo VarSet
deep_co, [Coercion] -> Endo VarSet
deep_cos) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo TyCoFolder VarSet (Endo VarSet)
deepTcvFolder VarSet
emptyVarSet
deepTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet)
deepTcvFolder :: TyCoFolder VarSet (Endo VarSet)
deepTcvFolder = TyCoFolder { tcf_view :: Type -> Maybe Type
tcf_view = Type -> Maybe Type
noView
, tcf_tyvar :: VarSet -> TyCoVar -> Endo VarSet
tcf_tyvar = VarSet -> TyCoVar -> Endo VarSet
do_tcv, tcf_covar :: VarSet -> TyCoVar -> Endo VarSet
tcf_covar = VarSet -> TyCoVar -> Endo VarSet
do_tcv
, tcf_hole :: VarSet -> CoercionHole -> Endo VarSet
tcf_hole = VarSet -> CoercionHole -> Endo VarSet
do_hole, tcf_tycobinder :: VarSet -> TyCoVar -> ForAllTyFlag -> VarSet
tcf_tycobinder = forall {p}. VarSet -> TyCoVar -> p -> VarSet
do_bndr }
where
do_tcv :: VarSet -> TyCoVar -> Endo VarSet
do_tcv VarSet
is TyCoVar
v = forall a. (a -> a) -> Endo a
Endo VarSet -> VarSet
do_it
where
do_it :: VarSet -> VarSet
do_it VarSet
acc | TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
is = VarSet
acc
| TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
acc = VarSet
acc
| Bool
otherwise = forall a. Endo a -> a -> a
appEndo (Type -> Endo VarSet
deep_ty (TyCoVar -> Type
varType TyCoVar
v)) forall a b. (a -> b) -> a -> b
$
VarSet
acc VarSet -> TyCoVar -> VarSet
`extendVarSet` TyCoVar
v
do_bndr :: VarSet -> TyCoVar -> p -> VarSet
do_bndr VarSet
is TyCoVar
tcv p
_ = VarSet -> TyCoVar -> VarSet
extendVarSet VarSet
is TyCoVar
tcv
do_hole :: VarSet -> CoercionHole -> Endo VarSet
do_hole VarSet
is CoercionHole
hole = VarSet -> TyCoVar -> Endo VarSet
do_tcv VarSet
is (CoercionHole -> TyCoVar
coHoleCoVar CoercionHole
hole)
shallowTyCoVarsOfType :: Type -> TyCoVarSet
shallowTyCoVarsOfType :: Type -> VarSet
shallowTyCoVarsOfType Type
ty = Endo VarSet -> VarSet
runTyCoVars (Type -> Endo VarSet
shallow_ty Type
ty)
shallowTyCoVarsOfTypes :: [Type] -> TyCoVarSet
shallowTyCoVarsOfTypes :: [Type] -> VarSet
shallowTyCoVarsOfTypes [Type]
tys = Endo VarSet -> VarSet
runTyCoVars ([Type] -> Endo VarSet
shallow_tys [Type]
tys)
shallowTyCoVarsOfCo :: Coercion -> TyCoVarSet
shallowTyCoVarsOfCo :: Coercion -> VarSet
shallowTyCoVarsOfCo Coercion
co = Endo VarSet -> VarSet
runTyCoVars (Coercion -> Endo VarSet
shallow_co Coercion
co)
shallowTyCoVarsOfCos :: [Coercion] -> TyCoVarSet
shallowTyCoVarsOfCos :: [Coercion] -> VarSet
shallowTyCoVarsOfCos [Coercion]
cos = Endo VarSet -> VarSet
runTyCoVars ([Coercion] -> Endo VarSet
shallow_cos [Coercion]
cos)
shallowTyCoVarsOfTyVarEnv :: TyVarEnv Type -> TyCoVarSet
shallowTyCoVarsOfTyVarEnv :: TyVarEnv Type -> VarSet
shallowTyCoVarsOfTyVarEnv TyVarEnv Type
tys = [Type] -> VarSet
shallowTyCoVarsOfTypes (forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM TyVarEnv Type
tys)
shallowTyCoVarsOfCoVarEnv :: CoVarEnv Coercion -> TyCoVarSet
shallowTyCoVarsOfCoVarEnv :: CoVarEnv Coercion -> VarSet
shallowTyCoVarsOfCoVarEnv CoVarEnv Coercion
cos = [Coercion] -> VarSet
shallowTyCoVarsOfCos (forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM CoVarEnv Coercion
cos)
shallow_ty :: Type -> Endo TyCoVarSet
shallow_tys :: [Type] -> Endo TyCoVarSet
shallow_co :: Coercion -> Endo TyCoVarSet
shallow_cos :: [Coercion] -> Endo TyCoVarSet
(Type -> Endo VarSet
shallow_ty, [Type] -> Endo VarSet
shallow_tys, Coercion -> Endo VarSet
shallow_co, [Coercion] -> Endo VarSet
shallow_cos) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo TyCoFolder VarSet (Endo VarSet)
shallowTcvFolder VarSet
emptyVarSet
shallowTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet)
shallowTcvFolder :: TyCoFolder VarSet (Endo VarSet)
shallowTcvFolder = TyCoFolder { tcf_view :: Type -> Maybe Type
tcf_view = Type -> Maybe Type
noView
, tcf_tyvar :: VarSet -> TyCoVar -> Endo VarSet
tcf_tyvar = VarSet -> TyCoVar -> Endo VarSet
do_tcv, tcf_covar :: VarSet -> TyCoVar -> Endo VarSet
tcf_covar = VarSet -> TyCoVar -> Endo VarSet
do_tcv
, tcf_hole :: VarSet -> CoercionHole -> Endo VarSet
tcf_hole = forall {a} {p} {p}. Monoid a => p -> p -> a
do_hole, tcf_tycobinder :: VarSet -> TyCoVar -> ForAllTyFlag -> VarSet
tcf_tycobinder = forall {p}. VarSet -> TyCoVar -> p -> VarSet
do_bndr }
where
do_tcv :: VarSet -> TyCoVar -> Endo VarSet
do_tcv VarSet
is TyCoVar
v = forall a. (a -> a) -> Endo a
Endo VarSet -> VarSet
do_it
where
do_it :: VarSet -> VarSet
do_it VarSet
acc | TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
is = VarSet
acc
| TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
acc = VarSet
acc
| Bool
otherwise = VarSet
acc VarSet -> TyCoVar -> VarSet
`extendVarSet` TyCoVar
v
do_bndr :: VarSet -> TyCoVar -> p -> VarSet
do_bndr VarSet
is TyCoVar
tcv p
_ = VarSet -> TyCoVar -> VarSet
extendVarSet VarSet
is TyCoVar
tcv
do_hole :: p -> p -> a
do_hole p
_ p
_ = forall a. Monoid a => a
mempty
coVarsOfType :: Type -> CoVarSet
coVarsOfTypes :: [Type] -> CoVarSet
coVarsOfCo :: Coercion -> CoVarSet
coVarsOfCos :: [Coercion] -> CoVarSet
coVarsOfType :: Type -> VarSet
coVarsOfType Type
ty = Endo VarSet -> VarSet
runTyCoVars (Type -> Endo VarSet
deep_cv_ty Type
ty)
coVarsOfTypes :: [Type] -> VarSet
coVarsOfTypes [Type]
tys = Endo VarSet -> VarSet
runTyCoVars ([Type] -> Endo VarSet
deep_cv_tys [Type]
tys)
coVarsOfCo :: Coercion -> VarSet
coVarsOfCo Coercion
co = Endo VarSet -> VarSet
runTyCoVars (Coercion -> Endo VarSet
deep_cv_co Coercion
co)
coVarsOfCos :: [Coercion] -> VarSet
coVarsOfCos [Coercion]
cos = Endo VarSet -> VarSet
runTyCoVars ([Coercion] -> Endo VarSet
deep_cv_cos [Coercion]
cos)
deep_cv_ty :: Type -> Endo CoVarSet
deep_cv_tys :: [Type] -> Endo CoVarSet
deep_cv_co :: Coercion -> Endo CoVarSet
deep_cv_cos :: [Coercion] -> Endo CoVarSet
(Type -> Endo VarSet
deep_cv_ty, [Type] -> Endo VarSet
deep_cv_tys, Coercion -> Endo VarSet
deep_cv_co, [Coercion] -> Endo VarSet
deep_cv_cos) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo TyCoFolder VarSet (Endo VarSet)
deepCoVarFolder VarSet
emptyVarSet
deepCoVarFolder :: TyCoFolder TyCoVarSet (Endo CoVarSet)
deepCoVarFolder :: TyCoFolder VarSet (Endo VarSet)
deepCoVarFolder = TyCoFolder { tcf_view :: Type -> Maybe Type
tcf_view = Type -> Maybe Type
noView
, tcf_tyvar :: VarSet -> TyCoVar -> Endo VarSet
tcf_tyvar = forall {a} {p} {p}. Monoid a => p -> p -> a
do_tyvar, tcf_covar :: VarSet -> TyCoVar -> Endo VarSet
tcf_covar = VarSet -> TyCoVar -> Endo VarSet
do_covar
, tcf_hole :: VarSet -> CoercionHole -> Endo VarSet
tcf_hole = VarSet -> CoercionHole -> Endo VarSet
do_hole, tcf_tycobinder :: VarSet -> TyCoVar -> ForAllTyFlag -> VarSet
tcf_tycobinder = forall {p}. VarSet -> TyCoVar -> p -> VarSet
do_bndr }
where
do_tyvar :: p -> p -> a
do_tyvar p
_ p
_ = forall a. Monoid a => a
mempty
do_covar :: VarSet -> TyCoVar -> Endo VarSet
do_covar VarSet
is TyCoVar
v = forall a. (a -> a) -> Endo a
Endo VarSet -> VarSet
do_it
where
do_it :: VarSet -> VarSet
do_it VarSet
acc | TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
is = VarSet
acc
| TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
acc = VarSet
acc
| Bool
otherwise = forall a. Endo a -> a -> a
appEndo (Type -> Endo VarSet
deep_cv_ty (TyCoVar -> Type
varType TyCoVar
v)) forall a b. (a -> b) -> a -> b
$
VarSet
acc VarSet -> TyCoVar -> VarSet
`extendVarSet` TyCoVar
v
do_bndr :: VarSet -> TyCoVar -> p -> VarSet
do_bndr VarSet
is TyCoVar
tcv p
_ = VarSet -> TyCoVar -> VarSet
extendVarSet VarSet
is TyCoVar
tcv
do_hole :: VarSet -> CoercionHole -> Endo VarSet
do_hole VarSet
is CoercionHole
hole = VarSet -> TyCoVar -> Endo VarSet
do_covar VarSet
is (CoercionHole -> TyCoVar
coHoleCoVar CoercionHole
hole)
closeOverKinds :: TyCoVarSet -> TyCoVarSet
closeOverKinds :: VarSet -> VarSet
closeOverKinds VarSet
vs = forall a. (TyCoVar -> a -> a) -> a -> VarSet -> a
nonDetStrictFoldVarSet TyCoVar -> VarSet -> VarSet
do_one VarSet
vs VarSet
vs
where
do_one :: TyCoVar -> VarSet -> VarSet
do_one TyCoVar
v VarSet
acc = forall a. Endo a -> a -> a
appEndo (Type -> Endo VarSet
deep_ty (TyCoVar -> Type
varType TyCoVar
v)) VarSet
acc
closeOverKindsFV :: [TyVar] -> FV
closeOverKindsFV :: [TyCoVar] -> FV
closeOverKindsFV [TyCoVar]
tvs =
forall a. (a -> FV) -> [a] -> FV
mapUnionFV (Type -> FV
tyCoFVsOfType forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCoVar -> Type
tyVarKind) [TyCoVar]
tvs FV -> FV -> FV
`unionFV` [TyCoVar] -> FV
mkFVs [TyCoVar]
tvs
closeOverKindsList :: [TyVar] -> [TyVar]
closeOverKindsList :: [TyCoVar] -> [TyCoVar]
closeOverKindsList [TyCoVar]
tvs = FV -> [TyCoVar]
fvVarList forall a b. (a -> b) -> a -> b
$ [TyCoVar] -> FV
closeOverKindsFV [TyCoVar]
tvs
closeOverKindsDSet :: DTyVarSet -> DTyVarSet
closeOverKindsDSet :: DTyVarSet -> DTyVarSet
closeOverKindsDSet = FV -> DTyVarSet
fvDVarSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. [TyCoVar] -> FV
closeOverKindsFV forall b c a. (b -> c) -> (a -> b) -> a -> c
. DTyVarSet -> [TyCoVar]
dVarSetElems
tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet
tyCoVarsOfTypeDSet :: Type -> DTyVarSet
tyCoVarsOfTypeDSet Type
ty = FV -> DTyVarSet
fvDVarSet forall a b. (a -> b) -> a -> b
$ Type -> FV
tyCoFVsOfType Type
ty
tyCoVarsOfTypeList :: Type -> [TyCoVar]
tyCoVarsOfTypeList :: Type -> [TyCoVar]
tyCoVarsOfTypeList Type
ty = FV -> [TyCoVar]
fvVarList forall a b. (a -> b) -> a -> b
$ Type -> FV
tyCoFVsOfType Type
ty
tyCoVarsOfTypesDSet :: [Type] -> DTyCoVarSet
tyCoVarsOfTypesDSet :: [Type] -> DTyVarSet
tyCoVarsOfTypesDSet [Type]
tys = FV -> DTyVarSet
fvDVarSet forall a b. (a -> b) -> a -> b
$ [Type] -> FV
tyCoFVsOfTypes [Type]
tys
tyCoVarsOfTypesList :: [Type] -> [TyCoVar]
tyCoVarsOfTypesList :: [Type] -> [TyCoVar]
tyCoVarsOfTypesList [Type]
tys = FV -> [TyCoVar]
fvVarList forall a b. (a -> b) -> a -> b
$ [Type] -> FV
tyCoFVsOfTypes [Type]
tys
tyCoFVsOfType :: Type -> FV
tyCoFVsOfType :: Type -> FV
tyCoFVsOfType (TyVarTy TyCoVar
v) InterestingVarFun
f VarSet
bound_vars ([TyCoVar]
acc_list, VarSet
acc_set)
| Bool -> Bool
not (InterestingVarFun
f TyCoVar
v) = ([TyCoVar]
acc_list, VarSet
acc_set)
| TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
bound_vars = ([TyCoVar]
acc_list, VarSet
acc_set)
| TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
acc_set = ([TyCoVar]
acc_list, VarSet
acc_set)
| Bool
otherwise = Type -> FV
tyCoFVsOfType (TyCoVar -> Type
tyVarKind TyCoVar
v) InterestingVarFun
f
VarSet
emptyVarSet
(TyCoVar
vforall a. a -> [a] -> [a]
:[TyCoVar]
acc_list, VarSet -> TyCoVar -> VarSet
extendVarSet VarSet
acc_set TyCoVar
v)
tyCoFVsOfType (TyConApp TyCon
_ [Type]
tys) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = [Type] -> FV
tyCoFVsOfTypes [Type]
tys InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (LitTy {}) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = FV
emptyFV InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (AppTy Type
fun Type
arg) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = (Type -> FV
tyCoFVsOfType Type
fun FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType Type
arg) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (FunTy FunTyFlag
_ Type
w Type
arg Type
res) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = (Type -> FV
tyCoFVsOfType Type
w FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType Type
arg FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType Type
res) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (ForAllTy ForAllTyBinder
bndr Type
ty) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = ForAllTyBinder -> FV -> FV
tyCoFVsBndr ForAllTyBinder
bndr (Type -> FV
tyCoFVsOfType Type
ty) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (CastTy Type
ty Coercion
co) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = (Type -> FV
tyCoFVsOfType Type
ty FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
co) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsOfType (CoercionTy Coercion
co) InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
f VarSet
bound_vars ([TyCoVar], VarSet)
acc
tyCoFVsBndr :: ForAllTyBinder -> FV -> FV
tyCoFVsBndr :: ForAllTyBinder -> FV -> FV
tyCoFVsBndr (Bndr TyCoVar
tv ForAllTyFlag
_) FV
fvs = TyCoVar -> FV -> FV
tyCoFVsVarBndr TyCoVar
tv FV
fvs
tyCoFVsVarBndrs :: [Var] -> FV -> FV
tyCoFVsVarBndrs :: [TyCoVar] -> FV -> FV
tyCoFVsVarBndrs [TyCoVar]
vars FV
fvs = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr TyCoVar -> FV -> FV
tyCoFVsVarBndr FV
fvs [TyCoVar]
vars
tyCoFVsVarBndr :: Var -> FV -> FV
tyCoFVsVarBndr :: TyCoVar -> FV -> FV
tyCoFVsVarBndr TyCoVar
var FV
fvs
= Type -> FV
tyCoFVsOfType (TyCoVar -> Type
varType TyCoVar
var)
FV -> FV -> FV
`unionFV` TyCoVar -> FV -> FV
delFV TyCoVar
var FV
fvs
tyCoFVsOfTypes :: [Type] -> FV
tyCoFVsOfTypes :: [Type] -> FV
tyCoFVsOfTypes (Type
ty:[Type]
tys) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = (Type -> FV
tyCoFVsOfType Type
ty FV -> FV -> FV
`unionFV` [Type] -> FV
tyCoFVsOfTypes [Type]
tys) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfTypes [] InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = FV
emptyFV InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet
tyCoVarsOfCoDSet :: Coercion -> DTyVarSet
tyCoVarsOfCoDSet Coercion
co = FV -> DTyVarSet
fvDVarSet forall a b. (a -> b) -> a -> b
$ Coercion -> FV
tyCoFVsOfCo Coercion
co
tyCoVarsOfCoList :: Coercion -> [TyCoVar]
tyCoVarsOfCoList :: Coercion -> [TyCoVar]
tyCoVarsOfCoList Coercion
co = FV -> [TyCoVar]
fvVarList forall a b. (a -> b) -> a -> b
$ Coercion -> FV
tyCoFVsOfCo Coercion
co
tyCoFVsOfMCo :: MCoercion -> FV
tyCoFVsOfMCo :: MCoercion -> FV
tyCoFVsOfMCo MCoercion
MRefl = FV
emptyFV
tyCoFVsOfMCo (MCo Coercion
co) = Coercion -> FV
tyCoFVsOfCo Coercion
co
tyCoFVsOfCo :: Coercion -> FV
tyCoFVsOfCo :: Coercion -> FV
tyCoFVsOfCo (Refl Type
ty) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= Type -> FV
tyCoFVsOfType Type
ty InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (GRefl Role
_ Type
ty MCoercion
mco) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (Type -> FV
tyCoFVsOfType Type
ty FV -> FV -> FV
`unionFV` MCoercion -> FV
tyCoFVsOfMCo MCoercion
mco) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (TyConAppCo Role
_ TyCon
_ [Coercion]
cos) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = [Coercion] -> FV
tyCoFVsOfCos [Coercion]
cos InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (AppCo Coercion
co Coercion
arg) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (Coercion -> FV
tyCoFVsOfCo Coercion
co FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
arg) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (ForAllCo TyCoVar
tv Coercion
kind_co Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (TyCoVar -> FV -> FV
tyCoFVsVarBndr TyCoVar
tv (Coercion -> FV
tyCoFVsOfCo Coercion
co) FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
kind_co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (FunCo { fco_mult :: Coercion -> Coercion
fco_mult = Coercion
w, fco_arg :: Coercion -> Coercion
fco_arg = Coercion
co1, fco_res :: Coercion -> Coercion
fco_res = Coercion
co2 }) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (Coercion -> FV
tyCoFVsOfCo Coercion
co1 FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
co2 FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
w) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (CoVarCo TyCoVar
v) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= TyCoVar -> FV
tyCoFVsOfCoVar TyCoVar
v InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (HoleCo CoercionHole
h) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= TyCoVar -> FV
tyCoFVsOfCoVar (CoercionHole -> TyCoVar
coHoleCoVar CoercionHole
h) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (AxiomInstCo CoAxiom Branched
_ BranchIndex
_ [Coercion]
cos) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = [Coercion] -> FV
tyCoFVsOfCos [Coercion]
cos InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (UnivCo UnivCoProvenance
p Role
_ Type
t1 Type
t2) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (UnivCoProvenance -> FV
tyCoFVsOfProv UnivCoProvenance
p FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType Type
t1
FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType Type
t2) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (SymCo Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (TransCo Coercion
co1 Coercion
co2) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = (Coercion -> FV
tyCoFVsOfCo Coercion
co1 FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
co2) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (SelCo CoSel
_ Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (LRCo LeftOrRight
_ Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (InstCo Coercion
co Coercion
arg) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = (Coercion -> FV
tyCoFVsOfCo Coercion
co FV -> FV -> FV
`unionFV` Coercion -> FV
tyCoFVsOfCo Coercion
arg) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (KindCo Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (SubCo Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCo (AxiomRuleCo CoAxiomRule
_ [Coercion]
cs) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = [Coercion] -> FV
tyCoFVsOfCos [Coercion]
cs InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCoVar :: CoVar -> FV
tyCoFVsOfCoVar :: TyCoVar -> FV
tyCoFVsOfCoVar TyCoVar
v InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
= (TyCoVar -> FV
unitFV TyCoVar
v FV -> FV -> FV
`unionFV` Type -> FV
tyCoFVsOfType (TyCoVar -> Type
varType TyCoVar
v)) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfProv :: UnivCoProvenance -> FV
tyCoFVsOfProv :: UnivCoProvenance -> FV
tyCoFVsOfProv (PhantomProv Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfProv (ProofIrrelProv Coercion
co) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = Coercion -> FV
tyCoFVsOfCo Coercion
co InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfProv (PluginProv String
_) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = FV
emptyFV InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfProv (CorePrepProv Bool
_) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = FV
emptyFV InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCos :: [Coercion] -> FV
tyCoFVsOfCos :: [Coercion] -> FV
tyCoFVsOfCos [] InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = FV
emptyFV InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
tyCoFVsOfCos (Coercion
co:[Coercion]
cos) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc = (Coercion -> FV
tyCoFVsOfCo Coercion
co FV -> FV -> FV
`unionFV` [Coercion] -> FV
tyCoFVsOfCos [Coercion]
cos) InterestingVarFun
fv_cand VarSet
in_scope ([TyCoVar], VarSet)
acc
almostDevoidCoVarOfCo :: CoVar -> Coercion -> Bool
almostDevoidCoVarOfCo :: TyCoVar -> Coercion -> Bool
almostDevoidCoVarOfCo TyCoVar
cv Coercion
co =
Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co :: Coercion -> CoVar -> Bool
almost_devoid_co_var_of_co :: Coercion -> InterestingVarFun
almost_devoid_co_var_of_co (Refl {}) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_co (GRefl {}) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_co (TyConAppCo Role
_ TyCon
_ [Coercion]
cos) TyCoVar
cv
= [Coercion] -> InterestingVarFun
almost_devoid_co_var_of_cos [Coercion]
cos TyCoVar
cv
almost_devoid_co_var_of_co (AppCo Coercion
co Coercion
arg) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
arg TyCoVar
cv
almost_devoid_co_var_of_co (ForAllCo TyCoVar
v Coercion
kind_co Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
kind_co TyCoVar
cv
Bool -> Bool -> Bool
&& (TyCoVar
v forall a. Eq a => a -> a -> Bool
== TyCoVar
cv Bool -> Bool -> Bool
|| Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv)
almost_devoid_co_var_of_co (FunCo { fco_mult :: Coercion -> Coercion
fco_mult = Coercion
w, fco_arg :: Coercion -> Coercion
fco_arg = Coercion
co1, fco_res :: Coercion -> Coercion
fco_res = Coercion
co2 }) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
w TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co1 TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co2 TyCoVar
cv
almost_devoid_co_var_of_co (CoVarCo TyCoVar
v) TyCoVar
cv = TyCoVar
v forall a. Eq a => a -> a -> Bool
/= TyCoVar
cv
almost_devoid_co_var_of_co (HoleCo CoercionHole
h) TyCoVar
cv = (CoercionHole -> TyCoVar
coHoleCoVar CoercionHole
h) forall a. Eq a => a -> a -> Bool
/= TyCoVar
cv
almost_devoid_co_var_of_co (AxiomInstCo CoAxiom Branched
_ BranchIndex
_ [Coercion]
cos) TyCoVar
cv
= [Coercion] -> InterestingVarFun
almost_devoid_co_var_of_cos [Coercion]
cos TyCoVar
cv
almost_devoid_co_var_of_co (UnivCo UnivCoProvenance
p Role
_ Type
t1 Type
t2) TyCoVar
cv
= UnivCoProvenance -> InterestingVarFun
almost_devoid_co_var_of_prov UnivCoProvenance
p TyCoVar
cv
Bool -> Bool -> Bool
&& Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
t1 TyCoVar
cv
Bool -> Bool -> Bool
&& Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
t2 TyCoVar
cv
almost_devoid_co_var_of_co (SymCo Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co (TransCo Coercion
co1 Coercion
co2) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co1 TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co2 TyCoVar
cv
almost_devoid_co_var_of_co (SelCo CoSel
_ Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co (LRCo LeftOrRight
_ Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co (InstCo Coercion
co Coercion
arg) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
arg TyCoVar
cv
almost_devoid_co_var_of_co (KindCo Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co (SubCo Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_co (AxiomRuleCo CoAxiomRule
_ [Coercion]
cs) TyCoVar
cv
= [Coercion] -> InterestingVarFun
almost_devoid_co_var_of_cos [Coercion]
cs TyCoVar
cv
almost_devoid_co_var_of_cos :: [Coercion] -> CoVar -> Bool
almost_devoid_co_var_of_cos :: [Coercion] -> InterestingVarFun
almost_devoid_co_var_of_cos [] TyCoVar
_ = Bool
True
almost_devoid_co_var_of_cos (Coercion
co:[Coercion]
cos) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
Bool -> Bool -> Bool
&& [Coercion] -> InterestingVarFun
almost_devoid_co_var_of_cos [Coercion]
cos TyCoVar
cv
almost_devoid_co_var_of_prov :: UnivCoProvenance -> CoVar -> Bool
almost_devoid_co_var_of_prov :: UnivCoProvenance -> InterestingVarFun
almost_devoid_co_var_of_prov (PhantomProv Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_prov (ProofIrrelProv Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_prov (PluginProv String
_) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_prov (CorePrepProv Bool
_) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_type :: Type -> CoVar -> Bool
almost_devoid_co_var_of_type :: Type -> InterestingVarFun
almost_devoid_co_var_of_type (TyVarTy TyCoVar
_) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_type (TyConApp TyCon
_ [Type]
tys) TyCoVar
cv
= [Type] -> InterestingVarFun
almost_devoid_co_var_of_types [Type]
tys TyCoVar
cv
almost_devoid_co_var_of_type (LitTy {}) TyCoVar
_ = Bool
True
almost_devoid_co_var_of_type (AppTy Type
fun Type
arg) TyCoVar
cv
= Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
fun TyCoVar
cv
Bool -> Bool -> Bool
&& Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
arg TyCoVar
cv
almost_devoid_co_var_of_type (FunTy FunTyFlag
_ Type
w Type
arg Type
res) TyCoVar
cv
= Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
w TyCoVar
cv
Bool -> Bool -> Bool
&& Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
arg TyCoVar
cv
Bool -> Bool -> Bool
&& Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
res TyCoVar
cv
almost_devoid_co_var_of_type (ForAllTy (Bndr TyCoVar
v ForAllTyFlag
_) Type
ty) TyCoVar
cv
= Type -> InterestingVarFun
almost_devoid_co_var_of_type (TyCoVar -> Type
varType TyCoVar
v) TyCoVar
cv
Bool -> Bool -> Bool
&& (TyCoVar
v forall a. Eq a => a -> a -> Bool
== TyCoVar
cv Bool -> Bool -> Bool
|| Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
ty TyCoVar
cv)
almost_devoid_co_var_of_type (CastTy Type
ty Coercion
co) TyCoVar
cv
= Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
ty TyCoVar
cv
Bool -> Bool -> Bool
&& Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_type (CoercionTy Coercion
co) TyCoVar
cv
= Coercion -> InterestingVarFun
almost_devoid_co_var_of_co Coercion
co TyCoVar
cv
almost_devoid_co_var_of_types :: [Type] -> CoVar -> Bool
almost_devoid_co_var_of_types :: [Type] -> InterestingVarFun
almost_devoid_co_var_of_types [] TyCoVar
_ = Bool
True
almost_devoid_co_var_of_types (Type
ty:[Type]
tys) TyCoVar
cv
= Type -> InterestingVarFun
almost_devoid_co_var_of_type Type
ty TyCoVar
cv
Bool -> Bool -> Bool
&& [Type] -> InterestingVarFun
almost_devoid_co_var_of_types [Type]
tys TyCoVar
cv
visVarsOfType :: Type -> Pair TyCoVarSet
visVarsOfType :: Type -> Pair VarSet
visVarsOfType Type
orig_ty = forall a. a -> a -> Pair a
Pair VarSet
invis_vars VarSet
vis_vars
where
Pair VarSet
invis_vars1 VarSet
vis_vars = Type -> Pair VarSet
go Type
orig_ty
invis_vars :: VarSet
invis_vars = VarSet
invis_vars1 VarSet -> VarSet -> VarSet
`minusVarSet` VarSet
vis_vars
go :: Type -> Pair VarSet
go (TyVarTy TyCoVar
tv) = forall a. a -> a -> Pair a
Pair (Type -> VarSet
tyCoVarsOfType forall a b. (a -> b) -> a -> b
$ TyCoVar -> Type
tyVarKind TyCoVar
tv) (TyCoVar -> VarSet
unitVarSet TyCoVar
tv)
go (AppTy Type
t1 Type
t2) = Type -> Pair VarSet
go Type
t1 forall a. Monoid a => a -> a -> a
`mappend` Type -> Pair VarSet
go Type
t2
go (TyConApp TyCon
tc [Type]
tys) = TyCon -> [Type] -> Pair VarSet
go_tc TyCon
tc [Type]
tys
go (FunTy FunTyFlag
_ Type
w Type
t1 Type
t2) = Type -> Pair VarSet
go Type
w forall a. Monoid a => a -> a -> a
`mappend` Type -> Pair VarSet
go Type
t1 forall a. Monoid a => a -> a -> a
`mappend` Type -> Pair VarSet
go Type
t2
go (ForAllTy (Bndr TyCoVar
tv ForAllTyFlag
_) Type
ty)
= ((VarSet -> TyCoVar -> VarSet
`delVarSet` TyCoVar
tv) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> Pair VarSet
go Type
ty) forall a. Monoid a => a -> a -> a
`mappend`
(VarSet -> Pair VarSet
invisible (Type -> VarSet
tyCoVarsOfType forall a b. (a -> b) -> a -> b
$ TyCoVar -> Type
varType TyCoVar
tv))
go (LitTy {}) = forall a. Monoid a => a
mempty
go (CastTy Type
ty Coercion
co) = Type -> Pair VarSet
go Type
ty forall a. Monoid a => a -> a -> a
`mappend` VarSet -> Pair VarSet
invisible (Coercion -> VarSet
tyCoVarsOfCo Coercion
co)
go (CoercionTy Coercion
co) = VarSet -> Pair VarSet
invisible forall a b. (a -> b) -> a -> b
$ Coercion -> VarSet
tyCoVarsOfCo Coercion
co
invisible :: VarSet -> Pair VarSet
invisible VarSet
vs = forall a. a -> a -> Pair a
Pair VarSet
vs VarSet
emptyVarSet
go_tc :: TyCon -> [Type] -> Pair VarSet
go_tc TyCon
tc [Type]
tys = let ([Type]
invis, [Type]
vis) = TyCon -> [Type] -> ([Type], [Type])
partitionInvisibleTypes TyCon
tc [Type]
tys in
VarSet -> Pair VarSet
invisible ([Type] -> VarSet
tyCoVarsOfTypes [Type]
invis) forall a. Monoid a => a -> a -> a
`mappend` forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Type -> Pair VarSet
go [Type]
vis
visVarsOfTypes :: [Type] -> Pair TyCoVarSet
visVarsOfTypes :: [Type] -> Pair VarSet
visVarsOfTypes = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Type -> Pair VarSet
visVarsOfType
injectiveVarsOfType :: Bool
-> Type -> FV
injectiveVarsOfType :: Bool -> Type -> FV
injectiveVarsOfType Bool
look_under_tfs = Type -> FV
go
where
go :: Type -> FV
go Type
ty | Just Type
ty' <- Type -> Maybe Type
coreView Type
ty
= Type -> FV
go Type
ty'
go (TyVarTy TyCoVar
v) = TyCoVar -> FV
unitFV TyCoVar
v FV -> FV -> FV
`unionFV` Type -> FV
go (TyCoVar -> Type
tyVarKind TyCoVar
v)
go (AppTy Type
f Type
a) = Type -> FV
go Type
f FV -> FV -> FV
`unionFV` Type -> FV
go Type
a
go (FunTy FunTyFlag
_ Type
w Type
ty1 Type
ty2) = Type -> FV
go Type
w FV -> FV -> FV
`unionFV` Type -> FV
go Type
ty1 FV -> FV -> FV
`unionFV` Type -> FV
go Type
ty2
go (TyConApp TyCon
tc [Type]
tys) =
case TyCon -> Injectivity
tyConInjectivityInfo TyCon
tc of
Injective [Bool]
inj
| Bool
look_under_tfs Bool -> Bool -> Bool
|| Bool -> Bool
not (TyCon -> Bool
isTypeFamilyTyCon TyCon
tc)
-> forall a. (a -> FV) -> [a] -> FV
mapUnionFV Type -> FV
go forall a b. (a -> b) -> a -> b
$
forall a. [Bool] -> [a] -> [a]
filterByList ([Bool]
inj forall a. [a] -> [a] -> [a]
++ forall a. a -> [a]
repeat Bool
True) [Type]
tys
Injectivity
_ -> FV
emptyFV
go (ForAllTy (Bndr TyCoVar
tv ForAllTyFlag
_) Type
ty) = Type -> FV
go (TyCoVar -> Type
tyVarKind TyCoVar
tv) FV -> FV -> FV
`unionFV` TyCoVar -> FV -> FV
delFV TyCoVar
tv (Type -> FV
go Type
ty)
go LitTy{} = FV
emptyFV
go (CastTy Type
ty Coercion
_) = Type -> FV
go Type
ty
go CoercionTy{} = FV
emptyFV
injectiveVarsOfTypes :: Bool
-> [Type] -> FV
injectiveVarsOfTypes :: Bool -> [Type] -> FV
injectiveVarsOfTypes Bool
look_under_tfs = forall a. (a -> FV) -> [a] -> FV
mapUnionFV (Bool -> Type -> FV
injectiveVarsOfType Bool
look_under_tfs)
invisibleVarsOfType :: Type -> FV
invisibleVarsOfType :: Type -> FV
invisibleVarsOfType = Type -> FV
go
where
go :: Type -> FV
go Type
ty | Just Type
ty' <- Type -> Maybe Type
coreView Type
ty
= Type -> FV
go Type
ty'
go (TyVarTy TyCoVar
v) = Type -> FV
go (TyCoVar -> Type
tyVarKind TyCoVar
v)
go (AppTy Type
f Type
a) = Type -> FV
go Type
f FV -> FV -> FV
`unionFV` Type -> FV
go Type
a
go (FunTy FunTyFlag
_ Type
w Type
ty1 Type
ty2) = Type -> FV
go Type
w FV -> FV -> FV
`unionFV` Type -> FV
go Type
ty1 FV -> FV -> FV
`unionFV` Type -> FV
go Type
ty2
go (TyConApp TyCon
tc [Type]
tys) = [Type] -> FV
tyCoFVsOfTypes [Type]
invisibles FV -> FV -> FV
`unionFV`
[Type] -> FV
invisibleVarsOfTypes [Type]
visibles
where ([Type]
invisibles, [Type]
visibles) = TyCon -> [Type] -> ([Type], [Type])
partitionInvisibleTypes TyCon
tc [Type]
tys
go (ForAllTy ForAllTyBinder
tvb Type
ty) = ForAllTyBinder -> FV -> FV
tyCoFVsBndr ForAllTyBinder
tvb forall a b. (a -> b) -> a -> b
$ Type -> FV
go Type
ty
go LitTy{} = FV
emptyFV
go (CastTy Type
ty Coercion
co) = Coercion -> FV
tyCoFVsOfCo Coercion
co FV -> FV -> FV
`unionFV` Type -> FV
go Type
ty
go (CoercionTy Coercion
co) = Coercion -> FV
tyCoFVsOfCo Coercion
co
invisibleVarsOfTypes :: [Type] -> FV
invisibleVarsOfTypes :: [Type] -> FV
invisibleVarsOfTypes = forall a. (a -> FV) -> [a] -> FV
mapUnionFV Type -> FV
invisibleVarsOfType
{-# INLINE afvFolder #-}
afvFolder :: (TyCoVar -> Bool) -> TyCoFolder TyCoVarSet DM.Any
afvFolder :: InterestingVarFun -> TyCoFolder VarSet Any
afvFolder InterestingVarFun
check_fv = TyCoFolder { tcf_view :: Type -> Maybe Type
tcf_view = Type -> Maybe Type
noView
, tcf_tyvar :: VarSet -> TyCoVar -> Any
tcf_tyvar = VarSet -> TyCoVar -> Any
do_tcv, tcf_covar :: VarSet -> TyCoVar -> Any
tcf_covar = VarSet -> TyCoVar -> Any
do_tcv
, tcf_hole :: VarSet -> CoercionHole -> Any
tcf_hole = forall {p} {p}. p -> p -> Any
do_hole, tcf_tycobinder :: VarSet -> TyCoVar -> ForAllTyFlag -> VarSet
tcf_tycobinder = forall {p}. VarSet -> TyCoVar -> p -> VarSet
do_bndr }
where
do_tcv :: VarSet -> TyCoVar -> Any
do_tcv VarSet
is TyCoVar
tv = Bool -> Any
Any (Bool -> Bool
not (TyCoVar
tv TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
is) Bool -> Bool -> Bool
&& InterestingVarFun
check_fv TyCoVar
tv)
do_hole :: p -> p -> Any
do_hole p
_ p
_ = Bool -> Any
Any Bool
False
do_bndr :: VarSet -> TyCoVar -> p -> VarSet
do_bndr VarSet
is TyCoVar
tv p
_ = VarSet
is VarSet -> TyCoVar -> VarSet
`extendVarSet` TyCoVar
tv
anyFreeVarsOfType :: (TyCoVar -> Bool) -> Type -> Bool
anyFreeVarsOfType :: InterestingVarFun -> Type -> Bool
anyFreeVarsOfType InterestingVarFun
check_fv Type
ty = Any -> Bool
DM.getAny (Type -> Any
f Type
ty)
where (Type -> Any
f, [Type] -> Any
_, Coercion -> Any
_, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder InterestingVarFun
check_fv) VarSet
emptyVarSet
anyFreeVarsOfTypes :: (TyCoVar -> Bool) -> [Type] -> Bool
anyFreeVarsOfTypes :: InterestingVarFun -> [Type] -> Bool
anyFreeVarsOfTypes InterestingVarFun
check_fv [Type]
tys = Any -> Bool
DM.getAny ([Type] -> Any
f [Type]
tys)
where (Type -> Any
_, [Type] -> Any
f, Coercion -> Any
_, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder InterestingVarFun
check_fv) VarSet
emptyVarSet
anyFreeVarsOfCo :: (TyCoVar -> Bool) -> Coercion -> Bool
anyFreeVarsOfCo :: InterestingVarFun -> Coercion -> Bool
anyFreeVarsOfCo InterestingVarFun
check_fv Coercion
co = Any -> Bool
DM.getAny (Coercion -> Any
f Coercion
co)
where (Type -> Any
_, [Type] -> Any
_, Coercion -> Any
f, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder InterestingVarFun
check_fv) VarSet
emptyVarSet
noFreeVarsOfType :: Type -> Bool
noFreeVarsOfType :: Type -> Bool
noFreeVarsOfType Type
ty = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ Any -> Bool
DM.getAny (Type -> Any
f Type
ty)
where (Type -> Any
f, [Type] -> Any
_, Coercion -> Any
_, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder (forall a b. a -> b -> a
const Bool
True)) VarSet
emptyVarSet
noFreeVarsOfTypes :: [Type] -> Bool
noFreeVarsOfTypes :: [Type] -> Bool
noFreeVarsOfTypes [Type]
tys = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ Any -> Bool
DM.getAny ([Type] -> Any
f [Type]
tys)
where (Type -> Any
_, [Type] -> Any
f, Coercion -> Any
_, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder (forall a b. a -> b -> a
const Bool
True)) VarSet
emptyVarSet
noFreeVarsOfCo :: Coercion -> Bool
noFreeVarsOfCo :: Coercion -> Bool
noFreeVarsOfCo Coercion
co = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ Any -> Bool
DM.getAny (Coercion -> Any
f Coercion
co)
where (Type -> Any
_, [Type] -> Any
_, Coercion -> Any
f, [Coercion] -> Any
_) = forall a env.
Monoid a =>
TyCoFolder env a
-> env -> (Type -> a, [Type] -> a, Coercion -> a, [Coercion] -> a)
foldTyCo (InterestingVarFun -> TyCoFolder VarSet Any
afvFolder (forall a b. a -> b -> a
const Bool
True)) VarSet
emptyVarSet
scopedSort :: [TyCoVar] -> [TyCoVar]
scopedSort :: [TyCoVar] -> [TyCoVar]
scopedSort = [TyCoVar] -> [VarSet] -> [TyCoVar] -> [TyCoVar]
go [] []
where
go :: [TyCoVar]
-> [TyCoVarSet]
-> [TyCoVar]
-> [TyCoVar]
go :: [TyCoVar] -> [VarSet] -> [TyCoVar] -> [TyCoVar]
go [TyCoVar]
acc [VarSet]
_fv_list [] = forall a. [a] -> [a]
reverse [TyCoVar]
acc
go [TyCoVar]
acc [VarSet]
fv_list (TyCoVar
tv:[TyCoVar]
tvs)
= [TyCoVar] -> [VarSet] -> [TyCoVar] -> [TyCoVar]
go [TyCoVar]
acc' [VarSet]
fv_list' [TyCoVar]
tvs
where
([TyCoVar]
acc', [VarSet]
fv_list') = TyCoVar -> [TyCoVar] -> [VarSet] -> ([TyCoVar], [VarSet])
insert TyCoVar
tv [TyCoVar]
acc [VarSet]
fv_list
insert :: TyCoVar
-> [TyCoVar]
-> [TyCoVarSet]
-> ([TyCoVar], [TyCoVarSet])
insert :: TyCoVar -> [TyCoVar] -> [VarSet] -> ([TyCoVar], [VarSet])
insert TyCoVar
tv [] [] = ([TyCoVar
tv], [Type -> VarSet
tyCoVarsOfType (TyCoVar -> Type
tyVarKind TyCoVar
tv)])
insert TyCoVar
tv (TyCoVar
a:[TyCoVar]
as) (VarSet
fvs:[VarSet]
fvss)
| TyCoVar
tv TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
fvs
, ([TyCoVar]
as', [VarSet]
fvss') <- TyCoVar -> [TyCoVar] -> [VarSet] -> ([TyCoVar], [VarSet])
insert TyCoVar
tv [TyCoVar]
as [VarSet]
fvss
= (TyCoVar
aforall a. a -> [a] -> [a]
:[TyCoVar]
as', VarSet
fvs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
fv_tv forall a. a -> [a] -> [a]
: [VarSet]
fvss')
| Bool
otherwise
= (TyCoVar
tvforall a. a -> [a] -> [a]
:TyCoVar
aforall a. a -> [a] -> [a]
:[TyCoVar]
as, VarSet
fvs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
fv_tv forall a. a -> [a] -> [a]
: VarSet
fvs forall a. a -> [a] -> [a]
: [VarSet]
fvss)
where
fv_tv :: VarSet
fv_tv = Type -> VarSet
tyCoVarsOfType (TyCoVar -> Type
tyVarKind TyCoVar
tv)
insert TyCoVar
_ [TyCoVar]
_ [VarSet]
_ = forall a. HasCallStack => String -> a
panic String
"scopedSort"
tyCoVarsOfTypeWellScoped :: Type -> [TyVar]
tyCoVarsOfTypeWellScoped :: Type -> [TyCoVar]
tyCoVarsOfTypeWellScoped = [TyCoVar] -> [TyCoVar]
scopedSort forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> [TyCoVar]
tyCoVarsOfTypeList
tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
tyCoVarsOfTypesWellScoped :: [Type] -> [TyCoVar]
tyCoVarsOfTypesWellScoped = [TyCoVar] -> [TyCoVar]
scopedSort forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Type] -> [TyCoVar]
tyCoVarsOfTypesList
tyConsOfType :: Type -> UniqSet TyCon
tyConsOfType :: Type -> UniqSet TyCon
tyConsOfType Type
ty
= Type -> UniqSet TyCon
go Type
ty
where
go :: Type -> UniqSet TyCon
go :: Type -> UniqSet TyCon
go Type
ty | Just Type
ty' <- Type -> Maybe Type
coreView Type
ty = Type -> UniqSet TyCon
go Type
ty'
go (TyVarTy {}) = forall a. UniqSet a
emptyUniqSet
go (LitTy {}) = forall a. UniqSet a
emptyUniqSet
go (TyConApp TyCon
tc [Type]
tys) = forall {a}. Uniquable a => a -> UniqSet a
go_tc TyCon
tc forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` [Type] -> UniqSet TyCon
tyConsOfTypes [Type]
tys
go (AppTy Type
a Type
b) = Type -> UniqSet TyCon
go Type
a forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Type -> UniqSet TyCon
go Type
b
go (FunTy FunTyFlag
af Type
w Type
a Type
b) = Type -> UniqSet TyCon
go Type
w forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets`
Type -> UniqSet TyCon
go Type
a forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Type -> UniqSet TyCon
go Type
b
forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` forall {a}. Uniquable a => a -> UniqSet a
go_tc (FunTyFlag -> TyCon
funTyFlagTyCon FunTyFlag
af)
go (ForAllTy (Bndr TyCoVar
tv ForAllTyFlag
_) Type
ty) = Type -> UniqSet TyCon
go Type
ty forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Type -> UniqSet TyCon
go (TyCoVar -> Type
varType TyCoVar
tv)
go (CastTy Type
ty Coercion
co) = Type -> UniqSet TyCon
go Type
ty forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
co
go (CoercionTy Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co :: Coercion -> UniqSet TyCon
go_co (Refl Type
ty) = Type -> UniqSet TyCon
go Type
ty
go_co (GRefl Role
_ Type
ty MCoercion
mco) = Type -> UniqSet TyCon
go Type
ty forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` MCoercion -> UniqSet TyCon
go_mco MCoercion
mco
go_co (TyConAppCo Role
_ TyCon
tc [Coercion]
args) = forall {a}. Uniquable a => a -> UniqSet a
go_tc TyCon
tc forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` [Coercion] -> UniqSet TyCon
go_cos [Coercion]
args
go_co (AppCo Coercion
co Coercion
arg) = Coercion -> UniqSet TyCon
go_co Coercion
co forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
arg
go_co (ForAllCo TyCoVar
_ Coercion
kind_co Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
kind_co forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (FunCo { fco_mult :: Coercion -> Coercion
fco_mult = Coercion
m, fco_arg :: Coercion -> Coercion
fco_arg = Coercion
a, fco_res :: Coercion -> Coercion
fco_res = Coercion
r })
= Coercion -> UniqSet TyCon
go_co Coercion
m forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
a forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
r
go_co (AxiomInstCo CoAxiom Branched
ax BranchIndex
_ [Coercion]
args) = forall {br :: BranchFlag}. CoAxiom br -> UniqSet TyCon
go_ax CoAxiom Branched
ax forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` [Coercion] -> UniqSet TyCon
go_cos [Coercion]
args
go_co (UnivCo UnivCoProvenance
p Role
_ Type
t1 Type
t2) = UnivCoProvenance -> UniqSet TyCon
go_prov UnivCoProvenance
p forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Type -> UniqSet TyCon
go Type
t1 forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Type -> UniqSet TyCon
go Type
t2
go_co (CoVarCo {}) = forall a. UniqSet a
emptyUniqSet
go_co (HoleCo {}) = forall a. UniqSet a
emptyUniqSet
go_co (SymCo Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (TransCo Coercion
co1 Coercion
co2) = Coercion -> UniqSet TyCon
go_co Coercion
co1 forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
co2
go_co (SelCo CoSel
_ Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (LRCo LeftOrRight
_ Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (InstCo Coercion
co Coercion
arg) = Coercion -> UniqSet TyCon
go_co Coercion
co forall a. UniqSet a -> UniqSet a -> UniqSet a
`unionUniqSets` Coercion -> UniqSet TyCon
go_co Coercion
arg
go_co (KindCo Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (SubCo Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_co (AxiomRuleCo CoAxiomRule
_ [Coercion]
cs) = [Coercion] -> UniqSet TyCon
go_cos [Coercion]
cs
go_mco :: MCoercion -> UniqSet TyCon
go_mco MCoercion
MRefl = forall a. UniqSet a
emptyUniqSet
go_mco (MCo Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_prov :: UnivCoProvenance -> UniqSet TyCon
go_prov (PhantomProv Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_prov (ProofIrrelProv Coercion
co) = Coercion -> UniqSet TyCon
go_co Coercion
co
go_prov (PluginProv String
_) = forall a. UniqSet a
emptyUniqSet
go_prov (CorePrepProv Bool
_) = forall a. UniqSet a
emptyUniqSet
go_cos :: [Coercion] -> UniqSet TyCon
go_cos [Coercion]
cos = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coercion -> UniqSet TyCon
go_co) forall a. UniqSet a
emptyUniqSet [Coercion]
cos
go_tc :: a -> UniqSet a
go_tc a
tc = forall {a}. Uniquable a => a -> UniqSet a
unitUniqSet a
tc
go_ax :: CoAxiom br -> UniqSet TyCon
go_ax CoAxiom br
ax = forall {a}. Uniquable a => a -> UniqSet a
go_tc forall a b. (a -> b) -> a -> b
$ forall (br :: BranchFlag). CoAxiom br -> TyCon
coAxiomTyCon CoAxiom br
ax
tyConsOfTypes :: [Type] -> UniqSet TyCon
tyConsOfTypes :: [Type] -> UniqSet TyCon
tyConsOfTypes [Type]
tys = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> UniqSet TyCon
tyConsOfType) forall a. UniqSet a
emptyUniqSet [Type]
tys
occCheckExpand :: [Var] -> Type -> Maybe Type
occCheckExpand :: [TyCoVar] -> Type -> Maybe Type
occCheckExpand [TyCoVar]
vs_to_avoid Type
ty
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
vs_to_avoid
= forall a. a -> Maybe a
Just Type
ty
| Bool
otherwise
= (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go ([TyCoVar] -> VarSet
mkVarSet [TyCoVar]
vs_to_avoid, forall a. VarEnv a
emptyVarEnv) Type
ty
where
go :: (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go :: (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet
as, VarEnv TyCoVar
env) ty :: Type
ty@(TyVarTy TyCoVar
tv)
| Just TyCoVar
tv' <- forall a. VarEnv a -> TyCoVar -> Maybe a
lookupVarEnv VarEnv TyCoVar
env TyCoVar
tv = forall (m :: * -> *) a. Monad m => a -> m a
return (TyCoVar -> Type
mkTyVarTy TyCoVar
tv')
| VarSet -> InterestingVarFun
bad_var_occ VarSet
as TyCoVar
tv = forall a. Maybe a
Nothing
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return Type
ty
go (VarSet, VarEnv TyCoVar)
_ ty :: Type
ty@(LitTy {}) = forall (m :: * -> *) a. Monad m => a -> m a
return Type
ty
go (VarSet, VarEnv TyCoVar)
cxt (AppTy Type
ty1 Type
ty2) = do { Type
ty1' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty1
; Type
ty2' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty2
; forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> Type -> Type
AppTy Type
ty1' Type
ty2') }
go (VarSet, VarEnv TyCoVar)
cxt ty :: Type
ty@(FunTy FunTyFlag
_ Type
w Type
ty1 Type
ty2)
= do { Type
w' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
w
; Type
ty1' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty1
; Type
ty2' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty2
; forall (m :: * -> *) a. Monad m => a -> m a
return (Type
ty { ft_mult :: Type
ft_mult = Type
w', ft_arg :: Type
ft_arg = Type
ty1', ft_res :: Type
ft_res = Type
ty2' }) }
go cxt :: (VarSet, VarEnv TyCoVar)
cxt@(VarSet
as, VarEnv TyCoVar
env) (ForAllTy (Bndr TyCoVar
tv ForAllTyFlag
vis) Type
body_ty)
= do { Type
ki' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt (TyCoVar -> Type
varType TyCoVar
tv)
; let tv' :: TyCoVar
tv' = TyCoVar -> Type -> TyCoVar
setVarType TyCoVar
tv Type
ki'
env' :: VarEnv TyCoVar
env' = forall a. VarEnv a -> TyCoVar -> a -> VarEnv a
extendVarEnv VarEnv TyCoVar
env TyCoVar
tv TyCoVar
tv'
as' :: VarSet
as' = VarSet
as VarSet -> TyCoVar -> VarSet
`delVarSet` TyCoVar
tv
; Type
body' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet
as', VarEnv TyCoVar
env') Type
body_ty
; forall (m :: * -> *) a. Monad m => a -> m a
return (ForAllTyBinder -> Type -> Type
ForAllTy (forall var argf. var -> argf -> VarBndr var argf
Bndr TyCoVar
tv' ForAllTyFlag
vis) Type
body') }
go (VarSet, VarEnv TyCoVar)
cxt ty :: Type
ty@(TyConApp TyCon
tc [Type]
tys)
= case forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt) [Type]
tys of
Just [Type]
tys' -> forall (m :: * -> *) a. Monad m => a -> m a
return (TyCon -> [Type] -> Type
TyConApp TyCon
tc [Type]
tys')
Maybe [Type]
Nothing | Just Type
ty' <- Type -> Maybe Type
coreView Type
ty -> (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty'
| Bool
otherwise -> forall a. Maybe a
Nothing
go (VarSet, VarEnv TyCoVar)
cxt (CastTy Type
ty Coercion
co) = do { Type
ty' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty
; Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> Coercion -> Type
CastTy Type
ty' Coercion
co') }
go (VarSet, VarEnv TyCoVar)
cxt (CoercionTy Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Type
CoercionTy Coercion
co') }
bad_var_occ :: VarSet -> Var -> Bool
bad_var_occ :: VarSet -> InterestingVarFun
bad_var_occ VarSet
vs_to_avoid TyCoVar
v
= TyCoVar
v TyCoVar -> VarSet -> Bool
`elemVarSet` VarSet
vs_to_avoid
Bool -> Bool -> Bool
|| Type -> VarSet
tyCoVarsOfType (TyCoVar -> Type
varType TyCoVar
v) VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
vs_to_avoid
go_mco :: (VarSet, VarEnv TyCoVar) -> MCoercion -> Maybe MCoercion
go_mco (VarSet, VarEnv TyCoVar)
_ MCoercion
MRefl = forall (m :: * -> *) a. Monad m => a -> m a
return MCoercion
MRefl
go_mco (VarSet, VarEnv TyCoVar)
ctx (MCo Coercion
co) = Coercion -> MCoercion
MCo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
ctx Coercion
co
go_co :: (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt (Refl Type
ty) = do { Type
ty' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty
; forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> Coercion
Refl Type
ty') }
go_co (VarSet, VarEnv TyCoVar)
cxt (GRefl Role
r Type
ty MCoercion
mco) = do { MCoercion
mco' <- (VarSet, VarEnv TyCoVar) -> MCoercion -> Maybe MCoercion
go_mco (VarSet, VarEnv TyCoVar)
cxt MCoercion
mco
; Type
ty' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty
; forall (m :: * -> *) a. Monad m => a -> m a
return (Role -> Type -> MCoercion -> Coercion
GRefl Role
r Type
ty' MCoercion
mco') }
go_co (VarSet, VarEnv TyCoVar)
cxt (TyConAppCo Role
r TyCon
tc [Coercion]
args) = do { [Coercion]
args' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt) [Coercion]
args
; forall (m :: * -> *) a. Monad m => a -> m a
return (Role -> TyCon -> [Coercion] -> Coercion
TyConAppCo Role
r TyCon
tc [Coercion]
args') }
go_co (VarSet, VarEnv TyCoVar)
cxt (AppCo Coercion
co Coercion
arg) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; Coercion
arg' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
arg
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion -> Coercion
AppCo Coercion
co' Coercion
arg') }
go_co cxt :: (VarSet, VarEnv TyCoVar)
cxt@(VarSet
as, VarEnv TyCoVar
env) (ForAllCo TyCoVar
tv Coercion
kind_co Coercion
body_co)
= do { Coercion
kind_co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
kind_co
; let tv' :: TyCoVar
tv' = TyCoVar -> Type -> TyCoVar
setVarType TyCoVar
tv forall a b. (a -> b) -> a -> b
$
Coercion -> Type
coercionLKind Coercion
kind_co'
env' :: VarEnv TyCoVar
env' = forall a. VarEnv a -> TyCoVar -> a -> VarEnv a
extendVarEnv VarEnv TyCoVar
env TyCoVar
tv TyCoVar
tv'
as' :: VarSet
as' = VarSet
as VarSet -> TyCoVar -> VarSet
`delVarSet` TyCoVar
tv
; Coercion
body' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet
as', VarEnv TyCoVar
env') Coercion
body_co
; forall (m :: * -> *) a. Monad m => a -> m a
return (TyCoVar -> Coercion -> Coercion -> Coercion
ForAllCo TyCoVar
tv' Coercion
kind_co' Coercion
body') }
go_co (VarSet, VarEnv TyCoVar)
cxt co :: Coercion
co@(FunCo { fco_mult :: Coercion -> Coercion
fco_mult = Coercion
w, fco_arg :: Coercion -> Coercion
fco_arg = Coercion
co1 ,fco_res :: Coercion -> Coercion
fco_res = Coercion
co2 })
= do { Coercion
co1' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co1
; Coercion
co2' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co2
; Coercion
w' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
w
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion
co { fco_mult :: Coercion
fco_mult = Coercion
w', fco_arg :: Coercion
fco_arg = Coercion
co1', fco_res :: Coercion
fco_res = Coercion
co2' })}
go_co (VarSet
as,VarEnv TyCoVar
env) co :: Coercion
co@(CoVarCo TyCoVar
c)
| Just TyCoVar
c' <- forall a. VarEnv a -> TyCoVar -> Maybe a
lookupVarEnv VarEnv TyCoVar
env TyCoVar
c = forall (m :: * -> *) a. Monad m => a -> m a
return (TyCoVar -> Coercion
CoVarCo TyCoVar
c')
| VarSet -> InterestingVarFun
bad_var_occ VarSet
as TyCoVar
c = forall a. Maybe a
Nothing
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return Coercion
co
go_co (VarSet
as,VarEnv TyCoVar
_) co :: Coercion
co@(HoleCo CoercionHole
h)
| VarSet -> InterestingVarFun
bad_var_occ VarSet
as (CoercionHole -> TyCoVar
ch_co_var CoercionHole
h) = forall a. Maybe a
Nothing
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return Coercion
co
go_co (VarSet, VarEnv TyCoVar)
cxt (AxiomInstCo CoAxiom Branched
ax BranchIndex
ind [Coercion]
args) = do { [Coercion]
args' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt) [Coercion]
args
; forall (m :: * -> *) a. Monad m => a -> m a
return (CoAxiom Branched -> BranchIndex -> [Coercion] -> Coercion
AxiomInstCo CoAxiom Branched
ax BranchIndex
ind [Coercion]
args') }
go_co (VarSet, VarEnv TyCoVar)
cxt (UnivCo UnivCoProvenance
p Role
r Type
ty1 Type
ty2) = do { UnivCoProvenance
p' <- (VarSet, VarEnv TyCoVar)
-> UnivCoProvenance -> Maybe UnivCoProvenance
go_prov (VarSet, VarEnv TyCoVar)
cxt UnivCoProvenance
p
; Type
ty1' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty1
; Type
ty2' <- (VarSet, VarEnv TyCoVar) -> Type -> Maybe Type
go (VarSet, VarEnv TyCoVar)
cxt Type
ty2
; forall (m :: * -> *) a. Monad m => a -> m a
return (UnivCoProvenance -> Role -> Type -> Type -> Coercion
UnivCo UnivCoProvenance
p' Role
r Type
ty1' Type
ty2') }
go_co (VarSet, VarEnv TyCoVar)
cxt (SymCo Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion
SymCo Coercion
co') }
go_co (VarSet, VarEnv TyCoVar)
cxt (TransCo Coercion
co1 Coercion
co2) = do { Coercion
co1' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co1
; Coercion
co2' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co2
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion -> Coercion
TransCo Coercion
co1' Coercion
co2') }
go_co (VarSet, VarEnv TyCoVar)
cxt (SelCo CoSel
n Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (CoSel -> Coercion -> Coercion
SelCo CoSel
n Coercion
co') }
go_co (VarSet, VarEnv TyCoVar)
cxt (LRCo LeftOrRight
lr Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (LeftOrRight -> Coercion -> Coercion
LRCo LeftOrRight
lr Coercion
co') }
go_co (VarSet, VarEnv TyCoVar)
cxt (InstCo Coercion
co Coercion
arg) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; Coercion
arg' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
arg
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion -> Coercion
InstCo Coercion
co' Coercion
arg') }
go_co (VarSet, VarEnv TyCoVar)
cxt (KindCo Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion
KindCo Coercion
co') }
go_co (VarSet, VarEnv TyCoVar)
cxt (SubCo Coercion
co) = do { Coercion
co' <- (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
; forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> Coercion
SubCo Coercion
co') }
go_co (VarSet, VarEnv TyCoVar)
cxt (AxiomRuleCo CoAxiomRule
ax [Coercion]
cs) = do { [Coercion]
cs' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt) [Coercion]
cs
; forall (m :: * -> *) a. Monad m => a -> m a
return (CoAxiomRule -> [Coercion] -> Coercion
AxiomRuleCo CoAxiomRule
ax [Coercion]
cs') }
go_prov :: (VarSet, VarEnv TyCoVar)
-> UnivCoProvenance -> Maybe UnivCoProvenance
go_prov (VarSet, VarEnv TyCoVar)
cxt (PhantomProv Coercion
co) = Coercion -> UnivCoProvenance
PhantomProv forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
go_prov (VarSet, VarEnv TyCoVar)
cxt (ProofIrrelProv Coercion
co) = Coercion -> UnivCoProvenance
ProofIrrelProv forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (VarSet, VarEnv TyCoVar) -> Coercion -> Maybe Coercion
go_co (VarSet, VarEnv TyCoVar)
cxt Coercion
co
go_prov (VarSet, VarEnv TyCoVar)
_ p :: UnivCoProvenance
p@(PluginProv String
_) = forall (m :: * -> *) a. Monad m => a -> m a
return UnivCoProvenance
p
go_prov (VarSet, VarEnv TyCoVar)
_ p :: UnivCoProvenance
p@(CorePrepProv Bool
_) = forall (m :: * -> *) a. Monad m => a -> m a
return UnivCoProvenance
p