module TcTypeableValidity (tyConIsTypeable, typeIsTypeable) where
import GhcPrelude
import TyCoRep
import TyCon
import Type
import Data.Maybe (isJust)
tyConIsTypeable :: TyCon -> Bool
tyConIsTypeable :: TyCon -> Bool
tyConIsTypeable TyCon
tc =
Maybe TyConRepName -> Bool
forall a. Maybe a -> Bool
isJust (TyCon -> Maybe TyConRepName
tyConRepName_maybe TyCon
tc)
Bool -> Bool -> Bool
&& Type -> Bool
typeIsTypeable (Type -> Type
dropForAlls (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ TyCon -> Type
tyConKind TyCon
tc)
typeIsTypeable :: Type -> Bool
typeIsTypeable :: Type -> Bool
typeIsTypeable Type
ty
| Just Type
ty' <- Type -> Maybe Type
coreView Type
ty = Type -> Bool
typeIsTypeable Type
ty'
typeIsTypeable Type
ty
| Type -> Bool
isLiftedTypeKind Type
ty = Bool
True
typeIsTypeable (TyVarTy Var
_) = Bool
True
typeIsTypeable (AppTy Type
a Type
b) = Type -> Bool
typeIsTypeable Type
a Bool -> Bool -> Bool
&& Type -> Bool
typeIsTypeable Type
b
typeIsTypeable (FunTy Type
a Type
b) = Type -> Bool
typeIsTypeable Type
a Bool -> Bool -> Bool
&& Type -> Bool
typeIsTypeable Type
b
typeIsTypeable (TyConApp TyCon
tc [Type]
args) = TyCon -> Bool
tyConIsTypeable TyCon
tc
Bool -> Bool -> Bool
&& (Type -> Bool) -> [Type] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Type -> Bool
typeIsTypeable [Type]
args
typeIsTypeable (ForAllTy{}) = Bool
False
typeIsTypeable (LitTy TyLit
_) = Bool
True
typeIsTypeable (CastTy{}) = Bool
False
typeIsTypeable (CoercionTy{}) = Bool
False