{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module TcTyDecls(
RolesInfo,
inferRoles,
checkSynCycles,
checkClassCycles,
addTyConsToGblEnv, mkDefaultMethodType,
tcRecSelBinds, mkRecSelBinds, mkOneRecordSelector
) where
#include "HsVersions.h"
import GhcPrelude
import TcRnMonad
import TcEnv
import TcBinds( tcValBinds )
import TyCoRep( Type(..), Coercion(..), MCoercion(..), UnivCoProvenance(..) )
import TcType
import Predicate
import TysWiredIn( unitTy )
import MkCore( rEC_SEL_ERROR_ID )
import GHC.Hs
import Class
import Type
import HscTypes
import TyCon
import ConLike
import DataCon
import Name
import NameEnv
import NameSet hiding (unitFV)
import RdrName ( mkVarUnqual )
import Id
import IdInfo
import VarEnv
import VarSet
import Coercion ( ltRole )
import BasicTypes
import SrcLoc
import Unique ( mkBuiltinUnique )
import Outputable
import Util
import Maybes
import Bag
import FastString
import FV
import Module
import Control.Monad
synonymTyConsOfType :: Type -> [TyCon]
synonymTyConsOfType :: Type -> [TyCon]
synonymTyConsOfType Type
ty
= NameEnv TyCon -> [TyCon]
forall a. NameEnv a -> [a]
nameEnvElts (Type -> NameEnv TyCon
go Type
ty)
where
go :: Type -> NameEnv TyCon
go :: Type -> NameEnv TyCon
go (TyConApp TyCon
tc [Type]
tys) = TyCon -> NameEnv TyCon
go_tc TyCon
tc NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` [Type] -> NameEnv TyCon
forall (t :: * -> *). Foldable t => t Type -> NameEnv TyCon
go_s [Type]
tys
go (LitTy TyLit
_) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go (TyVarTy Var
_) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go (AppTy Type
a Type
b) = Type -> NameEnv TyCon
go Type
a NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` Type -> NameEnv TyCon
go Type
b
go (FunTy AnonArgFlag
_ Type
a Type
b) = Type -> NameEnv TyCon
go Type
a NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` Type -> NameEnv TyCon
go Type
b
go (ForAllTy TyCoVarBinder
_ Type
ty) = Type -> NameEnv TyCon
go Type
ty
go (CastTy Type
ty KindCoercion
co) = Type -> NameEnv TyCon
go Type
ty NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go (CoercionTy KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_mco :: MCoercionN -> NameEnv TyCon
go_mco MCoercionN
MRefl = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_mco (MCo KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co :: KindCoercion -> NameEnv TyCon
go_co (Refl Type
ty) = Type -> NameEnv TyCon
go Type
ty
go_co (GRefl Role
_ Type
ty MCoercionN
mco) = Type -> NameEnv TyCon
go Type
ty NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` MCoercionN -> NameEnv TyCon
go_mco MCoercionN
mco
go_co (TyConAppCo Role
_ TyCon
tc [KindCoercion]
cs) = TyCon -> NameEnv TyCon
go_tc TyCon
tc NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cs
go_co (AppCo KindCoercion
co KindCoercion
co') = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co'
go_co (ForAllCo Var
_ KindCoercion
co KindCoercion
co') = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co'
go_co (FunCo Role
_ KindCoercion
co KindCoercion
co') = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co'
go_co (CoVarCo Var
_) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_co (HoleCo {}) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_co (AxiomInstCo CoAxiom Branched
_ BranchIndex
_ [KindCoercion]
cs) = [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cs
go_co (UnivCo UnivCoProvenance
p Role
_ Type
ty Type
ty') = UnivCoProvenance -> NameEnv TyCon
go_prov UnivCoProvenance
p NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` Type -> NameEnv TyCon
go Type
ty NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` Type -> NameEnv TyCon
go Type
ty'
go_co (SymCo KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (TransCo KindCoercion
co KindCoercion
co') = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co'
go_co (NthCo Role
_ BranchIndex
_ KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (LRCo LeftOrRight
_ KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (InstCo KindCoercion
co KindCoercion
co') = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
`plusNameEnv` KindCoercion -> NameEnv TyCon
go_co KindCoercion
co'
go_co (KindCo KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (SubCo KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (AxiomRuleCo CoAxiomRule
_ [KindCoercion]
cs) = [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cs
go_prov :: UnivCoProvenance -> NameEnv TyCon
go_prov UnivCoProvenance
UnsafeCoerceProv = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_prov (PhantomProv KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_prov (ProofIrrelProv KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_prov (PluginProv String
_) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_tc :: TyCon -> NameEnv TyCon
go_tc TyCon
tc | TyCon -> Bool
isTypeSynonymTyCon TyCon
tc = Name -> TyCon -> NameEnv TyCon
forall a. Name -> a -> NameEnv a
unitNameEnv (TyCon -> Name
tyConName TyCon
tc) TyCon
tc
| Bool
otherwise = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_s :: t Type -> NameEnv TyCon
go_s t Type
tys = (Type -> NameEnv TyCon -> NameEnv TyCon)
-> NameEnv TyCon -> t Type -> NameEnv TyCon
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
plusNameEnv (NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon)
-> (Type -> NameEnv TyCon)
-> Type
-> NameEnv TyCon
-> NameEnv TyCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type -> NameEnv TyCon
go) NameEnv TyCon
forall a. NameEnv a
emptyNameEnv t Type
tys
go_co_s :: [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cos = (KindCoercion -> NameEnv TyCon -> NameEnv TyCon)
-> NameEnv TyCon -> [KindCoercion] -> NameEnv TyCon
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon
forall a. NameEnv a -> NameEnv a -> NameEnv a
plusNameEnv (NameEnv TyCon -> NameEnv TyCon -> NameEnv TyCon)
-> (KindCoercion -> NameEnv TyCon)
-> KindCoercion
-> NameEnv TyCon
-> NameEnv TyCon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindCoercion -> NameEnv TyCon
go_co) NameEnv TyCon
forall a. NameEnv a
emptyNameEnv [KindCoercion]
cos
newtype SynCycleM a = SynCycleM {
SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
runSynCycleM :: SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState) }
deriving (a -> SynCycleM b -> SynCycleM a
(a -> b) -> SynCycleM a -> SynCycleM b
(forall a b. (a -> b) -> SynCycleM a -> SynCycleM b)
-> (forall a b. a -> SynCycleM b -> SynCycleM a)
-> Functor SynCycleM
forall a b. a -> SynCycleM b -> SynCycleM a
forall a b. (a -> b) -> SynCycleM a -> SynCycleM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SynCycleM b -> SynCycleM a
$c<$ :: forall a b. a -> SynCycleM b -> SynCycleM a
fmap :: (a -> b) -> SynCycleM a -> SynCycleM b
$cfmap :: forall a b. (a -> b) -> SynCycleM a -> SynCycleM b
Functor)
type SynCycleState = NameSet
instance Applicative SynCycleM where
pure :: a -> SynCycleM a
pure a
x = (SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
forall a.
(SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
SynCycleM ((SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a)
-> (SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
forall a b. (a -> b) -> a -> b
$ \SynCycleState
state -> (a, SynCycleState) -> Either (SrcSpan, SDoc) (a, SynCycleState)
forall a b. b -> Either a b
Right (a
x, SynCycleState
state)
<*> :: SynCycleM (a -> b) -> SynCycleM a -> SynCycleM b
(<*>) = SynCycleM (a -> b) -> SynCycleM a -> SynCycleM b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad SynCycleM where
SynCycleM a
m >>= :: SynCycleM a -> (a -> SynCycleM b) -> SynCycleM b
>>= a -> SynCycleM b
f = (SynCycleState -> Either (SrcSpan, SDoc) (b, SynCycleState))
-> SynCycleM b
forall a.
(SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
SynCycleM ((SynCycleState -> Either (SrcSpan, SDoc) (b, SynCycleState))
-> SynCycleM b)
-> (SynCycleState -> Either (SrcSpan, SDoc) (b, SynCycleState))
-> SynCycleM b
forall a b. (a -> b) -> a -> b
$ \SynCycleState
state ->
case SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
forall a.
SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
runSynCycleM SynCycleM a
m SynCycleState
state of
Right (a
x, SynCycleState
state') ->
SynCycleM b
-> SynCycleState -> Either (SrcSpan, SDoc) (b, SynCycleState)
forall a.
SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
runSynCycleM (a -> SynCycleM b
f a
x) SynCycleState
state'
Left (SrcSpan, SDoc)
err -> (SrcSpan, SDoc) -> Either (SrcSpan, SDoc) (b, SynCycleState)
forall a b. a -> Either a b
Left (SrcSpan, SDoc)
err
failSynCycleM :: SrcSpan -> SDoc -> SynCycleM ()
failSynCycleM :: SrcSpan -> SDoc -> SynCycleM ()
failSynCycleM SrcSpan
loc SDoc
err = (SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ()
forall a.
(SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
SynCycleM ((SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ())
-> (SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ()
forall a b. (a -> b) -> a -> b
$ \SynCycleState
_ -> (SrcSpan, SDoc) -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a b. a -> Either a b
Left (SrcSpan
loc, SDoc
err)
checkNameIsAcyclic :: Name -> SynCycleM () -> SynCycleM ()
checkNameIsAcyclic :: Name -> SynCycleM () -> SynCycleM ()
checkNameIsAcyclic Name
n SynCycleM ()
m = (SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ()
forall a.
(SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState))
-> SynCycleM a
SynCycleM ((SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ())
-> (SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState))
-> SynCycleM ()
forall a b. (a -> b) -> a -> b
$ \SynCycleState
s ->
if Name
n Name -> SynCycleState -> Bool
`elemNameSet` SynCycleState
s
then ((), SynCycleState) -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a b. b -> Either a b
Right ((), SynCycleState
s)
else case SynCycleM ()
-> SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a.
SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
runSynCycleM SynCycleM ()
m SynCycleState
s of
Right ((), SynCycleState
s') -> ((), SynCycleState) -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a b. b -> Either a b
Right ((), SynCycleState -> Name -> SynCycleState
extendNameSet SynCycleState
s' Name
n)
Left (SrcSpan, SDoc)
err -> (SrcSpan, SDoc) -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a b. a -> Either a b
Left (SrcSpan, SDoc)
err
checkSynCycles :: UnitId -> [TyCon] -> [LTyClDecl GhcRn] -> TcM ()
checkSynCycles :: UnitId -> [TyCon] -> [LTyClDecl GhcRn] -> TcM ()
checkSynCycles UnitId
this_uid [TyCon]
tcs [LTyClDecl GhcRn]
tyclds = do
case SynCycleM ()
-> SynCycleState -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a.
SynCycleM a
-> SynCycleState -> Either (SrcSpan, SDoc) (a, SynCycleState)
runSynCycleM ((TyCon -> SynCycleM ()) -> [TyCon] -> SynCycleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (SynCycleState -> [TyCon] -> TyCon -> SynCycleM ()
go SynCycleState
emptyNameSet []) [TyCon]
tcs) SynCycleState
emptyNameSet of
Left (SrcSpan
loc, SDoc
err) -> SrcSpan -> TcM () -> TcM ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan SrcSpan
loc (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ SDoc -> TcM ()
forall a. SDoc -> TcM a
failWithTc SDoc
err
Right ((), SynCycleState)
_ -> () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
lcl_decls :: NameEnv (LTyClDecl GhcRn)
lcl_decls = [(Name, LTyClDecl GhcRn)] -> NameEnv (LTyClDecl GhcRn)
forall a. [(Name, a)] -> NameEnv a
mkNameEnv ([Name] -> [LTyClDecl GhcRn] -> [(Name, LTyClDecl GhcRn)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((TyCon -> Name) -> [TyCon] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map TyCon -> Name
tyConName [TyCon]
tcs) [LTyClDecl GhcRn]
tyclds)
go :: NameSet -> [TyCon] -> TyCon -> SynCycleM ()
go :: SynCycleState -> [TyCon] -> TyCon -> SynCycleM ()
go SynCycleState
so_far [TyCon]
seen_tcs TyCon
tc =
Name -> SynCycleM () -> SynCycleM ()
checkNameIsAcyclic (TyCon -> Name
tyConName TyCon
tc) (SynCycleM () -> SynCycleM ()) -> SynCycleM () -> SynCycleM ()
forall a b. (a -> b) -> a -> b
$ SynCycleState -> [TyCon] -> TyCon -> SynCycleM ()
go' SynCycleState
so_far [TyCon]
seen_tcs TyCon
tc
go' :: NameSet -> [TyCon] -> TyCon -> SynCycleM ()
go' :: SynCycleState -> [TyCon] -> TyCon -> SynCycleM ()
go' SynCycleState
so_far [TyCon]
seen_tcs TyCon
tc
| Name
n Name -> SynCycleState -> Bool
`elemNameSet` SynCycleState
so_far
= SrcSpan -> SDoc -> SynCycleM ()
failSynCycleM (TyCon -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan ([TyCon] -> TyCon
forall a. [a] -> a
head [TyCon]
seen_tcs)) (SDoc -> SynCycleM ()) -> SDoc -> SynCycleM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
sep [ String -> SDoc
text String
"Cycle in type synonym declarations:"
, BranchIndex -> SDoc -> SDoc
nest BranchIndex
2 ([SDoc] -> SDoc
vcat ((TyCon -> SDoc) -> [TyCon] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map TyCon -> SDoc
ppr_decl [TyCon]
seen_tcs)) ]
| Bool -> Bool
not (Module -> Bool
isHoleModule Module
mod Bool -> Bool -> Bool
||
Module -> UnitId
moduleUnitId Module
mod UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
== UnitId
this_uid Bool -> Bool -> Bool
||
Module -> Bool
isInteractiveModule Module
mod)
= () -> SynCycleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Just Type
ty <- TyCon -> Maybe Type
synTyConRhs_maybe TyCon
tc =
SynCycleState -> [TyCon] -> Type -> SynCycleM ()
go_ty (SynCycleState -> Name -> SynCycleState
extendNameSet SynCycleState
so_far (TyCon -> Name
tyConName TyCon
tc)) (TyCon
tcTyCon -> [TyCon] -> [TyCon]
forall a. a -> [a] -> [a]
:[TyCon]
seen_tcs) Type
ty
| Bool
otherwise = () -> SynCycleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
n :: Name
n = TyCon -> Name
tyConName TyCon
tc
mod :: Module
mod = HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n
ppr_decl :: TyCon -> SDoc
ppr_decl TyCon
tc =
case NameEnv (LTyClDecl GhcRn) -> Name -> Maybe (LTyClDecl GhcRn)
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv (LTyClDecl GhcRn)
lcl_decls Name
n of
Just (LTyClDecl GhcRn -> Located (SrcSpanLess (LTyClDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L SrcSpan
loc SrcSpanLess (LTyClDecl GhcRn)
decl) -> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr SrcSpan
loc SDoc -> SDoc -> SDoc
<> SDoc
colon SDoc -> SDoc -> SDoc
<+> TyClDecl GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr SrcSpanLess (LTyClDecl GhcRn)
TyClDecl GhcRn
decl
Maybe (LTyClDecl GhcRn)
Nothing -> SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
n) SDoc -> SDoc -> SDoc
<> SDoc
colon SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"from external module"
where
n :: Name
n = TyCon -> Name
tyConName TyCon
tc
go_ty :: NameSet -> [TyCon] -> Type -> SynCycleM ()
go_ty :: SynCycleState -> [TyCon] -> Type -> SynCycleM ()
go_ty SynCycleState
so_far [TyCon]
seen_tcs Type
ty =
(TyCon -> SynCycleM ()) -> [TyCon] -> SynCycleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (SynCycleState -> [TyCon] -> TyCon -> SynCycleM ()
go SynCycleState
so_far [TyCon]
seen_tcs) (Type -> [TyCon]
synonymTyConsOfType Type
ty)
checkClassCycles :: Class -> Maybe SDoc
checkClassCycles :: Class -> Maybe SDoc
checkClassCycles Class
cls
= do { (Bool
definite_cycle, SDoc
err) <- SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go (Name -> SynCycleState
unitNameSet (Class -> Name
forall a. NamedThing a => a -> Name
getName Class
cls))
Class
cls ([Var] -> [Type]
mkTyVarTys (Class -> [Var]
classTyVars Class
cls))
; let herald :: SDoc
herald | Bool
definite_cycle = String -> SDoc
text String
"Superclass cycle for"
| Bool
otherwise = String -> SDoc
text String
"Potential superclass cycle for"
; SDoc -> Maybe SDoc
forall (m :: * -> *) a. Monad m => a -> m a
return ([SDoc] -> SDoc
vcat [ SDoc
herald SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Class -> SDoc
forall a. Outputable a => a -> SDoc
ppr Class
cls)
, BranchIndex -> SDoc -> SDoc
nest BranchIndex
2 SDoc
err, SDoc
hint]) }
where
hint :: SDoc
hint = String -> SDoc
text String
"Use UndecidableSuperClasses to accept this"
go :: NameSet -> Class -> [Type] -> Maybe (Bool, SDoc)
go :: SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go SynCycleState
so_far Class
cls [Type]
tys = [Maybe (Bool, SDoc)] -> Maybe (Bool, SDoc)
forall a. [Maybe a] -> Maybe a
firstJusts ([Maybe (Bool, SDoc)] -> Maybe (Bool, SDoc))
-> [Maybe (Bool, SDoc)] -> Maybe (Bool, SDoc)
forall a b. (a -> b) -> a -> b
$
(Type -> Maybe (Bool, SDoc)) -> [Type] -> [Maybe (Bool, SDoc)]
forall a b. (a -> b) -> [a] -> [b]
map (SynCycleState -> Type -> Maybe (Bool, SDoc)
go_pred SynCycleState
so_far) ([Type] -> [Maybe (Bool, SDoc)]) -> [Type] -> [Maybe (Bool, SDoc)]
forall a b. (a -> b) -> a -> b
$
Class -> [Type] -> [Type]
immSuperClasses Class
cls [Type]
tys
go_pred :: NameSet -> PredType -> Maybe (Bool, SDoc)
go_pred :: SynCycleState -> Type -> Maybe (Bool, SDoc)
go_pred SynCycleState
so_far Type
pred
| Just (TyCon
tc, [Type]
tys) <- HasCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
pred
= SynCycleState -> Type -> TyCon -> [Type] -> Maybe (Bool, SDoc)
go_tc SynCycleState
so_far Type
pred TyCon
tc [Type]
tys
| Type -> Bool
hasTyVarHead Type
pred
= (Bool, SDoc) -> Maybe (Bool, SDoc)
forall a. a -> Maybe a
Just (Bool
False, SDoc -> BranchIndex -> SDoc -> SDoc
hang (String -> SDoc
text String
"one of whose superclass constraints is headed by a type variable:")
BranchIndex
2 (SDoc -> SDoc
quotes (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pred)))
| Bool
otherwise
= Maybe (Bool, SDoc)
forall a. Maybe a
Nothing
go_tc :: NameSet -> PredType -> TyCon -> [Type] -> Maybe (Bool, SDoc)
go_tc :: SynCycleState -> Type -> TyCon -> [Type] -> Maybe (Bool, SDoc)
go_tc SynCycleState
so_far Type
pred TyCon
tc [Type]
tys
| TyCon -> Bool
isFamilyTyCon TyCon
tc
= (Bool, SDoc) -> Maybe (Bool, SDoc)
forall a. a -> Maybe a
Just (Bool
False, SDoc -> BranchIndex -> SDoc -> SDoc
hang (String -> SDoc
text String
"one of whose superclass constraints is headed by a type family:")
BranchIndex
2 (SDoc -> SDoc
quotes (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pred)))
| Just Class
cls <- TyCon -> Maybe Class
tyConClass_maybe TyCon
tc
= SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go_cls SynCycleState
so_far Class
cls [Type]
tys
| Bool
otherwise
= Maybe (Bool, SDoc)
forall a. Maybe a
Nothing
go_cls :: NameSet -> Class -> [Type] -> Maybe (Bool, SDoc)
go_cls :: SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go_cls SynCycleState
so_far Class
cls [Type]
tys
| Name
cls_nm Name -> SynCycleState -> Bool
`elemNameSet` SynCycleState
so_far
= (Bool, SDoc) -> Maybe (Bool, SDoc)
forall a. a -> Maybe a
Just (Bool
True, String -> SDoc
text String
"one of whose superclasses is" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Class -> SDoc
forall a. Outputable a => a -> SDoc
ppr Class
cls))
| Class -> Bool
isCTupleClass Class
cls
= SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go SynCycleState
so_far Class
cls [Type]
tys
| Bool
otherwise
= do { (Bool
b,SDoc
err) <- SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go (SynCycleState
so_far SynCycleState -> Name -> SynCycleState
`extendNameSet` Name
cls_nm) Class
cls [Type]
tys
; (Bool, SDoc) -> Maybe (Bool, SDoc)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
b, String -> SDoc
text String
"one of whose superclasses is" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Class -> SDoc
forall a. Outputable a => a -> SDoc
ppr Class
cls)
SDoc -> SDoc -> SDoc
$$ SDoc
err) }
where
cls_nm :: Name
cls_nm = Class -> Name
forall a. NamedThing a => a -> Name
getName Class
cls
type RolesInfo = Name -> [Role]
type RoleEnv = NameEnv [Role]
inferRoles :: HscSource -> RoleAnnotEnv -> [TyCon] -> Name -> [Role]
inferRoles :: HscSource -> RoleAnnotEnv -> [TyCon] -> Name -> [Role]
inferRoles HscSource
hsc_src RoleAnnotEnv
annots [TyCon]
tycons
= let role_env :: RoleEnv
role_env = HscSource -> RoleAnnotEnv -> [TyCon] -> RoleEnv
initialRoleEnv HscSource
hsc_src RoleAnnotEnv
annots [TyCon]
tycons
role_env' :: RoleEnv
role_env' = RoleEnv -> [TyCon] -> RoleEnv
irGroup RoleEnv
role_env [TyCon]
tycons in
\Name
name -> case RoleEnv -> Name -> Maybe [Role]
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv RoleEnv
role_env' Name
name of
Just [Role]
roles -> [Role]
roles
Maybe [Role]
Nothing -> String -> SDoc -> [Role]
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"inferRoles" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
initialRoleEnv :: HscSource -> RoleAnnotEnv -> [TyCon] -> RoleEnv
initialRoleEnv :: HscSource -> RoleAnnotEnv -> [TyCon] -> RoleEnv
initialRoleEnv HscSource
hsc_src RoleAnnotEnv
annots = RoleEnv -> [(Name, [Role])] -> RoleEnv
forall a. NameEnv a -> [(Name, a)] -> NameEnv a
extendNameEnvList RoleEnv
forall a. NameEnv a
emptyNameEnv ([(Name, [Role])] -> RoleEnv)
-> ([TyCon] -> [(Name, [Role])]) -> [TyCon] -> RoleEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(TyCon -> (Name, [Role])) -> [TyCon] -> [(Name, [Role])]
forall a b. (a -> b) -> [a] -> [b]
map (HscSource -> RoleAnnotEnv -> TyCon -> (Name, [Role])
initialRoleEnv1 HscSource
hsc_src RoleAnnotEnv
annots)
initialRoleEnv1 :: HscSource -> RoleAnnotEnv -> TyCon -> (Name, [Role])
initialRoleEnv1 :: HscSource -> RoleAnnotEnv -> TyCon -> (Name, [Role])
initialRoleEnv1 HscSource
hsc_src RoleAnnotEnv
annots_env TyCon
tc
| TyCon -> Bool
isFamilyTyCon TyCon
tc = (Name
name, (TyConBinder -> Role) -> [TyConBinder] -> [Role]
forall a b. (a -> b) -> [a] -> [b]
map (Role -> TyConBinder -> Role
forall a b. a -> b -> a
const Role
Nominal) [TyConBinder]
bndrs)
| TyCon -> Bool
isAlgTyCon TyCon
tc = (Name
name, [Role]
default_roles)
| TyCon -> Bool
isTypeSynonymTyCon TyCon
tc = (Name
name, [Role]
default_roles)
| Bool
otherwise = String -> SDoc -> (Name, [Role])
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"initialRoleEnv1" (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc)
where name :: Name
name = TyCon -> Name
tyConName TyCon
tc
bndrs :: [TyConBinder]
bndrs = TyCon -> [TyConBinder]
tyConBinders TyCon
tc
argflags :: [ArgFlag]
argflags = (TyConBinder -> ArgFlag) -> [TyConBinder] -> [ArgFlag]
forall a b. (a -> b) -> [a] -> [b]
map TyConBinder -> ArgFlag
tyConBinderArgFlag [TyConBinder]
bndrs
num_exps :: BranchIndex
num_exps = (ArgFlag -> Bool) -> [ArgFlag] -> BranchIndex
forall a. (a -> Bool) -> [a] -> BranchIndex
count ArgFlag -> Bool
isVisibleArgFlag [ArgFlag]
argflags
role_annots :: [Maybe Role]
role_annots
= case RoleAnnotEnv -> Name -> Maybe (LRoleAnnotDecl GhcRn)
lookupRoleAnnot RoleAnnotEnv
annots_env Name
name of
Just (LRoleAnnotDecl GhcRn
-> Located (SrcSpanLess (LRoleAnnotDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L SrcSpan
_ (RoleAnnotDecl _ _ annots))
| [Located (Maybe Role)]
annots [Located (Maybe Role)] -> BranchIndex -> Bool
forall a. [a] -> BranchIndex -> Bool
`lengthIs` BranchIndex
num_exps -> (Located (Maybe Role) -> Maybe Role)
-> [Located (Maybe Role)] -> [Maybe Role]
forall a b. (a -> b) -> [a] -> [b]
map Located (Maybe Role) -> Maybe Role
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (Maybe Role)]
annots
Maybe (LRoleAnnotDecl GhcRn)
_ -> BranchIndex -> Maybe Role -> [Maybe Role]
forall a. BranchIndex -> a -> [a]
replicate BranchIndex
num_exps Maybe Role
forall a. Maybe a
Nothing
default_roles :: [Role]
default_roles = [ArgFlag] -> [Maybe Role] -> [Role]
build_default_roles [ArgFlag]
argflags [Maybe Role]
role_annots
build_default_roles :: [ArgFlag] -> [Maybe Role] -> [Role]
build_default_roles (ArgFlag
argf : [ArgFlag]
argfs) (Maybe Role
m_annot : [Maybe Role]
ras)
| ArgFlag -> Bool
isVisibleArgFlag ArgFlag
argf
= (Maybe Role
m_annot Maybe Role -> Role -> Role
forall a. Maybe a -> a -> a
`orElse` Role
default_role) Role -> [Role] -> [Role]
forall a. a -> [a] -> [a]
: [ArgFlag] -> [Maybe Role] -> [Role]
build_default_roles [ArgFlag]
argfs [Maybe Role]
ras
build_default_roles (ArgFlag
_argf : [ArgFlag]
argfs) [Maybe Role]
ras
= Role
Nominal Role -> [Role] -> [Role]
forall a. a -> [a] -> [a]
: [ArgFlag] -> [Maybe Role] -> [Role]
build_default_roles [ArgFlag]
argfs [Maybe Role]
ras
build_default_roles [] [] = []
build_default_roles [ArgFlag]
_ [Maybe Role]
_ = String -> SDoc -> [Role]
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"initialRoleEnv1 (2)"
([SDoc] -> SDoc
vcat [TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
tc, [Maybe Role] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Maybe Role]
role_annots])
default_role :: Role
default_role
| TyCon -> Bool
isClassTyCon TyCon
tc = Role
Nominal
| HscSource
HsBootFile <- HscSource
hsc_src
, TyCon -> Bool
isAbstractTyCon TyCon
tc = Role
Representational
| HscSource
HsigFile <- HscSource
hsc_src
, TyCon -> Bool
isAbstractTyCon TyCon
tc = Role
Nominal
| Bool
otherwise = Role
Phantom
irGroup :: RoleEnv -> [TyCon] -> RoleEnv
irGroup :: RoleEnv -> [TyCon] -> RoleEnv
irGroup RoleEnv
env [TyCon]
tcs
= let (RoleEnv
env', Bool
update) = RoleEnv -> RoleM () -> (RoleEnv, Bool)
runRoleM RoleEnv
env (RoleM () -> (RoleEnv, Bool)) -> RoleM () -> (RoleEnv, Bool)
forall a b. (a -> b) -> a -> b
$ (TyCon -> RoleM ()) -> [TyCon] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ TyCon -> RoleM ()
irTyCon [TyCon]
tcs in
if Bool
update
then RoleEnv -> [TyCon] -> RoleEnv
irGroup RoleEnv
env' [TyCon]
tcs
else RoleEnv
env'
irTyCon :: TyCon -> RoleM ()
irTyCon :: TyCon -> RoleM ()
irTyCon TyCon
tc
| TyCon -> Bool
isAlgTyCon TyCon
tc
= do { [Role]
old_roles <- TyCon -> RoleM [Role]
lookupRoles TyCon
tc
; Bool -> RoleM () -> RoleM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ((Role -> Bool) -> [Role] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Role -> Role -> Bool
forall a. Eq a => a -> a -> Bool
== Role
Nominal) [Role]
old_roles) (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
TyCon -> RoleM () -> RoleM ()
forall a. TyCon -> RoleM a -> RoleM a
irTcTyVars TyCon
tc (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
do { (Type -> RoleM ()) -> [Type] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (VarSet -> Type -> RoleM ()
irType VarSet
emptyVarSet) (TyCon -> [Type]
tyConStupidTheta TyCon
tc)
; Maybe Class -> (Class -> RoleM ()) -> RoleM ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenIsJust (TyCon -> Maybe Class
tyConClass_maybe TyCon
tc) Class -> RoleM ()
irClass
; (DataCon -> RoleM ()) -> [DataCon] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ DataCon -> RoleM ()
irDataCon (AlgTyConRhs -> [DataCon]
visibleDataCons (AlgTyConRhs -> [DataCon]) -> AlgTyConRhs -> [DataCon]
forall a b. (a -> b) -> a -> b
$ TyCon -> AlgTyConRhs
algTyConRhs TyCon
tc) }}
| Just Type
ty <- TyCon -> Maybe Type
synTyConRhs_maybe TyCon
tc
= TyCon -> RoleM () -> RoleM ()
forall a. TyCon -> RoleM a -> RoleM a
irTcTyVars TyCon
tc (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
VarSet -> Type -> RoleM ()
irType VarSet
emptyVarSet Type
ty
| Bool
otherwise
= () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
irClass :: Class -> RoleM ()
irClass :: Class -> RoleM ()
irClass Class
cls
= (TyCon -> RoleM ()) -> [TyCon] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ TyCon -> RoleM ()
ir_at (Class -> [TyCon]
classATs Class
cls)
where
cls_tvs :: [Var]
cls_tvs = Class -> [Var]
classTyVars Class
cls
cls_tv_set :: VarSet
cls_tv_set = [Var] -> VarSet
mkVarSet [Var]
cls_tvs
ir_at :: TyCon -> RoleM ()
ir_at TyCon
at_tc
= (Var -> RoleM ()) -> [Var] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Role -> Var -> RoleM ()
updateRole Role
Nominal) [Var]
nvars
where nvars :: [Var]
nvars = (Var -> Bool) -> [Var] -> [Var]
forall a. (a -> Bool) -> [a] -> [a]
filter (Var -> VarSet -> Bool
`elemVarSet` VarSet
cls_tv_set) ([Var] -> [Var]) -> [Var] -> [Var]
forall a b. (a -> b) -> a -> b
$ TyCon -> [Var]
tyConTyVars TyCon
at_tc
irDataCon :: DataCon -> RoleM ()
irDataCon :: DataCon -> RoleM ()
irDataCon DataCon
datacon
= [Var] -> RoleM () -> RoleM ()
forall a. [Var] -> RoleM a -> RoleM a
setRoleInferenceVars [Var]
univ_tvs (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
[Var] -> (VarSet -> RoleM ()) -> RoleM ()
forall a. [Var] -> (VarSet -> RoleM a) -> RoleM a
irExTyVars [Var]
ex_tvs ((VarSet -> RoleM ()) -> RoleM ())
-> (VarSet -> RoleM ()) -> RoleM ()
forall a b. (a -> b) -> a -> b
$ \ VarSet
ex_var_set ->
(Type -> RoleM ()) -> [Type] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (VarSet -> Type -> RoleM ()
irType VarSet
ex_var_set)
((Var -> Type) -> [Var] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
tyVarKind [Var]
ex_tvs [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [EqSpec] -> [Type]
eqSpecPreds [EqSpec]
eq_spec [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
theta [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
arg_tys)
where
([Var]
univ_tvs, [Var]
ex_tvs, [EqSpec]
eq_spec, [Type]
theta, [Type]
arg_tys, Type
_res_ty)
= DataCon -> ([Var], [Var], [EqSpec], [Type], [Type], Type)
dataConFullSig DataCon
datacon
irType :: VarSet -> Type -> RoleM ()
irType :: VarSet -> Type -> RoleM ()
irType = VarSet -> Type -> RoleM ()
go
where
go :: VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty | Just Type
ty' <- Type -> Maybe Type
coreView Type
ty
= VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty'
go VarSet
lcls (TyVarTy Var
tv) = Bool -> RoleM () -> RoleM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Var
tv Var -> VarSet -> Bool
`elemVarSet` VarSet
lcls) (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
Role -> Var -> RoleM ()
updateRole Role
Representational Var
tv
go VarSet
lcls (AppTy Type
t1 Type
t2) = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
t1 RoleM () -> RoleM () -> RoleM ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> VarSet -> Type -> RoleM ()
markNominal VarSet
lcls Type
t2
go VarSet
lcls (TyConApp TyCon
tc [Type]
tys) = do { [Role]
roles <- TyCon -> RoleM [Role]
lookupRolesX TyCon
tc
; (Role -> Type -> RoleM ()) -> [Role] -> [Type] -> RoleM ()
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m ()
zipWithM_ (VarSet -> Role -> Type -> RoleM ()
go_app VarSet
lcls) [Role]
roles [Type]
tys }
go VarSet
lcls (ForAllTy TyCoVarBinder
tvb Type
ty) = do { let tv :: Var
tv = TyCoVarBinder -> Var
forall tv argf. VarBndr tv argf -> tv
binderVar TyCoVarBinder
tvb
lcls' :: VarSet
lcls' = VarSet -> Var -> VarSet
extendVarSet VarSet
lcls Var
tv
; VarSet -> Type -> RoleM ()
markNominal VarSet
lcls (Var -> Type
tyVarKind Var
tv)
; VarSet -> Type -> RoleM ()
go VarSet
lcls' Type
ty }
go VarSet
lcls (FunTy AnonArgFlag
_ Type
arg Type
res) = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
arg RoleM () -> RoleM () -> RoleM ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> VarSet -> Type -> RoleM ()
go VarSet
lcls Type
res
go VarSet
_ (LitTy {}) = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go VarSet
lcls (CastTy Type
ty KindCoercion
_) = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty
go VarSet
_ (CoercionTy KindCoercion
_) = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go_app :: VarSet -> Role -> Type -> RoleM ()
go_app VarSet
_ Role
Phantom Type
_ = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go_app VarSet
lcls Role
Nominal Type
ty = VarSet -> Type -> RoleM ()
markNominal VarSet
lcls Type
ty
go_app VarSet
lcls Role
Representational Type
ty = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty
irTcTyVars :: TyCon -> RoleM a -> RoleM a
irTcTyVars :: TyCon -> RoleM a -> RoleM a
irTcTyVars TyCon
tc RoleM a
thing
= Name -> RoleM a -> RoleM a
forall a. Name -> RoleM a -> RoleM a
setRoleInferenceTc (TyCon -> Name
tyConName TyCon
tc) (RoleM a -> RoleM a) -> RoleM a -> RoleM a
forall a b. (a -> b) -> a -> b
$ [Var] -> RoleM a
go (TyCon -> [Var]
tyConTyVars TyCon
tc)
where
go :: [Var] -> RoleM a
go [] = RoleM a
thing
go (Var
tv:[Var]
tvs) = do { VarSet -> Type -> RoleM ()
markNominal VarSet
emptyVarSet (Var -> Type
tyVarKind Var
tv)
; Var -> RoleM a -> RoleM a
forall a. Var -> RoleM a -> RoleM a
addRoleInferenceVar Var
tv (RoleM a -> RoleM a) -> RoleM a -> RoleM a
forall a b. (a -> b) -> a -> b
$ [Var] -> RoleM a
go [Var]
tvs }
irExTyVars :: [TyVar] -> (TyVarSet -> RoleM a) -> RoleM a
irExTyVars :: [Var] -> (VarSet -> RoleM a) -> RoleM a
irExTyVars [Var]
orig_tvs VarSet -> RoleM a
thing = VarSet -> [Var] -> RoleM a
go VarSet
emptyVarSet [Var]
orig_tvs
where
go :: VarSet -> [Var] -> RoleM a
go VarSet
lcls [] = VarSet -> RoleM a
thing VarSet
lcls
go VarSet
lcls (Var
tv:[Var]
tvs) = do { VarSet -> Type -> RoleM ()
markNominal VarSet
lcls (Var -> Type
tyVarKind Var
tv)
; VarSet -> [Var] -> RoleM a
go (VarSet -> Var -> VarSet
extendVarSet VarSet
lcls Var
tv) [Var]
tvs }
markNominal :: TyVarSet
-> Type -> RoleM ()
markNominal :: VarSet -> Type -> RoleM ()
markNominal VarSet
lcls Type
ty = let nvars :: [Var]
nvars = FV -> [Var]
fvVarList (VarSet -> FV -> FV
FV.delFVs VarSet
lcls (FV -> FV) -> FV -> FV
forall a b. (a -> b) -> a -> b
$ Type -> FV
get_ty_vars Type
ty) in
(Var -> RoleM ()) -> [Var] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Role -> Var -> RoleM ()
updateRole Role
Nominal) [Var]
nvars
where
get_ty_vars :: Type -> FV
get_ty_vars :: Type -> FV
get_ty_vars (TyVarTy Var
tv) = Var -> FV
unitFV Var
tv
get_ty_vars (AppTy Type
t1 Type
t2) = Type -> FV
get_ty_vars Type
t1 FV -> FV -> FV
`unionFV` Type -> FV
get_ty_vars Type
t2
get_ty_vars (FunTy AnonArgFlag
_ Type
t1 Type
t2) = Type -> FV
get_ty_vars Type
t1 FV -> FV -> FV
`unionFV` Type -> FV
get_ty_vars Type
t2
get_ty_vars (TyConApp TyCon
_ [Type]
tys) = (Type -> FV) -> [Type] -> FV
forall a. (a -> FV) -> [a] -> FV
mapUnionFV Type -> FV
get_ty_vars [Type]
tys
get_ty_vars (ForAllTy TyCoVarBinder
tvb Type
ty) = TyCoVarBinder -> FV -> FV
tyCoFVsBndr TyCoVarBinder
tvb (Type -> FV
get_ty_vars Type
ty)
get_ty_vars (LitTy {}) = FV
emptyFV
get_ty_vars (CastTy Type
ty KindCoercion
_) = Type -> FV
get_ty_vars Type
ty
get_ty_vars (CoercionTy KindCoercion
_) = FV
emptyFV
lookupRolesX :: TyCon -> RoleM [Role]
lookupRolesX :: TyCon -> RoleM [Role]
lookupRolesX TyCon
tc
= do { [Role]
roles <- TyCon -> RoleM [Role]
lookupRoles TyCon
tc
; [Role] -> RoleM [Role]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Role] -> RoleM [Role]) -> [Role] -> RoleM [Role]
forall a b. (a -> b) -> a -> b
$ [Role]
roles [Role] -> [Role] -> [Role]
forall a. [a] -> [a] -> [a]
++ Role -> [Role]
forall a. a -> [a]
repeat Role
Nominal }
lookupRoles :: TyCon -> RoleM [Role]
lookupRoles :: TyCon -> RoleM [Role]
lookupRoles TyCon
tc
= do { RoleEnv
env <- RoleM RoleEnv
getRoleEnv
; case RoleEnv -> Name -> Maybe [Role]
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv RoleEnv
env (TyCon -> Name
tyConName TyCon
tc) of
Just [Role]
roles -> [Role] -> RoleM [Role]
forall (m :: * -> *) a. Monad m => a -> m a
return [Role]
roles
Maybe [Role]
Nothing -> [Role] -> RoleM [Role]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Role] -> RoleM [Role]) -> [Role] -> RoleM [Role]
forall a b. (a -> b) -> a -> b
$ TyCon -> [Role]
tyConRoles TyCon
tc }
updateRole :: Role -> TyVar -> RoleM ()
updateRole :: Role -> Var -> RoleM ()
updateRole Role
role Var
tv
= do { VarPositions
var_ns <- RoleM VarPositions
getVarNs
; Name
name <- RoleM Name
getTyConName
; case VarPositions -> Var -> Maybe BranchIndex
forall a. VarEnv a -> Var -> Maybe a
lookupVarEnv VarPositions
var_ns Var
tv of
Maybe BranchIndex
Nothing -> String -> SDoc -> RoleM ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"updateRole" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
$$ Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
tv SDoc -> SDoc -> SDoc
$$ VarPositions -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarPositions
var_ns)
Just BranchIndex
n -> Name -> BranchIndex -> Role -> RoleM ()
updateRoleEnv Name
name BranchIndex
n Role
role }
data RoleInferenceState = RIS { RoleInferenceState -> RoleEnv
role_env :: RoleEnv
, RoleInferenceState -> Bool
update :: Bool }
type VarPositions = VarEnv Int
newtype RoleM a = RM { RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM :: Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState) }
deriving (a -> RoleM b -> RoleM a
(a -> b) -> RoleM a -> RoleM b
(forall a b. (a -> b) -> RoleM a -> RoleM b)
-> (forall a b. a -> RoleM b -> RoleM a) -> Functor RoleM
forall a b. a -> RoleM b -> RoleM a
forall a b. (a -> b) -> RoleM a -> RoleM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RoleM b -> RoleM a
$c<$ :: forall a b. a -> RoleM b -> RoleM a
fmap :: (a -> b) -> RoleM a -> RoleM b
$cfmap :: forall a b. (a -> b) -> RoleM a -> RoleM b
Functor)
instance Applicative RoleM where
pure :: a -> RoleM a
pure a
x = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \Maybe Name
_ VarPositions
_ BranchIndex
_ RoleInferenceState
state -> (a
x, RoleInferenceState
state)
<*> :: RoleM (a -> b) -> RoleM a -> RoleM b
(<*>) = RoleM (a -> b) -> RoleM a -> RoleM b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad RoleM where
RoleM a
a >>= :: RoleM a -> (a -> RoleM b) -> RoleM b
>>= a -> RoleM b
f = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b
forall a b. (a -> b) -> a -> b
$ \Maybe Name
m_info VarPositions
vps BranchIndex
nvps RoleInferenceState
state ->
let (a
a', RoleInferenceState
state') = RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
a Maybe Name
m_info VarPositions
vps BranchIndex
nvps RoleInferenceState
state in
RoleM b
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (b, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM (a -> RoleM b
f a
a') Maybe Name
m_info VarPositions
vps BranchIndex
nvps RoleInferenceState
state'
runRoleM :: RoleEnv -> RoleM () -> (RoleEnv, Bool)
runRoleM :: RoleEnv -> RoleM () -> (RoleEnv, Bool)
runRoleM RoleEnv
env RoleM ()
thing = (RoleEnv
env', Bool
update)
where RIS { role_env :: RoleInferenceState -> RoleEnv
role_env = RoleEnv
env', update :: RoleInferenceState -> Bool
update = Bool
update }
= ((), RoleInferenceState) -> RoleInferenceState
forall a b. (a, b) -> b
snd (((), RoleInferenceState) -> RoleInferenceState)
-> ((), RoleInferenceState) -> RoleInferenceState
forall a b. (a -> b) -> a -> b
$ RoleM ()
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> ((), RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM ()
thing Maybe Name
forall a. Maybe a
Nothing VarPositions
forall a. NameEnv a
emptyVarEnv BranchIndex
0 RoleInferenceState
state
state :: RoleInferenceState
state = RIS :: RoleEnv -> Bool -> RoleInferenceState
RIS { role_env :: RoleEnv
role_env = RoleEnv
env
, update :: Bool
update = Bool
False }
setRoleInferenceTc :: Name -> RoleM a -> RoleM a
setRoleInferenceTc :: Name -> RoleM a -> RoleM a
setRoleInferenceTc Name
name RoleM a
thing = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \Maybe Name
m_name VarPositions
vps BranchIndex
nvps RoleInferenceState
state ->
ASSERT( isNothing m_name )
ASSERT( isEmptyVarEnv vps )
ASSERT( nvps == 0 )
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
name) VarPositions
vps BranchIndex
nvps RoleInferenceState
state
addRoleInferenceVar :: TyVar -> RoleM a -> RoleM a
addRoleInferenceVar :: Var -> RoleM a -> RoleM a
addRoleInferenceVar Var
tv RoleM a
thing
= (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \Maybe Name
m_name VarPositions
vps BranchIndex
nvps RoleInferenceState
state ->
ASSERT( isJust m_name )
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing Maybe Name
m_name (VarPositions -> Var -> BranchIndex -> VarPositions
forall a. VarEnv a -> Var -> a -> VarEnv a
extendVarEnv VarPositions
vps Var
tv BranchIndex
nvps) (BranchIndex
nvpsBranchIndex -> BranchIndex -> BranchIndex
forall a. Num a => a -> a -> a
+BranchIndex
1) RoleInferenceState
state
setRoleInferenceVars :: [TyVar] -> RoleM a -> RoleM a
setRoleInferenceVars :: [Var] -> RoleM a -> RoleM a
setRoleInferenceVars [Var]
tvs RoleM a
thing
= (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \Maybe Name
m_name VarPositions
_vps BranchIndex
_nvps RoleInferenceState
state ->
ASSERT( isJust m_name )
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing Maybe Name
m_name ([(Var, BranchIndex)] -> VarPositions
forall a. [(Var, a)] -> VarEnv a
mkVarEnv ([Var] -> [BranchIndex] -> [(Var, BranchIndex)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Var]
tvs [BranchIndex
0..])) (String -> BranchIndex
forall a. String -> a
panic String
"setRoleInferenceVars")
RoleInferenceState
state
getRoleEnv :: RoleM RoleEnv
getRoleEnv :: RoleM RoleEnv
getRoleEnv = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv
forall a b. (a -> b) -> a -> b
$ \Maybe Name
_ VarPositions
_ BranchIndex
_ state :: RoleInferenceState
state@(RIS { role_env :: RoleInferenceState -> RoleEnv
role_env = RoleEnv
env }) -> (RoleEnv
env, RoleInferenceState
state)
getVarNs :: RoleM VarPositions
getVarNs :: RoleM VarPositions
getVarNs = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions
forall a b. (a -> b) -> a -> b
$ \Maybe Name
_ VarPositions
vps BranchIndex
_ RoleInferenceState
state -> (VarPositions
vps, RoleInferenceState
state)
getTyConName :: RoleM Name
getTyConName :: RoleM Name
getTyConName = (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name)
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name
forall a b. (a -> b) -> a -> b
$ \Maybe Name
m_name VarPositions
_ BranchIndex
_ RoleInferenceState
state ->
case Maybe Name
m_name of
Maybe Name
Nothing -> String -> (Name, RoleInferenceState)
forall a. String -> a
panic String
"getTyConName"
Just Name
name -> (Name
name, RoleInferenceState
state)
updateRoleEnv :: Name -> Int -> Role -> RoleM ()
updateRoleEnv :: Name -> BranchIndex -> Role -> RoleM ()
updateRoleEnv Name
name BranchIndex
n Role
role
= (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ()
forall a.
(Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ())
-> (Maybe Name
-> VarPositions
-> BranchIndex
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ()
forall a b. (a -> b) -> a -> b
$ \Maybe Name
_ VarPositions
_ BranchIndex
_ state :: RoleInferenceState
state@(RIS { role_env :: RoleInferenceState -> RoleEnv
role_env = RoleEnv
role_env }) -> ((),
case RoleEnv -> Name -> Maybe [Role]
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv RoleEnv
role_env Name
name of
Maybe [Role]
Nothing -> String -> SDoc -> RoleInferenceState
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"updateRoleEnv" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
Just [Role]
roles -> let ([Role]
before, Role
old_role : [Role]
after) = BranchIndex -> [Role] -> ([Role], [Role])
forall a. BranchIndex -> [a] -> ([a], [a])
splitAt BranchIndex
n [Role]
roles in
if Role
role Role -> Role -> Bool
`ltRole` Role
old_role
then let roles' :: [Role]
roles' = [Role]
before [Role] -> [Role] -> [Role]
forall a. [a] -> [a] -> [a]
++ Role
role Role -> [Role] -> [Role]
forall a. a -> [a] -> [a]
: [Role]
after
role_env' :: RoleEnv
role_env' = RoleEnv -> Name -> [Role] -> RoleEnv
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv RoleEnv
role_env Name
name [Role]
roles' in
RIS :: RoleEnv -> Bool -> RoleInferenceState
RIS { role_env :: RoleEnv
role_env = RoleEnv
role_env', update :: Bool
update = Bool
True }
else RoleInferenceState
state )
addTyConsToGblEnv :: [TyCon] -> TcM TcGblEnv
addTyConsToGblEnv :: [TyCon] -> TcM TcGblEnv
addTyConsToGblEnv [TyCon]
tyclss
= [TyCon] -> TcM TcGblEnv -> TcM TcGblEnv
forall r. [TyCon] -> TcM r -> TcM r
tcExtendTyConEnv [TyCon]
tyclss (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
[TyThing] -> TcM TcGblEnv -> TcM TcGblEnv
forall r. [TyThing] -> TcM r -> TcM r
tcExtendGlobalEnvImplicit [TyThing]
implicit_things (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
[Var] -> TcM TcGblEnv -> TcM TcGblEnv
forall a. [Var] -> TcM a -> TcM a
tcExtendGlobalValEnv [Var]
def_meth_ids (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcM ()
traceTc String
"tcAddTyCons" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ String -> SDoc
text String
"tycons" SDoc -> SDoc -> SDoc
<+> [TyCon] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyCon]
tyclss
, String -> SDoc
text String
"implicits" SDoc -> SDoc -> SDoc
<+> [TyThing] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyThing]
implicit_things ]
; TcGblEnv
gbl_env <- [(Var, LHsBind GhcRn)] -> TcM TcGblEnv
tcRecSelBinds ([TyCon] -> [(Var, LHsBind GhcRn)]
mkRecSelBinds [TyCon]
tyclss)
; TcGblEnv -> TcM TcGblEnv
forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
gbl_env }
where
implicit_things :: [TyThing]
implicit_things = (TyCon -> [TyThing]) -> [TyCon] -> [TyThing]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TyCon -> [TyThing]
implicitTyConThings [TyCon]
tyclss
def_meth_ids :: [Var]
def_meth_ids = [TyCon] -> [Var]
mkDefaultMethodIds [TyCon]
tyclss
mkDefaultMethodIds :: [TyCon] -> [Id]
mkDefaultMethodIds :: [TyCon] -> [Var]
mkDefaultMethodIds [TyCon]
tycons
= [ Name -> Type -> Var
mkExportedVanillaId Name
dm_name (Class -> Var -> DefMethSpec Type -> Type
mkDefaultMethodType Class
cls Var
sel_id DefMethSpec Type
dm_spec)
| TyCon
tc <- [TyCon]
tycons
, Just Class
cls <- [TyCon -> Maybe Class
tyConClass_maybe TyCon
tc]
, (Var
sel_id, Just (Name
dm_name, DefMethSpec Type
dm_spec)) <- Class -> [(Var, DefMethInfo)]
classOpItems Class
cls ]
mkDefaultMethodType :: Class -> Id -> DefMethSpec Type -> Type
mkDefaultMethodType :: Class -> Var -> DefMethSpec Type -> Type
mkDefaultMethodType Class
_ Var
sel_id DefMethSpec Type
VanillaDM = Var -> Type
idType Var
sel_id
mkDefaultMethodType Class
cls Var
_ (GenericDM Type
dm_ty) = [TyCoVarBinder] -> [Type] -> Type -> Type
mkSigmaTy [TyCoVarBinder]
tv_bndrs [Type
pred] Type
dm_ty
where
pred :: Type
pred = Class -> [Type] -> Type
mkClassPred Class
cls ([Var] -> [Type]
mkTyVarTys ([TyConBinder] -> [Var]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
cls_bndrs))
cls_bndrs :: [TyConBinder]
cls_bndrs = TyCon -> [TyConBinder]
tyConBinders (Class -> TyCon
classTyCon Class
cls)
tv_bndrs :: [TyCoVarBinder]
tv_bndrs = [TyConBinder] -> [TyCoVarBinder]
tyConTyVarBinders [TyConBinder]
cls_bndrs
tcRecSelBinds :: [(Id, LHsBind GhcRn)] -> TcM TcGblEnv
tcRecSelBinds :: [(Var, LHsBind GhcRn)] -> TcM TcGblEnv
tcRecSelBinds [(Var, LHsBind GhcRn)]
sel_bind_prs
= [Var] -> TcM TcGblEnv -> TcM TcGblEnv
forall a. [Var] -> TcM a -> TcM a
tcExtendGlobalValEnv [Var
sel_id | (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L SrcSpan
_ (IdSig _ sel_id)) <- [LSig GhcRn]
sigs] (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
do { ([(RecFlag, LHsBinds GhcTcId)]
rec_sel_binds, TcGblEnv
tcg_env) <- TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
-> TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
forall a. TcRn a -> TcRn a
discardWarnings (TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
-> TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv))
-> TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
-> TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
forall a b. (a -> b) -> a -> b
$
TopLevelFlag
-> [(RecFlag, LHsBinds GhcRn)]
-> [LSig GhcRn]
-> TcM TcGblEnv
-> TcRn ([(RecFlag, LHsBinds GhcTcId)], TcGblEnv)
forall thing.
TopLevelFlag
-> [(RecFlag, LHsBinds GhcRn)]
-> [LSig GhcRn]
-> TcM thing
-> TcM ([(RecFlag, LHsBinds GhcTcId)], thing)
tcValBinds TopLevelFlag
TopLevel [(RecFlag, LHsBinds GhcRn)]
binds [LSig GhcRn]
sigs TcM TcGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; TcGblEnv -> TcM TcGblEnv
forall (m :: * -> *) a. Monad m => a -> m a
return (TcGblEnv
tcg_env TcGblEnv -> [LHsBinds GhcTcId] -> TcGblEnv
`addTypecheckedBinds` ((RecFlag, LHsBinds GhcTcId) -> LHsBinds GhcTcId)
-> [(RecFlag, LHsBinds GhcTcId)] -> [LHsBinds GhcTcId]
forall a b. (a -> b) -> [a] -> [b]
map (RecFlag, LHsBinds GhcTcId) -> LHsBinds GhcTcId
forall a b. (a, b) -> b
snd [(RecFlag, LHsBinds GhcTcId)]
rec_sel_binds) }
where
sigs :: [LSig GhcRn]
sigs = [ SrcSpan -> SrcSpanLess (LSig GhcRn) -> LSig GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XIdSig GhcRn -> Var -> Sig GhcRn
forall pass. XIdSig pass -> Var -> Sig pass
IdSig XIdSig GhcRn
NoExtField
noExtField Var
sel_id) | (Var
sel_id, LHsBind GhcRn
_) <- [(Var, LHsBind GhcRn)]
sel_bind_prs
, let loc :: SrcSpan
loc = Var -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Var
sel_id ]
binds :: [(RecFlag, LHsBinds GhcRn)]
binds = [(RecFlag
NonRecursive, LHsBind GhcRn -> LHsBinds GhcRn
forall a. a -> Bag a
unitBag LHsBind GhcRn
bind) | (Var
_, LHsBind GhcRn
bind) <- [(Var, LHsBind GhcRn)]
sel_bind_prs]
mkRecSelBinds :: [TyCon] -> [(Id, LHsBind GhcRn)]
mkRecSelBinds :: [TyCon] -> [(Var, LHsBind GhcRn)]
mkRecSelBinds [TyCon]
tycons
= ((TyCon, FieldLabel) -> (Var, LHsBind GhcRn))
-> [(TyCon, FieldLabel)] -> [(Var, LHsBind GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (TyCon, FieldLabel) -> (Var, LHsBind GhcRn)
mkRecSelBind [ (TyCon
tc,FieldLabel
fld) | TyCon
tc <- [TyCon]
tycons
, FieldLabel
fld <- TyCon -> [FieldLabel]
tyConFieldLabels TyCon
tc ]
mkRecSelBind :: (TyCon, FieldLabel) -> (Id, LHsBind GhcRn)
mkRecSelBind :: (TyCon, FieldLabel) -> (Var, LHsBind GhcRn)
mkRecSelBind (TyCon
tycon, FieldLabel
fl)
= [ConLike] -> RecSelParent -> FieldLabel -> (Var, LHsBind GhcRn)
mkOneRecordSelector [ConLike]
all_cons (TyCon -> RecSelParent
RecSelData TyCon
tycon) FieldLabel
fl
where
all_cons :: [ConLike]
all_cons = (DataCon -> ConLike) -> [DataCon] -> [ConLike]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ConLike
RealDataCon (TyCon -> [DataCon]
tyConDataCons TyCon
tycon)
mkOneRecordSelector :: [ConLike] -> RecSelParent -> FieldLabel
-> (Id, LHsBind GhcRn)
mkOneRecordSelector :: [ConLike] -> RecSelParent -> FieldLabel -> (Var, LHsBind GhcRn)
mkOneRecordSelector [ConLike]
all_cons RecSelParent
idDetails FieldLabel
fl
= (Var
sel_id, SrcSpan -> SrcSpanLess (LHsBind GhcRn) -> LHsBind GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc SrcSpanLess (LHsBind GhcRn)
HsBind GhcRn
sel_bind)
where
loc :: SrcSpan
loc = Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
sel_name
lbl :: FieldLabelString
lbl = FieldLabel -> FieldLabelString
forall a. FieldLbl a -> FieldLabelString
flLabel FieldLabel
fl
sel_name :: Name
sel_name = FieldLabel -> Name
forall a. FieldLbl a -> a
flSelector FieldLabel
fl
sel_id :: Var
sel_id = IdDetails -> Name -> Type -> Var
mkExportedLocalId IdDetails
rec_details Name
sel_name Type
sel_ty
rec_details :: IdDetails
rec_details = RecSelId :: RecSelParent -> Bool -> IdDetails
RecSelId { sel_tycon :: RecSelParent
sel_tycon = RecSelParent
idDetails, sel_naughty :: Bool
sel_naughty = Bool
is_naughty }
cons_w_field :: [ConLike]
cons_w_field = [ConLike] -> [FieldLabelString] -> [ConLike]
conLikesWithFields [ConLike]
all_cons [FieldLabelString
lbl]
con1 :: ConLike
con1 = ASSERT( not (null cons_w_field) ) head cons_w_field
field_ty :: Type
field_ty = ConLike -> FieldLabelString -> Type
conLikeFieldType ConLike
con1 FieldLabelString
lbl
data_tvs :: [Var]
data_tvs = [Type] -> [Var]
tyCoVarsOfTypesWellScoped [Type]
inst_tys
data_tv_set :: VarSet
data_tv_set= [Var] -> VarSet
mkVarSet [Var]
data_tvs
is_naughty :: Bool
is_naughty = Bool -> Bool
not (Type -> VarSet
tyCoVarsOfType Type
field_ty VarSet -> VarSet -> Bool
`subVarSet` VarSet
data_tv_set)
([Var]
field_tvs, [Type]
field_theta, Type
field_tau) = Type -> ([Var], [Type], Type)
tcSplitSigmaTy Type
field_ty
sel_ty :: Type
sel_ty | Bool
is_naughty = Type
unitTy
| Bool
otherwise = [Var] -> Type -> Type
mkSpecForAllTys [Var]
data_tvs (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[Type] -> Type -> Type
mkPhiTy (ConLike -> [Type]
conLikeStupidTheta ConLike
con1) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkVisFunTy Type
data_ty (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[Var] -> Type -> Type
mkSpecForAllTys [Var]
field_tvs (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[Type] -> Type -> Type
mkPhiTy [Type]
field_theta (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[Type] -> Type -> Type
mkPhiTy [Type]
req_theta (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type
field_tau
sel_bind :: HsBind GhcRn
sel_bind = Origin
-> Located Name -> [LMatch GhcRn (LHsExpr GhcRn)] -> HsBind GhcRn
mkTopFunBind Origin
Generated Located Name
sel_lname [LMatch GhcRn (LHsExpr GhcRn)]
alts
where
alts :: [LMatch GhcRn (LHsExpr GhcRn)]
alts | Bool
is_naughty = [HsMatchContext (NameOrRdrName (IdP GhcRn))
-> [LPat GhcRn] -> LHsExpr GhcRn -> LMatch GhcRn (LHsExpr GhcRn)
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch (Located Name -> HsMatchContext Name
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs Located Name
sel_lname)
[] LHsExpr GhcRn
forall (a :: Pass). LHsExpr (GhcPass a)
unit_rhs]
| Bool
otherwise = (ConLike -> LMatch GhcRn (LHsExpr GhcRn))
-> [ConLike] -> [LMatch GhcRn (LHsExpr GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map ConLike -> LMatch GhcRn (LHsExpr GhcRn)
mk_match [ConLike]
cons_w_field [LMatch GhcRn (LHsExpr GhcRn)]
-> [LMatch GhcRn (LHsExpr GhcRn)] -> [LMatch GhcRn (LHsExpr GhcRn)]
forall a. [a] -> [a] -> [a]
++ [LMatch GhcRn (LHsExpr GhcRn)]
deflt
mk_match :: ConLike -> LMatch GhcRn (LHsExpr GhcRn)
mk_match ConLike
con = HsMatchContext (NameOrRdrName (IdP GhcRn))
-> [LPat GhcRn] -> LHsExpr GhcRn -> LMatch GhcRn (LHsExpr GhcRn)
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch (Located Name -> HsMatchContext Name
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs Located Name
sel_lname)
[SrcSpan -> SrcSpanLess (Located (Pat GhcRn)) -> Located (Pat GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (ConLike -> Pat GhcRn
mk_sel_pat ConLike
con)]
(SrcSpan -> SrcSpanLess (LHsExpr GhcRn) -> LHsExpr GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XVar GhcRn -> Located (IdP GhcRn) -> HsExpr GhcRn
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcRn
NoExtField
noExtField (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc Name
SrcSpanLess (Located Name)
field_var)))
mk_sel_pat :: ConLike -> Pat GhcRn
mk_sel_pat ConLike
con = Located (IdP GhcRn) -> HsConPatDetails GhcRn -> Pat GhcRn
forall p. Located (IdP p) -> HsConPatDetails p -> Pat p
ConPatIn (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (ConLike -> Name
forall a. NamedThing a => a -> Name
getName ConLike
con)) (HsRecFields GhcRn (Located (Pat GhcRn))
-> HsConDetails
(Located (Pat GhcRn)) (HsRecFields GhcRn (Located (Pat GhcRn)))
forall arg rec. rec -> HsConDetails arg rec
RecCon HsRecFields GhcRn (Located (Pat GhcRn))
rec_fields)
rec_fields :: HsRecFields GhcRn (Located (Pat GhcRn))
rec_fields = HsRecFields :: forall p arg.
[LHsRecField p arg]
-> Maybe (Located BranchIndex) -> HsRecFields p arg
HsRecFields { rec_flds :: [LHsRecField GhcRn (Located (Pat GhcRn))]
rec_flds = [LHsRecField GhcRn (Located (Pat GhcRn))
rec_field], rec_dotdot :: Maybe (Located BranchIndex)
rec_dotdot = Maybe (Located BranchIndex)
forall a. Maybe a
Nothing }
rec_field :: LHsRecField GhcRn (Located (Pat GhcRn))
rec_field = SrcSpanLess (LHsRecField GhcRn (Located (Pat GhcRn)))
-> LHsRecField GhcRn (Located (Pat GhcRn))
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (HsRecField :: forall id arg. Located id -> arg -> Bool -> HsRecField' id arg
HsRecField
{ hsRecFieldLbl :: Located (FieldOcc GhcRn)
hsRecFieldLbl
= SrcSpan
-> SrcSpanLess (Located (FieldOcc GhcRn))
-> Located (FieldOcc GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XCFieldOcc GhcRn -> Located RdrName -> FieldOcc GhcRn
forall pass. XCFieldOcc pass -> Located RdrName -> FieldOcc pass
FieldOcc Name
XCFieldOcc GhcRn
sel_name
(SrcSpan -> SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (SrcSpanLess (Located RdrName) -> Located RdrName)
-> SrcSpanLess (Located RdrName) -> Located RdrName
forall a b. (a -> b) -> a -> b
$ FieldLabelString -> RdrName
mkVarUnqual FieldLabelString
lbl))
, hsRecFieldArg :: Located (Pat GhcRn)
hsRecFieldArg
= SrcSpan -> SrcSpanLess (Located (Pat GhcRn)) -> Located (Pat GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XVarPat GhcRn -> Located (IdP GhcRn) -> Pat GhcRn
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcRn
NoExtField
noExtField (SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc Name
SrcSpanLess (Located Name)
field_var))
, hsRecPun :: Bool
hsRecPun = Bool
False })
sel_lname :: Located Name
sel_lname = SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc Name
SrcSpanLess (Located Name)
sel_name
field_var :: Name
field_var = Unique -> OccName -> SrcSpan -> Name
mkInternalName (BranchIndex -> Unique
mkBuiltinUnique BranchIndex
1) (Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName Name
sel_name) SrcSpan
loc
deflt :: [LMatch GhcRn (LHsExpr GhcRn)]
deflt | (ConLike -> Bool) -> [ConLike] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ConLike -> Bool
dealt_with [ConLike]
all_cons = []
| Bool
otherwise = [HsMatchContext (NameOrRdrName (IdP GhcRn))
-> [LPat GhcRn] -> LHsExpr GhcRn -> LMatch GhcRn (LHsExpr GhcRn)
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch HsMatchContext (NameOrRdrName (IdP GhcRn))
forall id. HsMatchContext id
CaseAlt
[SrcSpan -> SrcSpanLess (Located (Pat GhcRn)) -> Located (Pat GhcRn)
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XWildPat GhcRn -> Pat GhcRn
forall p. XWildPat p -> Pat p
WildPat XWildPat GhcRn
NoExtField
noExtField)]
(LHsExpr GhcRn -> LHsExpr GhcRn -> LHsExpr GhcRn
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
mkHsApp (SrcSpan -> SrcSpanLess (LHsExpr GhcRn) -> LHsExpr GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XVar GhcRn -> Located (IdP GhcRn) -> HsExpr GhcRn
forall p. XVar p -> Located (IdP p) -> HsExpr p
HsVar XVar GhcRn
NoExtField
noExtField
(SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (Var -> Name
forall a. NamedThing a => a -> Name
getName Var
rEC_SEL_ERROR_ID))))
(SrcSpan -> SrcSpanLess (LHsExpr GhcRn) -> LHsExpr GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XLitE GhcRn -> HsLit GhcRn -> HsExpr GhcRn
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcRn
NoExtField
noExtField HsLit GhcRn
msg_lit)))]
dealt_with :: ConLike -> Bool
dealt_with :: ConLike -> Bool
dealt_with (PatSynCon PatSyn
_) = Bool
False
dealt_with con :: ConLike
con@(RealDataCon DataCon
dc) =
ConLike
con ConLike -> [ConLike] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ConLike]
cons_w_field Bool -> Bool -> Bool
|| [Type] -> DataCon -> Bool
dataConCannotMatch [Type]
inst_tys DataCon
dc
([Var]
univ_tvs, [Var]
_, [EqSpec]
eq_spec, [Type]
_, [Type]
req_theta, [Type]
_, Type
data_ty) = ConLike -> ([Var], [Var], [EqSpec], [Type], [Type], [Type], Type)
conLikeFullSig ConLike
con1
eq_subst :: TCvSubst
eq_subst = [(Var, Type)] -> TCvSubst
mkTvSubstPrs ((EqSpec -> (Var, Type)) -> [EqSpec] -> [(Var, Type)]
forall a b. (a -> b) -> [a] -> [b]
map EqSpec -> (Var, Type)
eqSpecPair [EqSpec]
eq_spec)
inst_tys :: [Type]
inst_tys = TCvSubst -> [Var] -> [Type]
substTyVars TCvSubst
eq_subst [Var]
univ_tvs
unit_rhs :: LHsExpr (GhcPass a)
unit_rhs = [LHsExpr (GhcPass a)] -> LHsExpr (GhcPass a)
forall (a :: Pass). [LHsExpr (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsTupleExpr []
msg_lit :: HsLit GhcRn
msg_lit = XHsStringPrim GhcRn -> ByteString -> HsLit GhcRn
forall x. XHsStringPrim x -> ByteString -> HsLit x
HsStringPrim SourceText
XHsStringPrim GhcRn
NoSourceText (FieldLabelString -> ByteString
bytesFS FieldLabelString
lbl)