{-# LANGUAGE CPP #-}
{-# 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, addTypecheckedBinds )
import TyCoRep( Type(..), Coercion(..), MCoercion(..), UnivCoProvenance(..) )
import TcType
import TysWiredIn( unitTy )
import MkCore( rEC_SEL_ERROR_ID )
import HsSyn
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 ty :: 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 tc :: TyCon
tc tys :: [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 _) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go (TyVarTy _) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go (AppTy a :: Type
a b :: 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 a :: Type
a b :: 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 _ ty :: Type
ty) = Type -> NameEnv TyCon
go Type
ty
go (CastTy ty :: Type
ty co :: 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 co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_mco :: MCoercionN -> NameEnv TyCon
go_mco MRefl = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_mco (MCo co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co :: KindCoercion -> NameEnv TyCon
go_co (Refl ty :: Type
ty) = Type -> NameEnv TyCon
go Type
ty
go_co (GRefl _ ty :: Type
ty mco :: 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 _ tc :: TyCon
tc cs :: [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 co :: KindCoercion
co 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 _ co :: KindCoercion
co 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 _ co :: KindCoercion
co 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 _) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_co (HoleCo {}) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_co (AxiomInstCo _ _ cs :: [KindCoercion]
cs) = [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cs
go_co (UnivCo p :: UnivCoProvenance
p _ ty :: Type
ty 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 co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (TransCo co :: KindCoercion
co 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 _ _ co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (LRCo _ co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (InstCo co :: KindCoercion
co 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 co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (SubCo co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_co (AxiomRuleCo _ cs :: [KindCoercion]
cs) = [KindCoercion] -> NameEnv TyCon
go_co_s [KindCoercion]
cs
go_prov :: UnivCoProvenance -> NameEnv TyCon
go_prov UnsafeCoerceProv = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_prov (PhantomProv co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_prov (ProofIrrelProv co :: KindCoercion
co) = KindCoercion -> NameEnv TyCon
go_co KindCoercion
co
go_prov (PluginProv _) = NameEnv TyCon
forall a. NameEnv a
emptyNameEnv
go_tc :: TyCon -> NameEnv TyCon
go_tc 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 tys :: 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 cos :: [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) }
type SynCycleState = NameSet
instance Functor SynCycleM where
fmap :: (a -> b) -> SynCycleM a -> SynCycleM b
fmap = (a -> b) -> SynCycleM a -> SynCycleM b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM
instance Applicative SynCycleM where
pure :: a -> SynCycleM a
pure x :: 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
$ \state :: 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
m :: SynCycleM a
m >>= :: SynCycleM a -> (a -> SynCycleM b) -> SynCycleM b
>>= f :: 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
$ \state :: 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 (x :: a
x, state' :: 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 err :: (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 loc :: SrcSpan
loc err :: 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
$ \_ -> (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 n :: Name
n m :: 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
$ \s :: 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 ((), s' :: SynCycleState
s') -> ((), SynCycleState) -> Either (SrcSpan, SDoc) ((), SynCycleState)
forall a b. b -> Either a b
Right ((), SynCycleState -> Name -> SynCycleState
extendNameSet SynCycleState
s' Name
n)
Left err :: (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 this_uid :: UnitId
this_uid tcs :: [TyCon]
tcs tyclds :: [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 (loc :: SrcSpan
loc, err :: 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 _ -> () -> 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 so_far :: SynCycleState
so_far seen_tcs :: [TyCon]
seen_tcs tc :: 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' so_far :: SynCycleState
so_far seen_tcs :: [TyCon]
seen_tcs tc :: 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 "Cycle in type synonym declarations:"
, Int -> SDoc -> SDoc
nest 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 ty :: 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 tc :: 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 loc :: SrcSpan
loc decl :: 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
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 "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 so_far :: SynCycleState
so_far seen_tcs :: [TyCon]
seen_tcs ty :: 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 cls :: Class
cls
= do { (definite_cycle :: Bool
definite_cycle, err :: 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 ([TyVar] -> [Type]
mkTyVarTys (Class -> [TyVar]
classTyVars Class
cls))
; let herald :: SDoc
herald | Bool
definite_cycle = String -> SDoc
text "Superclass cycle for"
| Bool
otherwise = String -> SDoc
text "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)
, Int -> SDoc -> SDoc
nest 2 SDoc
err, SDoc
hint]) }
where
hint :: SDoc
hint = String -> SDoc
text "Use UndecidableSuperClasses to accept this"
go :: NameSet -> Class -> [Type] -> Maybe (Bool, SDoc)
go :: SynCycleState -> Class -> [Type] -> Maybe (Bool, SDoc)
go so_far :: SynCycleState
so_far cls :: Class
cls tys :: [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 so_far :: SynCycleState
so_far pred :: Type
pred
| Just (tc :: TyCon
tc, tys :: [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 -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "one of whose superclass constraints is headed by a type variable:")
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 so_far :: SynCycleState
so_far pred :: Type
pred tc :: TyCon
tc tys :: [Type]
tys
| TyCon -> Bool
isFamilyTyCon TyCon
tc
= (Bool, SDoc) -> Maybe (Bool, SDoc)
forall a. a -> Maybe a
Just (Bool
False, SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "one of whose superclass constraints is headed by a type family:")
2 (SDoc -> SDoc
quotes (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pred)))
| Just cls :: 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 so_far :: SynCycleState
so_far cls :: Class
cls tys :: [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 "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 { (b :: Bool
b,err :: 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 "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 hsc_src :: HscSource
hsc_src annots :: RoleAnnotEnv
annots tycons :: [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
name -> case RoleEnv -> Name -> Maybe [Role]
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv RoleEnv
role_env' Name
name of
Just roles :: [Role]
roles -> [Role]
roles
Nothing -> String -> SDoc -> [Role]
forall a. HasCallStack => String -> SDoc -> a
pprPanic "inferRoles" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
initialRoleEnv :: HscSource -> RoleAnnotEnv -> [TyCon] -> RoleEnv
initialRoleEnv :: HscSource -> RoleAnnotEnv -> [TyCon] -> RoleEnv
initialRoleEnv hsc_src :: HscSource
hsc_src annots :: 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 hsc_src :: HscSource
hsc_src annots_env :: RoleAnnotEnv
annots_env tc :: 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 "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 :: Int
num_exps = (ArgFlag -> Bool) -> [ArgFlag] -> Int
forall a. (a -> Bool) -> [a] -> Int
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 _ (RoleAnnotDecl _ _ annots))
| [Located (Maybe Role)]
annots [Located (Maybe Role)] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthIs` Int
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
_ -> Int -> Maybe Role -> [Maybe Role]
forall a. Int -> a -> [a]
replicate Int
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 (argf :: ArgFlag
argf : argfs :: [ArgFlag]
argfs) (m_annot :: Maybe Role
m_annot : ras :: [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 (_argf :: ArgFlag
_argf : argfs :: [ArgFlag]
argfs) ras :: [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 _ _ = String -> SDoc -> [Role]
forall a. HasCallStack => String -> SDoc -> a
pprPanic "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 env :: RoleEnv
env tcs :: [TyCon]
tcs
= let (env' :: RoleEnv
env', update :: 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 tc :: 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 ty :: 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 cls :: 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 :: [TyVar]
cls_tvs = Class -> [TyVar]
classTyVars Class
cls
cls_tv_set :: VarSet
cls_tv_set = [TyVar] -> VarSet
mkVarSet [TyVar]
cls_tvs
ir_at :: TyCon -> RoleM ()
ir_at at_tc :: TyCon
at_tc
= (TyVar -> RoleM ()) -> [TyVar] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Role -> TyVar -> RoleM ()
updateRole Role
Nominal) [TyVar]
nvars
where nvars :: [TyVar]
nvars = (TyVar -> Bool) -> [TyVar] -> [TyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter (TyVar -> VarSet -> Bool
`elemVarSet` VarSet
cls_tv_set) ([TyVar] -> [TyVar]) -> [TyVar] -> [TyVar]
forall a b. (a -> b) -> a -> b
$ TyCon -> [TyVar]
tyConTyVars TyCon
at_tc
irDataCon :: DataCon -> RoleM ()
irDataCon :: DataCon -> RoleM ()
irDataCon datacon :: DataCon
datacon
= [TyVar] -> RoleM () -> RoleM ()
forall a. [TyVar] -> RoleM a -> RoleM a
setRoleInferenceVars [TyVar]
univ_tvs (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
[TyVar] -> (VarSet -> RoleM ()) -> RoleM ()
forall a. [TyVar] -> (VarSet -> RoleM a) -> RoleM a
irExTyVars [TyVar]
ex_tvs ((VarSet -> RoleM ()) -> RoleM ())
-> (VarSet -> RoleM ()) -> RoleM ()
forall a b. (a -> b) -> a -> b
$ \ ex_var_set :: 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)
((TyVar -> Type) -> [TyVar] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> Type
tyVarKind [TyVar]
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
(univ_tvs :: [TyVar]
univ_tvs, ex_tvs :: [TyVar]
ex_tvs, eq_spec :: [EqSpec]
eq_spec, theta :: [Type]
theta, arg_tys :: [Type]
arg_tys, _res_ty :: Type
_res_ty)
= DataCon -> ([TyVar], [TyVar], [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 lcls :: VarSet
lcls ty :: Type
ty | Just ty' :: Type
ty' <- Type -> Maybe Type
coreView Type
ty
= VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty'
go lcls :: VarSet
lcls (TyVarTy tv :: TyVar
tv) = Bool -> RoleM () -> RoleM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (TyVar
tv TyVar -> VarSet -> Bool
`elemVarSet` VarSet
lcls) (RoleM () -> RoleM ()) -> RoleM () -> RoleM ()
forall a b. (a -> b) -> a -> b
$
Role -> TyVar -> RoleM ()
updateRole Role
Representational TyVar
tv
go lcls :: VarSet
lcls (AppTy t1 :: Type
t1 t2 :: 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 lcls :: VarSet
lcls (TyConApp tc :: TyCon
tc tys :: [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 lcls :: VarSet
lcls (ForAllTy tvb :: TyCoVarBinder
tvb ty :: Type
ty) = do { let tv :: TyVar
tv = TyCoVarBinder -> TyVar
forall tv argf. VarBndr tv argf -> tv
binderVar TyCoVarBinder
tvb
lcls' :: VarSet
lcls' = VarSet -> TyVar -> VarSet
extendVarSet VarSet
lcls TyVar
tv
; VarSet -> Type -> RoleM ()
markNominal VarSet
lcls (TyVar -> Type
tyVarKind TyVar
tv)
; VarSet -> Type -> RoleM ()
go VarSet
lcls' Type
ty }
go lcls :: VarSet
lcls (FunTy arg :: Type
arg res :: 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 _ (LitTy {}) = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go lcls :: VarSet
lcls (CastTy ty :: Type
ty _) = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty
go _ (CoercionTy _) = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go_app :: VarSet -> Role -> Type -> RoleM ()
go_app _ Phantom _ = () -> RoleM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
go_app lcls :: VarSet
lcls Nominal ty :: Type
ty = VarSet -> Type -> RoleM ()
markNominal VarSet
lcls Type
ty
go_app lcls :: VarSet
lcls Representational ty :: Type
ty = VarSet -> Type -> RoleM ()
go VarSet
lcls Type
ty
irTcTyVars :: TyCon -> RoleM a -> RoleM a
irTcTyVars :: TyCon -> RoleM a -> RoleM a
irTcTyVars tc :: TyCon
tc thing :: 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
$ [TyVar] -> RoleM a
go (TyCon -> [TyVar]
tyConTyVars TyCon
tc)
where
go :: [TyVar] -> RoleM a
go [] = RoleM a
thing
go (tv :: TyVar
tv:tvs :: [TyVar]
tvs) = do { VarSet -> Type -> RoleM ()
markNominal VarSet
emptyVarSet (TyVar -> Type
tyVarKind TyVar
tv)
; TyVar -> RoleM a -> RoleM a
forall a. TyVar -> RoleM a -> RoleM a
addRoleInferenceVar TyVar
tv (RoleM a -> RoleM a) -> RoleM a -> RoleM a
forall a b. (a -> b) -> a -> b
$ [TyVar] -> RoleM a
go [TyVar]
tvs }
irExTyVars :: [TyVar] -> (TyVarSet -> RoleM a) -> RoleM a
irExTyVars :: [TyVar] -> (VarSet -> RoleM a) -> RoleM a
irExTyVars orig_tvs :: [TyVar]
orig_tvs thing :: VarSet -> RoleM a
thing = VarSet -> [TyVar] -> RoleM a
go VarSet
emptyVarSet [TyVar]
orig_tvs
where
go :: VarSet -> [TyVar] -> RoleM a
go lcls :: VarSet
lcls [] = VarSet -> RoleM a
thing VarSet
lcls
go lcls :: VarSet
lcls (tv :: TyVar
tv:tvs :: [TyVar]
tvs) = do { VarSet -> Type -> RoleM ()
markNominal VarSet
lcls (TyVar -> Type
tyVarKind TyVar
tv)
; VarSet -> [TyVar] -> RoleM a
go (VarSet -> TyVar -> VarSet
extendVarSet VarSet
lcls TyVar
tv) [TyVar]
tvs }
markNominal :: TyVarSet
-> Type -> RoleM ()
markNominal :: VarSet -> Type -> RoleM ()
markNominal lcls :: VarSet
lcls ty :: Type
ty = let nvars :: [TyVar]
nvars = FV -> [TyVar]
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
(TyVar -> RoleM ()) -> [TyVar] -> RoleM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Role -> TyVar -> RoleM ()
updateRole Role
Nominal) [TyVar]
nvars
where
get_ty_vars :: Type -> FV
get_ty_vars :: Type -> FV
get_ty_vars (TyVarTy tv :: TyVar
tv) = TyVar -> FV
unitFV TyVar
tv
get_ty_vars (AppTy t1 :: Type
t1 t2 :: Type
t2) = Type -> FV
get_ty_vars Type
t1 FV -> FV -> FV
`unionFV` Type -> FV
get_ty_vars Type
t2
get_ty_vars (FunTy t1 :: Type
t1 t2 :: Type
t2) = Type -> FV
get_ty_vars Type
t1 FV -> FV -> FV
`unionFV` Type -> FV
get_ty_vars Type
t2
get_ty_vars (TyConApp _ tys :: [Type]
tys) = (Type -> FV) -> [Type] -> FV
forall a. (a -> FV) -> [a] -> FV
mapUnionFV Type -> FV
get_ty_vars [Type]
tys
get_ty_vars (ForAllTy tvb :: TyCoVarBinder
tvb ty :: 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 ty :: Type
ty _) = Type -> FV
get_ty_vars Type
ty
get_ty_vars (CoercionTy _) = FV
emptyFV
lookupRolesX :: TyCon -> RoleM [Role]
lookupRolesX :: TyCon -> RoleM [Role]
lookupRolesX tc :: 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 tc :: 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 roles :: [Role]
roles -> [Role] -> RoleM [Role]
forall (m :: * -> *) a. Monad m => a -> m a
return [Role]
roles
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 -> TyVar -> RoleM ()
updateRole role :: Role
role tv :: TyVar
tv
= do { VarPositions
var_ns <- RoleM VarPositions
getVarNs
; Name
name <- RoleM Name
getTyConName
; case VarPositions -> TyVar -> Maybe Int
forall a. VarEnv a -> TyVar -> Maybe a
lookupVarEnv VarPositions
var_ns TyVar
tv of
Nothing -> String -> SDoc -> RoleM ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic "updateRole" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
$$ TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv SDoc -> SDoc -> SDoc
$$ VarPositions -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarPositions
var_ns)
Just n :: Int
n -> Name -> Int -> Role -> RoleM ()
updateRoleEnv Name
name Int
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
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM :: Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState) }
instance Functor RoleM where
fmap :: (a -> b) -> RoleM a -> RoleM b
fmap = (a -> b) -> RoleM a -> RoleM b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM
instance Applicative RoleM where
pure :: a -> RoleM a
pure x :: a
x = (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \_ _ _ state :: 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
a :: RoleM a
a >>= :: RoleM a -> (a -> RoleM b) -> RoleM b
>>= f :: a -> RoleM b
f = (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (b, RoleInferenceState))
-> RoleM b
forall a b. (a -> b) -> a -> b
$ \m_info :: Maybe Name
m_info vps :: VarPositions
vps nvps :: Int
nvps state :: RoleInferenceState
state ->
let (a' :: a
a', state' :: RoleInferenceState
state') = RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
a Maybe Name
m_info VarPositions
vps Int
nvps RoleInferenceState
state in
RoleM b
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (b, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM (a -> RoleM b
f a
a') Maybe Name
m_info VarPositions
vps Int
nvps RoleInferenceState
state'
runRoleM :: RoleEnv -> RoleM () -> (RoleEnv, Bool)
runRoleM :: RoleEnv -> RoleM () -> (RoleEnv, Bool)
runRoleM env :: RoleEnv
env thing :: 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
-> Int
-> RoleInferenceState
-> ((), RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM ()
thing Maybe Name
forall a. Maybe a
Nothing VarPositions
forall a. NameEnv a
emptyVarEnv 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
name thing :: RoleM a
thing = (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \m_name :: Maybe Name
m_name vps :: VarPositions
vps nvps :: Int
nvps state :: RoleInferenceState
state ->
ASSERT( isNothing m_name )
ASSERT( isEmptyVarEnv vps )
ASSERT( nvps == 0 )
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
name) VarPositions
vps Int
nvps RoleInferenceState
state
addRoleInferenceVar :: TyVar -> RoleM a -> RoleM a
addRoleInferenceVar :: TyVar -> RoleM a -> RoleM a
addRoleInferenceVar tv :: TyVar
tv thing :: RoleM a
thing
= (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \m_name :: Maybe Name
m_name vps :: VarPositions
vps nvps :: Int
nvps state :: RoleInferenceState
state ->
ASSERT( isJust m_name )
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing Maybe Name
m_name (VarPositions -> TyVar -> Int -> VarPositions
forall a. VarEnv a -> TyVar -> a -> VarEnv a
extendVarEnv VarPositions
vps TyVar
tv Int
nvps) (Int
nvpsInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) RoleInferenceState
state
setRoleInferenceVars :: [TyVar] -> RoleM a -> RoleM a
setRoleInferenceVars :: [TyVar] -> RoleM a -> RoleM a
setRoleInferenceVars tvs :: [TyVar]
tvs thing :: RoleM a
thing
= (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
forall a b. (a -> b) -> a -> b
$ \m_name :: Maybe Name
m_name _vps :: VarPositions
_vps _nvps :: Int
_nvps state :: RoleInferenceState
state ->
ASSERT( isJust m_name )
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
forall a.
RoleM a
-> Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState)
unRM RoleM a
thing Maybe Name
m_name ([(TyVar, Int)] -> VarPositions
forall a. [(TyVar, a)] -> VarEnv a
mkVarEnv ([TyVar] -> [Int] -> [(TyVar, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [TyVar]
tvs [0..])) (String -> Int
forall a. String -> a
panic "setRoleInferenceVars")
RoleInferenceState
state
getRoleEnv :: RoleM RoleEnv
getRoleEnv :: RoleM RoleEnv
getRoleEnv = (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (RoleEnv, RoleInferenceState))
-> RoleM RoleEnv
forall a b. (a -> b) -> a -> b
$ \_ _ _ 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
-> Int
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (VarPositions, RoleInferenceState))
-> RoleM VarPositions
forall a b. (a -> b) -> a -> b
$ \_ vps :: VarPositions
vps _ state :: RoleInferenceState
state -> (VarPositions
vps, RoleInferenceState
state)
getTyConName :: RoleM Name
getTyConName :: RoleM Name
getTyConName = (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name)
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (Name, RoleInferenceState))
-> RoleM Name
forall a b. (a -> b) -> a -> b
$ \m_name :: Maybe Name
m_name _ _ state :: RoleInferenceState
state ->
case Maybe Name
m_name of
Nothing -> String -> (Name, RoleInferenceState)
forall a. String -> a
panic "getTyConName"
Just name :: Name
name -> (Name
name, RoleInferenceState
state)
updateRoleEnv :: Name -> Int -> Role -> RoleM ()
updateRoleEnv :: Name -> Int -> Role -> RoleM ()
updateRoleEnv name :: Name
name n :: Int
n role :: Role
role
= (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ()
forall a.
(Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> (a, RoleInferenceState))
-> RoleM a
RM ((Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ())
-> (Maybe Name
-> VarPositions
-> Int
-> RoleInferenceState
-> ((), RoleInferenceState))
-> RoleM ()
forall a b. (a -> b) -> a -> b
$ \_ _ _ 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
Nothing -> String -> SDoc -> RoleInferenceState
forall a. HasCallStack => String -> SDoc -> a
pprPanic "updateRoleEnv" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
Just roles :: [Role]
roles -> let (before :: [Role]
before, old_role :: Role
old_role : after :: [Role]
after) = Int -> [Role] -> ([Role], [Role])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
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 tyclss :: [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
$
[TyVar] -> TcM TcGblEnv -> TcM TcGblEnv
forall a. [TyVar] -> TcM a -> TcM a
tcExtendGlobalValEnv [TyVar]
def_meth_ids (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcM ()
traceTc "tcAddTyCons" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ String -> SDoc
text "tycons" SDoc -> SDoc -> SDoc
<+> [TyCon] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyCon]
tyclss
, String -> SDoc
text "implicits" SDoc -> SDoc -> SDoc
<+> [TyThing] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyThing]
implicit_things ]
; TcGblEnv
gbl_env <- [(TyVar, LHsBind GhcRn)] -> TcM TcGblEnv
tcRecSelBinds ([TyCon] -> [(TyVar, 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 :: [TyVar]
def_meth_ids = [TyCon] -> [TyVar]
mkDefaultMethodIds [TyCon]
tyclss
mkDefaultMethodIds :: [TyCon] -> [Id]
mkDefaultMethodIds :: [TyCon] -> [TyVar]
mkDefaultMethodIds tycons :: [TyCon]
tycons
= [ Name -> Type -> TyVar
mkExportedVanillaId Name
dm_name (Class -> TyVar -> DefMethSpec Type -> Type
mkDefaultMethodType Class
cls TyVar
sel_id DefMethSpec Type
dm_spec)
| TyCon
tc <- [TyCon]
tycons
, Just cls :: Class
cls <- [TyCon -> Maybe Class
tyConClass_maybe TyCon
tc]
, (sel_id :: TyVar
sel_id, Just (dm_name :: Name
dm_name, dm_spec :: DefMethSpec Type
dm_spec)) <- Class -> [(TyVar, DefMethInfo)]
classOpItems Class
cls ]
mkDefaultMethodType :: Class -> Id -> DefMethSpec Type -> Type
mkDefaultMethodType :: Class -> TyVar -> DefMethSpec Type -> Type
mkDefaultMethodType _ sel_id :: TyVar
sel_id VanillaDM = TyVar -> Type
idType TyVar
sel_id
mkDefaultMethodType cls :: Class
cls _ (GenericDM dm_ty :: 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 ([TyVar] -> [Type]
mkTyVarTys ([TyConBinder] -> [TyVar]
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 :: [(TyVar, LHsBind GhcRn)] -> TcM TcGblEnv
tcRecSelBinds sel_bind_prs :: [(TyVar, LHsBind GhcRn)]
sel_bind_prs
= [TyVar] -> TcM TcGblEnv -> TcM TcGblEnv
forall a. [TyVar] -> TcM a -> TcM a
tcExtendGlobalValEnv [TyVar
sel_id | (LSig GhcRn -> Located (SrcSpanLess (LSig GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (IdSig _ sel_id)) <- [LSig GhcRn]
sigs] (TcM TcGblEnv -> TcM TcGblEnv) -> TcM TcGblEnv -> TcM TcGblEnv
forall a b. (a -> b) -> a -> b
$
do { (rec_sel_binds :: [(RecFlag, LHsBinds GhcTcId)]
rec_sel_binds, tcg_env :: 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 -> TyVar -> Sig GhcRn
forall pass. XIdSig pass -> TyVar -> Sig pass
IdSig XIdSig GhcRn
NoExt
noExt TyVar
sel_id) | (sel_id :: TyVar
sel_id, _) <- [(TyVar, LHsBind GhcRn)]
sel_bind_prs
, let loc :: SrcSpan
loc = TyVar -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan TyVar
sel_id ]
binds :: [(RecFlag, LHsBinds GhcRn)]
binds = [(RecFlag
NonRecursive, LHsBind GhcRn -> LHsBinds GhcRn
forall a. a -> Bag a
unitBag LHsBind GhcRn
bind) | (_, bind :: LHsBind GhcRn
bind) <- [(TyVar, LHsBind GhcRn)]
sel_bind_prs]
mkRecSelBinds :: [TyCon] -> [(Id, LHsBind GhcRn)]
mkRecSelBinds :: [TyCon] -> [(TyVar, LHsBind GhcRn)]
mkRecSelBinds tycons :: [TyCon]
tycons
= ((TyCon, FieldLabel) -> (TyVar, LHsBind GhcRn))
-> [(TyCon, FieldLabel)] -> [(TyVar, LHsBind GhcRn)]
forall a b. (a -> b) -> [a] -> [b]
map (TyCon, FieldLabel) -> (TyVar, 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) -> (TyVar, LHsBind GhcRn)
mkRecSelBind (tycon :: TyCon
tycon, fl :: FieldLabel
fl)
= [ConLike] -> RecSelParent -> FieldLabel -> (TyVar, 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 -> (TyVar, LHsBind GhcRn)
mkOneRecordSelector all_cons :: [ConLike]
all_cons idDetails :: RecSelParent
idDetails fl :: FieldLabel
fl
= (TyVar
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 :: TyVar
sel_id = IdDetails -> Name -> Type -> TyVar
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 :: [TyVar]
data_tvs = [Type] -> [TyVar]
tyCoVarsOfTypesWellScoped [Type]
inst_tys
data_tv_set :: VarSet
data_tv_set= [TyVar] -> VarSet
mkVarSet [TyVar]
data_tvs
is_naughty :: Bool
is_naughty = Bool -> Bool
not (Type -> VarSet
tyCoVarsOfType Type
field_ty VarSet -> VarSet -> Bool
`subVarSet` VarSet
data_tv_set)
(field_tvs :: [TyVar]
field_tvs, field_theta :: [Type]
field_theta, field_tau :: Type
field_tau) = Type -> ([TyVar], [Type], Type)
tcSplitSigmaTy Type
field_ty
sel_ty :: Type
sel_ty | Bool
is_naughty = Type
unitTy
| Bool
otherwise = [TyVar] -> Type -> Type
mkSpecForAllTys [TyVar]
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
mkFunTy Type
data_ty (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[TyVar] -> Type -> Type
mkSpecForAllTys [TyVar]
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 con :: 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 (LPat GhcRn) -> LPat GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (ConLike -> LPat 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
NoExt
noExt (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 -> LPat GhcRn
mk_sel_pat con :: ConLike
con = Located (IdP GhcRn) -> HsConPatDetails GhcRn -> LPat 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 (LPat GhcRn) -> HsConPatDetails GhcRn
forall arg rec. rec -> HsConDetails arg rec
RecCon HsRecFields GhcRn (LPat GhcRn)
rec_fields)
rec_fields :: HsRecFields GhcRn (LPat GhcRn)
rec_fields = HsRecFields :: forall p arg. [LHsRecField p arg] -> Maybe Int -> HsRecFields p arg
HsRecFields { rec_flds :: [LHsRecField GhcRn (LPat GhcRn)]
rec_flds = [LHsRecField GhcRn (LPat GhcRn)
rec_field], rec_dotdot :: Maybe Int
rec_dotdot = Maybe Int
forall a. Maybe a
Nothing }
rec_field :: LHsRecField GhcRn (LPat GhcRn)
rec_field = SrcSpanLess (LHsRecField GhcRn (LPat GhcRn))
-> LHsRecField GhcRn (LPat 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 :: LPat GhcRn
hsRecFieldArg
= SrcSpan -> SrcSpanLess (LPat GhcRn) -> LPat GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XVarPat GhcRn -> Located (IdP GhcRn) -> LPat GhcRn
forall p. XVarPat p -> Located (IdP p) -> Pat p
VarPat XVarPat GhcRn
NoExt
noExt (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 (Int -> Unique
mkBuiltinUnique 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 (LPat GhcRn) -> LPat GhcRn
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (XWildPat GhcRn -> LPat GhcRn
forall p. XWildPat p -> Pat p
WildPat XWildPat GhcRn
NoExt
noExt)]
(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
NoExt
noExt
(SrcSpan -> SrcSpanLess (Located Name) -> Located Name
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (TyVar -> Name
forall a. NamedThing a => a -> Name
getName TyVar
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
NoExt
noExt HsLit GhcRn
msg_lit)))]
dealt_with :: ConLike -> Bool
dealt_with :: ConLike -> Bool
dealt_with (PatSynCon _) = Bool
False
dealt_with con :: ConLike
con@(RealDataCon dc :: 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
(univ_tvs :: [TyVar]
univ_tvs, _, eq_spec :: [EqSpec]
eq_spec, _, req_theta :: [Type]
req_theta, _, data_ty :: Type
data_ty) = ConLike
-> ([TyVar], [TyVar], [EqSpec], [Type], [Type], [Type], Type)
conLikeFullSig ConLike
con1
eq_subst :: TCvSubst
eq_subst = [(TyVar, Type)] -> TCvSubst
mkTvSubstPrs ((EqSpec -> (TyVar, Type)) -> [EqSpec] -> [(TyVar, Type)]
forall a b. (a -> b) -> [a] -> [b]
map EqSpec -> (TyVar, Type)
eqSpecPair [EqSpec]
eq_spec)
inst_tys :: [Type]
inst_tys = TCvSubst -> [TyVar] -> [Type]
substTyVars TCvSubst
eq_subst [TyVar]
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
fastStringToByteString FieldLabelString
lbl)