{-# LANGUAGE CPP, TupleSections, MultiWayIf #-}
module TcMType (
TcTyVar, TcKind, TcType, TcTauType, TcThetaType, TcTyVarSet,
newFlexiTyVar,
newFlexiTyVarTy,
newFlexiTyVarTys,
newOpenFlexiTyVarTy, newOpenTypeKind,
newMetaKindVar, newMetaKindVars, newMetaTyVarTyAtLevel,
cloneMetaTyVar,
newFmvTyVar, newFskTyVar,
readMetaTyVar, writeMetaTyVar, writeMetaTyVarRef,
newMetaDetails, isFilledMetaTyVar_maybe, isFilledMetaTyVar, isUnfilledMetaTyVar,
ExpType(..), ExpSigmaType, ExpRhoType,
mkCheckExpType,
newInferExpType, newInferExpTypeInst, newInferExpTypeNoInst,
readExpType, readExpType_maybe,
expTypeToType, checkingExpType_maybe, checkingExpType,
tauifyExpType, inferResultToType,
newEvVar, newEvVars, newDict,
newWanted, newWanteds, newHoleCt, cloneWanted, cloneWC,
emitWanted, emitWantedEq, emitWantedEvVar, emitWantedEvVars,
emitDerivedEqs,
newTcEvBinds, newNoTcEvBinds, addTcEvBind,
newCoercionHole, fillCoercionHole, isFilledCoercionHole,
unpackCoercionHole, unpackCoercionHole_maybe,
checkCoercionHole,
newMetaTyVars, newMetaTyVarX, newMetaTyVarsX,
newMetaTyVarTyVars, newMetaTyVarTyVarX,
newTyVarTyVar, newTauTyVar, newSkolemTyVar, newWildCardX,
tcInstType,
tcInstSkolTyVars, tcInstSkolTyVarsX, tcInstSkolTyVarsAt,
tcSkolDFunType, tcSuperSkolTyVars, tcInstSuperSkolTyVarsX,
freshenTyVarBndrs, freshenCoVarBndrsX,
zonkTidyTcType, zonkTidyTcTypes, zonkTidyOrigin,
tidyEvVar, tidyCt, tidySkolemInfo,
zonkTcTyVar, zonkTcTyVars,
zonkTcTyVarToTyVar, zonkTyVarTyVarPairs,
zonkTyCoVarsAndFV, zonkTcTypeAndFV,
zonkTyCoVarsAndFVList,
candidateQTyVarsOfType, candidateQTyVarsOfKind,
candidateQTyVarsOfTypes, candidateQTyVarsOfKinds,
CandidatesQTvs(..), delCandidates, candidateKindVars,
skolemiseQuantifiedTyVar, defaultTyVar,
quantifyTyVars,
zonkTcTyCoVarBndr, zonkTyConBinders,
zonkTcType, zonkTcTypes, zonkCo,
zonkTyCoVarKind,
zonkEvVar, zonkWC, zonkSimples,
zonkId, zonkCoVar,
zonkCt, zonkSkolemInfo,
tcGetGlobalTyCoVars,
ensureNotLevPoly, checkForLevPoly, checkForLevPolyX, formatLevPolyErr
) where
#include "HsVersions.h"
import GhcPrelude
import TyCoRep
import TcType
import Type
import TyCon
import Coercion
import Class
import Var
import TcRnMonad
import TcEvidence
import Id
import Name
import VarSet
import TysWiredIn
import TysPrim
import VarEnv
import NameEnv
import PrelNames
import Util
import Outputable
import FastString
import Bag
import Pair
import UniqSet
import qualified GHC.LanguageExtensions as LangExt
import Control.Monad
import Maybes
import Data.List ( mapAccumL )
import Control.Arrow ( second )
import qualified Data.Semigroup as Semi
mkKindName :: Unique -> Name
mkKindName :: Unique -> Name
mkKindName unique :: Unique
unique = Unique -> OccName -> Name
mkSystemName Unique
unique OccName
kind_var_occ
kind_var_occ :: OccName
kind_var_occ :: OccName
kind_var_occ = NameSpace -> String -> OccName
mkOccName NameSpace
tvName "k"
newMetaKindVar :: TcM TcKind
newMetaKindVar :: TcM TcKind
newMetaKindVar = do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TauTv
; let kv :: TyVar
kv = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar (Unique -> Name
mkKindName Unique
uniq) TcKind
liftedTypeKind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "newMetaKindVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
kv)
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind
mkTyVarTy TyVar
kv) }
newMetaKindVars :: Int -> TcM [TcKind]
newMetaKindVars :: Int -> TcM [TcKind]
newMetaKindVars n :: Int
n = (() -> TcM TcKind) -> [()] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\ _ -> TcM TcKind
newMetaKindVar) (Int -> () -> [()]
forall a. Int -> a -> [a]
nOfThem Int
n ())
newEvVars :: TcThetaType -> TcM [EvVar]
newEvVars :: [TcKind] -> TcM [TyVar]
newEvVars theta :: [TcKind]
theta = (TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar)
-> [TcKind] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall gbl lcl. TcKind -> TcRnIf gbl lcl TyVar
newEvVar [TcKind]
theta
newEvVar :: TcPredType -> TcRnIf gbl lcl EvVar
newEvVar :: TcKind -> TcRnIf gbl lcl TyVar
newEvVar ty :: TcKind
ty = do { Name
name <- OccName -> TcRnIf gbl lcl Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (TcKind -> OccName
predTypeOccName TcKind
ty)
; TyVar -> TcRnIf gbl lcl TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcKind -> TyVar
mkLocalIdOrCoVar Name
name TcKind
ty) }
newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence
newWanted :: CtOrigin -> Maybe TypeOrKind -> TcKind -> TcM CtEvidence
newWanted orig :: CtOrigin
orig t_or_k :: Maybe TypeOrKind
t_or_k pty :: TcKind
pty
= do CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
orig Maybe TypeOrKind
t_or_k
TcEvDest
d <- if TcKind -> Bool
isEqPred TcKind
pty then CoercionHole -> TcEvDest
HoleDest (CoercionHole -> TcEvDest)
-> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
-> IOEnv (Env TcGblEnv TcLclEnv) TcEvDest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole TcKind
pty
else TyVar -> TcEvDest
EvVarDest (TyVar -> TcEvDest)
-> IOEnv (Env TcGblEnv TcLclEnv) TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcEvDest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall gbl lcl. TcKind -> TcRnIf gbl lcl TyVar
newEvVar TcKind
pty
CtEvidence -> TcM CtEvidence
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> TcM CtEvidence) -> CtEvidence -> TcM CtEvidence
forall a b. (a -> b) -> a -> b
$ CtWanted :: TcKind -> TcEvDest -> ShadowInfo -> CtLoc -> CtEvidence
CtWanted { ctev_dest :: TcEvDest
ctev_dest = TcEvDest
d
, ctev_pred :: TcKind
ctev_pred = TcKind
pty
, ctev_nosh :: ShadowInfo
ctev_nosh = ShadowInfo
WDeriv
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc }
newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence]
newWanteds :: CtOrigin -> [TcKind] -> TcM [CtEvidence]
newWanteds orig :: CtOrigin
orig = (TcKind -> TcM CtEvidence) -> [TcKind] -> TcM [CtEvidence]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CtOrigin -> Maybe TypeOrKind -> TcKind -> TcM CtEvidence
newWanted CtOrigin
orig Maybe TypeOrKind
forall a. Maybe a
Nothing)
newHoleCt :: Hole -> Id -> Type -> TcM Ct
newHoleCt :: Hole -> TyVar -> TcKind -> TcM Ct
newHoleCt hole :: Hole
hole ev :: TyVar
ev ty :: TcKind
ty = do
CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
HoleOrigin Maybe TypeOrKind
forall a. Maybe a
Nothing
Ct -> TcM Ct
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ct -> TcM Ct) -> Ct -> TcM Ct
forall a b. (a -> b) -> a -> b
$ CHoleCan :: CtEvidence -> Hole -> Ct
CHoleCan { cc_ev :: CtEvidence
cc_ev = CtWanted :: TcKind -> TcEvDest -> ShadowInfo -> CtLoc -> CtEvidence
CtWanted { ctev_pred :: TcKind
ctev_pred = TcKind
ty
, ctev_dest :: TcEvDest
ctev_dest = TyVar -> TcEvDest
EvVarDest TyVar
ev
, ctev_nosh :: ShadowInfo
ctev_nosh = ShadowInfo
WDeriv
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc }
, cc_hole :: Hole
cc_hole = Hole
hole }
cloneWanted :: Ct -> TcM Ct
cloneWanted :: Ct -> TcM Ct
cloneWanted ct :: Ct
ct
| ev :: CtEvidence
ev@(CtWanted { ctev_dest :: CtEvidence -> TcEvDest
ctev_dest = HoleDest {}, ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pty }) <- Ct -> CtEvidence
ctEvidence Ct
ct
= do { CoercionHole
co_hole <- TcKind -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole TcKind
pty
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> Ct
mkNonCanonical (CtEvidence
ev { ctev_dest :: TcEvDest
ctev_dest = CoercionHole -> TcEvDest
HoleDest CoercionHole
co_hole })) }
| Bool
otherwise
= Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return Ct
ct
cloneWC :: WantedConstraints -> TcM WantedConstraints
cloneWC :: WantedConstraints -> TcM WantedConstraints
cloneWC wc :: WantedConstraints
wc@(WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics })
= do { Cts
simples' <- (Ct -> TcM Ct) -> Cts -> IOEnv (Env TcGblEnv TcLclEnv) Cts
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Ct -> TcM Ct
cloneWanted Cts
simples
; Bag Implication
implics' <- (Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication)
-> Bag Implication
-> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
cloneImplication Bag Implication
implics
; WantedConstraints -> TcM WantedConstraints
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wc { wc_simple :: Cts
wc_simple = Cts
simples', wc_impl :: Bag Implication
wc_impl = Bag Implication
implics' }) }
cloneImplication :: Implication -> TcM Implication
cloneImplication :: Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
cloneImplication implic :: Implication
implic@(Implic { ic_binds :: Implication -> EvBindsVar
ic_binds = EvBindsVar
binds, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
inner_wanted })
= do { EvBindsVar
binds' <- EvBindsVar -> TcM EvBindsVar
cloneEvBindsVar EvBindsVar
binds
; WantedConstraints
inner_wanted' <- WantedConstraints -> TcM WantedConstraints
cloneWC WantedConstraints
inner_wanted
; Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication
implic { ic_binds :: EvBindsVar
ic_binds = EvBindsVar
binds', ic_wanted :: WantedConstraints
ic_wanted = WantedConstraints
inner_wanted' }) }
emitWanted :: CtOrigin -> TcPredType -> TcM EvTerm
emitWanted :: CtOrigin -> TcKind -> TcM EvTerm
emitWanted origin :: CtOrigin
origin pty :: TcKind
pty
= do { CtEvidence
ev <- CtOrigin -> Maybe TypeOrKind -> TcKind -> TcM CtEvidence
newWanted CtOrigin
origin Maybe TypeOrKind
forall a. Maybe a
Nothing TcKind
pty
; Ct -> TcRn ()
emitSimple (Ct -> TcRn ()) -> Ct -> TcRn ()
forall a b. (a -> b) -> a -> b
$ CtEvidence -> Ct
mkNonCanonical CtEvidence
ev
; EvTerm -> TcM EvTerm
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTerm -> TcM EvTerm) -> EvTerm -> TcM EvTerm
forall a b. (a -> b) -> a -> b
$ CtEvidence -> EvTerm
ctEvTerm CtEvidence
ev }
emitDerivedEqs :: CtOrigin -> [(TcType,TcType)] -> TcM ()
emitDerivedEqs :: CtOrigin -> [(TcKind, TcKind)] -> TcRn ()
emitDerivedEqs origin :: CtOrigin
origin pairs :: [(TcKind, TcKind)]
pairs
| [(TcKind, TcKind)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(TcKind, TcKind)]
pairs
= () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
origin Maybe TypeOrKind
forall a. Maybe a
Nothing
; Cts -> TcRn ()
emitSimples ([Ct] -> Cts
forall a. [a] -> Bag a
listToBag (((TcKind, TcKind) -> Ct) -> [(TcKind, TcKind)] -> [Ct]
forall a b. (a -> b) -> [a] -> [b]
map (CtLoc -> (TcKind, TcKind) -> Ct
mk_one CtLoc
loc) [(TcKind, TcKind)]
pairs)) }
where
mk_one :: CtLoc -> (TcKind, TcKind) -> Ct
mk_one loc :: CtLoc
loc (ty1 :: TcKind
ty1, ty2 :: TcKind
ty2)
= CtEvidence -> Ct
mkNonCanonical (CtEvidence -> Ct) -> CtEvidence -> Ct
forall a b. (a -> b) -> a -> b
$
CtDerived :: TcKind -> CtLoc -> CtEvidence
CtDerived { ctev_pred :: TcKind
ctev_pred = TcKind -> TcKind -> TcKind
mkPrimEqPred TcKind
ty1 TcKind
ty2
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc }
emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcType -> TcType -> TcM Coercion
emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcKind -> TcKind -> TcM Coercion
emitWantedEq origin :: CtOrigin
origin t_or_k :: TypeOrKind
t_or_k role :: Role
role ty1 :: TcKind
ty1 ty2 :: TcKind
ty2
= do { CoercionHole
hole <- TcKind -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole TcKind
pty
; CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
origin (TypeOrKind -> Maybe TypeOrKind
forall a. a -> Maybe a
Just TypeOrKind
t_or_k)
; Ct -> TcRn ()
emitSimple (Ct -> TcRn ()) -> Ct -> TcRn ()
forall a b. (a -> b) -> a -> b
$ CtEvidence -> Ct
mkNonCanonical (CtEvidence -> Ct) -> CtEvidence -> Ct
forall a b. (a -> b) -> a -> b
$
CtWanted :: TcKind -> TcEvDest -> ShadowInfo -> CtLoc -> CtEvidence
CtWanted { ctev_pred :: TcKind
ctev_pred = TcKind
pty, ctev_dest :: TcEvDest
ctev_dest = CoercionHole -> TcEvDest
HoleDest CoercionHole
hole
, ctev_nosh :: ShadowInfo
ctev_nosh = ShadowInfo
WDeriv, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc }
; Coercion -> TcM Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return (CoercionHole -> Coercion
HoleCo CoercionHole
hole) }
where
pty :: TcKind
pty = Role -> TcKind -> TcKind -> TcKind
mkPrimEqPredRole Role
role TcKind
ty1 TcKind
ty2
emitWantedEvVar :: CtOrigin -> TcPredType -> TcM EvVar
emitWantedEvVar :: CtOrigin -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
emitWantedEvVar origin :: CtOrigin
origin ty :: TcKind
ty
= do { TyVar
new_cv <- TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall gbl lcl. TcKind -> TcRnIf gbl lcl TyVar
newEvVar TcKind
ty
; CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
origin Maybe TypeOrKind
forall a. Maybe a
Nothing
; let ctev :: CtEvidence
ctev = CtWanted :: TcKind -> TcEvDest -> ShadowInfo -> CtLoc -> CtEvidence
CtWanted { ctev_dest :: TcEvDest
ctev_dest = TyVar -> TcEvDest
EvVarDest TyVar
new_cv
, ctev_pred :: TcKind
ctev_pred = TcKind
ty
, ctev_nosh :: ShadowInfo
ctev_nosh = ShadowInfo
WDeriv
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc }
; Ct -> TcRn ()
emitSimple (Ct -> TcRn ()) -> Ct -> TcRn ()
forall a b. (a -> b) -> a -> b
$ CtEvidence -> Ct
mkNonCanonical CtEvidence
ctev
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
new_cv }
emitWantedEvVars :: CtOrigin -> [TcPredType] -> TcM [EvVar]
emitWantedEvVars :: CtOrigin -> [TcKind] -> TcM [TyVar]
emitWantedEvVars orig :: CtOrigin
orig = (TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar)
-> [TcKind] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (CtOrigin -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
emitWantedEvVar CtOrigin
orig)
newDict :: Class -> [TcType] -> TcM DictId
newDict :: Class -> [TcKind] -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newDict cls :: Class
cls tys :: [TcKind]
tys
= do { Name
name <- OccName -> TcRnIf TcGblEnv TcLclEnv Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (OccName -> OccName
mkDictOcc (Class -> OccName
forall a. NamedThing a => a -> OccName
getOccName Class
cls))
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcKind -> TyVar
mkLocalId Name
name (Class -> [TcKind] -> TcKind
mkClassPred Class
cls [TcKind]
tys)) }
predTypeOccName :: PredType -> OccName
predTypeOccName :: TcKind -> OccName
predTypeOccName ty :: TcKind
ty = case TcKind -> PredTree
classifyPredType TcKind
ty of
ClassPred cls :: Class
cls _ -> OccName -> OccName
mkDictOcc (Class -> OccName
forall a. NamedThing a => a -> OccName
getOccName Class
cls)
EqPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit "co")
IrredPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit "irred")
ForAllPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit "df")
newCoercionHole :: TcPredType -> TcM CoercionHole
newCoercionHole :: TcKind -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole pred_ty :: TcKind
pred_ty
= do { TyVar
co_var <- TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall gbl lcl. TcKind -> TcRnIf gbl lcl TyVar
newEvVar TcKind
pred_ty
; String -> SDoc -> TcRn ()
traceTc "New coercion hole:" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
co_var)
; IORef (Maybe Coercion)
ref <- Maybe Coercion
-> IOEnv (Env TcGblEnv TcLclEnv) (IORef (Maybe Coercion))
forall a env. a -> IOEnv env (IORef a)
newMutVar Maybe Coercion
forall a. Maybe a
Nothing
; CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
forall (m :: * -> *) a. Monad m => a -> m a
return (CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole)
-> CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
forall a b. (a -> b) -> a -> b
$ CoercionHole :: TyVar -> IORef (Maybe Coercion) -> CoercionHole
CoercionHole { ch_co_var :: TyVar
ch_co_var = TyVar
co_var, ch_ref :: IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref } }
fillCoercionHole :: CoercionHole -> Coercion -> TcM ()
fillCoercionHole :: CoercionHole -> Coercion -> TcRn ()
fillCoercionHole (CoercionHole { ch_ref :: CoercionHole -> IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref, ch_co_var :: CoercionHole -> TyVar
ch_co_var = TyVar
cv }) co :: Coercion
co
= do {
#if defined(DEBUG)
; cts <- readTcRef ref
; whenIsJust cts $ \old_co ->
pprPanic "Filling a filled coercion hole" (ppr cv $$ ppr co $$ ppr old_co)
#endif
; String -> SDoc -> TcRn ()
traceTc "Filling coercion hole" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
cv SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":=" SDoc -> SDoc -> SDoc
<+> Coercion -> SDoc
forall a. Outputable a => a -> SDoc
ppr Coercion
co)
; IORef (Maybe Coercion) -> Maybe Coercion -> TcRn ()
forall a gbl lcl. TcRef a -> a -> TcRnIf gbl lcl ()
writeTcRef IORef (Maybe Coercion)
ref (Coercion -> Maybe Coercion
forall a. a -> Maybe a
Just Coercion
co) }
isFilledCoercionHole :: CoercionHole -> TcM Bool
isFilledCoercionHole :: CoercionHole -> TcM Bool
isFilledCoercionHole (CoercionHole { ch_ref :: CoercionHole -> IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref }) = Maybe Coercion -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Coercion -> Bool)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion) -> TcM Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IORef (Maybe Coercion)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef (Maybe Coercion)
ref
unpackCoercionHole :: CoercionHole -> TcM Coercion
unpackCoercionHole :: CoercionHole -> TcM Coercion
unpackCoercionHole hole :: CoercionHole
hole
= do { Maybe Coercion
contents <- CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
unpackCoercionHole_maybe CoercionHole
hole
; case Maybe Coercion
contents of
Just co :: Coercion
co -> Coercion -> TcM Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return Coercion
co
Nothing -> String -> SDoc -> TcM Coercion
forall a. HasCallStack => String -> SDoc -> a
pprPanic "Unfilled coercion hole" (CoercionHole -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoercionHole
hole) }
unpackCoercionHole_maybe :: CoercionHole -> TcM (Maybe Coercion)
unpackCoercionHole_maybe :: CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
unpackCoercionHole_maybe (CoercionHole { ch_ref :: CoercionHole -> IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref }) = IORef (Maybe Coercion)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef (Maybe Coercion)
ref
checkCoercionHole :: CoVar -> Coercion -> TcM Coercion
checkCoercionHole :: TyVar -> Coercion -> TcM Coercion
checkCoercionHole cv :: TyVar
cv co :: Coercion
co
| Bool
debugIsOn
= do { TcKind
cv_ty <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
varType TyVar
cv)
; Coercion -> TcM Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> TcM Coercion) -> Coercion -> TcM Coercion
forall a b. (a -> b) -> a -> b
$
ASSERT2( ok cv_ty
, (text "Bad coercion hole" <+>
ppr cv <> colon <+> vcat [ ppr t1, ppr t2, ppr role
, ppr cv_ty ]) )
Coercion
co }
| Bool
otherwise
= Coercion -> TcM Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return Coercion
co
where
(Pair t1 :: TcKind
t1 t2 :: TcKind
t2, role :: Role
role) = Coercion -> (Pair TcKind, Role)
coercionKindRole Coercion
co
ok :: TcKind -> Bool
ok cv_ty :: TcKind
cv_ty | EqPred cv_rel :: EqRel
cv_rel cv_t1 :: TcKind
cv_t1 cv_t2 :: TcKind
cv_t2 <- TcKind -> PredTree
classifyPredType TcKind
cv_ty
= TcKind
t1 TcKind -> TcKind -> Bool
`eqType` TcKind
cv_t1
Bool -> Bool -> Bool
&& TcKind
t2 TcKind -> TcKind -> Bool
`eqType` TcKind
cv_t2
Bool -> Bool -> Bool
&& Role
role Role -> Role -> Bool
forall a. Eq a => a -> a -> Bool
== EqRel -> Role
eqRelRole EqRel
cv_rel
| Bool
otherwise
= Bool
False
newInferExpTypeNoInst :: TcM ExpSigmaType
newInferExpTypeNoInst :: TcM ExpSigmaType
newInferExpTypeNoInst = Bool -> TcM ExpSigmaType
newInferExpType Bool
False
newInferExpTypeInst :: TcM ExpRhoType
newInferExpTypeInst :: TcM ExpSigmaType
newInferExpTypeInst = Bool -> TcM ExpSigmaType
newInferExpType Bool
True
newInferExpType :: Bool -> TcM ExpType
newInferExpType :: Bool -> TcM ExpSigmaType
newInferExpType inst :: Bool
inst
= do { Unique
u <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcLevel
tclvl <- TcM TcLevel
getTcLevel
; String -> SDoc -> TcRn ()
traceTc "newOpenInferExpType" (Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unique
u SDoc -> SDoc -> SDoc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
inst SDoc -> SDoc -> SDoc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
tclvl)
; IORef (Maybe TcKind)
ref <- Maybe TcKind
-> IOEnv (Env TcGblEnv TcLclEnv) (IORef (Maybe TcKind))
forall a env. a -> IOEnv env (IORef a)
newMutVar Maybe TcKind
forall a. Maybe a
Nothing
; ExpSigmaType -> TcM ExpSigmaType
forall (m :: * -> *) a. Monad m => a -> m a
return (InferResult -> ExpSigmaType
Infer (IR :: Unique -> TcLevel -> Bool -> IORef (Maybe TcKind) -> InferResult
IR { ir_uniq :: Unique
ir_uniq = Unique
u, ir_lvl :: TcLevel
ir_lvl = TcLevel
tclvl
, ir_ref :: IORef (Maybe TcKind)
ir_ref = IORef (Maybe TcKind)
ref, ir_inst :: Bool
ir_inst = Bool
inst })) }
readExpType_maybe :: ExpType -> TcM (Maybe TcType)
readExpType_maybe :: ExpSigmaType -> TcM (Maybe TcKind)
readExpType_maybe (Check ty :: TcKind
ty) = Maybe TcKind -> TcM (Maybe TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcKind -> Maybe TcKind
forall a. a -> Maybe a
Just TcKind
ty)
readExpType_maybe (Infer (IR { ir_ref :: InferResult -> IORef (Maybe TcKind)
ir_ref = IORef (Maybe TcKind)
ref})) = IORef (Maybe TcKind) -> TcM (Maybe TcKind)
forall a env. IORef a -> IOEnv env a
readMutVar IORef (Maybe TcKind)
ref
readExpType :: ExpType -> TcM TcType
readExpType :: ExpSigmaType -> TcM TcKind
readExpType exp_ty :: ExpSigmaType
exp_ty
= do { Maybe TcKind
mb_ty <- ExpSigmaType -> TcM (Maybe TcKind)
readExpType_maybe ExpSigmaType
exp_ty
; case Maybe TcKind
mb_ty of
Just ty :: TcKind
ty -> TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return TcKind
ty
Nothing -> String -> SDoc -> TcM TcKind
forall a. HasCallStack => String -> SDoc -> a
pprPanic "Unknown expected type" (ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
exp_ty) }
checkingExpType_maybe :: ExpType -> Maybe TcType
checkingExpType_maybe :: ExpSigmaType -> Maybe TcKind
checkingExpType_maybe (Check ty :: TcKind
ty) = TcKind -> Maybe TcKind
forall a. a -> Maybe a
Just TcKind
ty
checkingExpType_maybe _ = Maybe TcKind
forall a. Maybe a
Nothing
checkingExpType :: String -> ExpType -> TcType
checkingExpType :: String -> ExpSigmaType -> TcKind
checkingExpType _ (Check ty :: TcKind
ty) = TcKind
ty
checkingExpType err :: String
err et :: ExpSigmaType
et = String -> SDoc -> TcKind
forall a. HasCallStack => String -> SDoc -> a
pprPanic "checkingExpType" (String -> SDoc
text String
err SDoc -> SDoc -> SDoc
$$ ExpSigmaType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpSigmaType
et)
tauifyExpType :: ExpType -> TcM ExpType
tauifyExpType :: ExpSigmaType -> TcM ExpSigmaType
tauifyExpType (Check ty :: TcKind
ty) = ExpSigmaType -> TcM ExpSigmaType
forall (m :: * -> *) a. Monad m => a -> m a
return (TcKind -> ExpSigmaType
Check TcKind
ty)
tauifyExpType (Infer inf_res :: InferResult
inf_res) = do { TcKind
ty <- InferResult -> TcM TcKind
inferResultToType InferResult
inf_res
; ExpSigmaType -> TcM ExpSigmaType
forall (m :: * -> *) a. Monad m => a -> m a
return (TcKind -> ExpSigmaType
Check TcKind
ty) }
expTypeToType :: ExpType -> TcM TcType
expTypeToType :: ExpSigmaType -> TcM TcKind
expTypeToType (Check ty :: TcKind
ty) = TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return TcKind
ty
expTypeToType (Infer inf_res :: InferResult
inf_res) = InferResult -> TcM TcKind
inferResultToType InferResult
inf_res
inferResultToType :: InferResult -> TcM Type
inferResultToType :: InferResult -> TcM TcKind
inferResultToType (IR { ir_uniq :: InferResult -> Unique
ir_uniq = Unique
u, ir_lvl :: InferResult -> TcLevel
ir_lvl = TcLevel
tc_lvl
, ir_ref :: InferResult -> IORef (Maybe TcKind)
ir_ref = IORef (Maybe TcKind)
ref })
= do { TcKind
rr <- TcLevel -> TcKind -> TcM TcKind
newMetaTyVarTyAtLevel TcLevel
tc_lvl TcKind
runtimeRepTy
; TcKind
tau <- TcLevel -> TcKind -> TcM TcKind
newMetaTyVarTyAtLevel TcLevel
tc_lvl (TcKind -> TcKind
tYPE TcKind
rr)
; IORef (Maybe TcKind) -> Maybe TcKind -> TcRn ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef (Maybe TcKind)
ref (TcKind -> Maybe TcKind
forall a. a -> Maybe a
Just TcKind
tau)
; String -> SDoc -> TcRn ()
traceTc "Forcing ExpType to be monomorphic:"
(Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unique
u SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":=" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
tau)
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return TcKind
tau }
tcInstType :: ([TyVar] -> TcM (TCvSubst, [TcTyVar]))
-> Id
-> TcM ([(Name, TcTyVar)], TcThetaType, TcType)
tcInstType :: ([TyVar] -> TcM (TCvSubst, [TyVar]))
-> TyVar -> TcM ([(Name, TyVar)], [TcKind], TcKind)
tcInstType inst_tyvars :: [TyVar] -> TcM (TCvSubst, [TyVar])
inst_tyvars id :: TyVar
id
= case TcKind -> ([TyVar], TcKind)
tcSplitForAllTys (TyVar -> TcKind
idType TyVar
id) of
([], rho :: TcKind
rho) -> let
(theta :: [TcKind]
theta, tau :: TcKind
tau) = TcKind -> ([TcKind], TcKind)
tcSplitPhiTy TcKind
rho
in
([(Name, TyVar)], [TcKind], TcKind)
-> TcM ([(Name, TyVar)], [TcKind], TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [TcKind]
theta, TcKind
tau)
(tyvars :: [TyVar]
tyvars, rho :: TcKind
rho) -> do { (subst :: TCvSubst
subst, tyvars' :: [TyVar]
tyvars') <- [TyVar] -> TcM (TCvSubst, [TyVar])
inst_tyvars [TyVar]
tyvars
; let (theta :: [TcKind]
theta, tau :: TcKind
tau) = TcKind -> ([TcKind], TcKind)
tcSplitPhiTy (TCvSubst -> TcKind -> TcKind
substTyAddInScope TCvSubst
subst TcKind
rho)
tv_prs :: [(Name, TyVar)]
tv_prs = (TyVar -> Name) -> [TyVar] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> Name
tyVarName [TyVar]
tyvars [Name] -> [TyVar] -> [(Name, TyVar)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [TyVar]
tyvars'
; ([(Name, TyVar)], [TcKind], TcKind)
-> TcM ([(Name, TyVar)], [TcKind], TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Name, TyVar)]
tv_prs, [TcKind]
theta, TcKind
tau) }
tcSkolDFunType :: DFunId -> TcM ([TcTyVar], TcThetaType, TcType)
tcSkolDFunType :: TyVar -> TcM ([TyVar], [TcKind], TcKind)
tcSkolDFunType dfun :: TyVar
dfun
= do { (tv_prs :: [(Name, TyVar)]
tv_prs, theta :: [TcKind]
theta, tau :: TcKind
tau) <- ([TyVar] -> TcM (TCvSubst, [TyVar]))
-> TyVar -> TcM ([(Name, TyVar)], [TcKind], TcKind)
tcInstType [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVars TyVar
dfun
; ([TyVar], [TcKind], TcKind) -> TcM ([TyVar], [TcKind], TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (((Name, TyVar) -> TyVar) -> [(Name, TyVar)] -> [TyVar]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TyVar) -> TyVar
forall a b. (a, b) -> b
snd [(Name, TyVar)]
tv_prs, [TcKind]
theta, TcKind
tau) }
tcSuperSkolTyVars :: [TyVar] -> (TCvSubst, [TcTyVar])
tcSuperSkolTyVars :: [TyVar] -> (TCvSubst, [TyVar])
tcSuperSkolTyVars = (TCvSubst -> TyVar -> (TCvSubst, TyVar))
-> TCvSubst -> [TyVar] -> (TCvSubst, [TyVar])
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> (a, c)) -> a -> t b -> (a, t c)
mapAccumL TCvSubst -> TyVar -> (TCvSubst, TyVar)
tcSuperSkolTyVar TCvSubst
emptyTCvSubst
tcSuperSkolTyVar :: TCvSubst -> TyVar -> (TCvSubst, TcTyVar)
tcSuperSkolTyVar :: TCvSubst -> TyVar -> (TCvSubst, TyVar)
tcSuperSkolTyVar subst :: TCvSubst
subst tv :: TyVar
tv
= (TCvSubst -> TyVar -> TyVar -> TCvSubst
extendTvSubstWithClone TCvSubst
subst TyVar
tv TyVar
new_tv, TyVar
new_tv)
where
kind :: TcKind
kind = TCvSubst -> TcKind -> TcKind
substTyUnchecked TCvSubst
subst (TyVar -> TcKind
tyVarKind TyVar
tv)
new_tv :: TyVar
new_tv = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar (TyVar -> Name
tyVarName TyVar
tv) TcKind
kind TcTyVarDetails
superSkolemTv
tcInstSkolTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
tcInstSkolTyVars :: [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVars = TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsX TCvSubst
emptyTCvSubst
tcInstSkolTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TcTyVar])
tcInstSkolTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsX = Bool -> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsPushLevel Bool
False
tcInstSuperSkolTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
tcInstSuperSkolTyVars :: [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVars = TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVarsX TCvSubst
emptyTCvSubst
tcInstSuperSkolTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TcTyVar])
tcInstSuperSkolTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSuperSkolTyVarsX subst :: TCvSubst
subst = Bool -> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsPushLevel Bool
True TCvSubst
subst
tcInstSkolTyVarsPushLevel :: Bool -> TCvSubst -> [TyVar]
-> TcM (TCvSubst, [TcTyVar])
tcInstSkolTyVarsPushLevel :: Bool -> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsPushLevel overlappable :: Bool
overlappable subst :: TCvSubst
subst tvs :: [TyVar]
tvs
= do { TcLevel
tc_lvl <- TcM TcLevel
getTcLevel
; let pushed_lvl :: TcLevel
pushed_lvl = TcLevel -> TcLevel
pushTcLevel TcLevel
tc_lvl
; TcLevel -> Bool -> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsAt TcLevel
pushed_lvl Bool
overlappable TCvSubst
subst [TyVar]
tvs }
tcInstSkolTyVarsAt :: TcLevel -> Bool
-> TCvSubst -> [TyVar]
-> TcM (TCvSubst, [TcTyVar])
tcInstSkolTyVarsAt :: TcLevel -> Bool -> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
tcInstSkolTyVarsAt lvl :: TcLevel
lvl overlappable :: Bool
overlappable subst :: TCvSubst
subst tvs :: [TyVar]
tvs
= (Name -> TcKind -> TyVar)
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVarsX Name -> TcKind -> TyVar
new_skol_tv TCvSubst
subst [TyVar]
tvs
where
details :: TcTyVarDetails
details = TcLevel -> Bool -> TcTyVarDetails
SkolemTv TcLevel
lvl Bool
overlappable
new_skol_tv :: Name -> TcKind -> TyVar
new_skol_tv name :: Name
name kind :: TcKind
kind = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details
freshenTyVarBndrs :: [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyVarBndrs :: [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyVarBndrs = (Name -> TcKind -> TyVar) -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVars Name -> TcKind -> TyVar
mkTyVar
freshenCoVarBndrsX :: TCvSubst -> [CoVar] -> TcM (TCvSubst, [CoVar])
freshenCoVarBndrsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenCoVarBndrsX subst :: TCvSubst
subst = (Name -> TcKind -> TyVar)
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVarsX Name -> TcKind -> TyVar
mkCoVar TCvSubst
subst
freshenTyCoVars :: (Name -> Kind -> TyCoVar)
-> [TyVar] -> TcM (TCvSubst, [TyCoVar])
freshenTyCoVars :: (Name -> TcKind -> TyVar) -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVars mk_tcv :: Name -> TcKind -> TyVar
mk_tcv = (Name -> TcKind -> TyVar)
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVarsX Name -> TcKind -> TyVar
mk_tcv TCvSubst
emptyTCvSubst
freshenTyCoVarsX :: (Name -> Kind -> TyCoVar)
-> TCvSubst -> [TyCoVar]
-> TcM (TCvSubst, [TyCoVar])
freshenTyCoVarsX :: (Name -> TcKind -> TyVar)
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
freshenTyCoVarsX mk_tcv :: Name -> TcKind -> TyVar
mk_tcv = (TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar))
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM ((Name -> TcKind -> TyVar)
-> TCvSubst
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
freshenTyCoVarX Name -> TcKind -> TyVar
mk_tcv)
freshenTyCoVarX :: (Name -> Kind -> TyCoVar)
-> TCvSubst -> TyCoVar -> TcM (TCvSubst, TyCoVar)
freshenTyCoVarX :: (Name -> TcKind -> TyVar)
-> TCvSubst
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
freshenTyCoVarX mk_tcv :: Name -> TcKind -> TyVar
mk_tcv subst :: TCvSubst
subst tycovar :: TyVar
tycovar
= do { SrcSpan
loc <- TcRn SrcSpan
getSrcSpanM
; Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; let old_name :: Name
old_name = TyVar -> Name
tyVarName TyVar
tycovar
new_name :: Name
new_name = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
uniq (Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName Name
old_name) SrcSpan
loc
new_kind :: TcKind
new_kind = TCvSubst -> TcKind -> TcKind
substTyUnchecked TCvSubst
subst (TyVar -> TcKind
tyVarKind TyVar
tycovar)
new_tcv :: TyVar
new_tcv = Name -> TcKind -> TyVar
mk_tcv Name
new_name TcKind
new_kind
subst1 :: TCvSubst
subst1 = TCvSubst -> TyVar -> TyVar -> TCvSubst
extendTCvSubstWithClone TCvSubst
subst TyVar
tycovar TyVar
new_tcv
; (TCvSubst, TyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (TCvSubst
subst1, TyVar
new_tcv) }
newTyVarTyVar :: Name -> Kind -> TcM TcTyVar
newTyVarTyVar :: Name -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newTyVarTyVar name :: Name
name kind :: TcKind
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TyVarTv
; let tyvar :: TyVar
tyvar = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "newTyVarTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tyvar }
newSkolemTyVar :: Name -> Kind -> TcM TcTyVar
newSkolemTyVar :: Name -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newSkolemTyVar name :: Name
name kind :: TcKind
kind = do { TcLevel
lvl <- TcM TcLevel
getTcLevel
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind (TcLevel -> Bool -> TcTyVarDetails
SkolemTv TcLevel
lvl Bool
False)) }
newFskTyVar :: TcType -> TcM TcTyVar
newFskTyVar :: TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newFskTyVar fam_ty :: TcKind
fam_ty
= do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; TcLevel
tclvl <- TcM TcLevel
getTcLevel
; let details :: TcTyVarDetails
details = MetaTv :: MetaInfo -> IORef MetaDetails -> TcLevel -> TcTyVarDetails
MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
FlatSkolTv
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }
name :: Name
name = Unique -> FastString -> Name
mkMetaTyVarName Unique
uniq (String -> FastString
fsLit "fsk")
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name (HasDebugCallStack => TcKind -> TcKind
TcKind -> TcKind
tcTypeKind TcKind
fam_ty) TcTyVarDetails
details) }
newFmvTyVar :: TcType -> TcM TcTyVar
newFmvTyVar :: TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newFmvTyVar fam_ty :: TcKind
fam_ty
= do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; TcLevel
tclvl <- TcM TcLevel
getTcLevel
; let details :: TcTyVarDetails
details = MetaTv :: MetaInfo -> IORef MetaDetails -> TcLevel -> TcTyVarDetails
MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
FlatMetaTv
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }
name :: Name
name = Unique -> FastString -> Name
mkMetaTyVarName Unique
uniq (String -> FastString
fsLit "s")
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name (HasDebugCallStack => TcKind -> TcKind
TcKind -> TcKind
tcTypeKind TcKind
fam_ty) TcTyVarDetails
details) }
newMetaDetails :: MetaInfo -> TcM TcTyVarDetails
newMetaDetails :: MetaInfo -> TcM TcTyVarDetails
newMetaDetails info :: MetaInfo
info
= do { IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; TcLevel
tclvl <- TcM TcLevel
getTcLevel
; TcTyVarDetails -> TcM TcTyVarDetails
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaTv :: MetaInfo -> IORef MetaDetails -> TcLevel -> TcTyVarDetails
MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
info
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }) }
cloneMetaTyVar :: TcTyVar -> TcM TcTyVar
cloneMetaTyVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
cloneMetaTyVar tv :: TyVar
tv
= ASSERT( isTcTyVar tv )
do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; let name' :: Name
name' = Name -> Unique -> Name
setNameUnique (TyVar -> Name
tyVarName TyVar
tv) Unique
uniq
details' :: TcTyVarDetails
details' = case TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tv of
details :: TcTyVarDetails
details@(MetaTv {}) -> TcTyVarDetails
details { mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref }
_ -> String -> SDoc -> TcTyVarDetails
forall a. HasCallStack => String -> SDoc -> a
pprPanic "cloneMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv)
tyvar :: TyVar
tyvar = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name' (TyVar -> TcKind
tyVarKind TyVar
tv) TcTyVarDetails
details'
; String -> SDoc -> TcRn ()
traceTc "cloneMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tyvar }
readMetaTyVar :: TyVar -> TcM MetaDetails
readMetaTyVar :: TyVar -> TcM MetaDetails
readMetaTyVar tyvar :: TyVar
tyvar = ASSERT2( isMetaTyVar tyvar, ppr tyvar )
IORef MetaDetails -> TcM MetaDetails
forall a env. IORef a -> IOEnv env a
readMutVar (TyVar -> IORef MetaDetails
metaTyVarRef TyVar
tyvar)
isFilledMetaTyVar_maybe :: TcTyVar -> TcM (Maybe Type)
isFilledMetaTyVar_maybe :: TyVar -> TcM (Maybe TcKind)
isFilledMetaTyVar_maybe tv :: TyVar
tv
| MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref } <- TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tv
= do { MetaDetails
cts <- IORef MetaDetails -> TcM MetaDetails
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef MetaDetails
ref
; case MetaDetails
cts of
Indirect ty :: TcKind
ty -> Maybe TcKind -> TcM (Maybe TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (TcKind -> Maybe TcKind
forall a. a -> Maybe a
Just TcKind
ty)
Flexi -> Maybe TcKind -> TcM (Maybe TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TcKind
forall a. Maybe a
Nothing }
| Bool
otherwise
= Maybe TcKind -> TcM (Maybe TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TcKind
forall a. Maybe a
Nothing
isFilledMetaTyVar :: TyVar -> TcM Bool
isFilledMetaTyVar :: TyVar -> TcM Bool
isFilledMetaTyVar tv :: TyVar
tv = Maybe TcKind -> Bool
forall a. Maybe a -> Bool
isJust (Maybe TcKind -> Bool) -> TcM (Maybe TcKind) -> TcM Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> TcM (Maybe TcKind)
isFilledMetaTyVar_maybe TyVar
tv
isUnfilledMetaTyVar :: TyVar -> TcM Bool
isUnfilledMetaTyVar :: TyVar -> TcM Bool
isUnfilledMetaTyVar tv :: TyVar
tv
| MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref } <- TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tv
= do { MetaDetails
details <- IORef MetaDetails -> TcM MetaDetails
forall a env. IORef a -> IOEnv env a
readMutVar IORef MetaDetails
ref
; Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaDetails -> Bool
isFlexi MetaDetails
details) }
| Bool
otherwise = Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
writeMetaTyVar :: TcTyVar -> TcType -> TcM ()
writeMetaTyVar :: TyVar -> TcKind -> TcRn ()
writeMetaTyVar tyvar :: TyVar
tyvar ty :: TcKind
ty
| Bool -> Bool
not Bool
debugIsOn
= TyVar -> IORef MetaDetails -> TcKind -> TcRn ()
writeMetaTyVarRef TyVar
tyvar (TyVar -> IORef MetaDetails
metaTyVarRef TyVar
tyvar) TcKind
ty
| Bool -> Bool
not (TyVar -> Bool
isTcTyVar TyVar
tyvar)
= ASSERT2( False, text "Writing to non-tc tyvar" <+> ppr tyvar )
() -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref } <- TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tyvar
= TyVar -> IORef MetaDetails -> TcKind -> TcRn ()
writeMetaTyVarRef TyVar
tyvar IORef MetaDetails
ref TcKind
ty
| Bool
otherwise
= ASSERT2( False, text "Writing to non-meta tyvar" <+> ppr tyvar )
() -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
writeMetaTyVarRef :: TcTyVar -> TcRef MetaDetails -> TcType -> TcM ()
writeMetaTyVarRef :: TyVar -> IORef MetaDetails -> TcKind -> TcRn ()
writeMetaTyVarRef tyvar :: TyVar
tyvar ref :: IORef MetaDetails
ref ty :: TcKind
ty
| Bool -> Bool
not Bool
debugIsOn
= do { String -> SDoc -> TcRn ()
traceTc "writeMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyVar -> TcKind
tyVarKind TyVar
tyvar)
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":=" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
ty)
; IORef MetaDetails -> MetaDetails -> TcRn ()
forall a gbl lcl. TcRef a -> a -> TcRnIf gbl lcl ()
writeTcRef IORef MetaDetails
ref (TcKind -> MetaDetails
Indirect TcKind
ty) }
| Bool
otherwise
= do { MetaDetails
meta_details <- IORef MetaDetails -> TcM MetaDetails
forall a env. IORef a -> IOEnv env a
readMutVar IORef MetaDetails
ref;
; TcKind
zonked_tv_kind <- TcKind -> TcM TcKind
zonkTcType TcKind
tv_kind
; TcKind
zonked_ty <- TcKind -> TcM TcKind
zonkTcType TcKind
ty
; let zonked_ty_kind :: TcKind
zonked_ty_kind = HasDebugCallStack => TcKind -> TcKind
TcKind -> TcKind
tcTypeKind TcKind
zonked_ty
kind_check_ok :: Bool
kind_check_ok = TcKind -> Bool
tcIsConstraintKind TcKind
zonked_tv_kind
Bool -> Bool -> Bool
|| HasDebugCallStack => TcKind -> TcKind -> Bool
TcKind -> TcKind -> Bool
tcEqKind TcKind
zonked_ty_kind TcKind
zonked_tv_kind
kind_msg :: SDoc
kind_msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Ill-kinded update to meta tyvar")
2 ( TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "::" SDoc -> SDoc -> SDoc
<+> (TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
tv_kind SDoc -> SDoc -> SDoc
$$ TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
zonked_tv_kind)
SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":="
SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
ty SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "::" SDoc -> SDoc -> SDoc
<+> (TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
zonked_ty_kind) )
; String -> SDoc -> TcRn ()
traceTc "writeMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":=" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
ty)
; MASSERT2( isFlexi meta_details, double_upd_msg meta_details )
; MASSERT2( level_check_ok, level_check_msg )
; MASSERT2( kind_check_ok, kind_msg )
; IORef MetaDetails -> MetaDetails -> TcRn ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef MetaDetails
ref (TcKind -> MetaDetails
Indirect TcKind
ty) }
where
tv_kind :: TcKind
tv_kind = TyVar -> TcKind
tyVarKind TyVar
tyvar
tv_lvl :: TcLevel
tv_lvl = TyVar -> TcLevel
tcTyVarLevel TyVar
tyvar
ty_lvl :: TcLevel
ty_lvl = TcKind -> TcLevel
tcTypeLevel TcKind
ty
level_check_ok :: Bool
level_check_ok = Bool -> Bool
not (TcLevel
ty_lvl TcLevel -> TcLevel -> Bool
`strictlyDeeperThan` TcLevel
tv_lvl)
level_check_msg :: SDoc
level_check_msg = TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
ty_lvl SDoc -> SDoc -> SDoc
$$ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
tv_lvl SDoc -> SDoc -> SDoc
$$ TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar SDoc -> SDoc -> SDoc
$$ TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
ty
double_upd_msg :: a -> SDoc
double_upd_msg details :: a
details = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Double update of meta tyvar")
2 (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar SDoc -> SDoc -> SDoc
$$ a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
details)
newTauTyVar :: Name -> Kind -> TcM TcTyVar
newTauTyVar :: Name -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newTauTyVar name :: Name
name kind :: TcKind
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TauTv
; let tyvar :: TyVar
tyvar = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "newTauTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tyvar }
mkMetaTyVarName :: Unique -> FastString -> Name
mkMetaTyVarName :: Unique -> FastString -> Name
mkMetaTyVarName uniq :: Unique
uniq str :: FastString
str = Unique -> OccName -> Name
mkSystemName Unique
uniq (FastString -> OccName
mkTyVarOccFS FastString
str)
newAnonMetaTyVar :: MetaInfo -> Kind -> TcM TcTyVar
newAnonMetaTyVar :: MetaInfo -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newAnonMetaTyVar meta_info :: MetaInfo
meta_info kind :: TcKind
kind
= do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; let name :: Name
name = Unique -> FastString -> Name
mkMetaTyVarName Unique
uniq FastString
s
s :: FastString
s = case MetaInfo
meta_info of
TauTv -> String -> FastString
fsLit "t"
FlatMetaTv -> String -> FastString
fsLit "fmv"
FlatSkolTv -> String -> FastString
fsLit "fsk"
TyVarTv -> String -> FastString
fsLit "a"
; TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
meta_info
; let tyvar :: TyVar
tyvar = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "newAnonMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tyvar }
cloneAnonMetaTyVar :: MetaInfo -> TyVar -> TcKind -> TcM TcTyVar
cloneAnonMetaTyVar :: MetaInfo -> TyVar -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
cloneAnonMetaTyVar info :: MetaInfo
info tv :: TyVar
tv kind :: TcKind
kind
= do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
info
; let name :: Name
name = Unique -> OccName -> Name
mkSystemName Unique
uniq (TyVar -> OccName
forall a. NamedThing a => a -> OccName
getOccName TyVar
tv)
tyvar :: TyVar
tyvar = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "cloneAnonMetaTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tyvar }
newFlexiTyVar :: Kind -> TcM TcTyVar
newFlexiTyVar :: TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newFlexiTyVar kind :: TcKind
kind = MetaInfo -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newAnonMetaTyVar MetaInfo
TauTv TcKind
kind
newFlexiTyVarTy :: Kind -> TcM TcType
newFlexiTyVarTy :: TcKind -> TcM TcKind
newFlexiTyVarTy kind :: TcKind
kind = do
TyVar
tc_tyvar <- TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newFlexiTyVar TcKind
kind
TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind
mkTyVarTy TyVar
tc_tyvar)
newFlexiTyVarTys :: Int -> Kind -> TcM [TcType]
newFlexiTyVarTys :: Int -> TcKind -> TcM [TcKind]
newFlexiTyVarTys n :: Int
n kind :: TcKind
kind = (TcKind -> TcM TcKind) -> [TcKind] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TcKind -> TcM TcKind
newFlexiTyVarTy (Int -> TcKind -> [TcKind]
forall a. Int -> a -> [a]
nOfThem Int
n TcKind
kind)
newOpenTypeKind :: TcM TcKind
newOpenTypeKind :: TcM TcKind
newOpenTypeKind
= do { TcKind
rr <- TcKind -> TcM TcKind
newFlexiTyVarTy TcKind
runtimeRepTy
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return (TcKind -> TcKind
tYPE TcKind
rr) }
newOpenFlexiTyVarTy :: TcM TcType
newOpenFlexiTyVarTy :: TcM TcKind
newOpenFlexiTyVarTy
= do { TcKind
kind <- TcM TcKind
newOpenTypeKind
; TcKind -> TcM TcKind
newFlexiTyVarTy TcKind
kind }
newMetaTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
newMetaTyVars :: [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVars = TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVarsX TCvSubst
emptyTCvSubst
newMetaTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TcTyVar])
newMetaTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVarsX subst :: TCvSubst
subst = (TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar))
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
newMetaTyVarX TCvSubst
subst
newMetaTyVarX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
newMetaTyVarX :: TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
newMetaTyVarX subst :: TCvSubst
subst tyvar :: TyVar
tyvar = MetaInfo
-> TCvSubst
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
new_meta_tv_x MetaInfo
TauTv TCvSubst
subst TyVar
tyvar
newMetaTyVarTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
newMetaTyVarTyVars :: [TyVar] -> TcM (TCvSubst, [TyVar])
newMetaTyVarTyVars = (TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar))
-> TCvSubst -> [TyVar] -> TcM (TCvSubst, [TyVar])
forall (m :: * -> *) acc x y.
Monad m =>
(acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
mapAccumLM TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
newMetaTyVarTyVarX TCvSubst
emptyTCvSubst
newMetaTyVarTyVarX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
newMetaTyVarTyVarX :: TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
newMetaTyVarTyVarX subst :: TCvSubst
subst tyvar :: TyVar
tyvar = MetaInfo
-> TCvSubst
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
new_meta_tv_x MetaInfo
TyVarTv TCvSubst
subst TyVar
tyvar
newWildCardX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
newWildCardX :: TCvSubst
-> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
newWildCardX subst :: TCvSubst
subst tv :: TyVar
tv
= do { TyVar
new_tv <- MetaInfo -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
newAnonMetaTyVar MetaInfo
TauTv (HasCallStack => TCvSubst -> TcKind -> TcKind
TCvSubst -> TcKind -> TcKind
substTy TCvSubst
subst (TyVar -> TcKind
tyVarKind TyVar
tv))
; (TCvSubst, TyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (TCvSubst -> TyVar -> TyVar -> TCvSubst
extendTvSubstWithClone TCvSubst
subst TyVar
tv TyVar
new_tv, TyVar
new_tv) }
new_meta_tv_x :: MetaInfo -> TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
new_meta_tv_x :: MetaInfo
-> TCvSubst
-> TyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
new_meta_tv_x info :: MetaInfo
info subst :: TCvSubst
subst tv :: TyVar
tv
= do { TyVar
new_tv <- MetaInfo -> TyVar -> TcKind -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
cloneAnonMetaTyVar MetaInfo
info TyVar
tv TcKind
substd_kind
; let subst1 :: TCvSubst
subst1 = TCvSubst -> TyVar -> TyVar -> TCvSubst
extendTvSubstWithClone TCvSubst
subst TyVar
tv TyVar
new_tv
; (TCvSubst, TyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) (TCvSubst, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (TCvSubst
subst1, TyVar
new_tv) }
where
substd_kind :: TcKind
substd_kind = TCvSubst -> TcKind -> TcKind
substTyUnchecked TCvSubst
subst (TyVar -> TcKind
tyVarKind TyVar
tv)
newMetaTyVarTyAtLevel :: TcLevel -> TcKind -> TcM TcType
newMetaTyVarTyAtLevel :: TcLevel -> TcKind -> TcM TcKind
newMetaTyVarTyAtLevel tc_lvl :: TcLevel
tc_lvl kind :: TcKind
kind
= do { Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; let name :: Name
name = Unique -> FastString -> Name
mkMetaTyVarName Unique
uniq (String -> FastString
fsLit "p")
details :: TcTyVarDetails
details = MetaTv :: MetaInfo -> IORef MetaDetails -> TcLevel -> TcTyVarDetails
MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
TauTv
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tc_lvl }
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind
mkTyVarTy (Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
name TcKind
kind TcTyVarDetails
details)) }
data CandidatesQTvs
= DV { CandidatesQTvs -> DTyVarSet
dv_kvs :: DTyVarSet
, CandidatesQTvs -> DTyVarSet
dv_tvs :: DTyVarSet
, CandidatesQTvs -> CoVarSet
dv_cvs :: CoVarSet
}
instance Semi.Semigroup CandidatesQTvs where
(DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kv1, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tv1, dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cv1 })
<> :: CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs
<> (DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kv2, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tv2, dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cv2 })
= DV :: DTyVarSet -> DTyVarSet -> CoVarSet -> CandidatesQTvs
DV { dv_kvs :: DTyVarSet
dv_kvs = DTyVarSet
kv1 DTyVarSet -> DTyVarSet -> DTyVarSet
`unionDVarSet` DTyVarSet
kv2
, dv_tvs :: DTyVarSet
dv_tvs = DTyVarSet
tv1 DTyVarSet -> DTyVarSet -> DTyVarSet
`unionDVarSet` DTyVarSet
tv2
, dv_cvs :: CoVarSet
dv_cvs = CoVarSet
cv1 CoVarSet -> CoVarSet -> CoVarSet
`unionVarSet` CoVarSet
cv2 }
instance Monoid CandidatesQTvs where
mempty :: CandidatesQTvs
mempty = DV :: DTyVarSet -> DTyVarSet -> CoVarSet -> CandidatesQTvs
DV { dv_kvs :: DTyVarSet
dv_kvs = DTyVarSet
emptyDVarSet, dv_tvs :: DTyVarSet
dv_tvs = DTyVarSet
emptyDVarSet, dv_cvs :: CoVarSet
dv_cvs = CoVarSet
emptyVarSet }
mappend :: CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs
mappend = CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs
forall a. Semigroup a => a -> a -> a
(Semi.<>)
instance Outputable CandidatesQTvs where
ppr :: CandidatesQTvs -> SDoc
ppr (DV {dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs, dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cvs })
= String -> SDoc
text "DV" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
braces ((SDoc -> SDoc) -> [SDoc] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SDoc -> SDoc
forall a. a -> a
id [ String -> SDoc
text "dv_kvs =" SDoc -> SDoc -> SDoc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
kvs
, String -> SDoc
text "dv_tvs =" SDoc -> SDoc -> SDoc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
tvs
, String -> SDoc
text "dv_cvs =" SDoc -> SDoc -> SDoc
<+> CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
cvs ])
candidateKindVars :: CandidatesQTvs -> TyVarSet
candidateKindVars :: CandidatesQTvs -> CoVarSet
candidateKindVars dvs :: CandidatesQTvs
dvs = DTyVarSet -> CoVarSet
dVarSetToVarSet (CandidatesQTvs -> DTyVarSet
dv_kvs CandidatesQTvs
dvs)
candidateQTyVarsOfType :: TcType
-> TcM CandidatesQTvs
candidateQTyVarsOfType :: TcKind -> TcM CandidatesQTvs
candidateQTyVarsOfType ty :: TcKind
ty = Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
False CoVarSet
emptyVarSet CandidatesQTvs
forall a. Monoid a => a
mempty TcKind
ty
candidateQTyVarsOfTypes :: [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes :: [TcKind] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes tys :: [TcKind]
tys = (CandidatesQTvs -> TcKind -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcKind] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM (Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
False CoVarSet
emptyVarSet) CandidatesQTvs
forall a. Monoid a => a
mempty [TcKind]
tys
candidateQTyVarsOfKind :: TcKind
-> TcM CandidatesQTvs
candidateQTyVarsOfKind :: TcKind -> TcM CandidatesQTvs
candidateQTyVarsOfKind ty :: TcKind
ty = Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
emptyVarSet CandidatesQTvs
forall a. Monoid a => a
mempty TcKind
ty
candidateQTyVarsOfKinds :: [TcKind]
-> TcM CandidatesQTvs
candidateQTyVarsOfKinds :: [TcKind] -> TcM CandidatesQTvs
candidateQTyVarsOfKinds tys :: [TcKind]
tys = (CandidatesQTvs -> TcKind -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcKind] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
emptyVarSet) CandidatesQTvs
forall a. Monoid a => a
mempty [TcKind]
tys
delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs
delCandidates :: CandidatesQTvs -> [TyVar] -> CandidatesQTvs
delCandidates (DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs, dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cvs }) vars :: [TyVar]
vars
= DV :: DTyVarSet -> DTyVarSet -> CoVarSet -> CandidatesQTvs
DV { dv_kvs :: DTyVarSet
dv_kvs = DTyVarSet
kvs DTyVarSet -> [TyVar] -> DTyVarSet
`delDVarSetList` [TyVar]
vars
, dv_tvs :: DTyVarSet
dv_tvs = DTyVarSet
tvs DTyVarSet -> [TyVar] -> DTyVarSet
`delDVarSetList` [TyVar]
vars
, dv_cvs :: CoVarSet
dv_cvs = CoVarSet
cvs CoVarSet -> [TyVar] -> CoVarSet
`delVarSetList` [TyVar]
vars }
collect_cand_qtvs
:: Bool
-> VarSet
-> CandidatesQTvs
-> Type
-> TcM CandidatesQTvs
collect_cand_qtvs :: Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs is_dep :: Bool
is_dep bound :: CoVarSet
bound dvs :: CandidatesQTvs
dvs ty :: TcKind
ty
= CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dvs TcKind
ty
where
is_bound :: TyVar -> Bool
is_bound tv :: TyVar
tv = TyVar
tv TyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
bound
go :: CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go :: CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go dv :: CandidatesQTvs
dv (AppTy t1 :: TcKind
t1 t2 :: TcKind
t2) = (CandidatesQTvs -> TcKind -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcKind] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcKind
t1, TcKind
t2]
go dv :: CandidatesQTvs
dv (TyConApp _ tys :: [TcKind]
tys) = (CandidatesQTvs -> TcKind -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcKind] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcKind]
tys
go dv :: CandidatesQTvs
dv (FunTy arg :: TcKind
arg res :: TcKind
res) = (CandidatesQTvs -> TcKind -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcKind] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcKind
arg, TcKind
res]
go dv :: CandidatesQTvs
dv (LitTy {}) = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go dv :: CandidatesQTvs
dv (CastTy ty :: TcKind
ty co :: Coercion
co) = do CandidatesQTvs
dv1 <- CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dv TcKind
ty
CoVarSet -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
collect_cand_qtvs_co CoVarSet
bound CandidatesQTvs
dv1 Coercion
co
go dv :: CandidatesQTvs
dv (CoercionTy co :: Coercion
co) = CoVarSet -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
collect_cand_qtvs_co CoVarSet
bound CandidatesQTvs
dv Coercion
co
go dv :: CandidatesQTvs
dv (TyVarTy tv :: TyVar
tv)
| TyVar -> Bool
is_bound TyVar
tv = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise = do { Maybe TcKind
m_contents <- TyVar -> TcM (Maybe TcKind)
isFilledMetaTyVar_maybe TyVar
tv
; case Maybe TcKind
m_contents of
Just ind_ty :: TcKind
ind_ty -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
go CandidatesQTvs
dv TcKind
ind_ty
Nothing -> CandidatesQTvs -> TyVar -> TcM CandidatesQTvs
go_tv CandidatesQTvs
dv TyVar
tv }
go dv :: CandidatesQTvs
dv (ForAllTy (Bndr tv :: TyVar
tv _) ty :: TcKind
ty)
= do { CandidatesQTvs
dv1 <- Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv (TyVar -> TcKind
tyVarKind TyVar
tv)
; Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
is_dep (CoVarSet
bound CoVarSet -> TyVar -> CoVarSet
`extendVarSet` TyVar
tv) CandidatesQTvs
dv1 TcKind
ty }
go_tv :: CandidatesQTvs -> TyVar -> TcM CandidatesQTvs
go_tv dv :: CandidatesQTvs
dv@(DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs }) tv :: TyVar
tv
| TyVar
tv TyVar -> DTyVarSet -> Bool
`elemDVarSet` DTyVarSet
kvs
= CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool -> Bool
not Bool
is_dep
, TyVar
tv TyVar -> DTyVarSet -> Bool
`elemDVarSet` DTyVarSet
tvs
= CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise
= do { TcKind
tv_kind <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
tyVarKind TyVar
tv)
; TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; if TyVar -> TcLevel
tcTyVarLevel TyVar
tv TcLevel -> TcLevel -> Bool
`strictlyDeeperThan` TcLevel
cur_lvl Bool -> Bool -> Bool
&&
CoVarSet -> CoVarSet -> Bool
intersectsVarSet CoVarSet
bound (TcKind -> CoVarSet
tyCoVarsOfType TcKind
tv_kind)
then
do { String -> SDoc -> TcRn ()
traceTc "Zapping naughty quantifier" (TyVar -> SDoc
pprTyVar TyVar
tv)
; TyVar -> TcKind -> TcRn ()
writeMetaTyVar TyVar
tv (TcKind -> TcKind
anyTypeOfKind TcKind
tv_kind)
; Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv TcKind
tv_kind }
else do { let tv' :: TyVar
tv' = TyVar
tv TyVar -> TcKind -> TyVar
`setTyVarKind` TcKind
tv_kind
dv' :: CandidatesQTvs
dv' | Bool
is_dep = CandidatesQTvs
dv { dv_kvs :: DTyVarSet
dv_kvs = DTyVarSet
kvs DTyVarSet -> TyVar -> DTyVarSet
`extendDVarSet` TyVar
tv' }
| Bool
otherwise = CandidatesQTvs
dv { dv_tvs :: DTyVarSet
dv_tvs = DTyVarSet
tvs DTyVarSet -> TyVar -> DTyVarSet
`extendDVarSet` TyVar
tv' }
; Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
emptyVarSet CandidatesQTvs
dv' TcKind
tv_kind } }
collect_cand_qtvs_co :: VarSet
-> CandidatesQTvs -> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co :: CoVarSet -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
collect_cand_qtvs_co bound :: CoVarSet
bound = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co
where
go_co :: CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co dv :: CandidatesQTvs
dv (Refl ty :: TcKind
ty) = Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv TcKind
ty
go_co dv :: CandidatesQTvs
dv (GRefl _ ty :: TcKind
ty mco :: MCoercionN
mco) = do CandidatesQTvs
dv1 <- Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv TcKind
ty
CandidatesQTvs -> MCoercionN -> TcM CandidatesQTvs
go_mco CandidatesQTvs
dv1 MCoercionN
mco
go_co dv :: CandidatesQTvs
dv (TyConAppCo _ _ cos :: [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co dv :: CandidatesQTvs
dv (AppCo co1 :: Coercion
co1 co2 :: Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co dv :: CandidatesQTvs
dv (FunCo _ co1 :: Coercion
co1 co2 :: Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co dv :: CandidatesQTvs
dv (AxiomInstCo _ _ cos :: [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co dv :: CandidatesQTvs
dv (AxiomRuleCo _ cos :: [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co dv :: CandidatesQTvs
dv (UnivCo prov :: UnivCoProvenance
prov _ t1 :: TcKind
t1 t2 :: TcKind
t2) = do CandidatesQTvs
dv1 <- CandidatesQTvs -> UnivCoProvenance -> TcM CandidatesQTvs
go_prov CandidatesQTvs
dv UnivCoProvenance
prov
CandidatesQTvs
dv2 <- Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv1 TcKind
t1
Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
bound CandidatesQTvs
dv2 TcKind
t2
go_co dv :: CandidatesQTvs
dv (SymCo co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co dv :: CandidatesQTvs
dv (TransCo co1 :: Coercion
co1 co2 :: Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co dv :: CandidatesQTvs
dv (NthCo _ _ co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co dv :: CandidatesQTvs
dv (LRCo _ co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co dv :: CandidatesQTvs
dv (InstCo co1 :: Coercion
co1 co2 :: Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> [b] -> m a
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co dv :: CandidatesQTvs
dv (KindCo co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co dv :: CandidatesQTvs
dv (SubCo co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co dv :: CandidatesQTvs
dv (HoleCo hole :: CoercionHole
hole) = do Maybe Coercion
m_co <- CoercionHole -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
unpackCoercionHole_maybe CoercionHole
hole
case Maybe Coercion
m_co of
Just co :: Coercion
co -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
Nothing -> CandidatesQTvs -> TyVar -> TcM CandidatesQTvs
go_cv CandidatesQTvs
dv (CoercionHole -> TyVar
coHoleCoVar CoercionHole
hole)
go_co dv :: CandidatesQTvs
dv (CoVarCo cv :: TyVar
cv) = CandidatesQTvs -> TyVar -> TcM CandidatesQTvs
go_cv CandidatesQTvs
dv TyVar
cv
go_co dv :: CandidatesQTvs
dv (ForAllCo tcv :: TyVar
tcv kind_co :: Coercion
kind_co co :: Coercion
co)
= do { CandidatesQTvs
dv1 <- CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
kind_co
; CoVarSet -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
collect_cand_qtvs_co (CoVarSet
bound CoVarSet -> TyVar -> CoVarSet
`extendVarSet` TyVar
tcv) CandidatesQTvs
dv1 Coercion
co }
go_mco :: CandidatesQTvs -> MCoercionN -> TcM CandidatesQTvs
go_mco dv :: CandidatesQTvs
dv MRefl = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_mco dv :: CandidatesQTvs
dv (MCo co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov :: CandidatesQTvs -> UnivCoProvenance -> TcM CandidatesQTvs
go_prov dv :: CandidatesQTvs
dv UnsafeCoerceProv = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_prov dv :: CandidatesQTvs
dv (PhantomProv co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov dv :: CandidatesQTvs
dv (ProofIrrelProv co :: Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov dv :: CandidatesQTvs
dv (PluginProv _) = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_cv :: CandidatesQTvs -> CoVar -> TcM CandidatesQTvs
go_cv :: CandidatesQTvs -> TyVar -> TcM CandidatesQTvs
go_cv dv :: CandidatesQTvs
dv@(DV { dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cvs }) cv :: TyVar
cv
| TyVar -> Bool
is_bound TyVar
cv = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| TyVar
cv TyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
cvs = CandidatesQTvs -> TcM CandidatesQTvs
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise = Bool -> CoVarSet -> CandidatesQTvs -> TcKind -> TcM CandidatesQTvs
collect_cand_qtvs Bool
True CoVarSet
emptyVarSet
(CandidatesQTvs
dv { dv_cvs :: CoVarSet
dv_cvs = CoVarSet
cvs CoVarSet -> TyVar -> CoVarSet
`extendVarSet` TyVar
cv })
(TyVar -> TcKind
idType TyVar
cv)
is_bound :: TyVar -> Bool
is_bound tv :: TyVar
tv = TyVar
tv TyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
bound
quantifyTyVars
:: TcTyCoVarSet
-> CandidatesQTvs
-> TcM [TcTyVar]
quantifyTyVars :: CoVarSet -> CandidatesQTvs -> TcM [TyVar]
quantifyTyVars gbl_tvs :: CoVarSet
gbl_tvs
dvs :: CandidatesQTvs
dvs@(DV{ dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
dep_tkvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
nondep_tkvs, dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
covars })
= do { TcLevel
outer_tclvl <- TcM TcLevel
getTcLevel
; String -> SDoc -> TcRn ()
traceTc "quantifyTyVars 1" ([SDoc] -> SDoc
vcat [TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
outer_tclvl, CandidatesQTvs -> SDoc
forall a. Outputable a => a -> SDoc
ppr CandidatesQTvs
dvs, CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
gbl_tvs])
; let co_tvs :: CoVarSet
co_tvs = CoVarSet -> CoVarSet
closeOverKinds CoVarSet
covars
mono_tvs :: CoVarSet
mono_tvs = CoVarSet
gbl_tvs CoVarSet -> CoVarSet -> CoVarSet
`unionVarSet` CoVarSet
co_tvs
dep_kvs :: [TyVar]
dep_kvs = DTyVarSet -> [TyVar]
dVarSetElemsWellScoped (DTyVarSet -> [TyVar]) -> DTyVarSet -> [TyVar]
forall a b. (a -> b) -> a -> b
$
DTyVarSet
dep_tkvs DTyVarSet -> CoVarSet -> DTyVarSet
`dVarSetMinusVarSet` CoVarSet
mono_tvs
nondep_tvs :: [TyVar]
nondep_tvs = DTyVarSet -> [TyVar]
dVarSetElems (DTyVarSet -> [TyVar]) -> DTyVarSet -> [TyVar]
forall a b. (a -> b) -> a -> b
$
(DTyVarSet
nondep_tkvs DTyVarSet -> DTyVarSet -> DTyVarSet
`minusDVarSet` DTyVarSet
dep_tkvs)
DTyVarSet -> CoVarSet -> DTyVarSet
`dVarSetMinusVarSet` CoVarSet
mono_tvs
; let dep_kvs2 :: [TyVar]
dep_kvs2 = DTyVarSet -> [TyVar]
dVarSetElemsWellScoped (DTyVarSet -> [TyVar]) -> DTyVarSet -> [TyVar]
forall a b. (a -> b) -> a -> b
$
(TyVar -> Bool) -> DTyVarSet -> DTyVarSet
filterDVarSet (TcLevel -> TyVar -> Bool
quantifiableTv TcLevel
outer_tclvl) DTyVarSet
dep_tkvs
nondep_tvs2 :: [TyVar]
nondep_tvs2 = (TyVar -> Bool) -> [TyVar] -> [TyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter (TcLevel -> TyVar -> Bool
quantifiableTv TcLevel
outer_tclvl) ([TyVar] -> [TyVar]) -> [TyVar] -> [TyVar]
forall a b. (a -> b) -> a -> b
$
DTyVarSet -> [TyVar]
dVarSetElems (DTyVarSet
nondep_tkvs DTyVarSet -> DTyVarSet -> DTyVarSet
`minusDVarSet` DTyVarSet
dep_tkvs)
all_ok :: Bool
all_ok = [TyVar]
dep_kvs [TyVar] -> [TyVar] -> Bool
forall a. Eq a => a -> a -> Bool
== [TyVar]
dep_kvs2 Bool -> Bool -> Bool
&& [TyVar]
nondep_tvs [TyVar] -> [TyVar] -> Bool
forall a. Eq a => a -> a -> Bool
== [TyVar]
nondep_tvs2
bad_msg :: SDoc
bad_msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Quantification by level numbers would fail")
2 ([SDoc] -> SDoc
vcat [ String -> SDoc
text "Outer level =" SDoc -> SDoc -> SDoc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
outer_tclvl
, String -> SDoc
text "dep_tkvs =" SDoc -> SDoc -> SDoc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
dep_tkvs
, String -> SDoc
text "co_vars =" SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat [ TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
cv SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyVar -> TcKind
varType TyVar
cv)
| TyVar
cv <- CoVarSet -> [TyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
covars ]
, String -> SDoc
text "co_tvs =" SDoc -> SDoc -> SDoc
<+> CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
co_tvs
, String -> SDoc
text "dep_kvs =" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyVar]
dep_kvs
, String -> SDoc
text "dep_kvs2 =" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyVar]
dep_kvs2
, String -> SDoc
text "nondep_tvs =" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyVar]
nondep_tvs
, String -> SDoc
text "nondep_tvs2 =" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyVar]
nondep_tvs2 ])
; WARN( not all_ok, bad_msg ) return ()
; Bool
poly_kinds <- Extension -> TcM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PolyKinds
; [TyVar]
dep_kvs' <- (TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar))
-> [TyVar] -> TcM [TyVar]
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM (Bool -> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
zonk_quant (Bool -> Bool
not Bool
poly_kinds)) [TyVar]
dep_kvs
; [TyVar]
nondep_tvs' <- (TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar))
-> [TyVar] -> TcM [TyVar]
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM (Bool -> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
zonk_quant Bool
False) [TyVar]
nondep_tvs
; let final_qtvs :: [TyVar]
final_qtvs = [TyVar]
dep_kvs' [TyVar] -> [TyVar] -> [TyVar]
forall a. [a] -> [a] -> [a]
++ [TyVar]
nondep_tvs'
; String -> SDoc -> TcRn ()
traceTc "quantifyTyVars 2"
([SDoc] -> SDoc
vcat [ String -> SDoc
text "globals:" SDoc -> SDoc -> SDoc
<+> CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
gbl_tvs
, String -> SDoc
text "mono_tvs:" SDoc -> SDoc -> SDoc
<+> CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
mono_tvs
, String -> SDoc
text "nondep:" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
pprTyVars [TyVar]
nondep_tvs
, String -> SDoc
text "dep:" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
pprTyVars [TyVar]
dep_kvs
, String -> SDoc
text "dep_kvs'" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
pprTyVars [TyVar]
dep_kvs'
, String -> SDoc
text "nondep_tvs'" SDoc -> SDoc -> SDoc
<+> [TyVar] -> SDoc
pprTyVars [TyVar]
nondep_tvs' ])
; let co_vars :: [TyVar]
co_vars = (TyVar -> Bool) -> [TyVar] -> [TyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TyVar -> Bool
isCoVar [TyVar]
final_qtvs
; MASSERT2( null co_vars, ppr co_vars )
; [TyVar] -> TcM [TyVar]
forall (m :: * -> *) a. Monad m => a -> m a
return [TyVar]
final_qtvs }
where
zonk_quant :: Bool -> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
zonk_quant default_kind :: Bool
default_kind tkv :: TyVar
tkv
| Bool -> Bool
not (TyVar -> Bool
isTyVar TyVar
tkv)
= Maybe TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TyVar
forall a. Maybe a
Nothing
| Bool -> Bool
not (TyVar -> Bool
isTcTyVar TyVar
tkv)
= ASSERT2( False, text "quantifying over a TyVar" <+> ppr tkv)
Maybe TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> Maybe TyVar
forall a. a -> Maybe a
Just TyVar
tkv)
| Bool
otherwise
= do { Bool
deflt_done <- Bool -> TyVar -> TcM Bool
defaultTyVar Bool
default_kind TyVar
tkv
; case Bool
deflt_done of
True -> Maybe TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TyVar
forall a. Maybe a
Nothing
False -> do { TyVar
tv <- TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
skolemiseQuantifiedTyVar TyVar
tkv
; Maybe TyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> Maybe TyVar
forall a. a -> Maybe a
Just TyVar
tv) } }
quantifiableTv :: TcLevel
-> TcTyVar
-> Bool
quantifiableTv :: TcLevel -> TyVar -> Bool
quantifiableTv outer_tclvl :: TcLevel
outer_tclvl tcv :: TyVar
tcv
| TyVar -> Bool
isTcTyVar TyVar
tcv
= TyVar -> TcLevel
tcTyVarLevel TyVar
tcv TcLevel -> TcLevel -> Bool
forall a. Ord a => a -> a -> Bool
> TcLevel
outer_tclvl
| Bool
otherwise
= Bool
False
skolemiseQuantifiedTyVar :: TcTyVar -> TcM TcTyVar
skolemiseQuantifiedTyVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
skolemiseQuantifiedTyVar tv :: TyVar
tv
= case TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tv of
SkolemTv {} -> do { TcKind
kind <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
tyVarKind TyVar
tv)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind -> TyVar
setTyVarKind TyVar
tv TcKind
kind) }
MetaTv {} -> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
skolemiseUnboundMetaTyVar TyVar
tv
_other :: TcTyVarDetails
_other -> String -> SDoc -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall a. HasCallStack => String -> SDoc -> a
pprPanic "skolemiseQuantifiedTyVar" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv)
defaultTyVar :: Bool
-> TcTyVar
-> TcM Bool
defaultTyVar :: Bool -> TyVar -> TcM Bool
defaultTyVar default_kind :: Bool
default_kind tv :: TyVar
tv
| Bool -> Bool
not (TyVar -> Bool
isMetaTyVar TyVar
tv)
= Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| TyVar -> Bool
isTyVarTyVar TyVar
tv
= Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| TyVar -> Bool
isRuntimeRepVar TyVar
tv
= do { String -> SDoc -> TcRn ()
traceTc "Defaulting a RuntimeRep var to LiftedRep" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv)
; TyVar -> TcKind -> TcRn ()
writeMetaTyVar TyVar
tv TcKind
liftedRepTy
; Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| Bool
default_kind
= do { TyVar -> TcRn ()
default_kind_var TyVar
tv
; Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| Bool
otherwise
= Bool -> TcM Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
where
default_kind_var :: TyVar -> TcM ()
default_kind_var :: TyVar -> TcRn ()
default_kind_var kv :: TyVar
kv
| TcKind -> Bool
isLiftedTypeKind (TyVar -> TcKind
tyVarKind TyVar
kv)
= do { String -> SDoc -> TcRn ()
traceTc "Defaulting a kind var to *" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
kv)
; TyVar -> TcKind -> TcRn ()
writeMetaTyVar TyVar
kv TcKind
liftedTypeKind }
| Bool
otherwise
= SDoc -> TcRn ()
addErr ([SDoc] -> SDoc
vcat [ String -> SDoc
text "Cannot default kind variable" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
kv')
, String -> SDoc
text "of kind:" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyVar -> TcKind
tyVarKind TyVar
kv')
, String -> SDoc
text "Perhaps enable PolyKinds or add a kind signature" ])
where
(_, kv' :: TyVar
kv') = TidyEnv -> TyVar -> (TidyEnv, TyVar)
tidyOpenTyCoVar TidyEnv
emptyTidyEnv TyVar
kv
skolemiseUnboundMetaTyVar :: TcTyVar -> TcM TyVar
skolemiseUnboundMetaTyVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
skolemiseUnboundMetaTyVar tv :: TyVar
tv
= ASSERT2( isMetaTyVar tv, ppr tv )
do { Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (TyVar -> TcRn ()
check_empty TyVar
tv)
; SrcSpan
span <- TcRn SrcSpan
getSrcSpanM
; TcKind
kind <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
tyVarKind TyVar
tv)
; let uniq :: Unique
uniq = TyVar -> Unique
forall a. Uniquable a => a -> Unique
getUnique TyVar
tv
tv_name :: OccName
tv_name = TyVar -> OccName
forall a. NamedThing a => a -> OccName
getOccName TyVar
tv
final_name :: Name
final_name = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
uniq OccName
tv_name SrcSpan
span
final_tv :: TyVar
final_tv = Name -> TcKind -> TcTyVarDetails -> TyVar
mkTcTyVar Name
final_name TcKind
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc "Skolemising" (TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv SDoc -> SDoc -> SDoc
<+> String -> SDoc
text ":=" SDoc -> SDoc -> SDoc
<+> TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
final_tv)
; TyVar -> TcKind -> TcRn ()
writeMetaTyVar TyVar
tv (TyVar -> TcKind
mkTyVarTy TyVar
final_tv)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
final_tv }
where
details :: TcTyVarDetails
details = TcLevel -> Bool -> TcTyVarDetails
SkolemTv (TyVar -> TcLevel
metaTyVarTcLevel TyVar
tv) Bool
False
check_empty :: TyVar -> TcRn ()
check_empty tv :: TyVar
tv
= Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
do { MetaDetails
cts <- TyVar -> TcM MetaDetails
readMetaTyVar TyVar
tv
; case MetaDetails
cts of
Flexi -> () -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Indirect ty :: TcKind
ty -> WARN( True, ppr tv $$ ppr ty )
() -> TcRn ()
forall (m :: * -> *) a. Monad m => a -> m a
return () }
tcGetGlobalTyCoVars :: TcM TcTyVarSet
tcGetGlobalTyCoVars :: TcM CoVarSet
tcGetGlobalTyCoVars
= do { (TcLclEnv {tcl_tyvars :: TcLclEnv -> TcRef CoVarSet
tcl_tyvars = TcRef CoVarSet
gtv_var}) <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
; CoVarSet
gbl_tvs <- TcRef CoVarSet -> TcM CoVarSet
forall a env. IORef a -> IOEnv env a
readMutVar TcRef CoVarSet
gtv_var
; CoVarSet
gbl_tvs' <- CoVarSet -> TcM CoVarSet
zonkTyCoVarsAndFV CoVarSet
gbl_tvs
; TcRef CoVarSet -> CoVarSet -> TcRn ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar TcRef CoVarSet
gtv_var CoVarSet
gbl_tvs'
; CoVarSet -> TcM CoVarSet
forall (m :: * -> *) a. Monad m => a -> m a
return CoVarSet
gbl_tvs' }
zonkTcTypeAndFV :: TcType -> TcM DTyCoVarSet
zonkTcTypeAndFV :: TcKind -> TcM DTyVarSet
zonkTcTypeAndFV ty :: TcKind
ty
= TcKind -> DTyVarSet
tyCoVarsOfTypeDSet (TcKind -> DTyVarSet) -> TcM TcKind -> TcM DTyVarSet
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcKind -> TcM TcKind
zonkTcType TcKind
ty
zonkTyCoVar :: TyCoVar -> TcM TcType
zonkTyCoVar :: TyVar -> TcM TcKind
zonkTyCoVar tv :: TyVar
tv | TyVar -> Bool
isTcTyVar TyVar
tv = TyVar -> TcM TcKind
zonkTcTyVar TyVar
tv
| TyVar -> Bool
isTyVar TyVar
tv = TyVar -> TcKind
mkTyVarTy (TyVar -> TcKind)
-> IOEnv (Env TcGblEnv TcLclEnv) TyVar -> TcM TcKind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
tv
| Bool
otherwise = ASSERT2( isCoVar tv, ppr tv )
Coercion -> TcKind
mkCoercionTy (Coercion -> TcKind) -> (TyVar -> Coercion) -> TyVar -> TcKind
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyVar -> Coercion
mkCoVarCo (TyVar -> TcKind)
-> IOEnv (Env TcGblEnv TcLclEnv) TyVar -> TcM TcKind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
tv
zonkTyCoVarsAndFV :: TyCoVarSet -> TcM TyCoVarSet
zonkTyCoVarsAndFV :: CoVarSet -> TcM CoVarSet
zonkTyCoVarsAndFV tycovars :: CoVarSet
tycovars
= [TcKind] -> CoVarSet
tyCoVarsOfTypes ([TcKind] -> CoVarSet) -> TcM [TcKind] -> TcM CoVarSet
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TyVar -> TcM TcKind) -> [TyVar] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyVar -> TcM TcKind
zonkTyCoVar (CoVarSet -> [TyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
tycovars)
zonkTyCoVarsAndFVList :: [TyCoVar] -> TcM [TyCoVar]
zonkTyCoVarsAndFVList :: [TyVar] -> TcM [TyVar]
zonkTyCoVarsAndFVList tycovars :: [TyVar]
tycovars
= [TcKind] -> [TyVar]
tyCoVarsOfTypesList ([TcKind] -> [TyVar]) -> TcM [TcKind] -> TcM [TyVar]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TyVar -> TcM TcKind) -> [TyVar] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyVar -> TcM TcKind
zonkTyCoVar [TyVar]
tycovars
zonkTcTyVars :: [TcTyVar] -> TcM [TcType]
zonkTcTyVars :: [TyVar] -> TcM [TcKind]
zonkTcTyVars tyvars :: [TyVar]
tyvars = (TyVar -> TcM TcKind) -> [TyVar] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyVar -> TcM TcKind
zonkTcTyVar [TyVar]
tyvars
zonkTyCoVarKind :: TyCoVar -> TcM TyCoVar
zonkTyCoVarKind :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind tv :: TyVar
tv = do { TcKind
kind' <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
tyVarKind TyVar
tv)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind -> TyVar
setTyVarKind TyVar
tv TcKind
kind') }
zonkTcTypes :: [TcType] -> TcM [TcType]
zonkTcTypes :: [TcKind] -> TcM [TcKind]
zonkTcTypes tys :: [TcKind]
tys = (TcKind -> TcM TcKind) -> [TcKind] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TcKind -> TcM TcKind
zonkTcType [TcKind]
tys
zonkImplication :: Implication -> TcM Implication
zonkImplication :: Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
zonkImplication implic :: Implication
implic@(Implic { ic_skols :: Implication -> [TyVar]
ic_skols = [TyVar]
skols
, ic_given :: Implication -> [TyVar]
ic_given = [TyVar]
given
, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wanted
, ic_info :: Implication -> SkolemInfo
ic_info = SkolemInfo
info })
= do { [TyVar]
skols' <- (TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar)
-> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind [TyVar]
skols
; [TyVar]
given' <- (TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar)
-> [TyVar] -> TcM [TyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkEvVar [TyVar]
given
; SkolemInfo
info' <- SkolemInfo -> TcM SkolemInfo
zonkSkolemInfo SkolemInfo
info
; WantedConstraints
wanted' <- WantedConstraints -> TcM WantedConstraints
zonkWCRec WantedConstraints
wanted
; Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication
implic { ic_skols :: [TyVar]
ic_skols = [TyVar]
skols'
, ic_given :: [TyVar]
ic_given = [TyVar]
given'
, ic_wanted :: WantedConstraints
ic_wanted = WantedConstraints
wanted'
, ic_info :: SkolemInfo
ic_info = SkolemInfo
info' }) }
zonkEvVar :: EvVar -> TcM EvVar
zonkEvVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkEvVar var :: TyVar
var = do { TcKind
ty' <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
varType TyVar
var)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind -> TyVar
setVarType TyVar
var TcKind
ty') }
zonkWC :: WantedConstraints -> TcM WantedConstraints
zonkWC :: WantedConstraints -> TcM WantedConstraints
zonkWC wc :: WantedConstraints
wc = WantedConstraints -> TcM WantedConstraints
zonkWCRec WantedConstraints
wc
zonkWCRec :: WantedConstraints -> TcM WantedConstraints
zonkWCRec :: WantedConstraints -> TcM WantedConstraints
zonkWCRec (WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simple, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implic })
= do { Cts
simple' <- Cts -> IOEnv (Env TcGblEnv TcLclEnv) Cts
zonkSimples Cts
simple
; Bag Implication
implic' <- (Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication)
-> Bag Implication
-> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
zonkImplication Bag Implication
implic
; WantedConstraints -> TcM WantedConstraints
forall (m :: * -> *) a. Monad m => a -> m a
return (WC :: Cts -> Bag Implication -> WantedConstraints
WC { wc_simple :: Cts
wc_simple = Cts
simple', wc_impl :: Bag Implication
wc_impl = Bag Implication
implic' }) }
zonkSimples :: Cts -> TcM Cts
zonkSimples :: Cts -> IOEnv (Env TcGblEnv TcLclEnv) Cts
zonkSimples cts :: Cts
cts = do { Cts
cts' <- (Ct -> TcM Ct) -> Cts -> IOEnv (Env TcGblEnv TcLclEnv) Cts
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Ct -> TcM Ct
zonkCt' Cts
cts
; String -> SDoc -> TcRn ()
traceTc "zonkSimples done:" (Cts -> SDoc
forall a. Outputable a => a -> SDoc
ppr Cts
cts')
; Cts -> IOEnv (Env TcGblEnv TcLclEnv) Cts
forall (m :: * -> *) a. Monad m => a -> m a
return Cts
cts' }
zonkCt' :: Ct -> TcM Ct
zonkCt' :: Ct -> TcM Ct
zonkCt' ct :: Ct
ct = Ct -> TcM Ct
zonkCt Ct
ct
zonkCt :: Ct -> TcM Ct
zonkCt :: Ct -> TcM Ct
zonkCt ct :: Ct
ct@(CHoleCan { cc_ev :: Ct -> CtEvidence
cc_ev = CtEvidence
ev })
= do { CtEvidence
ev' <- CtEvidence -> TcM CtEvidence
zonkCtEvidence CtEvidence
ev
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (Ct -> TcM Ct) -> Ct -> TcM Ct
forall a b. (a -> b) -> a -> b
$ Ct
ct { cc_ev :: CtEvidence
cc_ev = CtEvidence
ev' } }
zonkCt ct :: Ct
ct@(CDictCan { cc_ev :: Ct -> CtEvidence
cc_ev = CtEvidence
ev, cc_tyargs :: Ct -> [TcKind]
cc_tyargs = [TcKind]
args })
= do { CtEvidence
ev' <- CtEvidence -> TcM CtEvidence
zonkCtEvidence CtEvidence
ev
; [TcKind]
args' <- (TcKind -> TcM TcKind) -> [TcKind] -> TcM [TcKind]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TcKind -> TcM TcKind
zonkTcType [TcKind]
args
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (Ct -> TcM Ct) -> Ct -> TcM Ct
forall a b. (a -> b) -> a -> b
$ Ct
ct { cc_ev :: CtEvidence
cc_ev = CtEvidence
ev', cc_tyargs :: [TcKind]
cc_tyargs = [TcKind]
args' } }
zonkCt ct :: Ct
ct@(CTyEqCan { cc_ev :: Ct -> CtEvidence
cc_ev = CtEvidence
ev, cc_tyvar :: Ct -> TyVar
cc_tyvar = TyVar
tv, cc_rhs :: Ct -> TcKind
cc_rhs = TcKind
rhs })
= do { CtEvidence
ev' <- CtEvidence -> TcM CtEvidence
zonkCtEvidence CtEvidence
ev
; TcKind
tv_ty' <- TyVar -> TcM TcKind
zonkTcTyVar TyVar
tv
; case TcKind -> Maybe TyVar
getTyVar_maybe TcKind
tv_ty' of
Just tv' :: TyVar
tv' -> do { TcKind
rhs' <- TcKind -> TcM TcKind
zonkTcType TcKind
rhs
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return Ct
ct { cc_ev :: CtEvidence
cc_ev = CtEvidence
ev'
, cc_tyvar :: TyVar
cc_tyvar = TyVar
tv'
, cc_rhs :: TcKind
cc_rhs = TcKind
rhs' } }
Nothing -> Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> Ct
mkNonCanonical CtEvidence
ev') }
zonkCt ct :: Ct
ct@(CIrredCan { cc_ev :: Ct -> CtEvidence
cc_ev = CtEvidence
ev })
= do { CtEvidence
ev' <- CtEvidence -> TcM CtEvidence
zonkCtEvidence CtEvidence
ev
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (Ct
ct { cc_ev :: CtEvidence
cc_ev = CtEvidence
ev' }) }
zonkCt ct :: Ct
ct
= ASSERT( not (isCFunEqCan ct) )
do { CtEvidence
fl' <- CtEvidence -> TcM CtEvidence
zonkCtEvidence (Ct -> CtEvidence
ctEvidence Ct
ct)
; Ct -> TcM Ct
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> Ct
mkNonCanonical CtEvidence
fl') }
zonkCtEvidence :: CtEvidence -> TcM CtEvidence
zonkCtEvidence :: CtEvidence -> TcM CtEvidence
zonkCtEvidence ctev :: CtEvidence
ctev@(CtGiven { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred })
= do { TcKind
pred' <- TcKind -> TcM TcKind
zonkTcType TcKind
pred
; CtEvidence -> TcM CtEvidence
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TcKind
pred'}) }
zonkCtEvidence ctev :: CtEvidence
ctev@(CtWanted { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred, ctev_dest :: CtEvidence -> TcEvDest
ctev_dest = TcEvDest
dest })
= do { TcKind
pred' <- TcKind -> TcM TcKind
zonkTcType TcKind
pred
; let dest' :: TcEvDest
dest' = case TcEvDest
dest of
EvVarDest ev :: TyVar
ev -> TyVar -> TcEvDest
EvVarDest (TyVar -> TcEvDest) -> TyVar -> TcEvDest
forall a b. (a -> b) -> a -> b
$ TyVar -> TcKind -> TyVar
setVarType TyVar
ev TcKind
pred'
HoleDest h :: CoercionHole
h -> CoercionHole -> TcEvDest
HoleDest CoercionHole
h
; CtEvidence -> TcM CtEvidence
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TcKind
pred', ctev_dest :: TcEvDest
ctev_dest = TcEvDest
dest' }) }
zonkCtEvidence ctev :: CtEvidence
ctev@(CtDerived { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred })
= do { TcKind
pred' <- TcKind -> TcM TcKind
zonkTcType TcKind
pred
; CtEvidence -> TcM CtEvidence
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TcKind
pred' }) }
zonkSkolemInfo :: SkolemInfo -> TcM SkolemInfo
zonkSkolemInfo :: SkolemInfo -> TcM SkolemInfo
zonkSkolemInfo (SigSkol cx :: UserTypeCtxt
cx ty :: TcKind
ty tv_prs :: [(Name, TyVar)]
tv_prs) = do { TcKind
ty' <- TcKind -> TcM TcKind
zonkTcType TcKind
ty
; SkolemInfo -> TcM SkolemInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (UserTypeCtxt -> TcKind -> [(Name, TyVar)] -> SkolemInfo
SigSkol UserTypeCtxt
cx TcKind
ty' [(Name, TyVar)]
tv_prs) }
zonkSkolemInfo (InferSkol ntys :: [(Name, TcKind)]
ntys) = do { [(Name, TcKind)]
ntys' <- ((Name, TcKind) -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcKind))
-> [(Name, TcKind)]
-> IOEnv (Env TcGblEnv TcLclEnv) [(Name, TcKind)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name, TcKind) -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TcKind)
forall a. (a, TcKind) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TcKind)
do_one [(Name, TcKind)]
ntys
; SkolemInfo -> TcM SkolemInfo
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Name, TcKind)] -> SkolemInfo
InferSkol [(Name, TcKind)]
ntys') }
where
do_one :: (a, TcKind) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TcKind)
do_one (n :: a
n, ty :: TcKind
ty) = do { TcKind
ty' <- TcKind -> TcM TcKind
zonkTcType TcKind
ty; (a, TcKind) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
n, TcKind
ty') }
zonkSkolemInfo skol_info :: SkolemInfo
skol_info = SkolemInfo -> TcM SkolemInfo
forall (m :: * -> *) a. Monad m => a -> m a
return SkolemInfo
skol_info
zonkId :: TcId -> TcM TcId
zonkId :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkId id :: TyVar
id
= do { TcKind
ty' <- TcKind -> TcM TcKind
zonkTcType (TyVar -> TcKind
idType TyVar
id)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind -> TyVar
Id.setIdType TyVar
id TcKind
ty') }
zonkCoVar :: CoVar -> TcM CoVar
zonkCoVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkCoVar = TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkId
zonkTcTypeMapper :: TyCoMapper () TcM
zonkTcTypeMapper :: TyCoMapper () TcM
zonkTcTypeMapper = TyCoMapper :: forall env (m :: * -> *).
Bool
-> (env -> TyVar -> m TcKind)
-> (env -> TyVar -> m Coercion)
-> (env -> CoercionHole -> m Coercion)
-> (env -> TyVar -> ArgFlag -> m (env, TyVar))
-> (TyCon -> m TyCon)
-> TyCoMapper env m
TyCoMapper
{ tcm_smart :: Bool
tcm_smart = Bool
True
, tcm_tyvar :: () -> TyVar -> TcM TcKind
tcm_tyvar = (TyVar -> TcM TcKind) -> () -> TyVar -> TcM TcKind
forall a b. a -> b -> a
const TyVar -> TcM TcKind
zonkTcTyVar
, tcm_covar :: () -> TyVar -> TcM Coercion
tcm_covar = (TyVar -> TcM Coercion) -> () -> TyVar -> TcM Coercion
forall a b. a -> b -> a
const (\cv :: TyVar
cv -> TyVar -> Coercion
mkCoVarCo (TyVar -> Coercion)
-> IOEnv (Env TcGblEnv TcLclEnv) TyVar -> TcM Coercion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
cv)
, tcm_hole :: () -> CoercionHole -> TcM Coercion
tcm_hole = () -> CoercionHole -> TcM Coercion
hole
, tcm_tycobinder :: () -> TyVar -> ArgFlag -> TcM ((), TyVar)
tcm_tycobinder = \_env :: ()
_env tv :: TyVar
tv _vis :: ArgFlag
_vis -> ((), ) (TyVar -> ((), TyVar))
-> IOEnv (Env TcGblEnv TcLclEnv) TyVar -> TcM ((), TyVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
tv
, tcm_tycon :: TyCon -> TcM TyCon
tcm_tycon = TyCon -> TcM TyCon
forall (m :: * -> *) a. Monad m => a -> m a
return }
where
hole :: () -> CoercionHole -> TcM Coercion
hole :: () -> CoercionHole -> TcM Coercion
hole _ hole :: CoercionHole
hole@(CoercionHole { ch_ref :: CoercionHole -> IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref, ch_co_var :: CoercionHole -> TyVar
ch_co_var = TyVar
cv })
= do { Maybe Coercion
contents <- IORef (Maybe Coercion)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
forall a gbl lcl. TcRef a -> TcRnIf gbl lcl a
readTcRef IORef (Maybe Coercion)
ref
; case Maybe Coercion
contents of
Just co :: Coercion
co -> do { Coercion
co' <- Coercion -> TcM Coercion
zonkCo Coercion
co
; TyVar -> Coercion -> TcM Coercion
checkCoercionHole TyVar
cv Coercion
co' }
Nothing -> do { TyVar
cv' <- TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkCoVar TyVar
cv
; Coercion -> TcM Coercion
forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion -> TcM Coercion) -> Coercion -> TcM Coercion
forall a b. (a -> b) -> a -> b
$ CoercionHole -> Coercion
HoleCo (CoercionHole
hole { ch_co_var :: TyVar
ch_co_var = TyVar
cv' }) } }
zonkTcType :: TcType -> TcM TcType
zonkTcType :: TcKind -> TcM TcKind
zonkTcType = TyCoMapper () TcM -> () -> TcKind -> TcM TcKind
forall (m :: * -> *) env.
Monad m =>
TyCoMapper env m -> env -> TcKind -> m TcKind
mapType TyCoMapper () TcM
zonkTcTypeMapper ()
zonkCo :: Coercion -> TcM Coercion
zonkCo :: Coercion -> TcM Coercion
zonkCo = TyCoMapper () TcM -> () -> Coercion -> TcM Coercion
forall (m :: * -> *) env.
Monad m =>
TyCoMapper env m -> env -> Coercion -> m Coercion
mapCoercion TyCoMapper () TcM
zonkTcTypeMapper ()
zonkTcTyCoVarBndr :: TcTyCoVar -> TcM TcTyCoVar
zonkTcTyCoVarBndr :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTcTyCoVarBndr tyvar :: TyVar
tyvar
| TyVar -> Bool
isTyVarTyVar TyVar
tyvar
= do { TcKind
zonked_ty <- TyVar -> TcM TcKind
zonkTcTyVar TyVar
tyvar
; let zonked_tyvar :: TyVar
zonked_tyvar = String -> TcKind -> TyVar
tcGetTyVar "zonkTcTyCoVarBndr TyVarTv" TcKind
zonked_ty
zonked_name :: Name
zonked_name = TyVar -> Name
forall a. NamedThing a => a -> Name
getName TyVar
zonked_tyvar
reloc'd_name :: Name
reloc'd_name = Name -> SrcSpan -> Name
setNameLoc Name
zonked_name (TyVar -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan TyVar
tyvar)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> Name -> TyVar
setTyVarName TyVar
zonked_tyvar Name
reloc'd_name) }
| Bool
otherwise
= ASSERT2( isImmutableTyVar tyvar || isCoVar tyvar, pprTyVar tyvar )
TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
tyvar
zonkTyConBinders :: [TyConBinder] -> TcM [TyConBinder]
zonkTyConBinders :: [TyConBinder] -> TcM [TyConBinder]
zonkTyConBinders = (TyConBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder)
-> [TyConBinder] -> TcM [TyConBinder]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyConBinder -> IOEnv (Env TcGblEnv TcLclEnv) TyConBinder
forall argf.
VarBndr TyVar argf
-> IOEnv (Env TcGblEnv TcLclEnv) (VarBndr TyVar argf)
zonk1
where
zonk1 :: VarBndr TyVar argf
-> IOEnv (Env TcGblEnv TcLclEnv) (VarBndr TyVar argf)
zonk1 (Bndr tv :: TyVar
tv vis :: argf
vis)
= do { TyVar
tv' <- TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTcTyCoVarBndr TyVar
tv
; VarBndr TyVar argf
-> IOEnv (Env TcGblEnv TcLclEnv) (VarBndr TyVar argf)
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> argf -> VarBndr TyVar argf
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv' argf
vis) }
zonkTcTyVar :: TcTyVar -> TcM TcType
zonkTcTyVar :: TyVar -> TcM TcKind
zonkTcTyVar tv :: TyVar
tv
| TyVar -> Bool
isTcTyVar TyVar
tv
= case TyVar -> TcTyVarDetails
tcTyVarDetails TyVar
tv of
SkolemTv {} -> TcM TcKind
zonk_kind_and_return
RuntimeUnk {} -> TcM TcKind
zonk_kind_and_return
MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref }
-> do { MetaDetails
cts <- IORef MetaDetails -> TcM MetaDetails
forall a env. IORef a -> IOEnv env a
readMutVar IORef MetaDetails
ref
; case MetaDetails
cts of
Flexi -> TcM TcKind
zonk_kind_and_return
Indirect ty :: TcKind
ty -> do { TcKind
zty <- TcKind -> TcM TcKind
zonkTcType TcKind
ty
; IORef MetaDetails -> MetaDetails -> TcRn ()
forall a gbl lcl. TcRef a -> a -> TcRnIf gbl lcl ()
writeTcRef IORef MetaDetails
ref (TcKind -> MetaDetails
Indirect TcKind
zty)
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return TcKind
zty } }
| Bool
otherwise
= TcM TcKind
zonk_kind_and_return
where
zonk_kind_and_return :: TcM TcKind
zonk_kind_and_return = do { TyVar
z_tv <- TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTyCoVarKind TyVar
tv
; TcKind -> TcM TcKind
forall (m :: * -> *) a. Monad m => a -> m a
return (TyVar -> TcKind
mkTyVarTy TyVar
z_tv) }
zonkTcTyVarToTyVar :: HasDebugCallStack => TcTyVar -> TcM TcTyVar
zonkTcTyVarToTyVar :: TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTcTyVarToTyVar tv :: TyVar
tv
= do { TcKind
ty <- TyVar -> TcM TcKind
zonkTcTyVar TyVar
tv
; let tv' :: TyVar
tv' = case TcKind -> Maybe TyVar
tcGetTyVar_maybe TcKind
ty of
Just tv' :: TyVar
tv' -> TyVar
tv'
Nothing -> String -> SDoc -> TyVar
forall a. HasCallStack => String -> SDoc -> a
pprPanic "zonkTcTyVarToTyVar"
(TyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyVar
tv SDoc -> SDoc -> SDoc
$$ TcKind -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcKind
ty)
; TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
forall (m :: * -> *) a. Monad m => a -> m a
return TyVar
tv' }
zonkTyVarTyVarPairs :: [(Name,TcTyVar)] -> TcM [(Name,TcTyVar)]
zonkTyVarTyVarPairs :: [(Name, TyVar)] -> TcM [(Name, TyVar)]
zonkTyVarTyVarPairs prs :: [(Name, TyVar)]
prs
= ((Name, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar))
-> [(Name, TyVar)] -> TcM [(Name, TyVar)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Name, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (Name, TyVar)
forall a. (a, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TyVar)
do_one [(Name, TyVar)]
prs
where
do_one :: (a, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TyVar)
do_one (nm :: a
nm, tv :: TyVar
tv) = do { TyVar
tv' <- HasDebugCallStack => TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
TyVar -> IOEnv (Env TcGblEnv TcLclEnv) TyVar
zonkTcTyVarToTyVar TyVar
tv
; (a, TyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (a, TyVar)
forall (m :: * -> *) a. Monad m => a -> m a
return (a
nm, TyVar
tv') }
zonkTidyTcType :: TidyEnv -> TcType -> TcM (TidyEnv, TcType)
zonkTidyTcType :: TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType env :: TidyEnv
env ty :: TcKind
ty = do { TcKind
ty' <- TcKind -> TcM TcKind
zonkTcType TcKind
ty
; (TidyEnv, TcKind) -> TcM (TidyEnv, TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv -> TcKind -> (TidyEnv, TcKind)
tidyOpenType TidyEnv
env TcKind
ty') }
zonkTidyTcTypes :: TidyEnv -> [TcType] -> TcM (TidyEnv, [TcType])
zonkTidyTcTypes :: TidyEnv -> [TcKind] -> TcM (TidyEnv, [TcKind])
zonkTidyTcTypes = [TcKind] -> TidyEnv -> [TcKind] -> TcM (TidyEnv, [TcKind])
zonkTidyTcTypes' []
where zonkTidyTcTypes' :: [TcKind] -> TidyEnv -> [TcKind] -> TcM (TidyEnv, [TcKind])
zonkTidyTcTypes' zs :: [TcKind]
zs env :: TidyEnv
env [] = (TidyEnv, [TcKind]) -> TcM (TidyEnv, [TcKind])
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env, [TcKind] -> [TcKind]
forall a. [a] -> [a]
reverse [TcKind]
zs)
zonkTidyTcTypes' zs :: [TcKind]
zs env :: TidyEnv
env (ty :: TcKind
ty:tys :: [TcKind]
tys)
= do { (env' :: TidyEnv
env', ty' :: TcKind
ty') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env TcKind
ty
; [TcKind] -> TidyEnv -> [TcKind] -> TcM (TidyEnv, [TcKind])
zonkTidyTcTypes' (TcKind
ty'TcKind -> [TcKind] -> [TcKind]
forall a. a -> [a] -> [a]
:[TcKind]
zs) TidyEnv
env' [TcKind]
tys }
zonkTidyOrigin :: TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
zonkTidyOrigin :: TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
zonkTidyOrigin env :: TidyEnv
env (GivenOrigin skol_info :: SkolemInfo
skol_info)
= do { SkolemInfo
skol_info1 <- SkolemInfo -> TcM SkolemInfo
zonkSkolemInfo SkolemInfo
skol_info
; let skol_info2 :: SkolemInfo
skol_info2 = TidyEnv -> SkolemInfo -> SkolemInfo
tidySkolemInfo TidyEnv
env SkolemInfo
skol_info1
; (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env, SkolemInfo -> CtOrigin
GivenOrigin SkolemInfo
skol_info2) }
zonkTidyOrigin env :: TidyEnv
env orig :: CtOrigin
orig@(TypeEqOrigin { uo_actual :: CtOrigin -> TcKind
uo_actual = TcKind
act
, uo_expected :: CtOrigin -> TcKind
uo_expected = TcKind
exp })
= do { (env1 :: TidyEnv
env1, act' :: TcKind
act') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env TcKind
act
; (env2 :: TidyEnv
env2, exp' :: TcKind
exp') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env1 TcKind
exp
; (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return ( TidyEnv
env2, CtOrigin
orig { uo_actual :: TcKind
uo_actual = TcKind
act'
, uo_expected :: TcKind
uo_expected = TcKind
exp' }) }
zonkTidyOrigin env :: TidyEnv
env (KindEqOrigin ty1 :: TcKind
ty1 m_ty2 :: Maybe TcKind
m_ty2 orig :: CtOrigin
orig t_or_k :: Maybe TypeOrKind
t_or_k)
= do { (env1 :: TidyEnv
env1, ty1' :: TcKind
ty1') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env TcKind
ty1
; (env2 :: TidyEnv
env2, m_ty2' :: Maybe TcKind
m_ty2') <- case Maybe TcKind
m_ty2 of
Just ty2 :: TcKind
ty2 -> (TcKind -> Maybe TcKind)
-> (TidyEnv, TcKind) -> (TidyEnv, Maybe TcKind)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second TcKind -> Maybe TcKind
forall a. a -> Maybe a
Just ((TidyEnv, TcKind) -> (TidyEnv, Maybe TcKind))
-> TcM (TidyEnv, TcKind)
-> IOEnv (Env TcGblEnv TcLclEnv) (TidyEnv, Maybe TcKind)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env1 TcKind
ty2
Nothing -> (TidyEnv, Maybe TcKind)
-> IOEnv (Env TcGblEnv TcLclEnv) (TidyEnv, Maybe TcKind)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env1, Maybe TcKind
forall a. Maybe a
Nothing)
; (env3 :: TidyEnv
env3, orig' :: CtOrigin
orig') <- TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
zonkTidyOrigin TidyEnv
env2 CtOrigin
orig
; (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env3, TcKind -> Maybe TcKind -> CtOrigin -> Maybe TypeOrKind -> CtOrigin
KindEqOrigin TcKind
ty1' Maybe TcKind
m_ty2' CtOrigin
orig' Maybe TypeOrKind
t_or_k) }
zonkTidyOrigin env :: TidyEnv
env (FunDepOrigin1 p1 :: TcKind
p1 l1 :: CtLoc
l1 p2 :: TcKind
p2 l2 :: CtLoc
l2)
= do { (env1 :: TidyEnv
env1, p1' :: TcKind
p1') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env TcKind
p1
; (env2 :: TidyEnv
env2, p2' :: TcKind
p2') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env1 TcKind
p2
; (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env2, TcKind -> CtLoc -> TcKind -> CtLoc -> CtOrigin
FunDepOrigin1 TcKind
p1' CtLoc
l1 TcKind
p2' CtLoc
l2) }
zonkTidyOrigin env :: TidyEnv
env (FunDepOrigin2 p1 :: TcKind
p1 o1 :: CtOrigin
o1 p2 :: TcKind
p2 l2 :: SrcSpan
l2)
= do { (env1 :: TidyEnv
env1, p1' :: TcKind
p1') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env TcKind
p1
; (env2 :: TidyEnv
env2, p2' :: TcKind
p2') <- TidyEnv -> TcKind -> TcM (TidyEnv, TcKind)
zonkTidyTcType TidyEnv
env1 TcKind
p2
; (env3 :: TidyEnv
env3, o1' :: CtOrigin
o1') <- TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
zonkTidyOrigin TidyEnv
env2 CtOrigin
o1
; (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env3, TcKind -> CtOrigin -> TcKind -> SrcSpan -> CtOrigin
FunDepOrigin2 TcKind
p1' CtOrigin
o1' TcKind
p2' SrcSpan
l2) }
zonkTidyOrigin env :: TidyEnv
env orig :: CtOrigin
orig = (TidyEnv, CtOrigin) -> TcM (TidyEnv, CtOrigin)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
env, CtOrigin
orig)
tidyCt :: TidyEnv -> Ct -> Ct
tidyCt :: TidyEnv -> Ct -> Ct
tidyCt env :: TidyEnv
env ct :: Ct
ct
= case Ct
ct of
CHoleCan { cc_ev :: Ct -> CtEvidence
cc_ev = CtEvidence
ev }
-> Ct
ct { cc_ev :: CtEvidence
cc_ev = TidyEnv -> CtEvidence -> CtEvidence
tidy_ev TidyEnv
env CtEvidence
ev }
_ -> CtEvidence -> Ct
mkNonCanonical (TidyEnv -> CtEvidence -> CtEvidence
tidy_ev TidyEnv
env (Ct -> CtEvidence
ctEvidence Ct
ct))
where
tidy_ev :: TidyEnv -> CtEvidence -> CtEvidence
tidy_ev :: TidyEnv -> CtEvidence -> CtEvidence
tidy_ev env :: TidyEnv
env ctev :: CtEvidence
ctev@(CtGiven { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred })
= CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
pred }
tidy_ev env :: TidyEnv
env ctev :: CtEvidence
ctev@(CtWanted { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred })
= CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
pred }
tidy_ev env :: TidyEnv
env ctev :: CtEvidence
ctev@(CtDerived { ctev_pred :: CtEvidence -> TcKind
ctev_pred = TcKind
pred })
= CtEvidence
ctev { ctev_pred :: TcKind
ctev_pred = TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
pred }
tidyEvVar :: TidyEnv -> EvVar -> EvVar
tidyEvVar :: TidyEnv -> TyVar -> TyVar
tidyEvVar env :: TidyEnv
env var :: TyVar
var = TyVar -> TcKind -> TyVar
setVarType TyVar
var (TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env (TyVar -> TcKind
varType TyVar
var))
tidySkolemInfo :: TidyEnv -> SkolemInfo -> SkolemInfo
tidySkolemInfo :: TidyEnv -> SkolemInfo -> SkolemInfo
tidySkolemInfo env :: TidyEnv
env (DerivSkol ty :: TcKind
ty) = TcKind -> SkolemInfo
DerivSkol (TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
ty)
tidySkolemInfo env :: TidyEnv
env (SigSkol cx :: UserTypeCtxt
cx ty :: TcKind
ty tv_prs :: [(Name, TyVar)]
tv_prs) = TidyEnv -> UserTypeCtxt -> TcKind -> [(Name, TyVar)] -> SkolemInfo
tidySigSkol TidyEnv
env UserTypeCtxt
cx TcKind
ty [(Name, TyVar)]
tv_prs
tidySkolemInfo env :: TidyEnv
env (InferSkol ids :: [(Name, TcKind)]
ids) = [(Name, TcKind)] -> SkolemInfo
InferSkol ((TcKind -> TcKind) -> [(Name, TcKind)] -> [(Name, TcKind)]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSnd (TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env) [(Name, TcKind)]
ids)
tidySkolemInfo env :: TidyEnv
env (UnifyForAllSkol ty :: TcKind
ty) = TcKind -> SkolemInfo
UnifyForAllSkol (TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
ty)
tidySkolemInfo _ info :: SkolemInfo
info = SkolemInfo
info
tidySigSkol :: TidyEnv -> UserTypeCtxt
-> TcType -> [(Name,TcTyVar)] -> SkolemInfo
tidySigSkol :: TidyEnv -> UserTypeCtxt -> TcKind -> [(Name, TyVar)] -> SkolemInfo
tidySigSkol env :: TidyEnv
env cx :: UserTypeCtxt
cx ty :: TcKind
ty tv_prs :: [(Name, TyVar)]
tv_prs
= UserTypeCtxt -> TcKind -> [(Name, TyVar)] -> SkolemInfo
SigSkol UserTypeCtxt
cx (TidyEnv -> TcKind -> TcKind
tidy_ty TidyEnv
env TcKind
ty) [(Name, TyVar)]
tv_prs'
where
tv_prs' :: [(Name, TyVar)]
tv_prs' = (TyVar -> TyVar) -> [(Name, TyVar)] -> [(Name, TyVar)]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSnd (TidyEnv -> TyVar -> TyVar
tidyTyCoVarOcc TidyEnv
env) [(Name, TyVar)]
tv_prs
inst_env :: NameEnv TyVar
inst_env = [(Name, TyVar)] -> NameEnv TyVar
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(Name, TyVar)]
tv_prs'
tidy_ty :: TidyEnv -> TcKind -> TcKind
tidy_ty env :: TidyEnv
env (ForAllTy (Bndr tv :: TyVar
tv vis :: ArgFlag
vis) ty :: TcKind
ty)
= VarBndr TyVar ArgFlag -> TcKind -> TcKind
ForAllTy (TyVar -> ArgFlag -> VarBndr TyVar ArgFlag
forall var argf. var -> argf -> VarBndr var argf
Bndr TyVar
tv' ArgFlag
vis) (TidyEnv -> TcKind -> TcKind
tidy_ty TidyEnv
env' TcKind
ty)
where
(env' :: TidyEnv
env', tv' :: TyVar
tv') = TidyEnv -> TyVar -> (TidyEnv, TyVar)
tidy_tv_bndr TidyEnv
env TyVar
tv
tidy_ty env :: TidyEnv
env (FunTy arg :: TcKind
arg res :: TcKind
res)
= TcKind -> TcKind -> TcKind
FunTy (TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
arg) (TidyEnv -> TcKind -> TcKind
tidy_ty TidyEnv
env TcKind
res)
tidy_ty env :: TidyEnv
env ty :: TcKind
ty = TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
env TcKind
ty
tidy_tv_bndr :: TidyEnv -> TyCoVar -> (TidyEnv, TyCoVar)
tidy_tv_bndr :: TidyEnv -> TyVar -> (TidyEnv, TyVar)
tidy_tv_bndr env :: TidyEnv
env@(occ_env :: TidyOccEnv
occ_env, subst :: NameEnv TyVar
subst) tv :: TyVar
tv
| Just tv' :: TyVar
tv' <- NameEnv TyVar -> Name -> Maybe TyVar
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv TyVar
inst_env (TyVar -> Name
tyVarName TyVar
tv)
= ((TidyOccEnv
occ_env, NameEnv TyVar -> TyVar -> TyVar -> NameEnv TyVar
forall a. VarEnv a -> TyVar -> a -> VarEnv a
extendVarEnv NameEnv TyVar
subst TyVar
tv TyVar
tv'), TyVar
tv')
| Bool
otherwise
= TidyEnv -> TyVar -> (TidyEnv, TyVar)
tidyVarBndr TidyEnv
env TyVar
tv
ensureNotLevPoly :: Type
-> SDoc
-> TcM ()
ensureNotLevPoly :: TcKind -> SDoc -> TcRn ()
ensureNotLevPoly ty :: TcKind
ty doc :: SDoc
doc
= TcRn () -> TcRn ()
whenNoErrs (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
SDoc -> TcKind -> TcRn ()
checkForLevPoly SDoc
doc TcKind
ty
checkForLevPoly :: SDoc -> Type -> TcM ()
checkForLevPoly :: SDoc -> TcKind -> TcRn ()
checkForLevPoly = (SDoc -> TcRn ()) -> SDoc -> TcKind -> TcRn ()
forall (m :: * -> *).
Monad m =>
(SDoc -> m ()) -> SDoc -> TcKind -> m ()
checkForLevPolyX SDoc -> TcRn ()
addErr
checkForLevPolyX :: Monad m
=> (SDoc -> m ())
-> SDoc -> Type -> m ()
checkForLevPolyX :: (SDoc -> m ()) -> SDoc -> TcKind -> m ()
checkForLevPolyX add_err :: SDoc -> m ()
add_err extra :: SDoc
extra ty :: TcKind
ty
| TcKind -> Bool
isTypeLevPoly TcKind
ty
= SDoc -> m ()
add_err (TcKind -> SDoc
formatLevPolyErr TcKind
ty SDoc -> SDoc -> SDoc
$$ SDoc
extra)
| Bool
otherwise
= () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
formatLevPolyErr :: Type
-> SDoc
formatLevPolyErr :: TcKind -> SDoc
formatLevPolyErr ty :: TcKind
ty
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "A levity-polymorphic type is not allowed here:")
2 ([SDoc] -> SDoc
vcat [ String -> SDoc
text "Type:" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
pprWithTYPE TcKind
tidy_ty
, String -> SDoc
text "Kind:" SDoc -> SDoc -> SDoc
<+> TcKind -> SDoc
pprWithTYPE TcKind
tidy_ki ])
where
(tidy_env :: TidyEnv
tidy_env, tidy_ty :: TcKind
tidy_ty) = TidyEnv -> TcKind -> (TidyEnv, TcKind)
tidyOpenType TidyEnv
emptyTidyEnv TcKind
ty
tidy_ki :: TcKind
tidy_ki = TidyEnv -> TcKind -> TcKind
tidyType TidyEnv
tidy_env (HasDebugCallStack => TcKind -> TcKind
TcKind -> TcKind
tcTypeKind TcKind
ty)