{-# LANGUAGE CPP, FlexibleInstances #-}
module TyCon(
TyCon,
AlgTyConRhs(..), visibleDataCons,
AlgTyConFlav(..), isNoParent,
FamTyConFlav(..), Role(..), Injectivity(..),
RuntimeRepInfo(..), TyConFlavour(..),
TyConBinder, TyConBndrVis(..), TyConTyCoBinder,
mkNamedTyConBinder, mkNamedTyConBinders,
mkRequiredTyConBinder,
mkAnonTyConBinder, mkAnonTyConBinders,
tyConBinderArgFlag, tyConBndrVisArgFlag, isNamedTyConBinder,
isVisibleTyConBinder, isInvisibleTyConBinder,
tyConFieldLabels, lookupTyConFieldLabel,
mkAlgTyCon,
mkClassTyCon,
mkFunTyCon,
mkPrimTyCon,
mkKindTyCon,
mkLiftedPrimTyCon,
mkTupleTyCon,
mkSumTyCon,
mkDataTyConRhs,
mkSynonymTyCon,
mkFamilyTyCon,
mkPromotedDataCon,
mkTcTyCon,
isAlgTyCon, isVanillaAlgTyCon,
isClassTyCon, isFamInstTyCon,
isFunTyCon,
isPrimTyCon,
isTupleTyCon, isUnboxedTupleTyCon, isBoxedTupleTyCon,
isUnboxedSumTyCon, isPromotedTupleTyCon,
isTypeSynonymTyCon,
mightBeUnsaturatedTyCon,
isPromotedDataCon, isPromotedDataCon_maybe,
isKindTyCon, isLiftedTypeKindTyConName,
isTauTyCon, isFamFreeTyCon,
isDataTyCon, isProductTyCon, isDataProductTyCon_maybe,
isDataSumTyCon_maybe,
isEnumerationTyCon,
isNewTyCon, isAbstractTyCon,
isFamilyTyCon, isOpenFamilyTyCon,
isTypeFamilyTyCon, isDataFamilyTyCon,
isOpenTypeFamilyTyCon, isClosedSynFamilyTyConWithAxiom_maybe,
tyConInjectivityInfo,
isBuiltInSynFamTyCon_maybe,
isUnliftedTyCon,
isGadtSyntaxTyCon, isInjectiveTyCon, isGenerativeTyCon, isGenInjAlgRhs,
isTyConAssoc, tyConAssoc_maybe, tyConFlavourAssoc_maybe,
isImplicitTyCon,
isTyConWithSrcDataCons,
isTcTyCon, isTcLevPoly,
tyConName,
tyConSkolem,
tyConKind,
tyConUnique,
tyConTyVars, tyConVisibleTyVars,
tyConCType, tyConCType_maybe,
tyConDataCons, tyConDataCons_maybe,
tyConSingleDataCon_maybe, tyConSingleDataCon,
tyConSingleAlgDataCon_maybe,
tyConFamilySize,
tyConStupidTheta,
tyConArity,
tyConRoles,
tyConFlavour,
tyConTuple_maybe, tyConClass_maybe, tyConATs,
tyConFamInst_maybe, tyConFamInstSig_maybe, tyConFamilyCoercion_maybe,
tyConFamilyResVar_maybe,
synTyConDefn_maybe, synTyConRhs_maybe,
famTyConFlav_maybe, famTcResVar,
algTyConRhs,
newTyConRhs, newTyConEtadArity, newTyConEtadRhs,
unwrapNewTyCon_maybe, unwrapNewTyConEtad_maybe,
newTyConDataCon_maybe,
algTcFields,
tyConRuntimeRepInfo,
tyConBinders, tyConResKind, tyConTyVarBinders,
tcTyConScopedTyVars, tcTyConUserTyVars, tcTyConIsPoly,
mkTyConTagMap,
expandSynTyCon_maybe,
makeRecoveryTyCon,
newTyConCo, newTyConCo_maybe,
pprPromotionQuote, mkTyConKind,
tcFlavourCanBeUnsaturated, tcFlavourIsOpen,
TyConRepName, tyConRepName_maybe,
mkPrelTyConRepName,
tyConRepModOcc,
PrimRep(..), PrimElemRep(..),
isVoidRep, isGcPtrRep,
primRepSizeB,
primElemRepSizeB,
primRepIsFloat,
RecTcChecker, initRecTc, defaultRecTcMaxBound,
setRecTcMaxBound, checkRecTc
) where
#include "HsVersions.h"
import GhcPrelude
import {-# SOURCE #-} TyCoRep ( Kind, Type, PredType, pprType )
import {-# SOURCE #-} TysWiredIn ( runtimeRepTyCon, constraintKind
, vecCountTyCon, vecElemTyCon, liftedTypeKind
, mkFunKind, mkForAllKind )
import {-# SOURCE #-} DataCon ( DataCon, dataConExTyCoVars, dataConFieldLabels
, dataConTyCon, dataConFullSig
, isUnboxedSumCon )
import Binary
import Var
import VarSet
import Class
import BasicTypes
import DynFlags
import ForeignCall
import Name
import NameEnv
import CoAxiom
import PrelNames
import Maybes
import Outputable
import FastStringEnv
import FieldLabel
import Constants
import Util
import Unique( tyConRepNameUnique, dataConTyRepNameUnique )
import UniqSet
import Module
import qualified Data.Data as Data
type TyConBinder = VarBndr TyVar TyConBndrVis
type TyConTyCoBinder = VarBndr TyCoVar TyConBndrVis
data TyConBndrVis
= NamedTCB ArgFlag
| AnonTCB
instance Outputable TyConBndrVis where
ppr :: TyConBndrVis -> SDoc
ppr (NamedTCB flag :: ArgFlag
flag) = String -> SDoc
text "NamedTCB" SDoc -> SDoc -> SDoc
<+> ArgFlag -> SDoc
forall a. Outputable a => a -> SDoc
ppr ArgFlag
flag
ppr AnonTCB = String -> SDoc
text "AnonTCB"
mkAnonTyConBinder :: TyVar -> TyConBinder
mkAnonTyConBinder :: TyVar -> TyConBinder
mkAnonTyConBinder tv :: TyVar
tv = ASSERT( isTyVar tv)
TyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv TyConBndrVis
AnonTCB
mkAnonTyConBinders :: [TyVar] -> [TyConBinder]
mkAnonTyConBinders :: [TyVar] -> [TyConBinder]
mkAnonTyConBinders tvs :: [TyVar]
tvs = (TyVar -> TyConBinder) -> [TyVar] -> [TyConBinder]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> TyConBinder
mkAnonTyConBinder [TyVar]
tvs
mkNamedTyConBinder :: ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder :: ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder vis :: ArgFlag
vis tv :: TyVar
tv = ASSERT( isTyVar tv )
TyVar -> TyConBndrVis -> TyConBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv (ArgFlag -> TyConBndrVis
NamedTCB ArgFlag
vis)
mkNamedTyConBinders :: ArgFlag -> [TyVar] -> [TyConBinder]
mkNamedTyConBinders :: ArgFlag -> [TyVar] -> [TyConBinder]
mkNamedTyConBinders vis :: ArgFlag
vis tvs :: [TyVar]
tvs = (TyVar -> TyConBinder) -> [TyVar] -> [TyConBinder]
forall a b. (a -> b) -> [a] -> [b]
map (ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder ArgFlag
vis) [TyVar]
tvs
mkRequiredTyConBinder :: TyCoVarSet
-> TyVar
-> TyConBinder
mkRequiredTyConBinder :: TyCoVarSet -> TyVar -> TyConBinder
mkRequiredTyConBinder dep_set :: TyCoVarSet
dep_set tv :: TyVar
tv
| TyVar
tv TyVar -> TyCoVarSet -> Bool
`elemVarSet` TyCoVarSet
dep_set = ArgFlag -> TyVar -> TyConBinder
mkNamedTyConBinder ArgFlag
Required TyVar
tv
| Bool
otherwise = TyVar -> TyConBinder
mkAnonTyConBinder TyVar
tv
tyConBinderArgFlag :: TyConBinder -> ArgFlag
tyConBinderArgFlag :: TyConBinder -> ArgFlag
tyConBinderArgFlag (Bndr _ vis :: TyConBndrVis
vis) = TyConBndrVis -> ArgFlag
tyConBndrVisArgFlag TyConBndrVis
vis
tyConBndrVisArgFlag :: TyConBndrVis -> ArgFlag
tyConBndrVisArgFlag :: TyConBndrVis -> ArgFlag
tyConBndrVisArgFlag (NamedTCB vis :: ArgFlag
vis) = ArgFlag
vis
tyConBndrVisArgFlag AnonTCB = ArgFlag
Required
isNamedTyConBinder :: TyConBinder -> Bool
isNamedTyConBinder :: TyConBinder -> Bool
isNamedTyConBinder (Bndr _ (NamedTCB {})) = Bool
True
isNamedTyConBinder _ = Bool
False
isVisibleTyConBinder :: VarBndr tv TyConBndrVis -> Bool
isVisibleTyConBinder :: VarBndr tv TyConBndrVis -> Bool
isVisibleTyConBinder (Bndr _ tcb_vis :: TyConBndrVis
tcb_vis) = TyConBndrVis -> Bool
isVisibleTcbVis TyConBndrVis
tcb_vis
isVisibleTcbVis :: TyConBndrVis -> Bool
isVisibleTcbVis :: TyConBndrVis -> Bool
isVisibleTcbVis (NamedTCB vis :: ArgFlag
vis) = ArgFlag -> Bool
isVisibleArgFlag ArgFlag
vis
isVisibleTcbVis AnonTCB = Bool
True
isInvisibleTyConBinder :: VarBndr tv TyConBndrVis -> Bool
isInvisibleTyConBinder :: VarBndr tv TyConBndrVis -> Bool
isInvisibleTyConBinder tcb :: VarBndr tv TyConBndrVis
tcb = Bool -> Bool
not (VarBndr tv TyConBndrVis -> Bool
forall tv. VarBndr tv TyConBndrVis -> Bool
isVisibleTyConBinder VarBndr tv TyConBndrVis
tcb)
mkTyConKind :: [TyConBinder] -> Kind -> Kind
mkTyConKind :: [TyConBinder] -> Kind -> Kind
mkTyConKind bndrs :: [TyConBinder]
bndrs res_kind :: Kind
res_kind = (TyConBinder -> Kind -> Kind) -> Kind -> [TyConBinder] -> Kind
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr TyConBinder -> Kind -> Kind
mk Kind
res_kind [TyConBinder]
bndrs
where
mk :: TyConBinder -> Kind -> Kind
mk :: TyConBinder -> Kind -> Kind
mk (Bndr tv :: TyVar
tv AnonTCB) k :: Kind
k = Kind -> Kind -> Kind
mkFunKind (TyVar -> Kind
varType TyVar
tv) Kind
k
mk (Bndr tv :: TyVar
tv (NamedTCB vis :: ArgFlag
vis)) k :: Kind
k = TyVar -> ArgFlag -> Kind -> Kind
mkForAllKind TyVar
tv ArgFlag
vis Kind
k
tyConTyVarBinders :: [TyConBinder]
-> [TyVarBinder]
tyConTyVarBinders :: [TyConBinder] -> [TyVarBinder]
tyConTyVarBinders tc_bndrs :: [TyConBinder]
tc_bndrs
= (TyConBinder -> TyVarBinder) -> [TyConBinder] -> [TyVarBinder]
forall a b. (a -> b) -> [a] -> [b]
map TyConBinder -> TyVarBinder
mk_binder [TyConBinder]
tc_bndrs
where
mk_binder :: TyConBinder -> TyVarBinder
mk_binder (Bndr tv :: TyVar
tv tc_vis :: TyConBndrVis
tc_vis) = ArgFlag -> TyVar -> TyVarBinder
mkTyVarBinder ArgFlag
vis TyVar
tv
where
vis :: ArgFlag
vis = case TyConBndrVis
tc_vis of
AnonTCB -> ArgFlag
Specified
NamedTCB Required -> ArgFlag
Specified
NamedTCB vis -> ArgFlag
vis
tyConVisibleTyVars :: TyCon -> [TyVar]
tyConVisibleTyVars :: TyCon -> [TyVar]
tyConVisibleTyVars tc :: TyCon
tc
= [ TyVar
tv | Bndr tv :: TyVar
tv vis :: TyConBndrVis
vis <- TyCon -> [TyConBinder]
tyConBinders TyCon
tc
, TyConBndrVis -> Bool
isVisibleTcbVis TyConBndrVis
vis ]
instance Outputable tv => Outputable (VarBndr tv TyConBndrVis) where
ppr :: VarBndr tv TyConBndrVis -> SDoc
ppr (Bndr v :: tv
v AnonTCB) = String -> SDoc
text "anon" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v)
ppr (Bndr v :: tv
v (NamedTCB Required)) = String -> SDoc
text "req" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v)
ppr (Bndr v :: tv
v (NamedTCB Specified)) = String -> SDoc
text "spec" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v)
ppr (Bndr v :: tv
v (NamedTCB Inferred)) = String -> SDoc
text "inf" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v)
instance Binary TyConBndrVis where
put_ :: BinHandle -> TyConBndrVis -> IO ()
put_ bh :: BinHandle
bh AnonTCB = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh 0
put_ bh :: BinHandle
bh (NamedTCB vis :: ArgFlag
vis) = do { BinHandle -> Word8 -> IO ()
putByte BinHandle
bh 1; BinHandle -> ArgFlag -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh ArgFlag
vis }
get :: BinHandle -> IO TyConBndrVis
get bh :: BinHandle
bh = do { Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
; case Word8
h of
0 -> TyConBndrVis -> IO TyConBndrVis
forall (m :: * -> *) a. Monad m => a -> m a
return TyConBndrVis
AnonTCB
_ -> do { ArgFlag
vis <- BinHandle -> IO ArgFlag
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; TyConBndrVis -> IO TyConBndrVis
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgFlag -> TyConBndrVis
NamedTCB ArgFlag
vis) } }
data TyCon
=
FunTyCon {
TyCon -> Unique
tyConUnique :: Unique,
TyCon -> Name
tyConName :: Name,
TyCon -> [TyConBinder]
tyConBinders :: [TyConBinder],
TyCon -> Kind
tyConResKind :: Kind,
TyCon -> Kind
tyConKind :: Kind,
TyCon -> Int
tyConArity :: Arity,
TyCon -> Name
tcRepName :: TyConRepName
}
| AlgTyCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConBinder],
TyCon -> [TyVar]
tyConTyVars :: [TyVar],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
TyCon -> [Role]
tcRoles :: [Role],
TyCon -> Maybe CType
tyConCType :: Maybe CType,
TyCon -> Bool
algTcGadtSyntax :: Bool,
TyCon -> [Kind]
algTcStupidTheta :: [PredType],
TyCon -> AlgTyConRhs
algTcRhs :: AlgTyConRhs,
TyCon -> FieldLabelEnv
algTcFields :: FieldLabelEnv,
TyCon -> AlgTyConFlav
algTcParent :: AlgTyConFlav
}
| SynonymTyCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConBinder],
tyConTyVars :: [TyVar],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
tcRoles :: [Role],
TyCon -> Kind
synTcRhs :: Type,
TyCon -> Bool
synIsTau :: Bool,
TyCon -> Bool
synIsFamFree :: Bool
}
| FamilyTyCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConBinder],
tyConTyVars :: [TyVar],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
TyCon -> Maybe Name
famTcResVar :: Maybe Name,
TyCon -> FamTyConFlav
famTcFlav :: FamTyConFlav,
TyCon -> Maybe TyCon
famTcParent :: Maybe TyCon,
TyCon -> Injectivity
famTcInj :: Injectivity
}
| PrimTyCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConBinder],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
tcRoles :: [Role],
TyCon -> Bool
isUnlifted :: Bool,
TyCon -> Maybe Name
primRepName :: Maybe TyConRepName
}
| PromotedDataCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConTyCoBinder],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
tcRoles :: [Role],
TyCon -> DataCon
dataCon :: DataCon,
tcRepName :: TyConRepName,
TyCon -> RuntimeRepInfo
promDcRepInfo :: RuntimeRepInfo
}
| TcTyCon {
tyConUnique :: Unique,
tyConName :: Name,
tyConBinders :: [TyConBinder],
tyConTyVars :: [TyVar],
tyConResKind :: Kind,
tyConKind :: Kind,
tyConArity :: Arity,
TyCon -> [(Name, TyVar)]
tcTyConScopedTyVars :: [(Name,TyVar)],
TyCon -> SDoc
tcTyConUserTyVars :: SDoc,
TyCon -> Bool
tcTyConIsPoly :: Bool,
TyCon -> TyConFlavour
tcTyConFlavour :: TyConFlavour
}
data AlgTyConRhs
= AbstractTyCon
| DataTyCon {
AlgTyConRhs -> [DataCon]
data_cons :: [DataCon],
AlgTyConRhs -> Int
data_cons_size :: Int,
AlgTyConRhs -> Bool
is_enum :: Bool
}
| TupleTyCon {
AlgTyConRhs -> DataCon
data_con :: DataCon,
AlgTyConRhs -> TupleSort
tup_sort :: TupleSort
}
| SumTyCon {
data_cons :: [DataCon],
data_cons_size :: Int
}
| NewTyCon {
data_con :: DataCon,
AlgTyConRhs -> Kind
nt_rhs :: Type,
AlgTyConRhs -> ([TyVar], Kind)
nt_etad_rhs :: ([TyVar], Type),
AlgTyConRhs -> CoAxiom Unbranched
nt_co :: CoAxiom Unbranched
}
mkSumTyConRhs :: [DataCon] -> AlgTyConRhs
mkSumTyConRhs :: [DataCon] -> AlgTyConRhs
mkSumTyConRhs data_cons :: [DataCon]
data_cons = [DataCon] -> Int -> AlgTyConRhs
SumTyCon [DataCon]
data_cons ([DataCon] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DataCon]
data_cons)
mkDataTyConRhs :: [DataCon] -> AlgTyConRhs
mkDataTyConRhs :: [DataCon] -> AlgTyConRhs
mkDataTyConRhs cons :: [DataCon]
cons
= DataTyCon :: [DataCon] -> Int -> Bool -> AlgTyConRhs
DataTyCon {
data_cons :: [DataCon]
data_cons = [DataCon]
cons,
data_cons_size :: Int
data_cons_size = [DataCon] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DataCon]
cons,
is_enum :: Bool
is_enum = Bool -> Bool
not ([DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
cons) Bool -> Bool -> Bool
&& (DataCon -> Bool) -> [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all DataCon -> Bool
is_enum_con [DataCon]
cons
}
where
is_enum_con :: DataCon -> Bool
is_enum_con con :: DataCon
con
| (_univ_tvs :: [TyVar]
_univ_tvs, ex_tvs :: [TyVar]
ex_tvs, eq_spec :: [EqSpec]
eq_spec, theta :: [Kind]
theta, arg_tys :: [Kind]
arg_tys, _res :: Kind
_res)
<- DataCon -> ([TyVar], [TyVar], [EqSpec], [Kind], [Kind], Kind)
dataConFullSig DataCon
con
= [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyVar]
ex_tvs Bool -> Bool -> Bool
&& [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec Bool -> Bool -> Bool
&& [Kind] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Kind]
theta Bool -> Bool -> Bool
&& [Kind] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Kind]
arg_tys
data RuntimeRepInfo
= NoRRI
| RuntimeRep ([Type] -> [PrimRep])
| VecCount Int
| VecElem PrimElemRep
visibleDataCons :: AlgTyConRhs -> [DataCon]
visibleDataCons :: AlgTyConRhs -> [DataCon]
visibleDataCons (AbstractTyCon {}) = []
visibleDataCons (DataTyCon{ data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cs }) = [DataCon]
cs
visibleDataCons (NewTyCon{ data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
c }) = [DataCon
c]
visibleDataCons (TupleTyCon{ data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
c }) = [DataCon
c]
visibleDataCons (SumTyCon{ data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cs }) = [DataCon]
cs
data AlgTyConFlav
=
VanillaAlgTyCon
TyConRepName
| UnboxedAlgTyCon
(Maybe TyConRepName)
| ClassTyCon
Class
TyConRepName
| DataFamInstTyCon
(CoAxiom Unbranched)
TyCon
[Type]
instance Outputable AlgTyConFlav where
ppr :: AlgTyConFlav -> SDoc
ppr (VanillaAlgTyCon {}) = String -> SDoc
text "Vanilla ADT"
ppr (UnboxedAlgTyCon {}) = String -> SDoc
text "Unboxed ADT"
ppr (ClassTyCon cls :: Class
cls _) = String -> SDoc
text "Class parent" SDoc -> SDoc -> SDoc
<+> Class -> SDoc
forall a. Outputable a => a -> SDoc
ppr Class
cls
ppr (DataFamInstTyCon _ tc :: TyCon
tc tys :: [Kind]
tys) = String -> SDoc
text "Family parent (family instance)"
SDoc -> SDoc -> SDoc
<+> TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
sep ((Kind -> SDoc) -> [Kind] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Kind -> SDoc
pprType [Kind]
tys)
okParent :: Name -> AlgTyConFlav -> Bool
okParent :: Name -> AlgTyConFlav -> Bool
okParent _ (VanillaAlgTyCon {}) = Bool
True
okParent _ (UnboxedAlgTyCon {}) = Bool
True
okParent tc_name :: Name
tc_name (ClassTyCon cls :: Class
cls _) = Name
tc_name Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon -> Name
tyConName (Class -> TyCon
classTyCon Class
cls)
okParent _ (DataFamInstTyCon _ fam_tc :: TyCon
fam_tc tys :: [Kind]
tys) = [Kind]
tys [Kind] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthAtLeast` TyCon -> Int
tyConArity TyCon
fam_tc
isNoParent :: AlgTyConFlav -> Bool
isNoParent :: AlgTyConFlav -> Bool
isNoParent (VanillaAlgTyCon {}) = Bool
True
isNoParent _ = Bool
False
data Injectivity
= NotInjective
| Injective [Bool]
deriving( Injectivity -> Injectivity -> Bool
(Injectivity -> Injectivity -> Bool)
-> (Injectivity -> Injectivity -> Bool) -> Eq Injectivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Injectivity -> Injectivity -> Bool
$c/= :: Injectivity -> Injectivity -> Bool
== :: Injectivity -> Injectivity -> Bool
$c== :: Injectivity -> Injectivity -> Bool
Eq )
data FamTyConFlav
=
DataFamilyTyCon
TyConRepName
| OpenSynFamilyTyCon
| ClosedSynFamilyTyCon (Maybe (CoAxiom Branched))
| AbstractClosedSynFamilyTyCon
| BuiltInSynFamTyCon BuiltInSynFamily
instance Outputable FamTyConFlav where
ppr :: FamTyConFlav -> SDoc
ppr (DataFamilyTyCon n :: Name
n) = String -> SDoc
text "data family" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n
ppr OpenSynFamilyTyCon = String -> SDoc
text "open type family"
ppr (ClosedSynFamilyTyCon Nothing) = String -> SDoc
text "closed type family"
ppr (ClosedSynFamilyTyCon (Just coax :: CoAxiom Branched
coax)) = String -> SDoc
text "closed type family" SDoc -> SDoc -> SDoc
<+> CoAxiom Branched -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoAxiom Branched
coax
ppr AbstractClosedSynFamilyTyCon = String -> SDoc
text "abstract closed type family"
ppr (BuiltInSynFamTyCon _) = String -> SDoc
text "built-in type family"
type TyConRepName = Name
tyConRepName_maybe :: TyCon -> Maybe TyConRepName
tyConRepName_maybe :: TyCon -> Maybe Name
tyConRepName_maybe (FunTyCon { tcRepName :: TyCon -> Name
tcRepName = Name
rep_nm })
= Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm
tyConRepName_maybe (PrimTyCon { primRepName :: TyCon -> Maybe Name
primRepName = Maybe Name
mb_rep_nm })
= Maybe Name
mb_rep_nm
tyConRepName_maybe (AlgTyCon { algTcParent :: TyCon -> AlgTyConFlav
algTcParent = AlgTyConFlav
parent })
| VanillaAlgTyCon rep_nm :: Name
rep_nm <- AlgTyConFlav
parent = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm
| ClassTyCon _ rep_nm :: Name
rep_nm <- AlgTyConFlav
parent = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm
| UnboxedAlgTyCon rep_nm :: Maybe Name
rep_nm <- AlgTyConFlav
parent = Maybe Name
rep_nm
tyConRepName_maybe (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = DataFamilyTyCon rep_nm :: Name
rep_nm })
= Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm
tyConRepName_maybe (PromotedDataCon { dataCon :: TyCon -> DataCon
dataCon = DataCon
dc, tcRepName :: TyCon -> Name
tcRepName = Name
rep_nm })
| DataCon -> Bool
isUnboxedSumCon DataCon
dc
= Maybe Name
forall a. Maybe a
Nothing
| Bool
otherwise
= Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm
tyConRepName_maybe _ = Maybe Name
forall a. Maybe a
Nothing
mkPrelTyConRepName :: Name -> TyConRepName
mkPrelTyConRepName :: Name -> Name
mkPrelTyConRepName tc_name :: Name
tc_name
= Unique -> Module -> OccName -> SrcSpan -> Name
mkExternalName Unique
rep_uniq Module
rep_mod OccName
rep_occ (Name -> SrcSpan
nameSrcSpan Name
tc_name)
where
name_occ :: OccName
name_occ = Name -> OccName
nameOccName Name
tc_name
name_mod :: Module
name_mod = HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
tc_name
name_uniq :: Unique
name_uniq = Name -> Unique
nameUnique Name
tc_name
rep_uniq :: Unique
rep_uniq | OccName -> Bool
isTcOcc OccName
name_occ = Unique -> Unique
tyConRepNameUnique Unique
name_uniq
| Bool
otherwise = Unique -> Unique
dataConTyRepNameUnique Unique
name_uniq
(rep_mod :: Module
rep_mod, rep_occ :: OccName
rep_occ) = Module -> OccName -> (Module, OccName)
tyConRepModOcc Module
name_mod OccName
name_occ
tyConRepModOcc :: Module -> OccName -> (Module, OccName)
tyConRepModOcc :: Module -> OccName -> (Module, OccName)
tyConRepModOcc tc_module :: Module
tc_module tc_occ :: OccName
tc_occ = (Module
rep_module, OccName -> OccName
mkTyConRepOcc OccName
tc_occ)
where
rep_module :: Module
rep_module
| Module
tc_module Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
gHC_PRIM = Module
gHC_TYPES
| Bool
otherwise = Module
tc_module
data PrimRep
= VoidRep
| LiftedRep
| UnliftedRep
| Int8Rep
| Int16Rep
| IntRep
| WordRep
| Int64Rep
| Word8Rep
| Word16Rep
| Word64Rep
| AddrRep
| FloatRep
| DoubleRep
| VecRep Int PrimElemRep
deriving( PrimRep -> PrimRep -> Bool
(PrimRep -> PrimRep -> Bool)
-> (PrimRep -> PrimRep -> Bool) -> Eq PrimRep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrimRep -> PrimRep -> Bool
$c/= :: PrimRep -> PrimRep -> Bool
== :: PrimRep -> PrimRep -> Bool
$c== :: PrimRep -> PrimRep -> Bool
Eq, Int -> PrimRep -> ShowS
[PrimRep] -> ShowS
PrimRep -> String
(Int -> PrimRep -> ShowS)
-> (PrimRep -> String) -> ([PrimRep] -> ShowS) -> Show PrimRep
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrimRep] -> ShowS
$cshowList :: [PrimRep] -> ShowS
show :: PrimRep -> String
$cshow :: PrimRep -> String
showsPrec :: Int -> PrimRep -> ShowS
$cshowsPrec :: Int -> PrimRep -> ShowS
Show )
data PrimElemRep
= Int8ElemRep
| Int16ElemRep
| Int32ElemRep
| Int64ElemRep
| Word8ElemRep
| Word16ElemRep
| Word32ElemRep
| Word64ElemRep
| FloatElemRep
| DoubleElemRep
deriving( PrimElemRep -> PrimElemRep -> Bool
(PrimElemRep -> PrimElemRep -> Bool)
-> (PrimElemRep -> PrimElemRep -> Bool) -> Eq PrimElemRep
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrimElemRep -> PrimElemRep -> Bool
$c/= :: PrimElemRep -> PrimElemRep -> Bool
== :: PrimElemRep -> PrimElemRep -> Bool
$c== :: PrimElemRep -> PrimElemRep -> Bool
Eq, Int -> PrimElemRep -> ShowS
[PrimElemRep] -> ShowS
PrimElemRep -> String
(Int -> PrimElemRep -> ShowS)
-> (PrimElemRep -> String)
-> ([PrimElemRep] -> ShowS)
-> Show PrimElemRep
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrimElemRep] -> ShowS
$cshowList :: [PrimElemRep] -> ShowS
show :: PrimElemRep -> String
$cshow :: PrimElemRep -> String
showsPrec :: Int -> PrimElemRep -> ShowS
$cshowsPrec :: Int -> PrimElemRep -> ShowS
Show )
instance Outputable PrimRep where
ppr :: PrimRep -> SDoc
ppr r :: PrimRep
r = String -> SDoc
text (PrimRep -> String
forall a. Show a => a -> String
show PrimRep
r)
instance Outputable PrimElemRep where
ppr :: PrimElemRep -> SDoc
ppr r :: PrimElemRep
r = String -> SDoc
text (PrimElemRep -> String
forall a. Show a => a -> String
show PrimElemRep
r)
isVoidRep :: PrimRep -> Bool
isVoidRep :: PrimRep -> Bool
isVoidRep VoidRep = Bool
True
isVoidRep _other :: PrimRep
_other = Bool
False
isGcPtrRep :: PrimRep -> Bool
isGcPtrRep :: PrimRep -> Bool
isGcPtrRep LiftedRep = Bool
True
isGcPtrRep UnliftedRep = Bool
True
isGcPtrRep _ = Bool
False
primRepSizeB :: DynFlags -> PrimRep -> Int
primRepSizeB :: DynFlags -> PrimRep -> Int
primRepSizeB dflags :: DynFlags
dflags IntRep = DynFlags -> Int
wORD_SIZE DynFlags
dflags
primRepSizeB dflags :: DynFlags
dflags WordRep = DynFlags -> Int
wORD_SIZE DynFlags
dflags
primRepSizeB _ Int8Rep = 1
primRepSizeB _ Int16Rep = 2
primRepSizeB _ Int64Rep = Int
wORD64_SIZE
primRepSizeB _ Word8Rep = 1
primRepSizeB _ Word16Rep = 2
primRepSizeB _ Word64Rep = Int
wORD64_SIZE
primRepSizeB _ FloatRep = Int
fLOAT_SIZE
primRepSizeB dflags :: DynFlags
dflags DoubleRep = DynFlags -> Int
dOUBLE_SIZE DynFlags
dflags
primRepSizeB dflags :: DynFlags
dflags AddrRep = DynFlags -> Int
wORD_SIZE DynFlags
dflags
primRepSizeB dflags :: DynFlags
dflags LiftedRep = DynFlags -> Int
wORD_SIZE DynFlags
dflags
primRepSizeB dflags :: DynFlags
dflags UnliftedRep = DynFlags -> Int
wORD_SIZE DynFlags
dflags
primRepSizeB _ VoidRep = 0
primRepSizeB _ (VecRep len :: Int
len rep :: PrimElemRep
rep) = Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
* PrimElemRep -> Int
primElemRepSizeB PrimElemRep
rep
primElemRepSizeB :: PrimElemRep -> Int
primElemRepSizeB :: PrimElemRep -> Int
primElemRepSizeB Int8ElemRep = 1
primElemRepSizeB Int16ElemRep = 2
primElemRepSizeB Int32ElemRep = 4
primElemRepSizeB Int64ElemRep = 8
primElemRepSizeB Word8ElemRep = 1
primElemRepSizeB Word16ElemRep = 2
primElemRepSizeB Word32ElemRep = 4
primElemRepSizeB Word64ElemRep = 8
primElemRepSizeB FloatElemRep = 4
primElemRepSizeB DoubleElemRep = 8
primRepIsFloat :: PrimRep -> Maybe Bool
primRepIsFloat :: PrimRep -> Maybe Bool
primRepIsFloat FloatRep = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
primRepIsFloat DoubleRep = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
primRepIsFloat (VecRep _ _) = Maybe Bool
forall a. Maybe a
Nothing
primRepIsFloat _ = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
tyConFieldLabels :: TyCon -> [FieldLabel]
tyConFieldLabels :: TyCon -> [FieldLabel]
tyConFieldLabels tc :: TyCon
tc = FieldLabelEnv -> [FieldLabel]
forall a. DFastStringEnv a -> [a]
dFsEnvElts (FieldLabelEnv -> [FieldLabel]) -> FieldLabelEnv -> [FieldLabel]
forall a b. (a -> b) -> a -> b
$ TyCon -> FieldLabelEnv
tyConFieldLabelEnv TyCon
tc
tyConFieldLabelEnv :: TyCon -> FieldLabelEnv
tyConFieldLabelEnv :: TyCon -> FieldLabelEnv
tyConFieldLabelEnv tc :: TyCon
tc
| TyCon -> Bool
isAlgTyCon TyCon
tc = TyCon -> FieldLabelEnv
algTcFields TyCon
tc
| Bool
otherwise = FieldLabelEnv
forall a. DFastStringEnv a
emptyDFsEnv
lookupTyConFieldLabel :: FieldLabelString -> TyCon -> Maybe FieldLabel
lookupTyConFieldLabel :: FieldLabelString -> TyCon -> Maybe FieldLabel
lookupTyConFieldLabel lbl :: FieldLabelString
lbl tc :: TyCon
tc = FieldLabelEnv -> FieldLabelString -> Maybe FieldLabel
forall a. DFastStringEnv a -> FieldLabelString -> Maybe a
lookupDFsEnv (TyCon -> FieldLabelEnv
tyConFieldLabelEnv TyCon
tc) FieldLabelString
lbl
fieldsOfAlgTcRhs :: AlgTyConRhs -> FieldLabelEnv
fieldsOfAlgTcRhs :: AlgTyConRhs -> FieldLabelEnv
fieldsOfAlgTcRhs rhs :: AlgTyConRhs
rhs = [(FieldLabelString, FieldLabel)] -> FieldLabelEnv
forall a. [(FieldLabelString, a)] -> DFastStringEnv a
mkDFsEnv [ (FieldLabel -> FieldLabelString
forall a. FieldLbl a -> FieldLabelString
flLabel FieldLabel
fl, FieldLabel
fl)
| FieldLabel
fl <- [DataCon] -> [FieldLabel]
forall (t :: * -> *). Foldable t => t DataCon -> [FieldLabel]
dataConsFields (AlgTyConRhs -> [DataCon]
visibleDataCons AlgTyConRhs
rhs) ]
where
dataConsFields :: t DataCon -> [FieldLabel]
dataConsFields dcs :: t DataCon
dcs = (DataCon -> [FieldLabel]) -> t DataCon -> [FieldLabel]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap DataCon -> [FieldLabel]
dataConFieldLabels t DataCon
dcs
mkFunTyCon :: Name -> [TyConBinder] -> Name -> TyCon
mkFunTyCon :: Name -> [TyConBinder] -> Name -> TyCon
mkFunTyCon name :: Name
name binders :: [TyConBinder]
binders rep_nm :: Name
rep_nm
= FunTyCon :: Unique
-> Name -> [TyConBinder] -> Kind -> Kind -> Int -> Name -> TyCon
FunTyCon {
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConName :: Name
tyConName = Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
liftedTypeKind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
liftedTypeKind,
tyConArity :: Int
tyConArity = [TyConBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyConBinder]
binders,
tcRepName :: Name
tcRepName = Name
rep_nm
}
mkAlgTyCon :: Name
-> [TyConBinder]
-> Kind
-> [Role]
-> Maybe CType
-> [PredType]
-> AlgTyConRhs
-> AlgTyConFlav
-> Bool
-> TyCon
mkAlgTyCon :: Name
-> [TyConBinder]
-> Kind
-> [Role]
-> Maybe CType
-> [Kind]
-> AlgTyConRhs
-> AlgTyConFlav
-> Bool
-> TyCon
mkAlgTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles cType :: Maybe CType
cType stupid :: [Kind]
stupid rhs :: AlgTyConRhs
rhs parent :: AlgTyConFlav
parent gadt_syn :: Bool
gadt_syn
= AlgTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> [Role]
-> Maybe CType
-> Bool
-> [Kind]
-> AlgTyConRhs
-> FieldLabelEnv
-> AlgTyConFlav
-> TyCon
AlgTyCon {
tyConName :: Name
tyConName = Name
name,
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
tyConArity :: Int
tyConArity = [TyConBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyConBinder]
binders,
tyConTyVars :: [TyVar]
tyConTyVars = [TyConBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
binders,
tcRoles :: [Role]
tcRoles = [Role]
roles,
tyConCType :: Maybe CType
tyConCType = Maybe CType
cType,
algTcStupidTheta :: [Kind]
algTcStupidTheta = [Kind]
stupid,
algTcRhs :: AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs,
algTcFields :: FieldLabelEnv
algTcFields = AlgTyConRhs -> FieldLabelEnv
fieldsOfAlgTcRhs AlgTyConRhs
rhs,
algTcParent :: AlgTyConFlav
algTcParent = ASSERT2( okParent name parent, ppr name $$ ppr parent ) parent,
algTcGadtSyntax :: Bool
algTcGadtSyntax = Bool
gadt_syn
}
mkClassTyCon :: Name -> [TyConBinder]
-> [Role] -> AlgTyConRhs -> Class
-> Name -> TyCon
mkClassTyCon :: Name
-> [TyConBinder] -> [Role] -> AlgTyConRhs -> Class -> Name -> TyCon
mkClassTyCon name :: Name
name binders :: [TyConBinder]
binders roles :: [Role]
roles rhs :: AlgTyConRhs
rhs clas :: Class
clas tc_rep_name :: Name
tc_rep_name
= Name
-> [TyConBinder]
-> Kind
-> [Role]
-> Maybe CType
-> [Kind]
-> AlgTyConRhs
-> AlgTyConFlav
-> Bool
-> TyCon
mkAlgTyCon Name
name [TyConBinder]
binders Kind
constraintKind [Role]
roles Maybe CType
forall a. Maybe a
Nothing [] AlgTyConRhs
rhs
(Class -> Name -> AlgTyConFlav
ClassTyCon Class
clas Name
tc_rep_name)
Bool
False
mkTupleTyCon :: Name
-> [TyConBinder]
-> Kind
-> Arity
-> DataCon
-> TupleSort
-> AlgTyConFlav
-> TyCon
mkTupleTyCon :: Name
-> [TyConBinder]
-> Kind
-> Int
-> DataCon
-> TupleSort
-> AlgTyConFlav
-> TyCon
mkTupleTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind arity :: Int
arity con :: DataCon
con sort :: TupleSort
sort parent :: AlgTyConFlav
parent
= AlgTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> [Role]
-> Maybe CType
-> Bool
-> [Kind]
-> AlgTyConRhs
-> FieldLabelEnv
-> AlgTyConFlav
-> TyCon
AlgTyCon {
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConName :: Name
tyConName = Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConTyVars :: [TyVar]
tyConTyVars = [TyConBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
tyConArity :: Int
tyConArity = Int
arity,
tcRoles :: [Role]
tcRoles = Int -> Role -> [Role]
forall a. Int -> a -> [a]
replicate Int
arity Role
Representational,
tyConCType :: Maybe CType
tyConCType = Maybe CType
forall a. Maybe a
Nothing,
algTcGadtSyntax :: Bool
algTcGadtSyntax = Bool
False,
algTcStupidTheta :: [Kind]
algTcStupidTheta = [],
algTcRhs :: AlgTyConRhs
algTcRhs = TupleTyCon :: DataCon -> TupleSort -> AlgTyConRhs
TupleTyCon { data_con :: DataCon
data_con = DataCon
con,
tup_sort :: TupleSort
tup_sort = TupleSort
sort },
algTcFields :: FieldLabelEnv
algTcFields = FieldLabelEnv
forall a. DFastStringEnv a
emptyDFsEnv,
algTcParent :: AlgTyConFlav
algTcParent = AlgTyConFlav
parent
}
mkSumTyCon :: Name
-> [TyConBinder]
-> Kind
-> Arity
-> [TyVar]
-> [DataCon]
-> AlgTyConFlav
-> TyCon
mkSumTyCon :: Name
-> [TyConBinder]
-> Kind
-> Int
-> [TyVar]
-> [DataCon]
-> AlgTyConFlav
-> TyCon
mkSumTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind arity :: Int
arity tyvars :: [TyVar]
tyvars cons :: [DataCon]
cons parent :: AlgTyConFlav
parent
= AlgTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> [Role]
-> Maybe CType
-> Bool
-> [Kind]
-> AlgTyConRhs
-> FieldLabelEnv
-> AlgTyConFlav
-> TyCon
AlgTyCon {
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConName :: Name
tyConName = Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConTyVars :: [TyVar]
tyConTyVars = [TyVar]
tyvars,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
tyConArity :: Int
tyConArity = Int
arity,
tcRoles :: [Role]
tcRoles = Int -> Role -> [Role]
forall a. Int -> a -> [a]
replicate Int
arity Role
Representational,
tyConCType :: Maybe CType
tyConCType = Maybe CType
forall a. Maybe a
Nothing,
algTcGadtSyntax :: Bool
algTcGadtSyntax = Bool
False,
algTcStupidTheta :: [Kind]
algTcStupidTheta = [],
algTcRhs :: AlgTyConRhs
algTcRhs = [DataCon] -> AlgTyConRhs
mkSumTyConRhs [DataCon]
cons,
algTcFields :: FieldLabelEnv
algTcFields = FieldLabelEnv
forall a. DFastStringEnv a
emptyDFsEnv,
algTcParent :: AlgTyConFlav
algTcParent = AlgTyConFlav
parent
}
mkTcTyCon :: Name
-> SDoc
-> [TyConBinder]
-> Kind
-> [(Name,TcTyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon :: Name
-> SDoc
-> [TyConBinder]
-> Kind
-> [(Name, TyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon name :: Name
name tyvars :: SDoc
tyvars binders :: [TyConBinder]
binders res_kind :: Kind
res_kind scoped_tvs :: [(Name, TyVar)]
scoped_tvs poly :: Bool
poly flav :: TyConFlavour
flav
= TcTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> [(Name, TyVar)]
-> SDoc
-> Bool
-> TyConFlavour
-> TyCon
TcTyCon { tyConUnique :: Unique
tyConUnique = Name -> Unique
forall a. Uniquable a => a -> Unique
getUnique Name
name
, tyConName :: Name
tyConName = Name
name
, tyConTyVars :: [TyVar]
tyConTyVars = [TyConBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
binders
, tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders
, tyConResKind :: Kind
tyConResKind = Kind
res_kind
, tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind
, tyConArity :: Int
tyConArity = [TyConBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyConBinder]
binders
, tcTyConScopedTyVars :: [(Name, TyVar)]
tcTyConScopedTyVars = [(Name, TyVar)]
scoped_tvs
, tcTyConIsPoly :: Bool
tcTyConIsPoly = Bool
poly
, tcTyConFlavour :: TyConFlavour
tcTyConFlavour = TyConFlavour
flav
, tcTyConUserTyVars :: SDoc
tcTyConUserTyVars = SDoc
tyvars }
mkPrimTyCon :: Name -> [TyConBinder]
-> Kind
-> [Role] -> TyCon
mkPrimTyCon :: Name -> [TyConBinder] -> Kind -> [Role] -> TyCon
mkPrimTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles
= Name
-> [TyConBinder] -> Kind -> [Role] -> Bool -> Maybe Name -> TyCon
mkPrimTyCon' Name
name [TyConBinder]
binders Kind
res_kind [Role]
roles Bool
True (Name -> Maybe Name
forall a. a -> Maybe a
Just (Name -> Maybe Name) -> Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ Name -> Name
mkPrelTyConRepName Name
name)
mkKindTyCon :: Name -> [TyConBinder]
-> Kind
-> [Role] -> Name -> TyCon
mkKindTyCon :: Name -> [TyConBinder] -> Kind -> [Role] -> Name -> TyCon
mkKindTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles rep_nm :: Name
rep_nm
= TyCon
tc
where
tc :: TyCon
tc = Name
-> [TyConBinder] -> Kind -> [Role] -> Bool -> Maybe Name -> TyCon
mkPrimTyCon' Name
name [TyConBinder]
binders Kind
res_kind [Role]
roles Bool
False (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm)
mkLiftedPrimTyCon :: Name -> [TyConBinder]
-> Kind
-> [Role] -> TyCon
mkLiftedPrimTyCon :: Name -> [TyConBinder] -> Kind -> [Role] -> TyCon
mkLiftedPrimTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles
= Name
-> [TyConBinder] -> Kind -> [Role] -> Bool -> Maybe Name -> TyCon
mkPrimTyCon' Name
name [TyConBinder]
binders Kind
res_kind [Role]
roles Bool
False (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
rep_nm)
where rep_nm :: Name
rep_nm = Name -> Name
mkPrelTyConRepName Name
name
mkPrimTyCon' :: Name -> [TyConBinder]
-> Kind
-> [Role]
-> Bool -> Maybe TyConRepName -> TyCon
mkPrimTyCon' :: Name
-> [TyConBinder] -> Kind -> [Role] -> Bool -> Maybe Name -> TyCon
mkPrimTyCon' name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles is_unlifted :: Bool
is_unlifted rep_nm :: Maybe Name
rep_nm
= PrimTyCon :: Unique
-> Name
-> [TyConBinder]
-> Kind
-> Kind
-> Int
-> [Role]
-> Bool
-> Maybe Name
-> TyCon
PrimTyCon {
tyConName :: Name
tyConName = Name
name,
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
tyConArity :: Int
tyConArity = [Role] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Role]
roles,
tcRoles :: [Role]
tcRoles = [Role]
roles,
isUnlifted :: Bool
isUnlifted = Bool
is_unlifted,
primRepName :: Maybe Name
primRepName = Maybe Name
rep_nm
}
mkSynonymTyCon :: Name -> [TyConBinder] -> Kind
-> [Role] -> Type -> Bool -> Bool -> TyCon
mkSynonymTyCon :: Name
-> [TyConBinder] -> Kind -> [Role] -> Kind -> Bool -> Bool -> TyCon
mkSynonymTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles rhs :: Kind
rhs is_tau :: Bool
is_tau is_fam_free :: Bool
is_fam_free
= SynonymTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> [Role]
-> Kind
-> Bool
-> Bool
-> TyCon
SynonymTyCon {
tyConName :: Name
tyConName = Name
name,
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
tyConArity :: Int
tyConArity = [TyConBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyConBinder]
binders,
tyConTyVars :: [TyVar]
tyConTyVars = [TyConBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
binders,
tcRoles :: [Role]
tcRoles = [Role]
roles,
synTcRhs :: Kind
synTcRhs = Kind
rhs,
synIsTau :: Bool
synIsTau = Bool
is_tau,
synIsFamFree :: Bool
synIsFamFree = Bool
is_fam_free
}
mkFamilyTyCon :: Name -> [TyConBinder] -> Kind
-> Maybe Name -> FamTyConFlav
-> Maybe Class -> Injectivity -> TyCon
mkFamilyTyCon :: Name
-> [TyConBinder]
-> Kind
-> Maybe Name
-> FamTyConFlav
-> Maybe Class
-> Injectivity
-> TyCon
mkFamilyTyCon name :: Name
name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind resVar :: Maybe Name
resVar flav :: FamTyConFlav
flav parent :: Maybe Class
parent inj :: Injectivity
inj
= FamilyTyCon :: Unique
-> Name
-> [TyConBinder]
-> [TyVar]
-> Kind
-> Kind
-> Int
-> Maybe Name
-> FamTyConFlav
-> Maybe TyCon
-> Injectivity
-> TyCon
FamilyTyCon
{ tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name
, tyConName :: Name
tyConName = Name
name
, tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders
, tyConResKind :: Kind
tyConResKind = Kind
res_kind
, tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind
, tyConArity :: Int
tyConArity = [TyConBinder] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TyConBinder]
binders
, tyConTyVars :: [TyVar]
tyConTyVars = [TyConBinder] -> [TyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
binders
, famTcResVar :: Maybe Name
famTcResVar = Maybe Name
resVar
, famTcFlav :: FamTyConFlav
famTcFlav = FamTyConFlav
flav
, famTcParent :: Maybe TyCon
famTcParent = Class -> TyCon
classTyCon (Class -> TyCon) -> Maybe Class -> Maybe TyCon
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Class
parent
, famTcInj :: Injectivity
famTcInj = Injectivity
inj
}
mkPromotedDataCon :: DataCon -> Name -> TyConRepName
-> [TyConTyCoBinder] -> Kind -> [Role]
-> RuntimeRepInfo -> TyCon
mkPromotedDataCon :: DataCon
-> Name
-> Name
-> [TyConBinder]
-> Kind
-> [Role]
-> RuntimeRepInfo
-> TyCon
mkPromotedDataCon con :: DataCon
con name :: Name
name rep_name :: Name
rep_name binders :: [TyConBinder]
binders res_kind :: Kind
res_kind roles :: [Role]
roles rep_info :: RuntimeRepInfo
rep_info
= PromotedDataCon :: Unique
-> Name
-> [TyConBinder]
-> Kind
-> Kind
-> Int
-> [Role]
-> DataCon
-> Name
-> RuntimeRepInfo
-> TyCon
PromotedDataCon {
tyConUnique :: Unique
tyConUnique = Name -> Unique
nameUnique Name
name,
tyConName :: Name
tyConName = Name
name,
tyConArity :: Int
tyConArity = [Role] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Role]
roles,
tcRoles :: [Role]
tcRoles = [Role]
roles,
tyConBinders :: [TyConBinder]
tyConBinders = [TyConBinder]
binders,
tyConResKind :: Kind
tyConResKind = Kind
res_kind,
tyConKind :: Kind
tyConKind = [TyConBinder] -> Kind -> Kind
mkTyConKind [TyConBinder]
binders Kind
res_kind,
dataCon :: DataCon
dataCon = DataCon
con,
tcRepName :: Name
tcRepName = Name
rep_name,
promDcRepInfo :: RuntimeRepInfo
promDcRepInfo = RuntimeRepInfo
rep_info
}
isFunTyCon :: TyCon -> Bool
isFunTyCon :: TyCon -> Bool
isFunTyCon (FunTyCon {}) = Bool
True
isFunTyCon _ = Bool
False
isAbstractTyCon :: TyCon -> Bool
isAbstractTyCon :: TyCon -> Bool
isAbstractTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
AbstractTyCon }) = Bool
True
isAbstractTyCon _ = Bool
False
makeRecoveryTyCon :: TyCon -> TyCon
makeRecoveryTyCon :: TyCon -> TyCon
makeRecoveryTyCon tc :: TyCon
tc
= Name
-> SDoc
-> [TyConBinder]
-> Kind
-> [(Name, TyVar)]
-> Bool
-> TyConFlavour
-> TyCon
mkTcTyCon (TyCon -> Name
tyConName TyCon
tc) SDoc
empty
(TyCon -> [TyConBinder]
tyConBinders TyCon
tc) (TyCon -> Kind
tyConResKind TyCon
tc)
[]
Bool
True
(TyCon -> TyConFlavour
tyConFlavour TyCon
tc)
isPrimTyCon :: TyCon -> Bool
isPrimTyCon :: TyCon -> Bool
isPrimTyCon (PrimTyCon {}) = Bool
True
isPrimTyCon _ = Bool
False
isUnliftedTyCon :: TyCon -> Bool
isUnliftedTyCon :: TyCon -> Bool
isUnliftedTyCon (PrimTyCon {isUnlifted :: TyCon -> Bool
isUnlifted = Bool
is_unlifted})
= Bool
is_unlifted
isUnliftedTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs } )
| TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort } <- AlgTyConRhs
rhs
= Bool -> Bool
not (Boxity -> Bool
isBoxed (TupleSort -> Boxity
tupleSortBoxity TupleSort
sort))
isUnliftedTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs } )
| SumTyCon {} <- AlgTyConRhs
rhs
= Bool
True
isUnliftedTyCon _ = Bool
False
isAlgTyCon :: TyCon -> Bool
isAlgTyCon :: TyCon -> Bool
isAlgTyCon (AlgTyCon {}) = Bool
True
isAlgTyCon _ = Bool
False
isVanillaAlgTyCon :: TyCon -> Bool
isVanillaAlgTyCon :: TyCon -> Bool
isVanillaAlgTyCon (AlgTyCon { algTcParent :: TyCon -> AlgTyConFlav
algTcParent = VanillaAlgTyCon _ }) = Bool
True
isVanillaAlgTyCon _ = Bool
False
isDataTyCon :: TyCon -> Bool
isDataTyCon :: TyCon -> Bool
isDataTyCon (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs})
= case AlgTyConRhs
rhs of
TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort }
-> Boxity -> Bool
isBoxed (TupleSort -> Boxity
tupleSortBoxity TupleSort
sort)
SumTyCon {} -> Bool
False
DataTyCon {} -> Bool
True
NewTyCon {} -> Bool
False
AbstractTyCon {} -> Bool
False
isDataTyCon _ = Bool
False
isInjectiveTyCon :: TyCon -> Role -> Bool
isInjectiveTyCon :: TyCon -> Role -> Bool
isInjectiveTyCon _ Phantom = Bool
False
isInjectiveTyCon (FunTyCon {}) _ = Bool
True
isInjectiveTyCon (AlgTyCon {}) Nominal = Bool
True
isInjectiveTyCon (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs}) Representational
= AlgTyConRhs -> Bool
isGenInjAlgRhs AlgTyConRhs
rhs
isInjectiveTyCon (SynonymTyCon {}) _ = Bool
False
isInjectiveTyCon (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = DataFamilyTyCon _ })
Nominal = Bool
True
isInjectiveTyCon (FamilyTyCon { famTcInj :: TyCon -> Injectivity
famTcInj = Injective inj :: [Bool]
inj }) Nominal = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Bool]
inj
isInjectiveTyCon (FamilyTyCon {}) _ = Bool
False
isInjectiveTyCon (PrimTyCon {}) _ = Bool
True
isInjectiveTyCon (PromotedDataCon {}) _ = Bool
True
isInjectiveTyCon (TcTyCon {}) _ = Bool
True
isGenerativeTyCon :: TyCon -> Role -> Bool
isGenerativeTyCon :: TyCon -> Role -> Bool
isGenerativeTyCon (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = DataFamilyTyCon _ }) Nominal = Bool
True
isGenerativeTyCon (FamilyTyCon {}) _ = Bool
False
isGenerativeTyCon tc :: TyCon
tc r :: Role
r = TyCon -> Role -> Bool
isInjectiveTyCon TyCon
tc Role
r
isGenInjAlgRhs :: AlgTyConRhs -> Bool
isGenInjAlgRhs :: AlgTyConRhs -> Bool
isGenInjAlgRhs (TupleTyCon {}) = Bool
True
isGenInjAlgRhs (SumTyCon {}) = Bool
True
isGenInjAlgRhs (DataTyCon {}) = Bool
True
isGenInjAlgRhs (AbstractTyCon {}) = Bool
False
isGenInjAlgRhs (NewTyCon {}) = Bool
False
isNewTyCon :: TyCon -> Bool
isNewTyCon :: TyCon -> Bool
isNewTyCon (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon {}}) = Bool
True
isNewTyCon _ = Bool
False
unwrapNewTyCon_maybe :: TyCon -> Maybe ([TyVar], Type, CoAxiom Unbranched)
unwrapNewTyCon_maybe :: TyCon -> Maybe ([TyVar], Kind, CoAxiom Unbranched)
unwrapNewTyCon_maybe (AlgTyCon { tyConTyVars :: TyCon -> [TyVar]
tyConTyVars = [TyVar]
tvs,
algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_co :: AlgTyConRhs -> CoAxiom Unbranched
nt_co = CoAxiom Unbranched
co,
nt_rhs :: AlgTyConRhs -> Kind
nt_rhs = Kind
rhs }})
= ([TyVar], Kind, CoAxiom Unbranched)
-> Maybe ([TyVar], Kind, CoAxiom Unbranched)
forall a. a -> Maybe a
Just ([TyVar]
tvs, Kind
rhs, CoAxiom Unbranched
co)
unwrapNewTyCon_maybe _ = Maybe ([TyVar], Kind, CoAxiom Unbranched)
forall a. Maybe a
Nothing
unwrapNewTyConEtad_maybe :: TyCon -> Maybe ([TyVar], Type, CoAxiom Unbranched)
unwrapNewTyConEtad_maybe :: TyCon -> Maybe ([TyVar], Kind, CoAxiom Unbranched)
unwrapNewTyConEtad_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_co :: AlgTyConRhs -> CoAxiom Unbranched
nt_co = CoAxiom Unbranched
co,
nt_etad_rhs :: AlgTyConRhs -> ([TyVar], Kind)
nt_etad_rhs = (tvs :: [TyVar]
tvs,rhs :: Kind
rhs) }})
= ([TyVar], Kind, CoAxiom Unbranched)
-> Maybe ([TyVar], Kind, CoAxiom Unbranched)
forall a. a -> Maybe a
Just ([TyVar]
tvs, Kind
rhs, CoAxiom Unbranched
co)
unwrapNewTyConEtad_maybe _ = Maybe ([TyVar], Kind, CoAxiom Unbranched)
forall a. Maybe a
Nothing
isProductTyCon :: TyCon -> Bool
isProductTyCon :: TyCon -> Bool
isProductTyCon tc :: TyCon
tc@(AlgTyCon {})
= case TyCon -> AlgTyConRhs
algTcRhs TyCon
tc of
TupleTyCon {} -> Bool
True
DataTyCon{ data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [data_con :: DataCon
data_con] }
-> [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [TyVar]
dataConExTyCoVars DataCon
data_con)
NewTyCon {} -> Bool
True
_ -> Bool
False
isProductTyCon _ = Bool
False
isDataProductTyCon_maybe :: TyCon -> Maybe DataCon
isDataProductTyCon_maybe :: TyCon -> Maybe DataCon
isDataProductTyCon_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [con :: DataCon
con] }
| [TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [TyVar]
dataConExTyCoVars DataCon
con)
-> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
con
TupleTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
con }
-> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
con
_ -> Maybe DataCon
forall a. Maybe a
Nothing
isDataProductTyCon_maybe _ = Maybe DataCon
forall a. Maybe a
Nothing
isDataSumTyCon_maybe :: TyCon -> Maybe [DataCon]
isDataSumTyCon_maybe :: TyCon -> Maybe [DataCon]
isDataSumTyCon_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cons }
| [DataCon]
cons [DataCon] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthExceeds` 1
, (DataCon -> Bool) -> [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ([TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([TyVar] -> Bool) -> (DataCon -> [TyVar]) -> DataCon -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataCon -> [TyVar]
dataConExTyCoVars) [DataCon]
cons
-> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon]
cons
SumTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cons }
| (DataCon -> Bool) -> [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ([TyVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([TyVar] -> Bool) -> (DataCon -> [TyVar]) -> DataCon -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataCon -> [TyVar]
dataConExTyCoVars) [DataCon]
cons
-> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon]
cons
_ -> Maybe [DataCon]
forall a. Maybe a
Nothing
isDataSumTyCon_maybe _ = Maybe [DataCon]
forall a. Maybe a
Nothing
isTypeSynonymTyCon :: TyCon -> Bool
isTypeSynonymTyCon :: TyCon -> Bool
isTypeSynonymTyCon (SynonymTyCon {}) = Bool
True
isTypeSynonymTyCon _ = Bool
False
isTauTyCon :: TyCon -> Bool
isTauTyCon :: TyCon -> Bool
isTauTyCon (SynonymTyCon { synIsTau :: TyCon -> Bool
synIsTau = Bool
is_tau }) = Bool
is_tau
isTauTyCon _ = Bool
True
isFamFreeTyCon :: TyCon -> Bool
isFamFreeTyCon :: TyCon -> Bool
isFamFreeTyCon (SynonymTyCon { synIsFamFree :: TyCon -> Bool
synIsFamFree = Bool
fam_free }) = Bool
fam_free
isFamFreeTyCon (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav }) = FamTyConFlav -> Bool
isDataFamFlav FamTyConFlav
flav
isFamFreeTyCon _ = Bool
True
mightBeUnsaturatedTyCon :: TyCon -> Bool
mightBeUnsaturatedTyCon :: TyCon -> Bool
mightBeUnsaturatedTyCon = TyConFlavour -> Bool
tcFlavourCanBeUnsaturated (TyConFlavour -> Bool) -> (TyCon -> TyConFlavour) -> TyCon -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCon -> TyConFlavour
tyConFlavour
isGadtSyntaxTyCon :: TyCon -> Bool
isGadtSyntaxTyCon :: TyCon -> Bool
isGadtSyntaxTyCon (AlgTyCon { algTcGadtSyntax :: TyCon -> Bool
algTcGadtSyntax = Bool
res }) = Bool
res
isGadtSyntaxTyCon _ = Bool
False
isEnumerationTyCon :: TyCon -> Bool
isEnumerationTyCon :: TyCon -> Bool
isEnumerationTyCon (AlgTyCon { tyConArity :: TyCon -> Int
tyConArity = Int
arity, algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { is_enum :: AlgTyConRhs -> Bool
is_enum = Bool
res } -> Bool
res
TupleTyCon {} -> Int
arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
_ -> Bool
False
isEnumerationTyCon _ = Bool
False
isFamilyTyCon :: TyCon -> Bool
isFamilyTyCon :: TyCon -> Bool
isFamilyTyCon (FamilyTyCon {}) = Bool
True
isFamilyTyCon _ = Bool
False
isOpenFamilyTyCon :: TyCon -> Bool
isOpenFamilyTyCon :: TyCon -> Bool
isOpenFamilyTyCon (FamilyTyCon {famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav })
| FamTyConFlav
OpenSynFamilyTyCon <- FamTyConFlav
flav = Bool
True
| DataFamilyTyCon {} <- FamTyConFlav
flav = Bool
True
isOpenFamilyTyCon _ = Bool
False
isTypeFamilyTyCon :: TyCon -> Bool
isTypeFamilyTyCon :: TyCon -> Bool
isTypeFamilyTyCon (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav }) = Bool -> Bool
not (FamTyConFlav -> Bool
isDataFamFlav FamTyConFlav
flav)
isTypeFamilyTyCon _ = Bool
False
isDataFamilyTyCon :: TyCon -> Bool
isDataFamilyTyCon :: TyCon -> Bool
isDataFamilyTyCon (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav }) = FamTyConFlav -> Bool
isDataFamFlav FamTyConFlav
flav
isDataFamilyTyCon _ = Bool
False
isOpenTypeFamilyTyCon :: TyCon -> Bool
isOpenTypeFamilyTyCon :: TyCon -> Bool
isOpenTypeFamilyTyCon (FamilyTyCon {famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
OpenSynFamilyTyCon }) = Bool
True
isOpenTypeFamilyTyCon _ = Bool
False
isClosedSynFamilyTyConWithAxiom_maybe :: TyCon -> Maybe (CoAxiom Branched)
isClosedSynFamilyTyConWithAxiom_maybe :: TyCon -> Maybe (CoAxiom Branched)
isClosedSynFamilyTyConWithAxiom_maybe
(FamilyTyCon {famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = ClosedSynFamilyTyCon mb :: Maybe (CoAxiom Branched)
mb}) = Maybe (CoAxiom Branched)
mb
isClosedSynFamilyTyConWithAxiom_maybe _ = Maybe (CoAxiom Branched)
forall a. Maybe a
Nothing
tyConInjectivityInfo :: TyCon -> Injectivity
tyConInjectivityInfo :: TyCon -> Injectivity
tyConInjectivityInfo tc :: TyCon
tc
| FamilyTyCon { famTcInj :: TyCon -> Injectivity
famTcInj = Injectivity
inj } <- TyCon
tc
= Injectivity
inj
| TyCon -> Role -> Bool
isInjectiveTyCon TyCon
tc Role
Nominal
= [Bool] -> Injectivity
Injective (Int -> Bool -> [Bool]
forall a. Int -> a -> [a]
replicate (TyCon -> Int
tyConArity TyCon
tc) Bool
True)
| Bool
otherwise
= Injectivity
NotInjective
isBuiltInSynFamTyCon_maybe :: TyCon -> Maybe BuiltInSynFamily
isBuiltInSynFamTyCon_maybe :: TyCon -> Maybe BuiltInSynFamily
isBuiltInSynFamTyCon_maybe
(FamilyTyCon {famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = BuiltInSynFamTyCon ops :: BuiltInSynFamily
ops }) = BuiltInSynFamily -> Maybe BuiltInSynFamily
forall a. a -> Maybe a
Just BuiltInSynFamily
ops
isBuiltInSynFamTyCon_maybe _ = Maybe BuiltInSynFamily
forall a. Maybe a
Nothing
isDataFamFlav :: FamTyConFlav -> Bool
isDataFamFlav :: FamTyConFlav -> Bool
isDataFamFlav (DataFamilyTyCon {}) = Bool
True
isDataFamFlav _ = Bool
False
isTyConAssoc :: TyCon -> Bool
isTyConAssoc :: TyCon -> Bool
isTyConAssoc = Maybe TyCon -> Bool
forall a. Maybe a -> Bool
isJust (Maybe TyCon -> Bool) -> (TyCon -> Maybe TyCon) -> TyCon -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCon -> Maybe TyCon
tyConAssoc_maybe
tyConAssoc_maybe :: TyCon -> Maybe TyCon
tyConAssoc_maybe :: TyCon -> Maybe TyCon
tyConAssoc_maybe = TyConFlavour -> Maybe TyCon
tyConFlavourAssoc_maybe (TyConFlavour -> Maybe TyCon)
-> (TyCon -> TyConFlavour) -> TyCon -> Maybe TyCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCon -> TyConFlavour
tyConFlavour
tyConFlavourAssoc_maybe :: TyConFlavour -> Maybe TyCon
tyConFlavourAssoc_maybe :: TyConFlavour -> Maybe TyCon
tyConFlavourAssoc_maybe (DataFamilyFlavour mb_parent :: Maybe TyCon
mb_parent) = Maybe TyCon
mb_parent
tyConFlavourAssoc_maybe (OpenTypeFamilyFlavour mb_parent :: Maybe TyCon
mb_parent) = Maybe TyCon
mb_parent
tyConFlavourAssoc_maybe _ = Maybe TyCon
forall a. Maybe a
Nothing
isTupleTyCon :: TyCon -> Bool
isTupleTyCon :: TyCon -> Bool
isTupleTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = TupleTyCon {} }) = Bool
True
isTupleTyCon _ = Bool
False
tyConTuple_maybe :: TyCon -> Maybe TupleSort
tyConTuple_maybe :: TyCon -> Maybe TupleSort
tyConTuple_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
| TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort} <- AlgTyConRhs
rhs = TupleSort -> Maybe TupleSort
forall a. a -> Maybe a
Just TupleSort
sort
tyConTuple_maybe _ = Maybe TupleSort
forall a. Maybe a
Nothing
isUnboxedTupleTyCon :: TyCon -> Bool
isUnboxedTupleTyCon :: TyCon -> Bool
isUnboxedTupleTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
| TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort } <- AlgTyConRhs
rhs
= Bool -> Bool
not (Boxity -> Bool
isBoxed (TupleSort -> Boxity
tupleSortBoxity TupleSort
sort))
isUnboxedTupleTyCon _ = Bool
False
isBoxedTupleTyCon :: TyCon -> Bool
isBoxedTupleTyCon :: TyCon -> Bool
isBoxedTupleTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
| TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort } <- AlgTyConRhs
rhs
= Boxity -> Bool
isBoxed (TupleSort -> Boxity
tupleSortBoxity TupleSort
sort)
isBoxedTupleTyCon _ = Bool
False
isUnboxedSumTyCon :: TyCon -> Bool
isUnboxedSumTyCon :: TyCon -> Bool
isUnboxedSumTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
| SumTyCon {} <- AlgTyConRhs
rhs
= Bool
True
isUnboxedSumTyCon _ = Bool
False
isPromotedTupleTyCon :: TyCon -> Bool
isPromotedTupleTyCon :: TyCon -> Bool
isPromotedTupleTyCon tyCon :: TyCon
tyCon
| Just dataCon :: DataCon
dataCon <- TyCon -> Maybe DataCon
isPromotedDataCon_maybe TyCon
tyCon
, TyCon -> Bool
isTupleTyCon (DataCon -> TyCon
dataConTyCon DataCon
dataCon) = Bool
True
| Bool
otherwise = Bool
False
isPromotedDataCon :: TyCon -> Bool
isPromotedDataCon :: TyCon -> Bool
isPromotedDataCon (PromotedDataCon {}) = Bool
True
isPromotedDataCon _ = Bool
False
isPromotedDataCon_maybe :: TyCon -> Maybe DataCon
isPromotedDataCon_maybe :: TyCon -> Maybe DataCon
isPromotedDataCon_maybe (PromotedDataCon { dataCon :: TyCon -> DataCon
dataCon = DataCon
dc }) = DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
dc
isPromotedDataCon_maybe _ = Maybe DataCon
forall a. Maybe a
Nothing
isKindTyCon :: TyCon -> Bool
isKindTyCon :: TyCon -> Bool
isKindTyCon tc :: TyCon
tc = TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
tc Unique -> UniqSet Unique -> Bool
forall a. Uniquable a => a -> UniqSet a -> Bool
`elementOfUniqSet` UniqSet Unique
kindTyConKeys
kindTyConKeys :: UniqSet Unique
kindTyConKeys :: UniqSet Unique
kindTyConKeys = [UniqSet Unique] -> UniqSet Unique
forall a. [UniqSet a] -> UniqSet a
unionManyUniqSets
( [Unique] -> UniqSet Unique
forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet [ Unique
liftedTypeKindTyConKey, Unique
constraintKindTyConKey, Unique
tYPETyConKey ]
UniqSet Unique -> [UniqSet Unique] -> [UniqSet Unique]
forall a. a -> [a] -> [a]
: (TyCon -> UniqSet Unique) -> [TyCon] -> [UniqSet Unique]
forall a b. (a -> b) -> [a] -> [b]
map ([Unique] -> UniqSet Unique
forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet ([Unique] -> UniqSet Unique)
-> (TyCon -> [Unique]) -> TyCon -> UniqSet Unique
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCon -> [Unique]
tycon_with_datacons) [ TyCon
runtimeRepTyCon
, TyCon
vecCountTyCon, TyCon
vecElemTyCon ] )
where
tycon_with_datacons :: TyCon -> [Unique]
tycon_with_datacons tc :: TyCon
tc = TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
tc Unique -> [Unique] -> [Unique]
forall a. a -> [a] -> [a]
: (DataCon -> Unique) -> [DataCon] -> [Unique]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique (TyCon -> [DataCon]
tyConDataCons TyCon
tc)
isLiftedTypeKindTyConName :: Name -> Bool
isLiftedTypeKindTyConName :: Name -> Bool
isLiftedTypeKindTyConName = (Name -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
liftedTypeKindTyConKey)
isImplicitTyCon :: TyCon -> Bool
isImplicitTyCon :: TyCon -> Bool
isImplicitTyCon (FunTyCon {}) = Bool
True
isImplicitTyCon (PrimTyCon {}) = Bool
True
isImplicitTyCon (PromotedDataCon {}) = Bool
True
isImplicitTyCon (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs, tyConName :: TyCon -> Name
tyConName = Name
name })
| TupleTyCon {} <- AlgTyConRhs
rhs = Name -> Bool
isWiredInName Name
name
| SumTyCon {} <- AlgTyConRhs
rhs = Bool
True
| Bool
otherwise = Bool
False
isImplicitTyCon (FamilyTyCon { famTcParent :: TyCon -> Maybe TyCon
famTcParent = Maybe TyCon
parent }) = Maybe TyCon -> Bool
forall a. Maybe a -> Bool
isJust Maybe TyCon
parent
isImplicitTyCon (SynonymTyCon {}) = Bool
False
isImplicitTyCon (TcTyCon {}) = Bool
False
tyConCType_maybe :: TyCon -> Maybe CType
tyConCType_maybe :: TyCon -> Maybe CType
tyConCType_maybe tc :: TyCon
tc@(AlgTyCon {}) = TyCon -> Maybe CType
tyConCType TyCon
tc
tyConCType_maybe _ = Maybe CType
forall a. Maybe a
Nothing
isTcTyCon :: TyCon -> Bool
isTcTyCon :: TyCon -> Bool
isTcTyCon (TcTyCon {}) = Bool
True
isTcTyCon _ = Bool
False
isTcLevPoly :: TyCon -> Bool
isTcLevPoly :: TyCon -> Bool
isTcLevPoly FunTyCon{} = Bool
False
isTcLevPoly (AlgTyCon { algTcParent :: TyCon -> AlgTyConFlav
algTcParent = UnboxedAlgTyCon _ }) = Bool
True
isTcLevPoly AlgTyCon{} = Bool
False
isTcLevPoly SynonymTyCon{} = Bool
True
isTcLevPoly FamilyTyCon{} = Bool
True
isTcLevPoly PrimTyCon{} = Bool
False
isTcLevPoly TcTyCon{} = Bool
False
isTcLevPoly tc :: TyCon
tc@PromotedDataCon{} = String -> SDoc -> Bool
forall a. HasCallStack => String -> SDoc -> a
pprPanic "isTcLevPoly datacon" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
expandSynTyCon_maybe
:: TyCon
-> [tyco]
-> Maybe ([(TyVar,tyco)],
Type,
[tyco])
expandSynTyCon_maybe :: TyCon -> [tyco] -> Maybe ([(TyVar, tyco)], Kind, [tyco])
expandSynTyCon_maybe tc :: TyCon
tc tys :: [tyco]
tys
| SynonymTyCon { tyConTyVars :: TyCon -> [TyVar]
tyConTyVars = [TyVar]
tvs, synTcRhs :: TyCon -> Kind
synTcRhs = Kind
rhs, tyConArity :: TyCon -> Int
tyConArity = Int
arity } <- TyCon
tc
= case [tyco]
tys [tyco] -> Int -> Ordering
forall a. [a] -> Int -> Ordering
`listLengthCmp` Int
arity of
GT -> ([(TyVar, tyco)], Kind, [tyco])
-> Maybe ([(TyVar, tyco)], Kind, [tyco])
forall a. a -> Maybe a
Just ([TyVar]
tvs [TyVar] -> [tyco] -> [(TyVar, tyco)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [tyco]
tys, Kind
rhs, Int -> [tyco] -> [tyco]
forall a. Int -> [a] -> [a]
drop Int
arity [tyco]
tys)
EQ -> ([(TyVar, tyco)], Kind, [tyco])
-> Maybe ([(TyVar, tyco)], Kind, [tyco])
forall a. a -> Maybe a
Just ([TyVar]
tvs [TyVar] -> [tyco] -> [(TyVar, tyco)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [tyco]
tys, Kind
rhs, [])
LT -> Maybe ([(TyVar, tyco)], Kind, [tyco])
forall a. Maybe a
Nothing
| Bool
otherwise
= Maybe ([(TyVar, tyco)], Kind, [tyco])
forall a. Maybe a
Nothing
isTyConWithSrcDataCons :: TyCon -> Bool
isTyConWithSrcDataCons :: TyCon -> Bool
isTyConWithSrcDataCons (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs, algTcParent :: TyCon -> AlgTyConFlav
algTcParent = AlgTyConFlav
parent }) =
case AlgTyConRhs
rhs of
DataTyCon {} -> Bool
isSrcParent
NewTyCon {} -> Bool
isSrcParent
TupleTyCon {} -> Bool
isSrcParent
_ -> Bool
False
where
isSrcParent :: Bool
isSrcParent = AlgTyConFlav -> Bool
isNoParent AlgTyConFlav
parent
isTyConWithSrcDataCons (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = DataFamilyTyCon {} })
= Bool
True
isTyConWithSrcDataCons _ = Bool
False
tyConDataCons :: TyCon -> [DataCon]
tyConDataCons :: TyCon -> [DataCon]
tyConDataCons tycon :: TyCon
tycon = TyCon -> Maybe [DataCon]
tyConDataCons_maybe TyCon
tycon Maybe [DataCon] -> [DataCon] -> [DataCon]
forall a. Maybe a -> a -> a
`orElse` []
tyConDataCons_maybe :: TyCon -> Maybe [DataCon]
tyConDataCons_maybe :: TyCon -> Maybe [DataCon]
tyConDataCons_maybe (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs})
= case AlgTyConRhs
rhs of
DataTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cons } -> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon]
cons
NewTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
con } -> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon
con]
TupleTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
con } -> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon
con]
SumTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [DataCon]
cons } -> [DataCon] -> Maybe [DataCon]
forall a. a -> Maybe a
Just [DataCon]
cons
_ -> Maybe [DataCon]
forall a. Maybe a
Nothing
tyConDataCons_maybe _ = Maybe [DataCon]
forall a. Maybe a
Nothing
tyConSingleDataCon_maybe :: TyCon -> Maybe DataCon
tyConSingleDataCon_maybe :: TyCon -> Maybe DataCon
tyConSingleDataCon_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [c :: DataCon
c] } -> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
c
TupleTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
c } -> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
c
NewTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
c } -> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
c
_ -> Maybe DataCon
forall a. Maybe a
Nothing
tyConSingleDataCon_maybe _ = Maybe DataCon
forall a. Maybe a
Nothing
tyConSingleDataCon :: TyCon -> DataCon
tyConSingleDataCon :: TyCon -> DataCon
tyConSingleDataCon tc :: TyCon
tc
= case TyCon -> Maybe DataCon
tyConSingleDataCon_maybe TyCon
tc of
Just c :: DataCon
c -> DataCon
c
Nothing -> String -> SDoc -> DataCon
forall a. HasCallStack => String -> SDoc -> a
pprPanic "tyConDataCon" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
tyConSingleAlgDataCon_maybe :: TyCon -> Maybe DataCon
tyConSingleAlgDataCon_maybe :: TyCon -> Maybe DataCon
tyConSingleAlgDataCon_maybe (AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { data_cons :: AlgTyConRhs -> [DataCon]
data_cons = [c :: DataCon
c] } -> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
c
TupleTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
c } -> DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
c
_ -> Maybe DataCon
forall a. Maybe a
Nothing
tyConSingleAlgDataCon_maybe _ = Maybe DataCon
forall a. Maybe a
Nothing
tyConFamilySize :: TyCon -> Int
tyConFamilySize :: TyCon -> Int
tyConFamilySize tc :: TyCon
tc@(AlgTyCon { algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
= case AlgTyConRhs
rhs of
DataTyCon { data_cons_size :: AlgTyConRhs -> Int
data_cons_size = Int
size } -> Int
size
NewTyCon {} -> 1
TupleTyCon {} -> 1
SumTyCon { data_cons_size :: AlgTyConRhs -> Int
data_cons_size = Int
size } -> Int
size
_ -> String -> SDoc -> Int
forall a. HasCallStack => String -> SDoc -> a
pprPanic "tyConFamilySize 1" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
tyConFamilySize tc :: TyCon
tc = String -> SDoc -> Int
forall a. HasCallStack => String -> SDoc -> a
pprPanic "tyConFamilySize 2" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
algTyConRhs :: TyCon -> AlgTyConRhs
algTyConRhs :: TyCon -> AlgTyConRhs
algTyConRhs (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs}) = AlgTyConRhs
rhs
algTyConRhs other :: TyCon
other = String -> SDoc -> AlgTyConRhs
forall a. HasCallStack => String -> SDoc -> a
pprPanic "algTyConRhs" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
other)
tyConFamilyResVar_maybe :: TyCon -> Maybe Name
tyConFamilyResVar_maybe :: TyCon -> Maybe Name
tyConFamilyResVar_maybe (FamilyTyCon {famTcResVar :: TyCon -> Maybe Name
famTcResVar = Maybe Name
res}) = Maybe Name
res
tyConFamilyResVar_maybe _ = Maybe Name
forall a. Maybe a
Nothing
tyConRoles :: TyCon -> [Role]
tyConRoles :: TyCon -> [Role]
tyConRoles tc :: TyCon
tc
= case TyCon
tc of
{ FunTyCon {} -> [Role
Nominal, Role
Nominal, Role
Representational, Role
Representational]
; AlgTyCon { tcRoles :: TyCon -> [Role]
tcRoles = [Role]
roles } -> [Role]
roles
; SynonymTyCon { tcRoles :: TyCon -> [Role]
tcRoles = [Role]
roles } -> [Role]
roles
; FamilyTyCon {} -> Role -> [Role]
forall a. a -> [a]
const_role Role
Nominal
; PrimTyCon { tcRoles :: TyCon -> [Role]
tcRoles = [Role]
roles } -> [Role]
roles
; PromotedDataCon { tcRoles :: TyCon -> [Role]
tcRoles = [Role]
roles } -> [Role]
roles
; TcTyCon {} -> Role -> [Role]
forall a. a -> [a]
const_role Role
Nominal
}
where
const_role :: a -> [a]
const_role r :: a
r = Int -> a -> [a]
forall a. Int -> a -> [a]
replicate (TyCon -> Int
tyConArity TyCon
tc) a
r
newTyConRhs :: TyCon -> ([TyVar], Type)
newTyConRhs :: TyCon -> ([TyVar], Kind)
newTyConRhs (AlgTyCon {tyConTyVars :: TyCon -> [TyVar]
tyConTyVars = [TyVar]
tvs, algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_rhs :: AlgTyConRhs -> Kind
nt_rhs = Kind
rhs }})
= ([TyVar]
tvs, Kind
rhs)
newTyConRhs tycon :: TyCon
tycon = String -> SDoc -> ([TyVar], Kind)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "newTyConRhs" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon)
newTyConEtadArity :: TyCon -> Int
newTyConEtadArity :: TyCon -> Int
newTyConEtadArity (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_etad_rhs :: AlgTyConRhs -> ([TyVar], Kind)
nt_etad_rhs = ([TyVar], Kind)
tvs_rhs }})
= [TyVar] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (([TyVar], Kind) -> [TyVar]
forall a b. (a, b) -> a
fst ([TyVar], Kind)
tvs_rhs)
newTyConEtadArity tycon :: TyCon
tycon = String -> SDoc -> Int
forall a. HasCallStack => String -> SDoc -> a
pprPanic "newTyConEtadArity" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon)
newTyConEtadRhs :: TyCon -> ([TyVar], Type)
newTyConEtadRhs :: TyCon -> ([TyVar], Kind)
newTyConEtadRhs (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_etad_rhs :: AlgTyConRhs -> ([TyVar], Kind)
nt_etad_rhs = ([TyVar], Kind)
tvs_rhs }}) = ([TyVar], Kind)
tvs_rhs
newTyConEtadRhs tycon :: TyCon
tycon = String -> SDoc -> ([TyVar], Kind)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "newTyConEtadRhs" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon)
newTyConCo_maybe :: TyCon -> Maybe (CoAxiom Unbranched)
newTyConCo_maybe :: TyCon -> Maybe (CoAxiom Unbranched)
newTyConCo_maybe (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { nt_co :: AlgTyConRhs -> CoAxiom Unbranched
nt_co = CoAxiom Unbranched
co }}) = CoAxiom Unbranched -> Maybe (CoAxiom Unbranched)
forall a. a -> Maybe a
Just CoAxiom Unbranched
co
newTyConCo_maybe _ = Maybe (CoAxiom Unbranched)
forall a. Maybe a
Nothing
newTyConCo :: TyCon -> CoAxiom Unbranched
newTyConCo :: TyCon -> CoAxiom Unbranched
newTyConCo tc :: TyCon
tc = case TyCon -> Maybe (CoAxiom Unbranched)
newTyConCo_maybe TyCon
tc of
Just co :: CoAxiom Unbranched
co -> CoAxiom Unbranched
co
Nothing -> String -> SDoc -> CoAxiom Unbranched
forall a. HasCallStack => String -> SDoc -> a
pprPanic "newTyConCo" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
newTyConDataCon_maybe :: TyCon -> Maybe DataCon
newTyConDataCon_maybe :: TyCon -> Maybe DataCon
newTyConDataCon_maybe (AlgTyCon {algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = NewTyCon { data_con :: AlgTyConRhs -> DataCon
data_con = DataCon
con }}) = DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
con
newTyConDataCon_maybe _ = Maybe DataCon
forall a. Maybe a
Nothing
tyConStupidTheta :: TyCon -> [PredType]
tyConStupidTheta :: TyCon -> [Kind]
tyConStupidTheta (AlgTyCon {algTcStupidTheta :: TyCon -> [Kind]
algTcStupidTheta = [Kind]
stupid}) = [Kind]
stupid
tyConStupidTheta (FunTyCon {}) = []
tyConStupidTheta tycon :: TyCon
tycon = String -> SDoc -> [Kind]
forall a. HasCallStack => String -> SDoc -> a
pprPanic "tyConStupidTheta" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tycon)
synTyConDefn_maybe :: TyCon -> Maybe ([TyVar], Type)
synTyConDefn_maybe :: TyCon -> Maybe ([TyVar], Kind)
synTyConDefn_maybe (SynonymTyCon {tyConTyVars :: TyCon -> [TyVar]
tyConTyVars = [TyVar]
tyvars, synTcRhs :: TyCon -> Kind
synTcRhs = Kind
ty})
= ([TyVar], Kind) -> Maybe ([TyVar], Kind)
forall a. a -> Maybe a
Just ([TyVar]
tyvars, Kind
ty)
synTyConDefn_maybe _ = Maybe ([TyVar], Kind)
forall a. Maybe a
Nothing
synTyConRhs_maybe :: TyCon -> Maybe Type
synTyConRhs_maybe :: TyCon -> Maybe Kind
synTyConRhs_maybe (SynonymTyCon {synTcRhs :: TyCon -> Kind
synTcRhs = Kind
rhs}) = Kind -> Maybe Kind
forall a. a -> Maybe a
Just Kind
rhs
synTyConRhs_maybe _ = Maybe Kind
forall a. Maybe a
Nothing
famTyConFlav_maybe :: TyCon -> Maybe FamTyConFlav
famTyConFlav_maybe :: TyCon -> Maybe FamTyConFlav
famTyConFlav_maybe (FamilyTyCon {famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav}) = FamTyConFlav -> Maybe FamTyConFlav
forall a. a -> Maybe a
Just FamTyConFlav
flav
famTyConFlav_maybe _ = Maybe FamTyConFlav
forall a. Maybe a
Nothing
isClassTyCon :: TyCon -> Bool
isClassTyCon :: TyCon -> Bool
isClassTyCon (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = ClassTyCon {}}) = Bool
True
isClassTyCon _ = Bool
False
tyConClass_maybe :: TyCon -> Maybe Class
tyConClass_maybe :: TyCon -> Maybe Class
tyConClass_maybe (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = ClassTyCon clas :: Class
clas _}) = Class -> Maybe Class
forall a. a -> Maybe a
Just Class
clas
tyConClass_maybe _ = Maybe Class
forall a. Maybe a
Nothing
tyConATs :: TyCon -> [TyCon]
tyConATs :: TyCon -> [TyCon]
tyConATs (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = ClassTyCon clas :: Class
clas _}) = Class -> [TyCon]
classATs Class
clas
tyConATs _ = []
isFamInstTyCon :: TyCon -> Bool
isFamInstTyCon :: TyCon -> Bool
isFamInstTyCon (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = DataFamInstTyCon {} })
= Bool
True
isFamInstTyCon _ = Bool
False
tyConFamInstSig_maybe :: TyCon -> Maybe (TyCon, [Type], CoAxiom Unbranched)
tyConFamInstSig_maybe :: TyCon -> Maybe (TyCon, [Kind], CoAxiom Unbranched)
tyConFamInstSig_maybe (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = DataFamInstTyCon ax :: CoAxiom Unbranched
ax f :: TyCon
f ts :: [Kind]
ts })
= (TyCon, [Kind], CoAxiom Unbranched)
-> Maybe (TyCon, [Kind], CoAxiom Unbranched)
forall a. a -> Maybe a
Just (TyCon
f, [Kind]
ts, CoAxiom Unbranched
ax)
tyConFamInstSig_maybe _ = Maybe (TyCon, [Kind], CoAxiom Unbranched)
forall a. Maybe a
Nothing
tyConFamInst_maybe :: TyCon -> Maybe (TyCon, [Type])
tyConFamInst_maybe :: TyCon -> Maybe (TyCon, [Kind])
tyConFamInst_maybe (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = DataFamInstTyCon _ f :: TyCon
f ts :: [Kind]
ts })
= (TyCon, [Kind]) -> Maybe (TyCon, [Kind])
forall a. a -> Maybe a
Just (TyCon
f, [Kind]
ts)
tyConFamInst_maybe _ = Maybe (TyCon, [Kind])
forall a. Maybe a
Nothing
tyConFamilyCoercion_maybe :: TyCon -> Maybe (CoAxiom Unbranched)
tyConFamilyCoercion_maybe :: TyCon -> Maybe (CoAxiom Unbranched)
tyConFamilyCoercion_maybe (AlgTyCon {algTcParent :: TyCon -> AlgTyConFlav
algTcParent = DataFamInstTyCon ax :: CoAxiom Unbranched
ax _ _ })
= CoAxiom Unbranched -> Maybe (CoAxiom Unbranched)
forall a. a -> Maybe a
Just CoAxiom Unbranched
ax
tyConFamilyCoercion_maybe _ = Maybe (CoAxiom Unbranched)
forall a. Maybe a
Nothing
tyConRuntimeRepInfo :: TyCon -> RuntimeRepInfo
tyConRuntimeRepInfo :: TyCon -> RuntimeRepInfo
tyConRuntimeRepInfo (PromotedDataCon { promDcRepInfo :: TyCon -> RuntimeRepInfo
promDcRepInfo = RuntimeRepInfo
rri }) = RuntimeRepInfo
rri
tyConRuntimeRepInfo _ = RuntimeRepInfo
NoRRI
mkTyConTagMap :: TyCon -> NameEnv ConTag
mkTyConTagMap :: TyCon -> NameEnv Int
mkTyConTagMap tycon :: TyCon
tycon =
[(Name, Int)] -> NameEnv Int
forall a. [(Name, a)] -> NameEnv a
mkNameEnv ([(Name, Int)] -> NameEnv Int) -> [(Name, Int)] -> NameEnv Int
forall a b. (a -> b) -> a -> b
$ (DataCon -> Name) -> [DataCon] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> Name
forall a. NamedThing a => a -> Name
getName (TyCon -> [DataCon]
tyConDataCons TyCon
tycon) [Name] -> [Int] -> [(Name, Int)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Int
fIRST_TAG..]
instance Eq TyCon where
a :: TyCon
a == :: TyCon -> TyCon -> Bool
== b :: TyCon
b = TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
a Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
b
a :: TyCon
a /= :: TyCon -> TyCon -> Bool
/= b :: TyCon
b = TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
a Unique -> Unique -> Bool
forall a. Eq a => a -> a -> Bool
/= TyCon -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyCon
b
instance Uniquable TyCon where
getUnique :: TyCon -> Unique
getUnique tc :: TyCon
tc = TyCon -> Unique
tyConUnique TyCon
tc
instance Outputable TyCon where
ppr :: TyCon -> SDoc
ppr tc :: TyCon
tc = TyCon -> SDoc
pprPromotionQuote TyCon
tc SDoc -> SDoc -> SDoc
<> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCon -> Name
tyConName TyCon
tc) SDoc -> SDoc -> SDoc
<> SDoc
pp_tc
where
pp_tc :: SDoc
pp_tc = (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \sty :: PprStyle
sty -> if ((PprStyle -> Bool
debugStyle PprStyle
sty Bool -> Bool -> Bool
|| PprStyle -> Bool
dumpStyle PprStyle
sty) Bool -> Bool -> Bool
&& TyCon -> Bool
isTcTyCon TyCon
tc)
then String -> SDoc
text "[tc]"
else SDoc
empty
data TyConFlavour
= ClassFlavour
| TupleFlavour Boxity
| SumFlavour
| DataTypeFlavour
| NewtypeFlavour
| AbstractTypeFlavour
| DataFamilyFlavour (Maybe TyCon)
| OpenTypeFamilyFlavour (Maybe TyCon)
| ClosedTypeFamilyFlavour
| TypeSynonymFlavour
| BuiltInTypeFlavour
| PromotedDataConFlavour
deriving TyConFlavour -> TyConFlavour -> Bool
(TyConFlavour -> TyConFlavour -> Bool)
-> (TyConFlavour -> TyConFlavour -> Bool) -> Eq TyConFlavour
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TyConFlavour -> TyConFlavour -> Bool
$c/= :: TyConFlavour -> TyConFlavour -> Bool
== :: TyConFlavour -> TyConFlavour -> Bool
$c== :: TyConFlavour -> TyConFlavour -> Bool
Eq
instance Outputable TyConFlavour where
ppr :: TyConFlavour -> SDoc
ppr = String -> SDoc
text (String -> SDoc)
-> (TyConFlavour -> String) -> TyConFlavour -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyConFlavour -> String
go
where
go :: TyConFlavour -> String
go ClassFlavour = "class"
go (TupleFlavour boxed :: Boxity
boxed) | Boxity -> Bool
isBoxed Boxity
boxed = "tuple"
| Bool
otherwise = "unboxed tuple"
go SumFlavour = "unboxed sum"
go DataTypeFlavour = "data type"
go NewtypeFlavour = "newtype"
go AbstractTypeFlavour = "abstract type"
go (DataFamilyFlavour (Just _)) = "associated data family"
go (DataFamilyFlavour Nothing) = "data family"
go (OpenTypeFamilyFlavour (Just _)) = "associated type family"
go (OpenTypeFamilyFlavour Nothing) = "type family"
go ClosedTypeFamilyFlavour = "type family"
go TypeSynonymFlavour = "type synonym"
go BuiltInTypeFlavour = "built-in type"
go PromotedDataConFlavour = "promoted data constructor"
tyConFlavour :: TyCon -> TyConFlavour
tyConFlavour :: TyCon -> TyConFlavour
tyConFlavour (AlgTyCon { algTcParent :: TyCon -> AlgTyConFlav
algTcParent = AlgTyConFlav
parent, algTcRhs :: TyCon -> AlgTyConRhs
algTcRhs = AlgTyConRhs
rhs })
| ClassTyCon _ _ <- AlgTyConFlav
parent = TyConFlavour
ClassFlavour
| Bool
otherwise = case AlgTyConRhs
rhs of
TupleTyCon { tup_sort :: AlgTyConRhs -> TupleSort
tup_sort = TupleSort
sort }
-> Boxity -> TyConFlavour
TupleFlavour (TupleSort -> Boxity
tupleSortBoxity TupleSort
sort)
SumTyCon {} -> TyConFlavour
SumFlavour
DataTyCon {} -> TyConFlavour
DataTypeFlavour
NewTyCon {} -> TyConFlavour
NewtypeFlavour
AbstractTyCon {} -> TyConFlavour
AbstractTypeFlavour
tyConFlavour (FamilyTyCon { famTcFlav :: TyCon -> FamTyConFlav
famTcFlav = FamTyConFlav
flav, famTcParent :: TyCon -> Maybe TyCon
famTcParent = Maybe TyCon
parent })
= case FamTyConFlav
flav of
DataFamilyTyCon{} -> Maybe TyCon -> TyConFlavour
DataFamilyFlavour Maybe TyCon
parent
OpenSynFamilyTyCon -> Maybe TyCon -> TyConFlavour
OpenTypeFamilyFlavour Maybe TyCon
parent
ClosedSynFamilyTyCon{} -> TyConFlavour
ClosedTypeFamilyFlavour
AbstractClosedSynFamilyTyCon -> TyConFlavour
ClosedTypeFamilyFlavour
BuiltInSynFamTyCon{} -> TyConFlavour
ClosedTypeFamilyFlavour
tyConFlavour (SynonymTyCon {}) = TyConFlavour
TypeSynonymFlavour
tyConFlavour (FunTyCon {}) = TyConFlavour
BuiltInTypeFlavour
tyConFlavour (PrimTyCon {}) = TyConFlavour
BuiltInTypeFlavour
tyConFlavour (PromotedDataCon {}) = TyConFlavour
PromotedDataConFlavour
tyConFlavour (TcTyCon { tcTyConFlavour :: TyCon -> TyConFlavour
tcTyConFlavour = TyConFlavour
flav }) = TyConFlavour
flav
tcFlavourCanBeUnsaturated :: TyConFlavour -> Bool
tcFlavourCanBeUnsaturated :: TyConFlavour -> Bool
tcFlavourCanBeUnsaturated ClassFlavour = Bool
True
tcFlavourCanBeUnsaturated DataTypeFlavour = Bool
True
tcFlavourCanBeUnsaturated NewtypeFlavour = Bool
True
tcFlavourCanBeUnsaturated DataFamilyFlavour{} = Bool
True
tcFlavourCanBeUnsaturated TupleFlavour{} = Bool
True
tcFlavourCanBeUnsaturated SumFlavour = Bool
True
tcFlavourCanBeUnsaturated AbstractTypeFlavour = Bool
True
tcFlavourCanBeUnsaturated BuiltInTypeFlavour = Bool
True
tcFlavourCanBeUnsaturated PromotedDataConFlavour = Bool
True
tcFlavourCanBeUnsaturated TypeSynonymFlavour = Bool
False
tcFlavourCanBeUnsaturated OpenTypeFamilyFlavour{} = Bool
False
tcFlavourCanBeUnsaturated ClosedTypeFamilyFlavour = Bool
False
tcFlavourIsOpen :: TyConFlavour -> Bool
tcFlavourIsOpen :: TyConFlavour -> Bool
tcFlavourIsOpen DataFamilyFlavour{} = Bool
True
tcFlavourIsOpen OpenTypeFamilyFlavour{} = Bool
True
tcFlavourIsOpen ClosedTypeFamilyFlavour = Bool
False
tcFlavourIsOpen ClassFlavour = Bool
False
tcFlavourIsOpen DataTypeFlavour = Bool
False
tcFlavourIsOpen NewtypeFlavour = Bool
False
tcFlavourIsOpen TupleFlavour{} = Bool
False
tcFlavourIsOpen SumFlavour = Bool
False
tcFlavourIsOpen AbstractTypeFlavour = Bool
False
tcFlavourIsOpen BuiltInTypeFlavour = Bool
False
tcFlavourIsOpen PromotedDataConFlavour = Bool
False
tcFlavourIsOpen TypeSynonymFlavour = Bool
False
pprPromotionQuote :: TyCon -> SDoc
pprPromotionQuote :: TyCon -> SDoc
pprPromotionQuote tc :: TyCon
tc
= case TyCon
tc of
PromotedDataCon {} -> Char -> SDoc
char '\''
_ -> SDoc
empty
instance NamedThing TyCon where
getName :: TyCon -> Name
getName = TyCon -> Name
tyConName
instance Data.Data TyCon where
toConstr :: TyCon -> Constr
toConstr _ = String -> Constr
abstractConstr "TyCon"
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c TyCon
gunfold _ _ = String -> Constr -> c TyCon
forall a. HasCallStack => String -> a
error "gunfold"
dataTypeOf :: TyCon -> DataType
dataTypeOf _ = String -> DataType
mkNoRepType "TyCon"
instance Binary Injectivity where
put_ :: BinHandle -> Injectivity -> IO ()
put_ bh :: BinHandle
bh NotInjective = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh 0
put_ bh :: BinHandle
bh (Injective xs :: [Bool]
xs) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh 1 IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BinHandle -> [Bool] -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Bool]
xs
get :: BinHandle -> IO Injectivity
get bh :: BinHandle
bh = do { Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
; case Word8
h of
0 -> Injectivity -> IO Injectivity
forall (m :: * -> *) a. Monad m => a -> m a
return Injectivity
NotInjective
_ -> do { [Bool]
xs <- BinHandle -> IO [Bool]
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
; Injectivity -> IO Injectivity
forall (m :: * -> *) a. Monad m => a -> m a
return ([Bool] -> Injectivity
Injective [Bool]
xs) } }
data RecTcChecker = RC !Int (NameEnv Int)
initRecTc :: RecTcChecker
initRecTc :: RecTcChecker
initRecTc = Int -> NameEnv Int -> RecTcChecker
RC Int
defaultRecTcMaxBound NameEnv Int
forall a. NameEnv a
emptyNameEnv
defaultRecTcMaxBound :: Int
defaultRecTcMaxBound :: Int
defaultRecTcMaxBound = 100
setRecTcMaxBound :: Int -> RecTcChecker -> RecTcChecker
setRecTcMaxBound :: Int -> RecTcChecker -> RecTcChecker
setRecTcMaxBound new_bound :: Int
new_bound (RC _old_bound :: Int
_old_bound rec_nts :: NameEnv Int
rec_nts) = Int -> NameEnv Int -> RecTcChecker
RC Int
new_bound NameEnv Int
rec_nts
checkRecTc :: RecTcChecker -> TyCon -> Maybe RecTcChecker
checkRecTc :: RecTcChecker -> TyCon -> Maybe RecTcChecker
checkRecTc (RC bound :: Int
bound rec_nts :: NameEnv Int
rec_nts) tc :: TyCon
tc
= case NameEnv Int -> Name -> Maybe Int
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv Int
rec_nts Name
tc_name of
Just n :: Int
n | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
bound -> Maybe RecTcChecker
forall a. Maybe a
Nothing
| Bool
otherwise -> RecTcChecker -> Maybe RecTcChecker
forall a. a -> Maybe a
Just (Int -> NameEnv Int -> RecTcChecker
RC Int
bound (NameEnv Int -> Name -> Int -> NameEnv Int
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv NameEnv Int
rec_nts Name
tc_name (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)))
Nothing -> RecTcChecker -> Maybe RecTcChecker
forall a. a -> Maybe a
Just (Int -> NameEnv Int -> RecTcChecker
RC Int
bound (NameEnv Int -> Name -> Int -> NameEnv Int
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv NameEnv Int
rec_nts Name
tc_name 1))
where
tc_name :: Name
tc_name = TyCon -> Name
tyConName TyCon
tc
tyConSkolem :: TyCon -> Bool
tyConSkolem :: TyCon -> Bool
tyConSkolem = Name -> Bool
isHoleName (Name -> Bool) -> (TyCon -> Name) -> TyCon -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCon -> Name
tyConName