{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.Tc.Utils.TcMType (
TcTyVar, TcKind, TcType, TcTauType, TcThetaType, TcTyVarSet,
newFlexiTyVar,
newNamedFlexiTyVar,
newFlexiTyVarTy,
newFlexiTyVarTys,
newOpenFlexiTyVar, newOpenFlexiTyVarTy, newOpenTypeKind,
newOpenBoxedTypeKind,
newMetaKindVar, newMetaKindVars,
newMetaTyVarTyAtLevel, newConcreteTyVarTyAtLevel,
newAnonMetaTyVar, newConcreteTyVar,
cloneMetaTyVar, cloneMetaTyVarWithInfo,
newCycleBreakerTyVar,
newMultiplicityVar,
readMetaTyVar, writeMetaTyVar, writeMetaTyVarRef,
newTauTvDetailsAtLevel, newMetaDetails, newMetaTyVarName,
isFilledMetaTyVar_maybe, isFilledMetaTyVar, isUnfilledMetaTyVar,
newEvVar, newEvVars, newDict,
newWantedWithLoc, newWanted, newWanteds, cloneWanted, cloneWC, cloneWantedCtEv,
emitWanted, emitWantedEq, emitWantedEvVar, emitWantedEvVars,
emitWantedEqs,
newTcEvBinds, newNoTcEvBinds, addTcEvBind,
emitNewExprHole,
newCoercionHole, newCoercionHoleO, newVanillaCoercionHole,
fillCoercionHole, isFilledCoercionHole,
unpackCoercionHole, unpackCoercionHole_maybe,
checkCoercionHole,
newImplication,
newMetaTyVars, newMetaTyVarX, newMetaTyVarsX,
newMetaTyVarTyVarX,
newTyVarTyVar, cloneTyVarTyVar,
newPatSigTyVar, newSkolemTyVar, newWildCardX,
ExpType(..), ExpSigmaType, ExpRhoType,
mkCheckExpType, newInferExpType, newInferExpTypeFRR,
tcInfer, tcInferFRR,
readExpType, readExpType_maybe, readScaledExpType,
expTypeToType, scaledExpTypeToType,
checkingExpType_maybe, checkingExpType,
inferResultToType, ensureMonoType, promoteTcType,
tcCheckUsage,
defaultTyVar, promoteMetaTyVarTo, promoteTyVarSet,
quantifyTyVars, isQuantifiableTv,
zonkAndSkolemise, skolemiseQuantifiedTyVar,
doNotQuantifyTyVars,
candidateQTyVarsOfType, candidateQTyVarsOfKind,
candidateQTyVarsOfTypes, candidateQTyVarsOfKinds,
candidateQTyVarsWithBinders,
CandidatesQTvs(..), delCandidates,
candidateKindVars, partitionCandidates,
checkTypeHasFixedRuntimeRep,
mkHsDictLet, mkHsApp,
mkHsAppTy, mkHsCaseAlt,
tcShortCutLit, shortCutLit, hsOverLitName,
conLikeResTy
) where
import GHC.Prelude
import GHC.Hs
import GHC.Platform
import GHC.Driver.DynFlags
import qualified GHC.LanguageExtensions as LangExt
import {-# SOURCE #-} GHC.Tc.Utils.Unify( unifyInvisibleType, tcSubMult )
import GHC.Tc.Types.Origin
import GHC.Tc.Types.Constraint
import GHC.Tc.Types.Evidence
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.TcType
import GHC.Tc.Errors.Types
import GHC.Tc.Zonk.Type
import GHC.Tc.Zonk.TcType
import GHC.Builtin.Names
import GHC.Core.ConLike
import GHC.Core.DataCon
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Ppr
import GHC.Core.Type
import GHC.Core.TyCon
import GHC.Core.Coercion
import GHC.Core.Class
import GHC.Core.Predicate
import GHC.Core.UsageEnv
import GHC.Types.Var
import GHC.Types.Id as Id
import GHC.Types.Name
import GHC.Types.SourceText
import GHC.Types.Var.Set
import GHC.Builtin.Types
import GHC.Types.Var.Env
import GHC.Types.Unique.Set
import GHC.Types.Basic ( TypeOrKind(..)
, NonStandardDefaultingStrategy(..)
, DefaultingStrategy(..), defaultNonStandardTyVars )
import GHC.Data.FastString
import GHC.Data.Bag
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import GHC.Utils.Constants (debugIsOn)
import Control.Monad
import Data.IORef
import GHC.Data.Maybe
import qualified Data.Semigroup as Semi
import GHC.Types.Name.Reader
newMetaKindVar :: TcM TcKind
newMetaKindVar :: TcM TcType
newMetaKindVar
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TauTv
; Name
name <- FastString -> TcM Name
newMetaTyVarName (String -> FastString
fsLit String
"k")
; let kv :: TcTyVar
kv = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
liftedTypeKind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"newMetaKindVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
kv)
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> TcType
mkTyVarTy TcTyVar
kv) }
newMetaKindVars :: Int -> TcM [TcKind]
newMetaKindVars :: Int -> TcM [TcType]
newMetaKindVars Int
n = Int -> TcM TcType -> TcM [TcType]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n TcM TcType
newMetaKindVar
newEvVars :: TcThetaType -> TcM [EvVar]
newEvVars :: [TcType] -> TcM [TcTyVar]
newEvVars [TcType]
theta = (TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> [TcType] -> TcM [TcTyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. TcType -> TcRnIf gbl lcl TcTyVar
newEvVar [TcType]
theta
newEvVar :: TcPredType -> TcRnIf gbl lcl EvVar
newEvVar :: forall gbl lcl. TcType -> TcRnIf gbl lcl TcTyVar
newEvVar TcType
ty = do { Name
name <- OccName -> TcRnIf gbl lcl Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (TcType -> OccName
predTypeOccName TcType
ty)
; TcTyVar -> TcRnIf gbl lcl TcTyVar
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcType -> TcType -> TcTyVar
mkLocalIdOrCoVar Name
name TcType
ManyTy TcType
ty) }
newWantedWithLoc :: CtLoc -> PredType -> TcM CtEvidence
newWantedWithLoc :: CtLoc -> TcType -> TcM CtEvidence
newWantedWithLoc CtLoc
loc TcType
pty
= do TcEvDest
dst <- case TcType -> Pred
classifyPredType TcType
pty of
EqPred {} -> 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
<$> CtLoc -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole CtLoc
loc TcType
pty
Pred
_ -> TcTyVar -> TcEvDest
EvVarDest (TcTyVar -> TcEvDest)
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcEvDest
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. TcType -> TcRnIf gbl lcl TcTyVar
newEvVar TcType
pty
CtEvidence -> TcM CtEvidence
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence -> TcM CtEvidence) -> CtEvidence -> TcM CtEvidence
forall a b. (a -> b) -> a -> b
$ CtWanted { ctev_dest :: TcEvDest
ctev_dest = TcEvDest
dst
, ctev_pred :: TcType
ctev_pred = TcType
pty
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc
, ctev_rewriters :: RewriterSet
ctev_rewriters = RewriterSet
emptyRewriterSet }
newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence
newWanted :: CtOrigin -> Maybe TypeOrKind -> TcType -> TcM CtEvidence
newWanted CtOrigin
orig Maybe TypeOrKind
t_or_k TcType
pty
= do CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
orig Maybe TypeOrKind
t_or_k
CtLoc -> TcType -> TcM CtEvidence
newWantedWithLoc CtLoc
loc TcType
pty
newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence]
newWanteds :: CtOrigin -> [TcType] -> TcM [CtEvidence]
newWanteds CtOrigin
orig = (TcType -> TcM CtEvidence) -> [TcType] -> TcM [CtEvidence]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (CtOrigin -> Maybe TypeOrKind -> TcType -> TcM CtEvidence
newWanted CtOrigin
orig Maybe TypeOrKind
forall a. Maybe a
Nothing)
cloneWantedCtEv :: CtEvidence -> TcM CtEvidence
cloneWantedCtEv :: CtEvidence -> TcM CtEvidence
cloneWantedCtEv ctev :: CtEvidence
ctev@(CtWanted { ctev_pred :: CtEvidence -> TcType
ctev_pred = TcType
pty, ctev_dest :: CtEvidence -> TcEvDest
ctev_dest = HoleDest CoercionHole
_, ctev_loc :: CtEvidence -> CtLoc
ctev_loc = CtLoc
loc })
| TcType -> Bool
isEqPrimPred TcType
pty
= do { CoercionHole
co_hole <- CtLoc -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole CtLoc
loc TcType
pty
; CtEvidence -> TcM CtEvidence
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (CtEvidence
ctev { ctev_dest = HoleDest co_hole }) }
| Bool
otherwise
= String -> SDoc -> TcM CtEvidence
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"cloneWantedCtEv" (TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
pty)
cloneWantedCtEv CtEvidence
ctev = CtEvidence -> TcM CtEvidence
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CtEvidence
ctev
cloneWanted :: Ct -> TcM Ct
cloneWanted :: Ct -> TcM Ct
cloneWanted Ct
ct = CtEvidence -> Ct
mkNonCanonical (CtEvidence -> Ct) -> TcM CtEvidence -> TcM Ct
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CtEvidence -> TcM CtEvidence
cloneWantedCtEv (Ct -> CtEvidence
ctEvidence 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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wc { wc_simple = simples', wc_impl = 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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication
implic { ic_binds = binds', ic_wanted = inner_wanted' }) }
emitWanted :: CtOrigin -> TcPredType -> TcM EvTerm
emitWanted :: CtOrigin -> TcType -> TcM EvTerm
emitWanted CtOrigin
origin TcType
pty
= do { CtEvidence
ev <- CtOrigin -> Maybe TypeOrKind -> TcType -> TcM CtEvidence
newWanted CtOrigin
origin Maybe TypeOrKind
forall a. Maybe a
Nothing TcType
pty
; Ct -> TcRn ()
emitSimple (Ct -> TcRn ()) -> Ct -> TcRn ()
forall a b. (a -> b) -> a -> b
$ CtEvidence -> Ct
mkNonCanonical CtEvidence
ev
; EvTerm -> TcM EvTerm
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 }
emitWantedEqs :: CtOrigin -> [(TcType,TcType)] -> TcM ()
emitWantedEqs :: CtOrigin -> [(TcType, TcType)] -> TcRn ()
emitWantedEqs CtOrigin
origin [(TcType, TcType)]
pairs
| [(TcType, TcType)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(TcType, TcType)]
pairs
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= ((TcType, TcType) -> IOEnv (Env TcGblEnv TcLclEnv) Coercion)
-> [(TcType, TcType)] -> TcRn ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((TcType -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) Coercion)
-> (TcType, TcType) -> IOEnv (Env TcGblEnv TcLclEnv) Coercion
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (CtOrigin
-> TypeOrKind
-> Role
-> TcType
-> TcType
-> IOEnv (Env TcGblEnv TcLclEnv) Coercion
emitWantedEq CtOrigin
origin TypeOrKind
TypeLevel Role
Nominal)) [(TcType, TcType)]
pairs
emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcType -> TcType -> TcM Coercion
emitWantedEq :: CtOrigin
-> TypeOrKind
-> Role
-> TcType
-> TcType
-> IOEnv (Env TcGblEnv TcLclEnv) Coercion
emitWantedEq CtOrigin
origin TypeOrKind
t_or_k Role
role TcType
ty1 TcType
ty2
= do { CoercionHole
hole <- CtOrigin -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHoleO CtOrigin
origin TcType
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 { ctev_pred :: TcType
ctev_pred = TcType
pty
, ctev_dest :: TcEvDest
ctev_dest = CoercionHole -> TcEvDest
HoleDest CoercionHole
hole
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc
, ctev_rewriters :: RewriterSet
ctev_rewriters = RewriterSet
emptyRewriterSet }
; Coercion -> IOEnv (Env TcGblEnv TcLclEnv) Coercion
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (CoercionHole -> Coercion
HoleCo CoercionHole
hole) }
where
pty :: TcType
pty = Role -> TcType -> TcType -> TcType
mkPrimEqPredRole Role
role TcType
ty1 TcType
ty2
emitWantedEvVar :: CtOrigin -> TcPredType -> TcM EvVar
emitWantedEvVar :: CtOrigin -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
emitWantedEvVar CtOrigin
origin TcType
ty
= do { TcTyVar
new_cv <- TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. TcType -> TcRnIf gbl lcl TcTyVar
newEvVar TcType
ty
; CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
origin Maybe TypeOrKind
forall a. Maybe a
Nothing
; let ctev :: CtEvidence
ctev = CtWanted { ctev_pred :: TcType
ctev_pred = TcType
ty
, ctev_dest :: TcEvDest
ctev_dest = TcTyVar -> TcEvDest
EvVarDest TcTyVar
new_cv
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc
, ctev_rewriters :: RewriterSet
ctev_rewriters = RewriterSet
emptyRewriterSet }
; Ct -> TcRn ()
emitSimple (Ct -> TcRn ()) -> Ct -> TcRn ()
forall a b. (a -> b) -> a -> b
$ CtEvidence -> Ct
mkNonCanonical CtEvidence
ctev
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
new_cv }
emitWantedEvVars :: CtOrigin -> [TcPredType] -> TcM [EvVar]
emitWantedEvVars :: CtOrigin -> [TcType] -> TcM [TcTyVar]
emitWantedEvVars CtOrigin
orig = (TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> [TcType] -> TcM [TcTyVar]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (CtOrigin -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
emitWantedEvVar CtOrigin
orig)
emitNewExprHole :: RdrName
-> Type -> TcM HoleExprRef
emitNewExprHole :: RdrName -> TcType -> TcM HoleExprRef
emitNewExprHole RdrName
occ TcType
ty
= do { Unique
u <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcRef EvTerm
ref <- EvTerm -> IOEnv (Env TcGblEnv TcLclEnv) (TcRef EvTerm)
forall (m :: * -> *) a. MonadIO m => a -> m (TcRef a)
newTcRef (String -> SDoc -> EvTerm
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"unfilled unbound-variable evidence" (Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unique
u))
; let her :: HoleExprRef
her = TcRef EvTerm -> TcType -> Unique -> HoleExprRef
HER TcRef EvTerm
ref TcType
ty Unique
u
; CtLoc
loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM (Maybe RdrName -> CtOrigin
ExprHoleOrigin (RdrName -> Maybe RdrName
forall a. a -> Maybe a
Just RdrName
occ)) (TypeOrKind -> Maybe TypeOrKind
forall a. a -> Maybe a
Just TypeOrKind
TypeLevel)
; let hole :: Hole
hole = Hole { hole_sort :: HoleSort
hole_sort = HoleExprRef -> HoleSort
ExprHole HoleExprRef
her
, hole_occ :: RdrName
hole_occ = RdrName
occ
, hole_ty :: TcType
hole_ty = TcType
ty
, hole_loc :: CtLoc
hole_loc = CtLoc
loc }
; Hole -> TcRn ()
emitHole Hole
hole
; HoleExprRef -> TcM HoleExprRef
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return HoleExprRef
her }
newDict :: Class -> [TcType] -> TcM DictId
newDict :: Class -> [TcType] -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newDict Class
cls [TcType]
tys
= do { Name
name <- OccName -> TcM Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (OccName -> OccName
mkDictOcc (Class -> OccName
forall a. NamedThing a => a -> OccName
getOccName Class
cls))
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (HasDebugCallStack => Name -> TcType -> TcType -> TcTyVar
Name -> TcType -> TcType -> TcTyVar
mkLocalId Name
name TcType
ManyTy (Class -> [TcType] -> TcType
mkClassPred Class
cls [TcType]
tys)) }
predTypeOccName :: PredType -> OccName
predTypeOccName :: TcType -> OccName
predTypeOccName TcType
ty = case TcType -> Pred
classifyPredType TcType
ty of
ClassPred Class
cls [TcType]
_ -> OccName -> OccName
mkDictOcc (Class -> OccName
forall a. NamedThing a => a -> OccName
getOccName Class
cls)
EqPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"co")
IrredPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"irred")
ForAllPred {} -> FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"df")
newImplication :: TcM Implication
newImplication :: IOEnv (Env TcGblEnv TcLclEnv) Implication
newImplication
= do TcLclEnv
env <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
Bool
warn_inaccessible <- WarningFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
Opt_WarnInaccessibleCode
let in_gen_code :: Bool
in_gen_code = TcLclEnv -> Bool
lclEnvInGeneratedCode TcLclEnv
env
Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication)
-> Implication -> IOEnv (Env TcGblEnv TcLclEnv) Implication
forall a b. (a -> b) -> a -> b
$
(CtLocEnv -> Implication
implicationPrototype (TcLclEnv -> CtLocEnv
mkCtLocEnv TcLclEnv
env))
{ ic_warn_inaccessible = warn_inaccessible && not in_gen_code }
newVanillaCoercionHole :: TcPredType -> TcM CoercionHole
newVanillaCoercionHole :: TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newVanillaCoercionHole = Bool -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
new_coercion_hole Bool
False
newCoercionHole :: CtLoc -> TcPredType -> TcM CoercionHole
newCoercionHole :: CtLoc -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHole CtLoc
loc = CtOrigin -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHoleO (CtLoc -> CtOrigin
ctLocOrigin CtLoc
loc)
newCoercionHoleO :: CtOrigin -> TcPredType -> TcM CoercionHole
newCoercionHoleO :: CtOrigin -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
newCoercionHoleO (KindEqOrigin {}) = Bool -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
new_coercion_hole Bool
True
newCoercionHoleO CtOrigin
_ = Bool -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
new_coercion_hole Bool
False
new_coercion_hole :: Bool -> TcPredType -> TcM CoercionHole
new_coercion_hole :: Bool -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) CoercionHole
new_coercion_hole Bool
hetero_kind TcType
pred_ty
= do { TcTyVar
co_var <- TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. TcType -> TcRnIf gbl lcl TcTyVar
newEvVar TcType
pred_ty
; String -> SDoc -> TcRn ()
traceTc String
"New coercion hole:" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
co_var SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
pred_ty)
; 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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 { ch_co_var :: TcTyVar
ch_co_var = TcTyVar
co_var, ch_ref :: IORef (Maybe Coercion)
ch_ref = IORef (Maybe Coercion)
ref
, ch_hetero_kind :: Bool
ch_hetero_kind = Bool
hetero_kind } }
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 -> TcTyVar
ch_co_var = TcTyVar
cv }) Coercion
co = do
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
Maybe Coercion
cts <- IORef (Maybe Coercion)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe Coercion)
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
readTcRef IORef (Maybe Coercion)
ref
Maybe Coercion -> (Coercion -> TcRn ()) -> TcRn ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenIsJust Maybe Coercion
cts ((Coercion -> TcRn ()) -> TcRn ())
-> (Coercion -> TcRn ()) -> TcRn ()
forall a b. (a -> b) -> a -> b
$ \Coercion
old_co ->
String -> SDoc -> TcRn ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Filling a filled coercion hole" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
cv SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Coercion -> SDoc
forall a. Outputable a => a -> SDoc
ppr Coercion
co SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Coercion -> SDoc
forall a. Outputable a => a -> SDoc
ppr Coercion
old_co)
String -> SDoc -> TcRn ()
traceTc String
"Filling coercion hole" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
cv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
":=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Coercion -> SDoc
forall a. Outputable a => a -> SDoc
ppr Coercion
co)
IORef (Maybe Coercion) -> Maybe Coercion -> TcRn ()
forall (m :: * -> *) a. MonadIO m => TcRef a -> a -> m ()
writeTcRef IORef (Maybe Coercion)
ref (Coercion -> Maybe Coercion
forall a. a -> Maybe a
Just Coercion
co)
newInferExpType :: TcM ExpType
newInferExpType :: TcM ExpType
newInferExpType = Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType Maybe FixedRuntimeRepContext
forall a. Maybe a
Nothing
newInferExpTypeFRR :: FixedRuntimeRepContext -> TcM ExpTypeFRR
newInferExpTypeFRR :: FixedRuntimeRepContext -> TcM ExpType
newInferExpTypeFRR FixedRuntimeRepContext
frr_orig
= do { ThStage
th_stage <- TcM ThStage
getStage
; if
| Brack ThStage
_ (TcPending {}) <- ThStage
th_stage
-> Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType Maybe FixedRuntimeRepContext
forall a. Maybe a
Nothing
| Bool
otherwise
-> Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType (FixedRuntimeRepContext -> Maybe FixedRuntimeRepContext
forall a. a -> Maybe a
Just FixedRuntimeRepContext
frr_orig) }
new_inferExpType :: Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType :: Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType Maybe FixedRuntimeRepContext
mb_frr_orig
= do { Unique
u <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; TcLevel
tclvl <- TcM TcLevel
getTcLevel
; String -> SDoc -> TcRn ()
traceTc String
"newInferExpType" (Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unique
u SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
tclvl)
; IORef (Maybe TcType)
ref <- Maybe TcType
-> IOEnv (Env TcGblEnv TcLclEnv) (IORef (Maybe TcType))
forall a env. a -> IOEnv env (IORef a)
newMutVar Maybe TcType
forall a. Maybe a
Nothing
; ExpType -> TcM ExpType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (InferResult -> ExpType
Infer (IR { ir_uniq :: Unique
ir_uniq = Unique
u, ir_lvl :: TcLevel
ir_lvl = TcLevel
tclvl
, ir_ref :: IORef (Maybe TcType)
ir_ref = IORef (Maybe TcType)
ref
, ir_frr :: Maybe FixedRuntimeRepContext
ir_frr = Maybe FixedRuntimeRepContext
mb_frr_orig })) }
readExpType_maybe :: MonadIO m => ExpType -> m (Maybe TcType)
readExpType_maybe :: forall (m :: * -> *). MonadIO m => ExpType -> m (Maybe TcType)
readExpType_maybe (Check TcType
ty) = Maybe TcType -> m (Maybe TcType)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> Maybe TcType
forall a. a -> Maybe a
Just TcType
ty)
readExpType_maybe (Infer (IR { ir_ref :: InferResult -> IORef (Maybe TcType)
ir_ref = IORef (Maybe TcType)
ref})) = IO (Maybe TcType) -> m (Maybe TcType)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe TcType) -> m (Maybe TcType))
-> IO (Maybe TcType) -> m (Maybe TcType)
forall a b. (a -> b) -> a -> b
$ IORef (Maybe TcType) -> IO (Maybe TcType)
forall a. IORef a -> IO a
readIORef IORef (Maybe TcType)
ref
{-# INLINEABLE readExpType_maybe #-}
readScaledExpType :: MonadIO m => Scaled ExpType -> m (Scaled Type)
readScaledExpType :: forall (m :: * -> *).
MonadIO m =>
Scaled ExpType -> m (Scaled TcType)
readScaledExpType (Scaled TcType
m ExpType
exp_ty)
= do { TcType
ty <- ExpType -> m TcType
forall (m :: * -> *). MonadIO m => ExpType -> m TcType
readExpType ExpType
exp_ty
; Scaled TcType -> m (Scaled TcType)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> TcType -> Scaled TcType
forall a. TcType -> a -> Scaled a
Scaled TcType
m TcType
ty) }
{-# INLINEABLE readScaledExpType #-}
readExpType :: MonadIO m => ExpType -> m TcType
readExpType :: forall (m :: * -> *). MonadIO m => ExpType -> m TcType
readExpType ExpType
exp_ty
= do { Maybe TcType
mb_ty <- ExpType -> m (Maybe TcType)
forall (m :: * -> *). MonadIO m => ExpType -> m (Maybe TcType)
readExpType_maybe ExpType
exp_ty
; case Maybe TcType
mb_ty of
Just TcType
ty -> TcType -> m TcType
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty
Maybe TcType
Nothing -> String -> SDoc -> m TcType
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Unknown expected type" (ExpType -> SDoc
forall a. Outputable a => a -> SDoc
ppr ExpType
exp_ty) }
{-# INLINEABLE readExpType #-}
scaledExpTypeToType :: Scaled ExpType -> TcM (Scaled TcType)
scaledExpTypeToType :: Scaled ExpType -> TcM (Scaled TcType)
scaledExpTypeToType (Scaled TcType
m ExpType
exp_ty)
= do { TcType
ty <- ExpType -> TcM TcType
expTypeToType ExpType
exp_ty
; Scaled TcType -> TcM (Scaled TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> TcType -> Scaled TcType
forall a. TcType -> a -> Scaled a
Scaled TcType
m TcType
ty) }
expTypeToType :: ExpType -> TcM TcType
expTypeToType :: ExpType -> TcM TcType
expTypeToType (Check TcType
ty) = TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty
expTypeToType (Infer InferResult
inf_res) = InferResult -> TcM TcType
inferResultToType InferResult
inf_res
inferResultToType :: InferResult -> TcM Type
inferResultToType :: InferResult -> TcM TcType
inferResultToType (IR { ir_uniq :: InferResult -> Unique
ir_uniq = Unique
u, ir_lvl :: InferResult -> TcLevel
ir_lvl = TcLevel
tc_lvl
, ir_ref :: InferResult -> IORef (Maybe TcType)
ir_ref = IORef (Maybe TcType)
ref
, ir_frr :: InferResult -> Maybe FixedRuntimeRepContext
ir_frr = Maybe FixedRuntimeRepContext
mb_frr })
= do { Maybe TcType
mb_inferred_ty <- IORef (Maybe TcType)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
readTcRef IORef (Maybe TcType)
ref
; TcType
tau <- case Maybe TcType
mb_inferred_ty of
Just TcType
ty -> do { TcType -> TcRn ()
ensureMonoType TcType
ty
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
ty }
Maybe TcType
Nothing -> do { TcType
tau <- TcM TcType
new_meta
; IORef (Maybe TcType) -> Maybe TcType -> TcRn ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef (Maybe TcType)
ref (TcType -> Maybe TcType
forall a. a -> Maybe a
Just TcType
tau)
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
tau }
; String -> SDoc -> TcRn ()
traceTc String
"Forcing ExpType to be monomorphic:"
(Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr Unique
u SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
":=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
tau)
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
tau }
where
new_meta :: TcM TcType
new_meta = case Maybe FixedRuntimeRepContext
mb_frr of
Maybe FixedRuntimeRepContext
Nothing -> do { TcType
rr <- TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
tc_lvl TcType
runtimeRepTy
; TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
tc_lvl (TcType -> TcType
mkTYPEapp TcType
rr) }
Just FixedRuntimeRepContext
frr -> mdo { TcType
rr <- ConcreteTvOrigin -> TcLevel -> TcType -> TcM TcType
newConcreteTyVarTyAtLevel ConcreteTvOrigin
conc_orig TcLevel
tc_lvl TcType
runtimeRepTy
; TcType
tau <- TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
tc_lvl (TcType -> TcType
mkTYPEapp TcType
rr)
; let conc_orig :: ConcreteTvOrigin
conc_orig = FixedRuntimeRepOrigin -> ConcreteTvOrigin
ConcreteFRR (FixedRuntimeRepOrigin -> ConcreteTvOrigin)
-> FixedRuntimeRepOrigin -> ConcreteTvOrigin
forall a b. (a -> b) -> a -> b
$ TcType -> FixedRuntimeRepContext -> FixedRuntimeRepOrigin
FixedRuntimeRepOrigin TcType
tau FixedRuntimeRepContext
frr
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
tau }
tcInfer :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
tcInfer :: forall a. (ExpType -> TcM a) -> TcM (a, TcType)
tcInfer = Maybe FixedRuntimeRepContext
-> (ExpType -> TcM a) -> TcM (a, TcType)
forall a.
Maybe FixedRuntimeRepContext
-> (ExpType -> TcM a) -> TcM (a, TcType)
tc_infer Maybe FixedRuntimeRepContext
forall a. Maybe a
Nothing
tcInferFRR :: FixedRuntimeRepContext -> (ExpSigmaTypeFRR -> TcM a) -> TcM (a, TcSigmaTypeFRR)
tcInferFRR :: forall a.
FixedRuntimeRepContext -> (ExpType -> TcM a) -> TcM (a, TcType)
tcInferFRR FixedRuntimeRepContext
frr_orig = Maybe FixedRuntimeRepContext
-> (ExpType -> TcM a) -> TcM (a, TcType)
forall a.
Maybe FixedRuntimeRepContext
-> (ExpType -> TcM a) -> TcM (a, TcType)
tc_infer (FixedRuntimeRepContext -> Maybe FixedRuntimeRepContext
forall a. a -> Maybe a
Just FixedRuntimeRepContext
frr_orig)
tc_infer :: Maybe FixedRuntimeRepContext -> (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
tc_infer :: forall a.
Maybe FixedRuntimeRepContext
-> (ExpType -> TcM a) -> TcM (a, TcType)
tc_infer Maybe FixedRuntimeRepContext
mb_frr ExpType -> TcM a
tc_check
= do { ExpType
res_ty <- Maybe FixedRuntimeRepContext -> TcM ExpType
new_inferExpType Maybe FixedRuntimeRepContext
mb_frr
; a
result <- ExpType -> TcM a
tc_check ExpType
res_ty
; TcType
res_ty <- ExpType -> TcM TcType
forall (m :: * -> *). MonadIO m => ExpType -> m TcType
readExpType ExpType
res_ty
; (a, TcType) -> TcM (a, TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, TcType
res_ty) }
ensureMonoType :: TcType -> TcM ()
ensureMonoType :: TcType -> TcRn ()
ensureMonoType TcType
res_ty
| TcType -> Bool
isTauTy TcType
res_ty
= () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { TcType
mono_ty <- TcM TcType
newOpenFlexiTyVarTy
; Coercion
_co <- TcType -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) Coercion
unifyInvisibleType TcType
res_ty TcType
mono_ty
; () -> TcRn ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return () }
promoteTcType :: TcLevel -> TcType -> TcM (TcCoercionN, TcType)
promoteTcType :: TcLevel -> TcType -> TcM (Coercion, TcType)
promoteTcType TcLevel
dest_lvl TcType
ty
= do { TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; if (TcLevel
cur_lvl TcLevel -> TcLevel -> Bool
`sameDepthAs` TcLevel
dest_lvl)
then (Coercion, TcType) -> TcM (Coercion, TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> Coercion
mkNomReflCo TcType
ty, TcType
ty)
else TcM (Coercion, TcType)
promote_it }
where
promote_it :: TcM (TcCoercion, TcType)
promote_it :: TcM (Coercion, TcType)
promote_it
= do { TcType
rr <- TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
dest_lvl TcType
runtimeRepTy
; TcType
prom_ty <- TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
dest_lvl (TcType -> TcType
mkTYPEapp TcType
rr)
; Coercion
co <- TcType -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) Coercion
unifyInvisibleType TcType
ty TcType
prom_ty
; (Coercion, TcType) -> TcM (Coercion, TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Coercion
co, TcType
prom_ty) }
newMetaTyVarName :: FastString -> TcM Name
newMetaTyVarName :: FastString -> TcM Name
newMetaTyVarName FastString
str
= OccName -> TcM Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (FastString -> OccName
mkTyVarOccFS FastString
str)
cloneMetaTyVarName :: Name -> TcM Name
cloneMetaTyVarName :: Name -> TcM Name
cloneMetaTyVarName Name
name
= OccName -> TcM Name
forall gbl lcl. OccName -> TcRnIf gbl lcl Name
newSysName (Name -> OccName
nameOccName Name
name)
metaInfoToTyVarName :: MetaInfo -> FastString
metaInfoToTyVarName :: MetaInfo -> FastString
metaInfoToTyVarName MetaInfo
meta_info =
case MetaInfo
meta_info of
MetaInfo
TauTv -> String -> FastString
fsLit String
"t"
MetaInfo
TyVarTv -> String -> FastString
fsLit String
"a"
MetaInfo
RuntimeUnkTv -> String -> FastString
fsLit String
"r"
MetaInfo
CycleBreakerTv -> String -> FastString
fsLit String
"b"
ConcreteTv {} -> String -> FastString
fsLit String
"c"
newAnonMetaTyVar :: MetaInfo -> Kind -> TcM TcTyVar
newAnonMetaTyVar :: MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newAnonMetaTyVar MetaInfo
mi = FastString
-> MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedAnonMetaTyVar (MetaInfo -> FastString
metaInfoToTyVarName MetaInfo
mi) MetaInfo
mi
newNamedAnonMetaTyVar :: FastString -> MetaInfo -> Kind -> TcM TcTyVar
newNamedAnonMetaTyVar :: FastString
-> MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedAnonMetaTyVar FastString
tyvar_name MetaInfo
meta_info TcType
kind
= do { Name
name <- FastString -> TcM Name
newMetaTyVarName FastString
tyvar_name
; TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
meta_info
; let tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"newAnonMetaTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
newSkolemTyVar :: SkolemInfo -> Name -> Kind -> TcM TcTyVar
newSkolemTyVar :: SkolemInfo
-> Name -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newSkolemTyVar SkolemInfo
skol_info Name
name TcType
kind
= do { TcLevel
lvl <- TcM TcLevel
getTcLevel
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind (SkolemInfo -> TcLevel -> Bool -> TcTyVarDetails
SkolemTv SkolemInfo
skol_info TcLevel
lvl Bool
False)) }
newTyVarTyVar :: Name -> Kind -> TcM TcTyVar
newTyVarTyVar :: Name -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newTyVarTyVar Name
name TcType
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TyVarTv
; let tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"newTyVarTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
cloneTyVarTyVar :: Name -> Kind -> TcM TcTyVar
cloneTyVarTyVar :: Name -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneTyVarTyVar Name
name TcType
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TyVarTv
; Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; let name' :: Name
name' = Name
name Name -> Unique -> Name
`setNameUnique` Unique
uniq
tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name' TcType
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"cloneTyVarTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
newConcreteTyVar :: HasDebugCallStack => ConcreteTvOrigin
-> FastString -> TcKind -> TcM TcTyVar
newConcreteTyVar :: HasDebugCallStack =>
ConcreteTvOrigin
-> FastString -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newConcreteTyVar ConcreteTvOrigin
reason FastString
fs TcType
kind
= Bool
-> SDoc
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcType -> Bool
isConcreteType TcType
kind) SDoc
assert_msg (IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a b. (a -> b) -> a -> b
$
FastString
-> MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedAnonMetaTyVar FastString
fs (ConcreteTvOrigin -> MetaInfo
ConcreteTv ConcreteTvOrigin
reason) TcType
kind
where
assert_msg :: SDoc
assert_msg = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"newConcreteTyVar: non-concrete kind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
kind
newPatSigTyVar :: Name -> Kind -> TcM TcTyVar
newPatSigTyVar :: Name -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newPatSigTyVar Name
name TcType
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
TauTv
; Unique
uniq <- TcRnIf TcGblEnv TcLclEnv Unique
forall gbl lcl. TcRnIf gbl lcl Unique
newUnique
; let name' :: Name
name' = Name
name Name -> Unique -> Name
`setNameUnique` Unique
uniq
tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name' TcType
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"newPatSigTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
cloneAnonMetaTyVar :: MetaInfo -> TyVar -> TcKind -> TcM TcTyVar
cloneAnonMetaTyVar :: MetaInfo
-> TcTyVar -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneAnonMetaTyVar MetaInfo
info TcTyVar
tv TcType
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
info
; Name
name <- Name -> TcM Name
cloneMetaTyVarName (TcTyVar -> Name
tyVarName TcTyVar
tv)
; let tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"cloneAnonMetaTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TcTyVar -> TcType
tyVarKind TcTyVar
tyvar))
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
newCycleBreakerTyVar :: TcKind -> TcM TcTyVar
newCycleBreakerTyVar :: TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newCycleBreakerTyVar TcType
kind
= do { TcTyVarDetails
details <- MetaInfo -> TcM TcTyVarDetails
newMetaDetails MetaInfo
CycleBreakerTv
; Name
name <- FastString -> TcM Name
newMetaTyVarName (String -> FastString
fsLit String
"cbv")
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details) }
newMetaDetails :: MetaInfo -> TcM TcTyVarDetails
newMetaDetails :: MetaInfo -> TcM TcTyVarDetails
newMetaDetails 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 a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
info
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }) }
newTauTvDetailsAtLevel :: TcLevel -> TcM TcTyVarDetails
newTauTvDetailsAtLevel :: TcLevel -> TcM TcTyVarDetails
newTauTvDetailsAtLevel TcLevel
tclvl
= do { IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; TcTyVarDetails -> TcM TcTyVarDetails
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
TauTv
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }) }
newConcreteTvDetailsAtLevel :: ConcreteTvOrigin -> TcLevel -> TcM TcTyVarDetails
newConcreteTvDetailsAtLevel :: ConcreteTvOrigin -> TcLevel -> TcM TcTyVarDetails
newConcreteTvDetailsAtLevel ConcreteTvOrigin
conc_orig TcLevel
tclvl
= do { IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; TcTyVarDetails -> TcM TcTyVarDetails
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaTv { mtv_info :: MetaInfo
mtv_info = ConcreteTvOrigin -> MetaInfo
ConcreteTv ConcreteTvOrigin
conc_orig
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tclvl }) }
cloneMetaTyVar :: TcTyVar -> TcM TcTyVar
cloneMetaTyVar :: TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneMetaTyVar TcTyVar
tv
= Bool
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. HasCallStack => Bool -> a -> a
assert (TcTyVar -> Bool
isTcTyVar TcTyVar
tv) (IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a b. (a -> b) -> a -> b
$
do { IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; Name
name' <- Name -> TcM Name
cloneMetaTyVarName (TcTyVar -> Name
tyVarName TcTyVar
tv)
; let details' :: TcTyVarDetails
details' = case TcTyVar -> TcTyVarDetails
tcTyVarDetails TcTyVar
tv of
details :: TcTyVarDetails
details@(MetaTv {}) -> TcTyVarDetails
details { mtv_ref = ref }
TcTyVarDetails
_ -> String -> SDoc -> TcTyVarDetails
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"cloneMetaTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv)
tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name' (TcTyVar -> TcType
tyVarKind TcTyVar
tv) TcTyVarDetails
details'
; String -> SDoc -> TcRn ()
traceTc String
"cloneMetaTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
cloneMetaTyVarWithInfo :: MetaInfo -> TcLevel -> TcTyVar -> TcM TcTyVar
cloneMetaTyVarWithInfo :: MetaInfo
-> TcLevel -> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneMetaTyVarWithInfo MetaInfo
info TcLevel
tc_lvl TcTyVar
tv
= Bool
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. HasCallStack => Bool -> a -> a
assert (TcTyVar -> Bool
isTcTyVar TcTyVar
tv) (IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a b. (a -> b) -> a -> b
$
do { IORef MetaDetails
ref <- MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) (IORef MetaDetails)
forall a env. a -> IOEnv env (IORef a)
newMutVar MetaDetails
Flexi
; Name
name' <- Name -> TcM Name
cloneMetaTyVarName (TcTyVar -> Name
tyVarName TcTyVar
tv)
; let details :: TcTyVarDetails
details = MetaTv { mtv_info :: MetaInfo
mtv_info = MetaInfo
info
, mtv_ref :: IORef MetaDetails
mtv_ref = IORef MetaDetails
ref
, mtv_tclvl :: TcLevel
mtv_tclvl = TcLevel
tc_lvl }
tyvar :: TcTyVar
tyvar = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name' (TcTyVar -> TcType
tyVarKind TcTyVar
tv) TcTyVarDetails
details
; String -> SDoc -> TcRn ()
traceTc String
"cloneMetaTyVarWithInfo" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar)
; TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
tyvar }
readMetaTyVar :: MonadIO m => TyVar -> m MetaDetails
readMetaTyVar :: forall (m :: * -> *). MonadIO m => TcTyVar -> m MetaDetails
readMetaTyVar TcTyVar
tyvar = Bool -> SDoc -> m MetaDetails -> m MetaDetails
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcTyVar -> Bool
isMetaTyVar TcTyVar
tyvar) (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tyvar) (m MetaDetails -> m MetaDetails) -> m MetaDetails -> m MetaDetails
forall a b. (a -> b) -> a -> b
$
IO MetaDetails -> m MetaDetails
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MetaDetails -> m MetaDetails)
-> IO MetaDetails -> m MetaDetails
forall a b. (a -> b) -> a -> b
$ IORef MetaDetails -> IO MetaDetails
forall a. IORef a -> IO a
readIORef (TcTyVar -> IORef MetaDetails
metaTyVarRef TcTyVar
tyvar)
{-# SPECIALISE readMetaTyVar :: TyVar -> TcM MetaDetails #-}
{-# SPECIALISE readMetaTyVar :: TyVar -> ZonkM MetaDetails #-}
isFilledMetaTyVar_maybe :: TcTyVar -> TcM (Maybe Type)
isFilledMetaTyVar_maybe :: TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
isFilledMetaTyVar_maybe TcTyVar
tv
| TcTyVar -> Bool
isTcTyVar TcTyVar
tv
, MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref } <- TcTyVar -> TcTyVarDetails
tcTyVarDetails TcTyVar
tv
= do { MetaDetails
cts <- IORef MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) MetaDetails
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
readTcRef IORef MetaDetails
ref
; case MetaDetails
cts of
Indirect TcType
ty -> Maybe TcType -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> Maybe TcType
forall a. a -> Maybe a
Just TcType
ty)
MetaDetails
Flexi -> Maybe TcType -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TcType
forall a. Maybe a
Nothing }
| Bool
otherwise
= Maybe TcType -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TcType
forall a. Maybe a
Nothing
isFilledMetaTyVar :: TyVar -> TcM Bool
isFilledMetaTyVar :: TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
isFilledMetaTyVar TcTyVar
tv = Maybe TcType -> Bool
forall a. Maybe a -> Bool
isJust (Maybe TcType -> Bool)
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
-> TcRnIf TcGblEnv TcLclEnv Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
isFilledMetaTyVar_maybe TcTyVar
tv
isUnfilledMetaTyVar :: TyVar -> TcM Bool
isUnfilledMetaTyVar :: TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
isUnfilledMetaTyVar TcTyVar
tv
| MetaTv { mtv_ref :: TcTyVarDetails -> IORef MetaDetails
mtv_ref = IORef MetaDetails
ref } <- TcTyVar -> TcTyVarDetails
tcTyVarDetails TcTyVar
tv
= do { MetaDetails
details <- IORef MetaDetails -> IOEnv (Env TcGblEnv TcLclEnv) MetaDetails
forall a env. IORef a -> IOEnv env a
readMutVar IORef MetaDetails
ref
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaDetails -> Bool
isFlexi MetaDetails
details) }
| Bool
otherwise = Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
newMultiplicityVar :: TcM TcType
newMultiplicityVar :: TcM TcType
newMultiplicityVar = TcType -> TcM TcType
newFlexiTyVarTy TcType
multiplicityTy
newFlexiTyVar :: Kind -> TcM TcTyVar
newFlexiTyVar :: TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newFlexiTyVar TcType
kind = MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newAnonMetaTyVar MetaInfo
TauTv TcType
kind
newNamedFlexiTyVar :: FastString -> Kind -> TcM TcTyVar
newNamedFlexiTyVar :: FastString -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedFlexiTyVar FastString
fs TcType
kind = FastString
-> MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newNamedAnonMetaTyVar FastString
fs MetaInfo
TauTv TcType
kind
newFlexiTyVarTy :: Kind -> TcM TcType
newFlexiTyVarTy :: TcType -> TcM TcType
newFlexiTyVarTy TcType
kind = do
TcTyVar
tc_tyvar <- TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newFlexiTyVar TcType
kind
TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> TcType
mkTyVarTy TcTyVar
tc_tyvar)
newFlexiTyVarTys :: Int -> Kind -> TcM [TcType]
newFlexiTyVarTys :: Int -> TcType -> TcM [TcType]
newFlexiTyVarTys Int
n TcType
kind = Int -> TcM TcType -> TcM [TcType]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (TcType -> TcM TcType
newFlexiTyVarTy TcType
kind)
newOpenTypeKind :: TcM TcKind
newOpenTypeKind :: TcM TcType
newOpenTypeKind
= do { TcType
rr <- TcType -> TcM TcType
newFlexiTyVarTy TcType
runtimeRepTy
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> TcType
mkTYPEapp TcType
rr) }
newOpenFlexiTyVarTy :: TcM TcType
newOpenFlexiTyVarTy :: TcM TcType
newOpenFlexiTyVarTy
= do { TcTyVar
tv <- IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newOpenFlexiTyVar
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> TcType
mkTyVarTy TcTyVar
tv) }
newOpenFlexiTyVar :: TcM TcTyVar
newOpenFlexiTyVar :: IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newOpenFlexiTyVar
= do { TcType
kind <- TcM TcType
newOpenTypeKind
; TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newFlexiTyVar TcType
kind }
newOpenBoxedTypeKind :: TcM TcKind
newOpenBoxedTypeKind :: TcM TcType
newOpenBoxedTypeKind
= do { TcType
lev <- TcType -> TcM TcType
newFlexiTyVarTy (TyCon -> TcType
mkTyConTy TyCon
levityTyCon)
; let rr :: TcType
rr = TyCon -> [TcType] -> TcType
mkTyConApp TyCon
boxedRepDataConTyCon [TcType
lev]
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType -> TcType
mkTYPEapp TcType
rr) }
newMetaTyVars :: [TyVar] -> TcM (Subst, [TcTyVar])
newMetaTyVars :: [TcTyVar] -> TcM (Subst, [TcTyVar])
newMetaTyVars = Subst -> [TcTyVar] -> TcM (Subst, [TcTyVar])
newMetaTyVarsX Subst
emptySubst
newMetaTyVarsX :: Subst -> [TyVar] -> TcM (Subst, [TcTyVar])
newMetaTyVarsX :: Subst -> [TcTyVar] -> TcM (Subst, [TcTyVar])
newMetaTyVarsX Subst
subst = (Subst
-> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar))
-> Subst -> [TcTyVar] -> TcM (Subst, [TcTyVar])
forall (m :: * -> *) (t :: * -> *) acc x y.
(Monad m, Traversable t) =>
(acc -> x -> m (acc, y)) -> acc -> t x -> m (acc, t y)
mapAccumLM Subst -> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
newMetaTyVarX Subst
subst
newMetaTyVarX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
newMetaTyVarX :: Subst -> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
newMetaTyVarX = MetaInfo
-> Subst
-> TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
new_meta_tv_x MetaInfo
TauTv
newMetaTyVarTyVarX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
newMetaTyVarTyVarX :: Subst -> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
newMetaTyVarTyVarX = MetaInfo
-> Subst
-> TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
new_meta_tv_x MetaInfo
TyVarTv
newWildCardX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
newWildCardX :: Subst -> TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
newWildCardX Subst
subst TcTyVar
tv
= do { TcTyVar
new_tv <- MetaInfo -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
newAnonMetaTyVar MetaInfo
TauTv (HasDebugCallStack => Subst -> TcType -> TcType
Subst -> TcType -> TcType
substTy Subst
subst (TcTyVar -> TcType
tyVarKind TcTyVar
tv))
; (Subst, TcTyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Subst -> TcTyVar -> TcTyVar -> Subst
extendTvSubstWithClone Subst
subst TcTyVar
tv TcTyVar
new_tv, TcTyVar
new_tv) }
new_meta_tv_x :: MetaInfo -> Subst -> TyVar -> TcM (Subst, TcTyVar)
new_meta_tv_x :: MetaInfo
-> Subst
-> TcTyVar
-> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
new_meta_tv_x MetaInfo
info Subst
subst TcTyVar
tv
= do { TcTyVar
new_tv <- MetaInfo
-> TcTyVar -> TcType -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneAnonMetaTyVar MetaInfo
info TcTyVar
tv TcType
substd_kind
; let subst1 :: Subst
subst1 = Subst -> TcTyVar -> TcTyVar -> Subst
extendTvSubstWithClone Subst
subst TcTyVar
tv TcTyVar
new_tv
; (Subst, TcTyVar) -> IOEnv (Env TcGblEnv TcLclEnv) (Subst, TcTyVar)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Subst
subst1, TcTyVar
new_tv) }
where
substd_kind :: TcType
substd_kind = Subst -> TcType -> TcType
substTyUnchecked Subst
subst (TcTyVar -> TcType
tyVarKind TcTyVar
tv)
newMetaTyVarTyAtLevel :: TcLevel -> TcKind -> TcM TcType
newMetaTyVarTyAtLevel :: TcLevel -> TcType -> TcM TcType
newMetaTyVarTyAtLevel TcLevel
tc_lvl TcType
kind
= do { TcTyVarDetails
details <- TcLevel -> TcM TcTyVarDetails
newTauTvDetailsAtLevel TcLevel
tc_lvl
; Name
name <- FastString -> TcM Name
newMetaTyVarName (String -> FastString
fsLit String
"p")
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> TcType
mkTyVarTy (Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details)) }
newConcreteTyVarTyAtLevel :: ConcreteTvOrigin -> TcLevel -> TcKind -> TcM TcType
newConcreteTyVarTyAtLevel :: ConcreteTvOrigin -> TcLevel -> TcType -> TcM TcType
newConcreteTyVarTyAtLevel ConcreteTvOrigin
conc_orig TcLevel
tc_lvl TcType
kind
= do { TcTyVarDetails
details <- ConcreteTvOrigin -> TcLevel -> TcM TcTyVarDetails
newConcreteTvDetailsAtLevel ConcreteTvOrigin
conc_orig TcLevel
tc_lvl
; Name
name <- FastString -> TcM Name
newMetaTyVarName (String -> FastString
fsLit String
"c")
; TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> TcType
mkTyVarTy (Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
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 { 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 { 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
forall doc. IsLine doc => String -> doc
text String
"DV" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
braces ((SDoc -> SDoc) -> [SDoc] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SDoc -> SDoc
forall a. a -> a
id [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"dv_kvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
kvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"dv_tvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
tvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"dv_cvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> CoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoVarSet
cvs ])
isEmptyCandidates :: CandidatesQTvs -> Bool
isEmptyCandidates :: CandidatesQTvs -> Bool
isEmptyCandidates (DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs })
= DTyVarSet -> Bool
isEmptyDVarSet DTyVarSet
kvs Bool -> Bool -> Bool
&& DTyVarSet -> Bool
isEmptyDVarSet DTyVarSet
tvs
candidateVars :: CandidatesQTvs -> ([TcTyVar], [TcTyVar])
candidateVars :: CandidatesQTvs -> ([TcTyVar], [TcTyVar])
candidateVars (DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
dep_kv_set, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
nondep_tkv_set })
= ([TcTyVar]
dep_kvs, [TcTyVar]
nondep_tvs)
where
dep_kvs :: [TcTyVar]
dep_kvs = [TcTyVar] -> [TcTyVar]
scopedSort ([TcTyVar] -> [TcTyVar]) -> [TcTyVar] -> [TcTyVar]
forall a b. (a -> b) -> a -> b
$ DTyVarSet -> [TcTyVar]
dVarSetElems DTyVarSet
dep_kv_set
nondep_tvs :: [TcTyVar]
nondep_tvs = DTyVarSet -> [TcTyVar]
dVarSetElems (DTyVarSet
nondep_tkv_set DTyVarSet -> DTyVarSet -> DTyVarSet
`minusDVarSet` DTyVarSet
dep_kv_set)
candidateKindVars :: CandidatesQTvs -> TyVarSet
candidateKindVars :: CandidatesQTvs -> CoVarSet
candidateKindVars CandidatesQTvs
dvs = DTyVarSet -> CoVarSet
dVarSetToVarSet (CandidatesQTvs -> DTyVarSet
dv_kvs CandidatesQTvs
dvs)
delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs
delCandidates :: CandidatesQTvs -> [TcTyVar] -> 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 }) [TcTyVar]
vars
= DV { dv_kvs :: DTyVarSet
dv_kvs = DTyVarSet
kvs DTyVarSet -> [TcTyVar] -> DTyVarSet
`delDVarSetList` [TcTyVar]
vars
, dv_tvs :: DTyVarSet
dv_tvs = DTyVarSet
tvs DTyVarSet -> [TcTyVar] -> DTyVarSet
`delDVarSetList` [TcTyVar]
vars
, dv_cvs :: CoVarSet
dv_cvs = CoVarSet
cvs CoVarSet -> [TcTyVar] -> CoVarSet
`delVarSetList` [TcTyVar]
vars }
partitionCandidates :: CandidatesQTvs -> (TyVar -> Bool) -> (TyVarSet, CandidatesQTvs)
partitionCandidates :: CandidatesQTvs -> (TcTyVar -> Bool) -> (CoVarSet, CandidatesQTvs)
partitionCandidates dvs :: CandidatesQTvs
dvs@(DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs }) TcTyVar -> Bool
pred
= (CoVarSet
extracted, CandidatesQTvs
dvs { dv_kvs = rest_kvs, dv_tvs = rest_tvs })
where
(DTyVarSet
extracted_kvs, DTyVarSet
rest_kvs) = (TcTyVar -> Bool) -> DTyVarSet -> (DTyVarSet, DTyVarSet)
partitionDVarSet TcTyVar -> Bool
pred DTyVarSet
kvs
(DTyVarSet
extracted_tvs, DTyVarSet
rest_tvs) = (TcTyVar -> Bool) -> DTyVarSet -> (DTyVarSet, DTyVarSet)
partitionDVarSet TcTyVar -> Bool
pred DTyVarSet
tvs
extracted :: CoVarSet
extracted = DTyVarSet -> CoVarSet
dVarSetToVarSet DTyVarSet
extracted_kvs CoVarSet -> CoVarSet -> CoVarSet
`unionVarSet` DTyVarSet -> CoVarSet
dVarSetToVarSet DTyVarSet
extracted_tvs
candidateQTyVarsWithBinders :: [TyVar] -> Type -> TcM CandidatesQTvs
candidateQTyVarsWithBinders :: [TcTyVar] -> TcType -> TcM CandidatesQTvs
candidateQTyVarsWithBinders [TcTyVar]
bound_tvs TcType
ty
= do { CandidatesQTvs
kvs <- [TcType] -> TcM CandidatesQTvs
candidateQTyVarsOfKinds ((TcTyVar -> TcType) -> [TcTyVar] -> [TcType]
forall a b. (a -> b) -> [a] -> [b]
map TcTyVar -> TcType
tyVarKind [TcTyVar]
bound_tvs)
; TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; CandidatesQTvs
all_tvs <- TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
ty Bool
False TcLevel
cur_lvl CoVarSet
emptyVarSet CandidatesQTvs
kvs TcType
ty
; CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (CandidatesQTvs
all_tvs CandidatesQTvs -> [TcTyVar] -> CandidatesQTvs
`delCandidates` [TcTyVar]
bound_tvs) }
candidateQTyVarsOfType :: TcType
-> TcM CandidatesQTvs
candidateQTyVarsOfType :: TcType -> TcM CandidatesQTvs
candidateQTyVarsOfType TcType
ty
= do { TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
ty Bool
False TcLevel
cur_lvl CoVarSet
emptyVarSet CandidatesQTvs
forall a. Monoid a => a
mempty TcType
ty }
candidateQTyVarsOfTypes :: [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes :: [TcType] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes [TcType]
tys
= do { TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; (CandidatesQTvs -> TcType -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcType] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM (\CandidatesQTvs
acc TcType
ty -> TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
ty Bool
False TcLevel
cur_lvl CoVarSet
emptyVarSet CandidatesQTvs
acc TcType
ty)
CandidatesQTvs
forall a. Monoid a => a
mempty [TcType]
tys }
candidateQTyVarsOfKind :: TcKind
-> TcM CandidatesQTvs
candidateQTyVarsOfKind :: TcType -> TcM CandidatesQTvs
candidateQTyVarsOfKind TcType
ty
= do { TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
ty Bool
True TcLevel
cur_lvl CoVarSet
emptyVarSet CandidatesQTvs
forall a. Monoid a => a
mempty TcType
ty }
candidateQTyVarsOfKinds :: [TcKind]
-> TcM CandidatesQTvs
candidateQTyVarsOfKinds :: [TcType] -> TcM CandidatesQTvs
candidateQTyVarsOfKinds [TcType]
tys
= do { TcLevel
cur_lvl <- TcM TcLevel
getTcLevel
; (CandidatesQTvs -> TcType -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcType] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (\CandidatesQTvs
acc TcType
ty -> TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
ty Bool
True TcLevel
cur_lvl CoVarSet
emptyVarSet CandidatesQTvs
acc TcType
ty)
CandidatesQTvs
forall a. Monoid a => a
mempty [TcType]
tys }
collect_cand_qtvs
:: TcType
-> Bool
-> TcLevel
-> VarSet
-> CandidatesQTvs
-> Type
-> TcM CandidatesQTvs
collect_cand_qtvs :: TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
is_dep TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dvs TcType
ty
= CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dvs TcType
ty
where
is_bound :: TcTyVar -> Bool
is_bound TcTyVar
tv = TcTyVar
tv TcTyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
bound
go :: CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go :: CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv (AppTy TcType
t1 TcType
t2) = (CandidatesQTvs -> TcType -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcType] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcType
t1, TcType
t2]
go CandidatesQTvs
dv (TyConApp TyCon
tc [TcType]
tys) = CandidatesQTvs -> [TyConBinder] -> [TcType] -> TcM CandidatesQTvs
go_tc_args CandidatesQTvs
dv (TyCon -> [TyConBinder]
tyConBinders TyCon
tc) [TcType]
tys
go CandidatesQTvs
dv (FunTy FunTyFlag
_ TcType
w TcType
arg TcType
res) = (CandidatesQTvs -> TcType -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcType] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcType
w, TcType
arg, TcType
res]
go CandidatesQTvs
dv (LitTy {}) = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go CandidatesQTvs
dv (CastTy TcType
ty Coercion
co) = do { CandidatesQTvs
dv1 <- CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv TcType
ty
; TcType
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co TcType
orig_ty TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv1 Coercion
co }
go CandidatesQTvs
dv (CoercionTy Coercion
co) = TcType
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co TcType
orig_ty TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv Coercion
co
go CandidatesQTvs
dv (TyVarTy TcTyVar
tv)
| TcTyVar -> Bool
is_bound TcTyVar
tv = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise = do { Maybe TcType
m_contents <- TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TcType)
isFilledMetaTyVar_maybe TcTyVar
tv
; case Maybe TcType
m_contents of
Just TcType
ind_ty -> CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv TcType
ind_ty
Maybe TcType
Nothing -> CandidatesQTvs -> TcTyVar -> TcM CandidatesQTvs
go_tv CandidatesQTvs
dv TcTyVar
tv }
go CandidatesQTvs
dv (ForAllTy (Bndr TcTyVar
tv ForAllTyFlag
_) TcType
ty)
= do { CandidatesQTvs
dv1 <- TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv (TcTyVar -> TcType
tyVarKind TcTyVar
tv)
; TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
is_dep TcLevel
cur_lvl (CoVarSet
bound CoVarSet -> TcTyVar -> CoVarSet
`extendVarSet` TcTyVar
tv) CandidatesQTvs
dv1 TcType
ty }
go_tc_args :: CandidatesQTvs -> [TyConBinder] -> [TcType] -> TcM CandidatesQTvs
go_tc_args CandidatesQTvs
dv (TyConBinder
tc_bndr:[TyConBinder]
tc_bndrs) (TcType
ty:[TcType]
tys)
= do { CandidatesQTvs
dv1 <- TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty (Bool
is_dep Bool -> Bool -> Bool
|| TyConBinder -> Bool
isNamedTyConBinder TyConBinder
tc_bndr)
TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv TcType
ty
; CandidatesQTvs -> [TyConBinder] -> [TcType] -> TcM CandidatesQTvs
go_tc_args CandidatesQTvs
dv1 [TyConBinder]
tc_bndrs [TcType]
tys }
go_tc_args CandidatesQTvs
dv [TyConBinder]
_bndrs [TcType]
tys
= (CandidatesQTvs -> TcType -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [TcType] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> TcType -> TcM CandidatesQTvs
go CandidatesQTvs
dv [TcType]
tys
go_tv :: CandidatesQTvs -> TcTyVar -> TcM CandidatesQTvs
go_tv dv :: CandidatesQTvs
dv@(DV { dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
tvs }) TcTyVar
tv
| TcTyVar -> TcLevel
tcTyVarLevel TcTyVar
tv TcLevel -> TcLevel -> Bool
forall a. Ord a => a -> a -> Bool
<= TcLevel
cur_lvl
= CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| case TcTyVar -> TcTyVarDetails
tcTyVarDetails TcTyVar
tv of
SkolemTv SkolemInfo
_ TcLevel
lvl Bool
_ -> TcLevel
lvl TcLevel -> TcLevel -> Bool
forall a. Ord a => a -> a -> Bool
> TcLevel -> TcLevel
pushTcLevel TcLevel
cur_lvl
TcTyVarDetails
_ -> Bool
False
= CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| TcTyVar
tv TcTyVar -> DTyVarSet -> Bool
`elemDVarSet` DTyVarSet
kvs
= CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool -> Bool
not Bool
is_dep
, TcTyVar
tv TcTyVar -> DTyVarSet -> Bool
`elemDVarSet` DTyVarSet
tvs
= CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise
= do { TcType
tv_kind <- ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ TcType -> ZonkM TcType
zonkTcType (TcTyVar -> TcType
tyVarKind TcTyVar
tv)
; let tv_kind_vars :: CoVarSet
tv_kind_vars = TcType -> CoVarSet
tyCoVarsOfType TcType
tv_kind
; if | CoVarSet -> CoVarSet -> Bool
intersectsVarSet CoVarSet
bound CoVarSet
tv_kind_vars
-> do { String -> SDoc -> TcRn ()
traceTc String
"Naughty quantifier" (SDoc -> TcRn ()) -> SDoc -> TcRn ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
tv_kind
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bound:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
pprTyVars (CoVarSet -> [TcTyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
bound)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
pprTyVars (CoVarSet -> [TcTyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
tv_kind_vars) ]
; let escapees :: CoVarSet
escapees = CoVarSet -> CoVarSet -> CoVarSet
intersectVarSet CoVarSet
bound CoVarSet
tv_kind_vars
; TcType -> TcTyVar -> CoVarSet -> TcM CandidatesQTvs
forall a. TcType -> TcTyVar -> CoVarSet -> TcM a
naughtyQuantification TcType
orig_ty TcTyVar
tv CoVarSet
escapees }
| Bool
otherwise
-> do { let tv' :: TcTyVar
tv' = TcTyVar
tv TcTyVar -> TcType -> TcTyVar
`setTyVarKind` TcType
tv_kind
dv' :: CandidatesQTvs
dv' | Bool
is_dep = CandidatesQTvs
dv { dv_kvs = kvs `extendDVarSet` tv' }
| Bool
otherwise = CandidatesQTvs
dv { dv_tvs = tvs `extendDVarSet` tv' }
; TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv' TcType
tv_kind } }
collect_cand_qtvs_co :: TcType
-> TcLevel
-> VarSet
-> CandidatesQTvs -> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co :: TcType
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co TcType
orig_ty TcLevel
cur_lvl CoVarSet
bound = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co
where
go_co :: CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv (Refl TcType
ty) = TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv TcType
ty
go_co CandidatesQTvs
dv (GRefl Role
_ TcType
ty MCoercionN
mco) = do { CandidatesQTvs
dv1 <- TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv TcType
ty
; CandidatesQTvs -> MCoercionN -> TcM CandidatesQTvs
go_mco CandidatesQTvs
dv1 MCoercionN
mco }
go_co CandidatesQTvs
dv (TyConAppCo Role
_ TyCon
_ [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co CandidatesQTvs
dv (AppCo Coercion
co1 Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co CandidatesQTvs
dv (FunCo Role
_ FunTyFlag
_ FunTyFlag
_ Coercion
w Coercion
co1 Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
w, Coercion
co1, Coercion
co2]
go_co CandidatesQTvs
dv (AxiomInstCo CoAxiom Branched
_ Int
_ [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co CandidatesQTvs
dv (AxiomRuleCo CoAxiomRule
_ [Coercion]
cos) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion]
cos
go_co CandidatesQTvs
dv (UnivCo UnivCoProvenance
prov Role
_ TcType
t1 TcType
t2) = do { CandidatesQTvs
dv1 <- CandidatesQTvs -> UnivCoProvenance -> TcM CandidatesQTvs
go_prov CandidatesQTvs
dv UnivCoProvenance
prov
; CandidatesQTvs
dv2 <- TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv1 TcType
t1
; TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound CandidatesQTvs
dv2 TcType
t2 }
go_co CandidatesQTvs
dv (SymCo Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co CandidatesQTvs
dv (TransCo Coercion
co1 Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co CandidatesQTvs
dv (SelCo CoSel
_ Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co CandidatesQTvs
dv (LRCo LeftOrRight
_ Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co CandidatesQTvs
dv (InstCo Coercion
co1 Coercion
co2) = (CandidatesQTvs -> Coercion -> TcM CandidatesQTvs)
-> CandidatesQTvs -> [Coercion] -> TcM CandidatesQTvs
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv [Coercion
co1, Coercion
co2]
go_co CandidatesQTvs
dv (KindCo Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co CandidatesQTvs
dv (SubCo Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_co CandidatesQTvs
dv (HoleCo 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 Coercion
co -> CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
Maybe Coercion
Nothing -> CandidatesQTvs -> TcTyVar -> TcM CandidatesQTvs
go_cv CandidatesQTvs
dv (CoercionHole -> TcTyVar
coHoleCoVar CoercionHole
hole)
go_co CandidatesQTvs
dv (CoVarCo TcTyVar
cv) = CandidatesQTvs -> TcTyVar -> TcM CandidatesQTvs
go_cv CandidatesQTvs
dv TcTyVar
cv
go_co CandidatesQTvs
dv (ForAllCo TcTyVar
tcv Coercion
kind_co Coercion
co)
= do { CandidatesQTvs
dv1 <- CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
kind_co
; TcType
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> Coercion
-> TcM CandidatesQTvs
collect_cand_qtvs_co TcType
orig_ty TcLevel
cur_lvl (CoVarSet
bound CoVarSet -> TcTyVar -> CoVarSet
`extendVarSet` TcTyVar
tcv) CandidatesQTvs
dv1 Coercion
co }
go_mco :: CandidatesQTvs -> MCoercionN -> TcM CandidatesQTvs
go_mco CandidatesQTvs
dv MCoercionN
MRefl = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_mco CandidatesQTvs
dv (MCo Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov :: CandidatesQTvs -> UnivCoProvenance -> TcM CandidatesQTvs
go_prov CandidatesQTvs
dv (PhantomProv Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov CandidatesQTvs
dv (ProofIrrelProv Coercion
co) = CandidatesQTvs -> Coercion -> TcM CandidatesQTvs
go_co CandidatesQTvs
dv Coercion
co
go_prov CandidatesQTvs
dv (PluginProv String
_) = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_prov CandidatesQTvs
dv (CorePrepProv Bool
_) = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
go_cv :: CandidatesQTvs -> CoVar -> TcM CandidatesQTvs
go_cv :: CandidatesQTvs -> TcTyVar -> TcM CandidatesQTvs
go_cv dv :: CandidatesQTvs
dv@(DV { dv_cvs :: CandidatesQTvs -> CoVarSet
dv_cvs = CoVarSet
cvs }) TcTyVar
cv
| TcTyVar -> Bool
is_bound TcTyVar
cv = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| TcTyVar
cv TcTyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
cvs = CandidatesQTvs -> TcM CandidatesQTvs
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return CandidatesQTvs
dv
| Bool
otherwise = TcType
-> Bool
-> TcLevel
-> CoVarSet
-> CandidatesQTvs
-> TcType
-> TcM CandidatesQTvs
collect_cand_qtvs TcType
orig_ty Bool
True TcLevel
cur_lvl CoVarSet
bound
(CandidatesQTvs
dv { dv_cvs = cvs `extendVarSet` cv })
(TcTyVar -> TcType
idType TcTyVar
cv)
is_bound :: TcTyVar -> Bool
is_bound TcTyVar
tv = TcTyVar
tv TcTyVar -> CoVarSet -> Bool
`elemVarSet` CoVarSet
bound
quantifyTyVars :: SkolemInfo
-> NonStandardDefaultingStrategy
-> CandidatesQTvs
-> TcM [TcTyVar]
quantifyTyVars :: SkolemInfo
-> NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
quantifyTyVars SkolemInfo
skol_info NonStandardDefaultingStrategy
ns_strat CandidatesQTvs
dvs
| CandidatesQTvs -> Bool
isEmptyCandidates CandidatesQTvs
dvs
= do { String -> SDoc -> TcRn ()
traceTc String
"quantifyTyVars has nothing to quantify" SDoc
forall doc. IsOutput doc => doc
empty
; [TcTyVar] -> TcM [TcTyVar]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [] }
| Bool
otherwise
= do { String -> SDoc -> TcRn ()
traceTc String
"quantifyTyVars {"
( [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ns_strat =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> NonStandardDefaultingStrategy -> SDoc
forall a. Outputable a => a -> SDoc
ppr NonStandardDefaultingStrategy
ns_strat
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"dvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> CandidatesQTvs -> SDoc
forall a. Outputable a => a -> SDoc
ppr CandidatesQTvs
dvs ])
; [TcTyVar]
undefaulted <- NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
defaultTyVars NonStandardDefaultingStrategy
ns_strat CandidatesQTvs
dvs
; [TcTyVar]
final_qtvs <- ZonkM [TcTyVar] -> TcM [TcTyVar]
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM [TcTyVar] -> TcM [TcTyVar])
-> ZonkM [TcTyVar] -> TcM [TcTyVar]
forall a b. (a -> b) -> a -> b
$ (TcTyVar -> ZonkM (Maybe TcTyVar)) -> [TcTyVar] -> ZonkM [TcTyVar]
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM TcTyVar -> ZonkM (Maybe TcTyVar)
zonk_quant [TcTyVar]
undefaulted
; String -> SDoc -> TcRn ()
traceTc String
"quantifyTyVars }"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"undefaulted:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
pprTyVars [TcTyVar]
undefaulted
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"final_qtvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
pprTyVars [TcTyVar]
final_qtvs ])
; let co_vars :: [TcTyVar]
co_vars = (TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TcTyVar -> Bool
isCoVar [TcTyVar]
final_qtvs
; Bool -> SDoc -> TcRn ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
co_vars) ([TcTyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcTyVar]
co_vars)
; [TcTyVar] -> TcM [TcTyVar]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [TcTyVar]
final_qtvs }
where
zonk_quant :: TcTyVar -> ZonkM (Maybe TcTyVar)
zonk_quant TcTyVar
tkv
| Bool -> Bool
not (TcTyVar -> Bool
isTyVar TcTyVar
tkv)
= Maybe TcTyVar -> ZonkM (Maybe TcTyVar)
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe TcTyVar
forall a. Maybe a
Nothing
| Bool
otherwise
= TcTyVar -> Maybe TcTyVar
forall a. a -> Maybe a
Just (TcTyVar -> Maybe TcTyVar)
-> ZonkM TcTyVar -> ZonkM (Maybe TcTyVar)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseQuantifiedTyVar SkolemInfo
skol_info TcTyVar
tkv
isQuantifiableTv :: TcLevel
-> TcTyVar
-> Bool
isQuantifiableTv :: TcLevel -> TcTyVar -> Bool
isQuantifiableTv TcLevel
outer_tclvl TcTyVar
tcv
| TcTyVar -> Bool
isTcTyVar TcTyVar
tcv
= TcTyVar -> TcLevel
tcTyVarLevel TcTyVar
tcv TcLevel -> TcLevel -> Bool
forall a. Ord a => a -> a -> Bool
> TcLevel
outer_tclvl
| Bool
otherwise
= Bool
False
zonkAndSkolemise :: SkolemInfo -> TcTyCoVar -> ZonkM TcTyCoVar
zonkAndSkolemise :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar
zonkAndSkolemise SkolemInfo
skol_info TcTyVar
tyvar
| TcTyVar -> Bool
isTyVarTyVar TcTyVar
tyvar
= do { TcTyVar
zonked_tyvar <- HasDebugCallStack => TcTyVar -> ZonkM TcTyVar
TcTyVar -> ZonkM TcTyVar
zonkTcTyVarToTcTyVar TcTyVar
tyvar
; SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseQuantifiedTyVar SkolemInfo
skol_info TcTyVar
zonked_tyvar }
| Bool
otherwise
= Bool -> SDoc -> ZonkM TcTyVar -> ZonkM TcTyVar
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcTyVar -> Bool
isImmutableTyVar TcTyVar
tyvar Bool -> Bool -> Bool
|| TcTyVar -> Bool
isCoVar TcTyVar
tyvar) (TcTyVar -> SDoc
pprTyVar TcTyVar
tyvar) (ZonkM TcTyVar -> ZonkM TcTyVar) -> ZonkM TcTyVar -> ZonkM TcTyVar
forall a b. (a -> b) -> a -> b
$
TcTyVar -> ZonkM TcTyVar
zonkTyCoVarKind TcTyVar
tyvar
skolemiseQuantifiedTyVar :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseQuantifiedTyVar :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseQuantifiedTyVar SkolemInfo
skol_info TcTyVar
tv
= case TcTyVar -> TcTyVarDetails
tcTyVarDetails TcTyVar
tv of
MetaTv {} -> SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseUnboundMetaTyVar SkolemInfo
skol_info TcTyVar
tv
SkolemTv SkolemInfo
_ TcLevel
lvl Bool
_
-> do { TcType
kind <- TcType -> ZonkM TcType
zonkTcType (TcTyVar -> TcType
tyVarKind TcTyVar
tv)
; let details :: TcTyVarDetails
details = SkolemInfo -> TcLevel -> Bool -> TcTyVarDetails
SkolemTv SkolemInfo
skol_info TcLevel
lvl Bool
False
name :: Name
name = TcTyVar -> Name
tyVarName TcTyVar
tv
; TcTyVar -> ZonkM TcTyVar
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
name TcType
kind TcTyVarDetails
details) }
TcTyVarDetails
_other -> String -> SDoc -> ZonkM TcTyVar
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"skolemiseQuantifiedTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv)
defaultTyVar :: DefaultingStrategy
-> TcTyVar
-> TcM Bool
defaultTyVar :: DefaultingStrategy -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
defaultTyVar DefaultingStrategy
def_strat TcTyVar
tv
| Bool -> Bool
not (TcTyVar -> Bool
isMetaTyVar TcTyVar
tv)
Bool -> Bool -> Bool
|| TcTyVar -> Bool
isTyVarTyVar TcTyVar
tv
= Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| TcTyVar -> Bool
isRuntimeRepVar TcTyVar
tv
, Bool
default_ns_vars
= do { String -> SDoc -> TcRn ()
traceTc String
"Defaulting a RuntimeRep var to LiftedRep" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv)
; ZonkM () -> TcRn ()
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM () -> TcRn ()) -> ZonkM () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
tv TcType
liftedRepTy
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| TcTyVar -> Bool
isLevityVar TcTyVar
tv
, Bool
default_ns_vars
= do { String -> SDoc -> TcRn ()
traceTc String
"Defaulting a Levity var to Lifted" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv)
; ZonkM () -> TcRn ()
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM () -> TcRn ()) -> ZonkM () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
tv TcType
liftedDataConTy
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| TcTyVar -> Bool
isMultiplicityVar TcTyVar
tv
, Bool
default_ns_vars
= do { String -> SDoc -> TcRn ()
traceTc String
"Defaulting a Multiplicity var to Many" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv)
; ZonkM () -> TcRn ()
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM () -> TcRn ()) -> ZonkM () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
tv TcType
manyDataConTy
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| TcTyVar -> Bool
isConcreteTyVar TcTyVar
tv
= do { TcLevel
lvl <- TcM TcLevel
getTcLevel
; Bool
_ <- HasDebugCallStack =>
TcLevel -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
TcLevel -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
promoteMetaTyVarTo TcLevel
lvl TcTyVar
tv
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| DefaultingStrategy
DefaultKindVars <- DefaultingStrategy
def_strat
= TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
default_kind_var TcTyVar
tv
| Bool
otherwise
= Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
where
default_ns_vars :: Bool
default_ns_vars :: Bool
default_ns_vars = DefaultingStrategy -> Bool
defaultNonStandardTyVars DefaultingStrategy
def_strat
default_kind_var :: TyVar -> TcM Bool
default_kind_var :: TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
default_kind_var TcTyVar
kv
| TcType -> Bool
isLiftedTypeKind (TcTyVar -> TcType
tyVarKind TcTyVar
kv)
= do { String -> SDoc -> TcRn ()
traceTc String
"Defaulting a kind var to *" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
kv)
; ZonkM () -> TcRn ()
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM () -> TcRn ()) -> ZonkM () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
kv TcType
liftedTypeKind
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| Bool
otherwise
= do { TcRnMessage -> TcRn ()
addErr (TcRnMessage -> TcRn ()) -> TcRnMessage -> TcRn ()
forall a b. (a -> b) -> a -> b
$ TcTyVar -> TcType -> TcRnMessage
TcRnCannotDefaultKindVar TcTyVar
kv' (TcTyVar -> TcType
tyVarKind TcTyVar
kv')
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
}
where
(TidyEnv
_, TcTyVar
kv') = TidyEnv -> TcTyVar -> (TidyEnv, TcTyVar)
tidyOpenTyCoVar TidyEnv
emptyTidyEnv TcTyVar
kv
defaultTyVars :: NonStandardDefaultingStrategy
-> CandidatesQTvs
-> TcM [TcTyVar]
defaultTyVars :: NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
defaultTyVars NonStandardDefaultingStrategy
ns_strat CandidatesQTvs
dvs
= do { Bool
poly_kinds <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PolyKinds
; let
def_tvs, def_kvs :: DefaultingStrategy
def_tvs :: DefaultingStrategy
def_tvs = NonStandardDefaultingStrategy -> DefaultingStrategy
NonStandardDefaulting NonStandardDefaultingStrategy
ns_strat
def_kvs :: DefaultingStrategy
def_kvs | Bool
poly_kinds = DefaultingStrategy
def_tvs
| Bool
otherwise = DefaultingStrategy
DefaultKindVars
; [Bool]
defaulted_kvs <- (TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool)
-> [TcTyVar] -> IOEnv (Env TcGblEnv TcLclEnv) [Bool]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (DefaultingStrategy -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
defaultTyVar DefaultingStrategy
def_kvs) [TcTyVar]
dep_kvs
; [Bool]
defaulted_tvs <- (TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool)
-> [TcTyVar] -> IOEnv (Env TcGblEnv TcLclEnv) [Bool]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (DefaultingStrategy -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
defaultTyVar DefaultingStrategy
def_tvs) [TcTyVar]
nondep_tvs
; let undefaulted_kvs :: [TcTyVar]
undefaulted_kvs = [ TcTyVar
kv | (TcTyVar
kv, Bool
False) <- [TcTyVar]
dep_kvs [TcTyVar] -> [Bool] -> [(TcTyVar, Bool)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Bool]
defaulted_kvs ]
undefaulted_tvs :: [TcTyVar]
undefaulted_tvs = [ TcTyVar
tv | (TcTyVar
tv, Bool
False) <- [TcTyVar]
nondep_tvs [TcTyVar] -> [Bool] -> [(TcTyVar, Bool)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Bool]
defaulted_tvs ]
; [TcTyVar] -> TcM [TcTyVar]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TcTyVar]
undefaulted_kvs [TcTyVar] -> [TcTyVar] -> [TcTyVar]
forall a. [a] -> [a] -> [a]
++ [TcTyVar]
undefaulted_tvs) }
where
([TcTyVar]
dep_kvs, [TcTyVar]
nondep_tvs) = CandidatesQTvs -> ([TcTyVar], [TcTyVar])
candidateVars CandidatesQTvs
dvs
skolemiseUnboundMetaTyVar :: SkolemInfo -> TcTyVar -> ZonkM TyVar
skolemiseUnboundMetaTyVar :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar
skolemiseUnboundMetaTyVar SkolemInfo
skol_info TcTyVar
tv
= Bool -> SDoc -> ZonkM TcTyVar -> ZonkM TcTyVar
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcTyVar -> Bool
isMetaTyVar TcTyVar
tv) (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv) (ZonkM TcTyVar -> ZonkM TcTyVar) -> ZonkM TcTyVar -> ZonkM TcTyVar
forall a b. (a -> b) -> a -> b
$
do { TcTyVar -> ZonkM ()
forall {f :: * -> *}. MonadIO f => TcTyVar -> f ()
check_empty TcTyVar
tv
; ZonkGblEnv { zge_src_span :: ZonkGblEnv -> SrcSpan
zge_src_span = SrcSpan
here, zge_tc_level :: ZonkGblEnv -> TcLevel
zge_tc_level = TcLevel
tc_lvl }
<- ZonkM ZonkGblEnv
getZonkGblEnv
; TcType
kind <- TcType -> ZonkM TcType
zonkTcType (TcTyVar -> TcType
tyVarKind TcTyVar
tv)
; let tv_name :: Name
tv_name = TcTyVar -> Name
tyVarName TcTyVar
tv
final_name :: Name
final_name | Name -> Bool
isSystemName Name
tv_name
= Unique -> OccName -> SrcSpan -> Name
mkInternalName (Name -> Unique
nameUnique Name
tv_name)
(Name -> OccName
nameOccName Name
tv_name) SrcSpan
here
| Bool
otherwise
= Name
tv_name
details :: TcTyVarDetails
details = SkolemInfo -> TcLevel -> Bool -> TcTyVarDetails
SkolemTv SkolemInfo
skol_info (TcLevel -> TcLevel
pushTcLevel TcLevel
tc_lvl) Bool
False
final_tv :: TcTyVar
final_tv = Name -> TcType -> TcTyVarDetails -> TcTyVar
mkTcTyVar Name
final_name TcType
kind TcTyVarDetails
details
; String -> SDoc -> ZonkM ()
traceZonk String
"Skolemising" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
":=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
final_tv)
; HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
tv (TcTyVar -> TcType
mkTyVarTy TcTyVar
final_tv)
; TcTyVar -> ZonkM TcTyVar
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return TcTyVar
final_tv }
where
check_empty :: TcTyVar -> f ()
check_empty TcTyVar
tv
= Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (f () -> f ()) -> f () -> f ()
forall a b. (a -> b) -> a -> b
$
do { MetaDetails
cts <- TcTyVar -> f MetaDetails
forall (m :: * -> *). MonadIO m => TcTyVar -> m MetaDetails
readMetaTyVar TcTyVar
tv
; case MetaDetails
cts of
MetaDetails
Flexi -> () -> f ()
forall a. a -> f a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Indirect TcType
ty -> Bool -> String -> SDoc -> f () -> f ()
forall a. HasCallStack => Bool -> String -> SDoc -> a -> a
warnPprTrace Bool
True String
"skolemiseUnboundMetaTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
ty) (f () -> f ()) -> f () -> f ()
forall a b. (a -> b) -> a -> b
$
() -> f ()
forall a. a -> f a
forall (m :: * -> *) a. Monad m => a -> m a
return () }
doNotQuantifyTyVars :: CandidatesQTvs
-> (TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx))
-> TcM ()
doNotQuantifyTyVars :: CandidatesQTvs
-> (TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)) -> TcRn ()
doNotQuantifyTyVars CandidatesQTvs
dvs TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)
where_found
| CandidatesQTvs -> Bool
isEmptyCandidates CandidatesQTvs
dvs
= String -> SDoc -> TcRn ()
traceTc String
"doNotQuantifyTyVars has nothing to error on" SDoc
forall doc. IsOutput doc => doc
empty
| Bool
otherwise
= do { String -> SDoc -> TcRn ()
traceTc String
"doNotQuantifyTyVars" (CandidatesQTvs -> SDoc
forall a. Outputable a => a -> SDoc
ppr CandidatesQTvs
dvs)
; [TcTyVar]
undefaulted <- NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
defaultTyVars NonStandardDefaultingStrategy
DefaultNonStandardTyVars CandidatesQTvs
dvs
; let leftover_metas :: [TcTyVar]
leftover_metas = (TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TcTyVar -> Bool
isMetaTyVar [TcTyVar]
undefaulted
; Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
leftover_metas) (TcRn () -> TcRn ()) -> TcRn () -> TcRn ()
forall a b. (a -> b) -> a -> b
$
do { let (TidyEnv
tidy_env1, [TcTyVar]
tidied_tvs) = TidyEnv -> [TcTyVar] -> (TidyEnv, [TcTyVar])
tidyOpenTyCoVars TidyEnv
emptyTidyEnv [TcTyVar]
leftover_metas
; (TidyEnv
tidy_env2, UninferrableTyVarCtx
where_doc) <- ZonkM (TidyEnv, UninferrableTyVarCtx)
-> TcM (TidyEnv, UninferrableTyVarCtx)
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM (TidyEnv, UninferrableTyVarCtx)
-> TcM (TidyEnv, UninferrableTyVarCtx))
-> ZonkM (TidyEnv, UninferrableTyVarCtx)
-> TcM (TidyEnv, UninferrableTyVarCtx)
forall a b. (a -> b) -> a -> b
$ TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)
where_found TidyEnv
tidy_env1
; let msg :: TcRnMessage
msg = [TcTyVar] -> UninferrableTyVarCtx -> TcRnMessage
TcRnUninferrableTyVar [TcTyVar]
tidied_tvs UninferrableTyVarCtx
where_doc
; (TidyEnv, TcRnMessage) -> TcRn ()
forall a. (TidyEnv, TcRnMessage) -> TcM a
failWithTcM (TidyEnv
tidy_env2, TcRnMessage
msg) }
; String -> SDoc -> TcRn ()
traceTc String
"doNotQuantifyTyVars success" SDoc
forall doc. IsOutput doc => doc
empty }
tcCheckUsage :: Name -> Mult -> TcM a -> TcM (a, HsWrapper)
tcCheckUsage :: forall a. Name -> TcType -> TcM a -> TcM (a, HsWrapper)
tcCheckUsage Name
name TcType
id_mult TcM a
thing_inside
= do { (UsageEnv
local_usage, a
result) <- TcM a -> TcM (UsageEnv, a)
forall a. TcM a -> TcM (UsageEnv, a)
tcCollectingUsage TcM a
thing_inside
; HsWrapper
wrapper <- UsageEnv -> TcM HsWrapper
check_then_add_usage UsageEnv
local_usage
; (a, HsWrapper) -> TcM (a, HsWrapper)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
result, HsWrapper
wrapper) }
where
check_then_add_usage :: UsageEnv -> TcM HsWrapper
check_then_add_usage :: UsageEnv -> TcM HsWrapper
check_then_add_usage UsageEnv
uenv
= do { let actual_u :: Usage
actual_u = UsageEnv -> Name -> Usage
forall n. NamedThing n => UsageEnv -> n -> Usage
lookupUE UsageEnv
uenv Name
name
; String -> SDoc -> TcRn ()
traceTc String
"check_then_add_usage" (TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
id_mult SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Usage -> SDoc
forall a. Outputable a => a -> SDoc
ppr Usage
actual_u)
; HsWrapper
wrapper <- case Usage
actual_u of
Usage
Bottom -> HsWrapper -> TcM HsWrapper
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return HsWrapper
idHsWrapper
Usage
Zero -> CtOrigin -> TcType -> TcType -> TcM HsWrapper
tcSubMult (Name -> CtOrigin
UsageEnvironmentOf Name
name) TcType
ManyTy TcType
id_mult
MUsage TcType
m -> do { TcType
m <- TcType -> TcM TcType
promote_mult TcType
m
; CtOrigin -> TcType -> TcType -> TcM HsWrapper
tcSubMult (Name -> CtOrigin
UsageEnvironmentOf Name
name) TcType
m TcType
id_mult }
; UsageEnv -> TcRn ()
tcEmitBindingUsage (UsageEnv -> Name -> UsageEnv
forall n. NamedThing n => UsageEnv -> n -> UsageEnv
deleteUE UsageEnv
uenv Name
name)
; HsWrapper -> TcM HsWrapper
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return HsWrapper
wrapper }
promote_mult :: TcType -> TcM TcType
promote_mult TcType
m = do { CoVarSet
fvs <- ZonkM CoVarSet -> TcM CoVarSet
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM CoVarSet -> TcM CoVarSet) -> ZonkM CoVarSet -> TcM CoVarSet
forall a b. (a -> b) -> a -> b
$ CoVarSet -> ZonkM CoVarSet
zonkTyCoVarsAndFV (TcType -> CoVarSet
tyCoVarsOfType TcType
m)
; Bool
any_promoted <- HasDebugCallStack => CoVarSet -> TcRnIf TcGblEnv TcLclEnv Bool
CoVarSet -> TcRnIf TcGblEnv TcLclEnv Bool
promoteTyVarSet CoVarSet
fvs
; if Bool
any_promoted then ZonkM TcType -> TcM TcType
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM TcType -> TcM TcType) -> ZonkM TcType -> TcM TcType
forall a b. (a -> b) -> a -> b
$ TcType -> ZonkM TcType
zonkTcType TcType
m else TcType -> TcM TcType
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return TcType
m
}
tcShortCutLit :: HsOverLit GhcRn -> ExpRhoType -> TcM (Maybe (HsOverLit GhcTc))
tcShortCutLit :: HsOverLit GhcRn -> ExpType -> TcM (Maybe (HsOverLit GhcTc))
tcShortCutLit lit :: HsOverLit GhcRn
lit@(OverLit { ol_val :: forall p. HsOverLit p -> OverLitVal
ol_val = OverLitVal
val, ol_ext :: forall p. HsOverLit p -> XOverLit p
ol_ext = OverLitRn Bool
rebindable LIdP GhcRn
_}) ExpType
exp_res_ty
| Bool -> Bool
not Bool
rebindable
, Just TcType
res_ty <- ExpType -> Maybe TcType
checkingExpType_maybe ExpType
exp_res_ty
= do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
; case Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc)
shortCutLit Platform
platform OverLitVal
val TcType
res_ty of
Just HsExpr GhcTc
expr -> Maybe (HsOverLit GhcTc) -> TcM (Maybe (HsOverLit GhcTc))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (HsOverLit GhcTc) -> TcM (Maybe (HsOverLit GhcTc)))
-> Maybe (HsOverLit GhcTc) -> TcM (Maybe (HsOverLit GhcTc))
forall a b. (a -> b) -> a -> b
$ HsOverLit GhcTc -> Maybe (HsOverLit GhcTc)
forall a. a -> Maybe a
Just (HsOverLit GhcTc -> Maybe (HsOverLit GhcTc))
-> HsOverLit GhcTc -> Maybe (HsOverLit GhcTc)
forall a b. (a -> b) -> a -> b
$
HsOverLit GhcRn
lit { ol_ext = OverLitTc False expr res_ty }
Maybe (HsExpr GhcTc)
Nothing -> Maybe (HsOverLit GhcTc) -> TcM (Maybe (HsOverLit GhcTc))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HsOverLit GhcTc)
forall a. Maybe a
Nothing }
| Bool
otherwise
= Maybe (HsOverLit GhcTc) -> TcM (Maybe (HsOverLit GhcTc))
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HsOverLit GhcTc)
forall a. Maybe a
Nothing
shortCutLit :: Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc)
shortCutLit :: Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc)
shortCutLit Platform
platform OverLitVal
val TcType
res_ty
= case OverLitVal
val of
HsIntegral IntegralLit
int_lit -> IntegralLit -> Maybe (HsExpr GhcTc)
go_integral IntegralLit
int_lit
HsFractional FractionalLit
frac_lit -> FractionalLit -> Maybe (HsExpr GhcTc)
go_fractional FractionalLit
frac_lit
HsIsString SourceText
s FastString
src -> SourceText -> FastString -> Maybe (HsExpr GhcTc)
go_string SourceText
s FastString
src
where
go_integral :: IntegralLit -> Maybe (HsExpr GhcTc)
go_integral int :: IntegralLit
int@(IL SourceText
src Bool
neg Integer
i)
| TcType -> Bool
isIntTy TcType
res_ty Bool -> Bool -> Bool
&& Platform -> Integer -> Bool
platformInIntRange Platform
platform Integer
i
= HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcTc
EpAnn NoEpAnns
forall a. EpAnn a
noAnn (XHsInt GhcTc -> IntegralLit -> HsLit GhcTc
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt XHsInt GhcTc
NoExtField
noExtField IntegralLit
int))
| TcType -> Bool
isWordTy TcType
res_ty Bool -> Bool -> Bool
&& Platform -> Integer -> Bool
platformInWordRange Platform
platform Integer
i
= HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
wordDataCon (XHsWordPrim GhcTc -> Integer -> HsLit GhcTc
forall x. XHsWordPrim x -> Integer -> HsLit x
HsWordPrim XHsWordPrim GhcTc
SourceText
src Integer
i))
| TcType -> Bool
isIntegerTy TcType
res_ty
= HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcTc
EpAnn NoEpAnns
forall a. EpAnn a
noAnn (XHsInteger GhcTc -> Integer -> TcType -> HsLit GhcTc
forall x. XHsInteger x -> Integer -> TcType -> HsLit x
HsInteger XHsInteger GhcTc
SourceText
src Integer
i TcType
res_ty))
| Bool
otherwise
= FractionalLit -> Maybe (HsExpr GhcTc)
go_fractional (Bool -> Integer -> FractionalLit
integralFractionalLit Bool
neg Integer
i)
go_fractional :: FractionalLit -> Maybe (HsExpr GhcTc)
go_fractional FractionalLit
f
| TcType -> Bool
isFloatTy TcType
res_ty Bool -> Bool -> Bool
&& Bool
valueInRange = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
floatDataCon (XHsFloatPrim GhcTc -> FractionalLit -> HsLit GhcTc
forall x. XHsFloatPrim x -> FractionalLit -> HsLit x
HsFloatPrim XHsFloatPrim GhcTc
NoExtField
noExtField FractionalLit
f))
| TcType -> Bool
isDoubleTy TcType
res_ty Bool -> Bool -> Bool
&& Bool
valueInRange = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
doubleDataCon (XHsDoublePrim GhcTc -> FractionalLit -> HsLit GhcTc
forall x. XHsDoublePrim x -> FractionalLit -> HsLit x
HsDoublePrim XHsDoublePrim GhcTc
NoExtField
noExtField FractionalLit
f))
| Bool
otherwise = Maybe (HsExpr GhcTc)
forall a. Maybe a
Nothing
where
valueInRange :: Bool
valueInRange =
case FractionalLit
f of
FL { fl_exp :: FractionalLit -> Integer
fl_exp = Integer
e } -> (-Integer
100) Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
e Bool -> Bool -> Bool
&& Integer
e Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
100
go_string :: SourceText -> FastString -> Maybe (HsExpr GhcTc)
go_string SourceText
src FastString
s
| TcType -> Bool
isStringTy TcType
res_ty = HsExpr GhcTc -> Maybe (HsExpr GhcTc)
forall a. a -> Maybe a
Just (XLitE GhcTc -> HsLit GhcTc -> HsExpr GhcTc
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcTc
EpAnn NoEpAnns
forall a. EpAnn a
noAnn (XHsString GhcTc -> FastString -> HsLit GhcTc
forall x. XHsString x -> FastString -> HsLit x
HsString XHsString GhcTc
SourceText
src FastString
s))
| Bool
otherwise = Maybe (HsExpr GhcTc)
forall a. Maybe a
Nothing
mkLit :: DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit :: DataCon -> HsLit GhcTc -> HsExpr GhcTc
mkLit DataCon
con HsLit GhcTc
lit = XApp GhcTc -> LHsExpr GhcTc -> LHsExpr GhcTc -> HsExpr GhcTc
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp GhcTc
EpAnn NoEpAnns
noComments (DataCon -> LHsExpr GhcTc
nlHsDataCon DataCon
con) (HsLit GhcTc -> LHsExpr GhcTc
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit HsLit GhcTc
lit)
hsOverLitName :: OverLitVal -> Name
hsOverLitName :: OverLitVal -> Name
hsOverLitName (HsIntegral {}) = Name
fromIntegerName
hsOverLitName (HsFractional {}) = Name
fromRationalName
hsOverLitName (HsIsString {}) = Name
fromStringName
promoteMetaTyVarTo :: HasDebugCallStack => TcLevel -> TcTyVar -> TcM Bool
promoteMetaTyVarTo :: HasDebugCallStack =>
TcLevel -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
promoteMetaTyVarTo TcLevel
tclvl TcTyVar
tv
| Bool -> SDoc -> Bool -> Bool
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TcTyVar -> Bool
isMetaTyVar TcTyVar
tv) (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv) (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
TcTyVar -> TcLevel
tcTyVarLevel TcTyVar
tv TcLevel -> TcLevel -> Bool
`strictlyDeeperThan` TcLevel
tclvl
= do { TcTyVar
cloned_tv <- TcTyVar -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
cloneMetaTyVar TcTyVar
tv
; let rhs_tv :: TcTyVar
rhs_tv = TcTyVar -> TcLevel -> TcTyVar
setMetaTyVarTcLevel TcTyVar
cloned_tv TcLevel
tclvl
; ZonkM () -> TcRn ()
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM () -> TcRn ()) -> ZonkM () -> TcRn ()
forall a b. (a -> b) -> a -> b
$ HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
TcTyVar -> TcType -> ZonkM ()
writeMetaTyVar TcTyVar
tv (TcTyVar -> TcType
mkTyVarTy TcTyVar
rhs_tv)
; String -> SDoc -> TcRn ()
traceTc String
"promoteTyVar" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
tv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-->" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
rhs_tv)
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| Bool
otherwise
= Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
promoteTyVarSet :: HasDebugCallStack => TcTyVarSet -> TcM Bool
promoteTyVarSet :: HasDebugCallStack => CoVarSet -> TcRnIf TcGblEnv TcLclEnv Bool
promoteTyVarSet CoVarSet
tvs
= do { TcLevel
tclvl <- TcM TcLevel
getTcLevel
; [Bool]
bools <- (TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool)
-> [TcTyVar] -> IOEnv (Env TcGblEnv TcLclEnv) [Bool]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (HasDebugCallStack =>
TcLevel -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
TcLevel -> TcTyVar -> TcRnIf TcGblEnv TcLclEnv Bool
promoteMetaTyVarTo TcLevel
tclvl) ([TcTyVar] -> IOEnv (Env TcGblEnv TcLclEnv) [Bool])
-> [TcTyVar] -> IOEnv (Env TcGblEnv TcLclEnv) [Bool]
forall a b. (a -> b) -> a -> b
$
(TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TcTyVar -> Bool
isPromotableMetaTyVar ([TcTyVar] -> [TcTyVar]) -> [TcTyVar] -> [TcTyVar]
forall a b. (a -> b) -> a -> b
$
CoVarSet -> [TcTyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
tvs
; Bool -> TcRnIf TcGblEnv TcLclEnv Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
bools) }
checkTypeHasFixedRuntimeRep :: FixedRuntimeRepProvenance -> Type -> TcM ()
checkTypeHasFixedRuntimeRep :: FixedRuntimeRepProvenance -> TcType -> TcRn ()
checkTypeHasFixedRuntimeRep FixedRuntimeRepProvenance
prov TcType
ty =
Bool -> TcRn () -> TcRn ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (HasDebugCallStack => TcType -> Bool
TcType -> Bool
typeHasFixedRuntimeRep TcType
ty)
((ErrInfo -> TcRnMessage) -> TcRn ()
addDetailedDiagnostic ((ErrInfo -> TcRnMessage) -> TcRn ())
-> (ErrInfo -> TcRnMessage) -> TcRn ()
forall a b. (a -> b) -> a -> b
$ TcType -> FixedRuntimeRepProvenance -> ErrInfo -> TcRnMessage
TcRnTypeDoesNotHaveFixedRuntimeRep TcType
ty FixedRuntimeRepProvenance
prov)
naughtyQuantification :: TcType
-> TcTyVar
-> TyVarSet
-> TcM a
naughtyQuantification :: forall a. TcType -> TcTyVar -> CoVarSet -> TcM a
naughtyQuantification TcType
orig_ty TcTyVar
tv CoVarSet
escapees
= do { (TcType
orig_ty1, [TcTyVar]
escapees') <- ZonkM (TcType, [TcTyVar]) -> TcM (TcType, [TcTyVar])
forall a. ZonkM a -> TcM a
liftZonkM (ZonkM (TcType, [TcTyVar]) -> TcM (TcType, [TcTyVar]))
-> ZonkM (TcType, [TcTyVar]) -> TcM (TcType, [TcTyVar])
forall a b. (a -> b) -> a -> b
$
do { TcType
orig_ty1 <- TcType -> ZonkM TcType
zonkTcType TcType
orig_ty
; [TcTyVar]
escapees' <- [TcTyVar] -> ZonkM [TcTyVar]
HasDebugCallStack => [TcTyVar] -> ZonkM [TcTyVar]
zonkTcTyVarsToTcTyVars ([TcTyVar] -> ZonkM [TcTyVar]) -> [TcTyVar] -> ZonkM [TcTyVar]
forall a b. (a -> b) -> a -> b
$
CoVarSet -> [TcTyVar]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet CoVarSet
escapees
; (TcType, [TcTyVar]) -> ZonkM (TcType, [TcTyVar])
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcType
orig_ty1, [TcTyVar]
escapees') }
; let fvs :: [TcTyVar]
fvs = TcType -> [TcTyVar]
tyCoVarsOfTypeWellScoped TcType
orig_ty1
env0 :: TidyEnv
env0 = TidyEnv -> [TcTyVar] -> TidyEnv
tidyFreeTyCoVars TidyEnv
emptyTidyEnv [TcTyVar]
fvs
env :: TidyEnv
env = TidyEnv
env0 TidyEnv -> [TcTyVar] -> TidyEnv
`delTidyEnvList` [TcTyVar]
escapees'
orig_ty' :: TcType
orig_ty' = TidyEnv -> TcType -> TcType
tidyType TidyEnv
env TcType
orig_ty1
tidied :: [TcTyVar]
tidied = (TcTyVar -> TcTyVar) -> [TcTyVar] -> [TcTyVar]
forall a b. (a -> b) -> [a] -> [b]
map (TidyEnv -> TcTyVar -> TcTyVar
tidyTyCoVarOcc TidyEnv
env) [TcTyVar]
escapees'
msg :: TcRnMessage
msg = [TcTyVar] -> TcTyVar -> TcType -> TcRnMessage
TcRnSkolemEscape [TcTyVar]
tidied (TidyEnv -> TcTyVar -> TcTyVar
tidyTyCoVarOcc TidyEnv
env TcTyVar
tv) TcType
orig_ty'
; (TidyEnv, TcRnMessage) -> TcM a
forall a. (TidyEnv, TcRnMessage) -> TcM a
failWithTcM (TidyEnv
env, TcRnMessage
msg) }