{-# LANGUAGE MultiWayIf, RecursiveDo, TupleSections #-}
module GHC.Tc.Solver(
InferMode(..), simplifyInfer, findInferredDiff,
growThetaTyVars,
simplifyAmbiguityCheck,
simplifyDefault,
simplifyTop, simplifyTopImplic,
simplifyInteractive,
solveEqualities,
pushLevelAndSolveEqualities, pushLevelAndSolveEqualitiesX,
reportUnsolvedEqualities,
simplifyWantedsTcM,
tcCheckGivens,
tcCheckWanteds,
tcNormalise,
captureTopConstraints,
simplifyTopWanteds,
promoteTyVarSet, simplifyAndEmitFlatConstraints,
solveWanteds,
approximateWC
) where
import GHC.Prelude
import GHC.Data.Bag
import GHC.Core.Class
import GHC.Core
import GHC.Core.DataCon
import GHC.Core.Make
import GHC.Driver.DynFlags
import GHC.Data.FastString
import GHC.Data.List.SetOps
import GHC.Types.Name
import GHC.Types.Id
import GHC.Utils.Outputable
import GHC.Builtin.Utils
import GHC.Builtin.Names
import GHC.Tc.Errors
import GHC.Tc.Errors.Types
import GHC.Tc.Types.Evidence
import GHC.Tc.Solver.Solve ( solveSimpleGivens, solveSimpleWanteds )
import GHC.Tc.Solver.Dict ( makeSuperClasses, solveCallStack )
import GHC.Tc.Solver.Rewrite ( rewriteType )
import GHC.Tc.Utils.Unify ( buildTvImplication )
import GHC.Tc.Utils.TcMType as TcM
import GHC.Tc.Utils.Monad as TcM
import GHC.Tc.Zonk.TcType as TcM
import GHC.Tc.Solver.InertSet
import GHC.Tc.Solver.Monad as TcS
import GHC.Tc.Types.Constraint
import GHC.Tc.Instance.FunDeps
import GHC.Core.Predicate
import GHC.Tc.Types.Origin
import GHC.Tc.Utils.TcType
import GHC.Core.Type
import GHC.Core.Ppr
import GHC.Core.TyCon ( TyConBinder, isTypeFamilyTyCon )
import GHC.Builtin.Types
import GHC.Core.Unify ( tcMatchTyKi )
import GHC.Unit.Module ( getModule )
import GHC.Utils.Misc
import GHC.Utils.Panic
import GHC.Types.Var
import GHC.Types.Var.Set
import GHC.Types.Basic
import GHC.Types.Id.Make ( unboxedUnitExpr )
import GHC.Types.Error
import qualified GHC.LanguageExtensions as LangExt
import Control.Monad
import Control.Monad.Trans.Class ( lift )
import Control.Monad.Trans.State.Strict ( StateT(runStateT), put )
import Data.Foldable ( toList )
import Data.List ( partition )
import Data.List.NonEmpty ( NonEmpty(..) )
import GHC.Data.Maybe ( mapMaybe )
captureTopConstraints :: TcM a -> TcM (a, WantedConstraints)
captureTopConstraints :: forall a. TcM a -> TcM (a, WantedConstraints)
captureTopConstraints TcM a
thing_inside
= do { TcRef WantedConstraints
static_wc_var <- WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) (TcRef WantedConstraints)
forall (m :: * -> *) a. MonadIO m => a -> m (TcRef a)
TcM.newTcRef WantedConstraints
emptyWC ;
; (Maybe a
mb_res, WantedConstraints
lie) <- (TcGblEnv -> TcGblEnv)
-> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
-> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
TcM.updGblEnv (\TcGblEnv
env -> TcGblEnv
env { tcg_static_wc = static_wc_var } ) (TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
-> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints))
-> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
-> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
forall a b. (a -> b) -> a -> b
$
TcM a -> TcRnIf TcGblEnv TcLclEnv (Maybe a, WantedConstraints)
forall a. TcM a -> TcM (Maybe a, WantedConstraints)
TcM.tryCaptureConstraints TcM a
thing_inside
; WantedConstraints
stWC <- TcRef WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
TcM.readTcRef TcRef WantedConstraints
static_wc_var
; case Maybe a
mb_res of
Just a
res -> (a, WantedConstraints) -> TcM (a, WantedConstraints)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
res, WantedConstraints
lie WantedConstraints -> WantedConstraints -> WantedConstraints
`andWC` WantedConstraints
stWC)
Maybe a
Nothing -> do { Bag EvBind
_ <- WantedConstraints -> TcM (Bag EvBind)
simplifyTop WantedConstraints
lie; TcM (a, WantedConstraints)
forall env a. IOEnv env a
failM } }
simplifyTopImplic :: Bag Implication -> TcM ()
simplifyTopImplic :: Bag Implication -> TcM ()
simplifyTopImplic Bag Implication
implics
= do { Bag EvBind
empty_binds <- WantedConstraints -> TcM (Bag EvBind)
simplifyTop (Bag Implication -> WantedConstraints
mkImplicWC Bag Implication
implics)
; Bool -> SDoc -> TcM ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr (Bag EvBind -> Bool
forall a. Bag a -> Bool
isEmptyBag Bag EvBind
empty_binds) (Bag EvBind -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bag EvBind
empty_binds)
; () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return () }
simplifyTop :: WantedConstraints -> TcM (Bag EvBind)
simplifyTop :: WantedConstraints -> TcM (Bag EvBind)
simplifyTop WantedConstraints
wanteds
= do { String -> SDoc -> TcM ()
traceTc String
"simplifyTop {" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wanted = " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanteds
; ((WantedConstraints
final_wc, Bag DictCt
unsafe_ol), EvBindMap
binds1) <- TcS (WantedConstraints, Bag DictCt)
-> TcM ((WantedConstraints, Bag DictCt), EvBindMap)
forall a. TcS a -> TcM (a, EvBindMap)
runTcS (TcS (WantedConstraints, Bag DictCt)
-> TcM ((WantedConstraints, Bag DictCt), EvBindMap))
-> TcS (WantedConstraints, Bag DictCt)
-> TcM ((WantedConstraints, Bag DictCt), EvBindMap)
forall a b. (a -> b) -> a -> b
$
do { WantedConstraints
final_wc <- WantedConstraints -> TcS WantedConstraints
simplifyTopWanteds WantedConstraints
wanteds
; Bag DictCt
unsafe_ol <- TcS (Bag DictCt)
getSafeOverlapFailures
; (WantedConstraints, Bag DictCt)
-> TcS (WantedConstraints, Bag DictCt)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
final_wc, Bag DictCt
unsafe_ol) }
; String -> SDoc -> TcM ()
traceTc String
"End simplifyTop }" SDoc
forall doc. IsOutput doc => doc
empty
; Bag EvBind
binds2 <- WantedConstraints -> TcM (Bag EvBind)
reportUnsolved WantedConstraints
final_wc
; String -> SDoc -> TcM ()
traceTc String
"reportUnsolved (unsafe overlapping) {" SDoc
forall doc. IsOutput doc => doc
empty
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bag DictCt -> Bool
forall a. Bag a -> Bool
isEmptyBag Bag DictCt
unsafe_ol) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ do {
; TcRef (Messages TcRnMessage)
errs_var <- TcRn (TcRef (Messages TcRnMessage))
getErrsVar
; Messages TcRnMessage
saved_msg <- TcRef (Messages TcRnMessage)
-> IOEnv (Env TcGblEnv TcLclEnv) (Messages TcRnMessage)
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
TcM.readTcRef TcRef (Messages TcRnMessage)
errs_var
; TcRef (Messages TcRnMessage) -> Messages TcRnMessage -> TcM ()
forall (m :: * -> *) a. MonadIO m => TcRef a -> a -> m ()
TcM.writeTcRef TcRef (Messages TcRnMessage)
errs_var Messages TcRnMessage
forall e. Messages e
emptyMessages
; WantedConstraints -> TcM ()
warnAllUnsolved (WantedConstraints -> TcM ()) -> WantedConstraints -> TcM ()
forall a b. (a -> b) -> a -> b
$ WantedConstraints
emptyWC { wc_simple = fmap CDictCan unsafe_ol }
; Bag (MsgEnvelope TcRnMessage)
whyUnsafe <- Messages TcRnMessage -> Bag (MsgEnvelope TcRnMessage)
forall e. Diagnostic e => Messages e -> Bag (MsgEnvelope e)
getWarningMessages (Messages TcRnMessage -> Bag (MsgEnvelope TcRnMessage))
-> IOEnv (Env TcGblEnv TcLclEnv) (Messages TcRnMessage)
-> IOEnv (Env TcGblEnv TcLclEnv) (Bag (MsgEnvelope TcRnMessage))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TcRef (Messages TcRnMessage)
-> IOEnv (Env TcGblEnv TcLclEnv) (Messages TcRnMessage)
forall (m :: * -> *) a. MonadIO m => TcRef a -> m a
TcM.readTcRef TcRef (Messages TcRnMessage)
errs_var
; TcRef (Messages TcRnMessage) -> Messages TcRnMessage -> TcM ()
forall (m :: * -> *) a. MonadIO m => TcRef a -> a -> m ()
TcM.writeTcRef TcRef (Messages TcRnMessage)
errs_var Messages TcRnMessage
saved_msg
; Messages TcRnMessage -> TcM ()
recordUnsafeInfer (Bag (MsgEnvelope TcRnMessage) -> Messages TcRnMessage
forall e. Bag (MsgEnvelope e) -> Messages e
mkMessages Bag (MsgEnvelope TcRnMessage)
whyUnsafe)
}
; String -> SDoc -> TcM ()
traceTc String
"reportUnsolved (unsafe overlapping) }" SDoc
forall doc. IsOutput doc => doc
empty
; Bag EvBind -> TcM (Bag EvBind)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (EvBindMap -> Bag EvBind
evBindMapBinds EvBindMap
binds1 Bag EvBind -> Bag EvBind -> Bag EvBind
forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag EvBind
binds2) }
pushLevelAndSolveEqualities :: SkolemInfoAnon -> [TyConBinder] -> TcM a -> TcM a
pushLevelAndSolveEqualities :: forall a. SkolemInfoAnon -> [TyConBinder] -> TcM a -> TcM a
pushLevelAndSolveEqualities SkolemInfoAnon
skol_info_anon [TyConBinder]
tcbs TcM a
thing_inside
= do { (TcLevel
tclvl, WantedConstraints
wanted, a
res) <- String -> TcM a -> TcM (TcLevel, WantedConstraints, a)
forall a. String -> TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndSolveEqualitiesX
String
"pushLevelAndSolveEqualities" TcM a
thing_inside
; SkolemInfoAnon
-> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM ()
report_unsolved_equalities SkolemInfoAnon
skol_info_anon ([TyConBinder] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [TyConBinder]
tcbs) TcLevel
tclvl WantedConstraints
wanted
; a -> TcM a
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res }
pushLevelAndSolveEqualitiesX :: String -> TcM a
-> TcM (TcLevel, WantedConstraints, a)
pushLevelAndSolveEqualitiesX :: forall a. String -> TcM a -> TcM (TcLevel, WantedConstraints, a)
pushLevelAndSolveEqualitiesX String
callsite TcM a
thing_inside
= do { String -> SDoc -> TcM ()
traceTc String
"pushLevelAndSolveEqualitiesX {" (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Called from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
callsite)
; (TcLevel
tclvl, (WantedConstraints
wanted, a
res))
<- TcM (WantedConstraints, a) -> TcM (TcLevel, (WantedConstraints, a))
forall a. TcM a -> TcM (TcLevel, a)
pushTcLevelM (TcM (WantedConstraints, a)
-> TcM (TcLevel, (WantedConstraints, a)))
-> TcM (WantedConstraints, a)
-> TcM (TcLevel, (WantedConstraints, a))
forall a b. (a -> b) -> a -> b
$
do { (a
res, WantedConstraints
wanted) <- TcM a -> TcM (a, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM a
thing_inside
; WantedConstraints
wanted <- TcS WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. TcS a -> TcM a
runTcSEqualities (WantedConstraints -> TcS WantedConstraints
simplifyTopWanteds WantedConstraints
wanted)
; (WantedConstraints, a) -> TcM (WantedConstraints, a)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanted,a
res) }
; String -> SDoc -> TcM ()
traceTc String
"pushLevelAndSolveEqualities }" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Residual:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanted
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Level:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
tclvl ])
; (TcLevel, WantedConstraints, a)
-> TcM (TcLevel, WantedConstraints, a)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcLevel
tclvl, WantedConstraints
wanted, a
res) }
solveEqualities :: String -> TcM a -> TcM a
solveEqualities :: forall a. String -> TcM a -> TcM a
solveEqualities String
callsite TcM a
thing_inside
= do { String -> SDoc -> TcM ()
traceTc String
"solveEqualities {" (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Called from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
callsite)
; (a
res, WantedConstraints
wanted) <- TcM a -> TcM (a, WantedConstraints)
forall a. TcM a -> TcM (a, WantedConstraints)
captureConstraints TcM a
thing_inside
; WantedConstraints -> TcM ()
simplifyAndEmitFlatConstraints WantedConstraints
wanted
; String -> SDoc -> TcM ()
traceTc String
"solveEqualities }" SDoc
forall doc. IsOutput doc => doc
empty
; a -> TcM a
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res }
simplifyAndEmitFlatConstraints :: WantedConstraints -> TcM ()
simplifyAndEmitFlatConstraints :: WantedConstraints -> TcM ()
simplifyAndEmitFlatConstraints WantedConstraints
wanted
= do {
WantedConstraints
wanted <- TcS WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. TcS a -> TcM a
runTcSEqualities (WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wanted)
; WantedConstraints
wanted <- ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> ZonkM WantedConstraints
TcM.zonkWC WantedConstraints
wanted
; String -> SDoc -> TcM ()
traceTc String
"emitFlatConstraints {" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanted)
; case WantedConstraints -> Maybe (Cts, Bag DelayedError)
floatKindEqualities WantedConstraints
wanted of
Maybe (Cts, Bag DelayedError)
Nothing -> do { String -> SDoc -> TcM ()
traceTc String
"emitFlatConstraints } failing" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanted)
; TcLevel
tclvl <- TcM TcLevel
TcM.getTcLevel
; Implication
implic <- SkolemInfoAnon
-> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM Implication
buildTvImplication SkolemInfoAnon
HasCallStack => SkolemInfoAnon
unkSkolAnon [] (TcLevel -> TcLevel
pushTcLevel TcLevel
tclvl) WantedConstraints
wanted
; Implication -> TcM ()
emitImplication Implication
implic
; TcM ()
forall env a. IOEnv env a
failM }
Just (Cts
simples, Bag DelayedError
errs)
-> do { Bool
_ <- HasDebugCallStack => VarSet -> TcM Bool
VarSet -> TcM Bool
promoteTyVarSet (Cts -> VarSet
tyCoVarsOfCts Cts
simples)
; String -> SDoc -> TcM ()
traceTc String
"emitFlatConstraints }" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"simples:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Cts -> SDoc
forall a. Outputable a => a -> SDoc
ppr Cts
simples
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"errs: " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bag DelayedError -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bag DelayedError
errs ]
; Bag DelayedError -> TcM ()
emitDelayedErrors Bag DelayedError
errs
; Cts -> TcM ()
emitSimples Cts
simples } }
floatKindEqualities :: WantedConstraints -> Maybe (Bag Ct, Bag DelayedError)
floatKindEqualities :: WantedConstraints -> Maybe (Cts, Bag DelayedError)
floatKindEqualities WantedConstraints
wc = VarSet -> WantedConstraints -> Maybe (Cts, Bag DelayedError)
float_wc VarSet
emptyVarSet WantedConstraints
wc
where
float_wc :: TcTyCoVarSet -> WantedConstraints -> Maybe (Bag Ct, Bag DelayedError)
float_wc :: VarSet -> WantedConstraints -> Maybe (Cts, Bag DelayedError)
float_wc VarSet
trapping_tvs (WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples
, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics
, wc_errors :: WantedConstraints -> Bag DelayedError
wc_errors = Bag DelayedError
errs })
| (Ct -> Bool) -> Cts -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Ct -> Bool
is_floatable Cts
simples
= do { (Cts
inner_simples, Bag DelayedError
inner_errs)
<- (Implication -> Maybe (Cts, Bag DelayedError))
-> Bag Implication -> Maybe (Cts, Bag DelayedError)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m (Bag b, Bag c)) -> Bag a -> m (Bag b, Bag c)
flatMapBagPairM (VarSet -> Implication -> Maybe (Cts, Bag DelayedError)
float_implic VarSet
trapping_tvs) Bag Implication
implics
; (Cts, Bag DelayedError) -> Maybe (Cts, Bag DelayedError)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ( Cts
simples Cts -> Cts -> Cts
forall a. Bag a -> Bag a -> Bag a
`unionBags` Cts
inner_simples
, Bag DelayedError
errs Bag DelayedError -> Bag DelayedError -> Bag DelayedError
forall a. Bag a -> Bag a -> Bag a
`unionBags` Bag DelayedError
inner_errs) }
| Bool
otherwise
= Maybe (Cts, Bag DelayedError)
forall a. Maybe a
Nothing
where
is_floatable :: Ct -> Bool
is_floatable Ct
ct
| Ct -> Bool
insolubleCt Ct
ct = Bool
False
| Bool
otherwise = Ct -> VarSet
tyCoVarsOfCt Ct
ct VarSet -> VarSet -> Bool
`disjointVarSet` VarSet
trapping_tvs
float_implic :: TcTyCoVarSet -> Implication -> Maybe (Bag Ct, Bag DelayedError)
float_implic :: VarSet -> Implication -> Maybe (Cts, Bag DelayedError)
float_implic VarSet
trapping_tvs (Implic { ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wanted, ic_given_eqs :: Implication -> HasGivenEqs
ic_given_eqs = HasGivenEqs
given_eqs
, ic_skols :: Implication -> [TcTyVar]
ic_skols = [TcTyVar]
skols, ic_status :: Implication -> ImplicStatus
ic_status = ImplicStatus
status })
| ImplicStatus -> Bool
isInsolubleStatus ImplicStatus
status
= Maybe (Cts, Bag DelayedError)
forall a. Maybe a
Nothing
| Bool
otherwise
= do { (Cts
simples, Bag DelayedError
holes) <- VarSet -> WantedConstraints -> Maybe (Cts, Bag DelayedError)
float_wc VarSet
new_trapping_tvs WantedConstraints
wanted
; Bool -> Maybe () -> Maybe ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (Cts -> Bool
forall a. Bag a -> Bool
isEmptyBag Cts
simples) Bool -> Bool -> Bool
&& HasGivenEqs
given_eqs HasGivenEqs -> HasGivenEqs -> Bool
forall a. Eq a => a -> a -> Bool
== HasGivenEqs
MaybeGivenEqs) (Maybe () -> Maybe ()) -> Maybe () -> Maybe ()
forall a b. (a -> b) -> a -> b
$
Maybe ()
forall a. Maybe a
Nothing
; (Cts, Bag DelayedError) -> Maybe (Cts, Bag DelayedError)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Cts
simples, Bag DelayedError
holes) }
where
new_trapping_tvs :: VarSet
new_trapping_tvs = VarSet
trapping_tvs VarSet -> [TcTyVar] -> VarSet
`extendVarSetList` [TcTyVar]
skols
reportUnsolvedEqualities :: SkolemInfo -> [TcTyVar] -> TcLevel
-> WantedConstraints -> TcM ()
reportUnsolvedEqualities :: SkolemInfo -> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM ()
reportUnsolvedEqualities SkolemInfo
skol_info [TcTyVar]
skol_tvs TcLevel
tclvl WantedConstraints
wanted
= SkolemInfoAnon
-> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM ()
report_unsolved_equalities (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
skol_info) [TcTyVar]
skol_tvs TcLevel
tclvl WantedConstraints
wanted
report_unsolved_equalities :: SkolemInfoAnon -> [TcTyVar] -> TcLevel
-> WantedConstraints -> TcM ()
report_unsolved_equalities :: SkolemInfoAnon
-> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM ()
report_unsolved_equalities SkolemInfoAnon
skol_info_anon [TcTyVar]
skol_tvs TcLevel
tclvl WantedConstraints
wanted
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanted
= () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= TcM () -> TcM ()
forall r. TcM r -> TcM r
checkNoErrs (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do { Implication
implic <- SkolemInfoAnon
-> [TcTyVar] -> TcLevel -> WantedConstraints -> TcM Implication
buildTvImplication SkolemInfoAnon
skol_info_anon [TcTyVar]
skol_tvs TcLevel
tclvl WantedConstraints
wanted
; WantedConstraints -> TcM ()
reportAllUnsolved (Bag Implication -> WantedConstraints
mkImplicWC (Implication -> Bag Implication
forall a. a -> Bag a
unitBag Implication
implic)) }
simplifyTopWanteds :: WantedConstraints -> TcS WantedConstraints
simplifyTopWanteds :: WantedConstraints -> TcS WantedConstraints
simplifyTopWanteds WantedConstraints
wanteds
= do { WantedConstraints
wc_first_go <- TcS WantedConstraints -> TcS WantedConstraints
forall a. TcS a -> TcS a
nestTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wanteds)
; DynFlags
dflags <- TcS DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; WantedConstraints
wc_defaulted <- DynFlags -> WantedConstraints -> TcS WantedConstraints
try_tyvar_defaulting DynFlags
dflags WantedConstraints
wc_first_go
; WantedConstraints -> TcS WantedConstraints
useUnsatisfiableGivens WantedConstraints
wc_defaulted }
where
try_tyvar_defaulting :: DynFlags -> WantedConstraints -> TcS WantedConstraints
try_tyvar_defaulting :: DynFlags -> WantedConstraints -> TcS WantedConstraints
try_tyvar_defaulting DynFlags
dflags WantedConstraints
wc
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wc
= WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc
| WantedConstraints -> Bool
insolubleWC WantedConstraints
wc
, GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_PrintExplicitRuntimeReps DynFlags
dflags
= WantedConstraints -> TcS WantedConstraints
try_class_defaulting WantedConstraints
wc
| Bool
otherwise
= do {
; [TcTyVar]
free_tvs <- [TcTyVar] -> TcS [TcTyVar]
TcS.zonkTyCoVarsAndFVList (WantedConstraints -> [TcTyVar]
tyCoVarsOfWCList WantedConstraints
wc)
; let defaultable_tvs :: [TcTyVar]
defaultable_tvs = (TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TcTyVar -> Bool
can_default [TcTyVar]
free_tvs
can_default :: TcTyVar -> Bool
can_default TcTyVar
tv
= TcTyVar -> Bool
isTyVar TcTyVar
tv
Bool -> Bool -> Bool
&& TcTyVar -> Bool
isMetaTyVar TcTyVar
tv
Bool -> Bool -> Bool
&& Bool -> Bool
not (TcTyVar
tv TcTyVar -> VarSet -> Bool
`elemVarSet` WantedConstraints -> VarSet
nonDefaultableTyVarsOfWC WantedConstraints
wc)
; [Bool]
defaulted <- (TcTyVar -> TcS Bool) -> [TcTyVar] -> TcS [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 TcTyVar -> TcS Bool
defaultTyVarTcS [TcTyVar]
defaultable_tvs
; if [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
defaulted
then do { WantedConstraints
wc_residual <- TcS WantedConstraints -> TcS WantedConstraints
forall a. TcS a -> TcS a
nestTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wc)
; WantedConstraints -> TcS WantedConstraints
try_class_defaulting WantedConstraints
wc_residual }
else WantedConstraints -> TcS WantedConstraints
try_class_defaulting WantedConstraints
wc }
try_class_defaulting :: WantedConstraints -> TcS WantedConstraints
try_class_defaulting :: WantedConstraints -> TcS WantedConstraints
try_class_defaulting WantedConstraints
wc
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wc Bool -> Bool -> Bool
|| WantedConstraints -> Bool
insolubleWC WantedConstraints
wc
= WantedConstraints -> TcS WantedConstraints
try_callstack_defaulting WantedConstraints
wc
| Bool
otherwise
= do { Bool
something_happened <- WantedConstraints -> TcS Bool
applyDefaultingRules WantedConstraints
wc
; if Bool
something_happened
then do { WantedConstraints
wc_residual <- TcS WantedConstraints -> TcS WantedConstraints
forall a. TcS a -> TcS a
nestTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wc)
; WantedConstraints -> TcS WantedConstraints
try_class_defaulting WantedConstraints
wc_residual }
else WantedConstraints -> TcS WantedConstraints
try_callstack_defaulting WantedConstraints
wc }
try_callstack_defaulting :: WantedConstraints -> TcS WantedConstraints
try_callstack_defaulting :: WantedConstraints -> TcS WantedConstraints
try_callstack_defaulting WantedConstraints
wc
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wc
= WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc
| Bool
otherwise
= WantedConstraints -> TcS WantedConstraints
defaultCallStacks WantedConstraints
wc
useUnsatisfiableGivens :: WantedConstraints -> TcS WantedConstraints
useUnsatisfiableGivens :: WantedConstraints -> TcS WantedConstraints
useUnsatisfiableGivens WantedConstraints
wc =
do { (WantedConstraints
final_wc, Bool
did_work) <- (StateT Bool TcS WantedConstraints
-> Bool -> TcS (WantedConstraints, Bool)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
`runStateT` Bool
False) (StateT Bool TcS WantedConstraints
-> TcS (WantedConstraints, Bool))
-> StateT Bool TcS WantedConstraints
-> TcS (WantedConstraints, Bool)
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> StateT Bool TcS WantedConstraints
go_wc WantedConstraints
wc
; if Bool
did_work
then TcS WantedConstraints -> TcS WantedConstraints
forall a. TcS a -> TcS a
nestTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
final_wc)
else WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
final_wc }
where
go_wc :: WantedConstraints -> StateT Bool TcS WantedConstraints
go_wc (WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
wtds, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
impls, wc_errors :: WantedConstraints -> Bag DelayedError
wc_errors = Bag DelayedError
errs })
= do Bag Implication
impls' <- (Implication -> StateT Bool TcS (Maybe Implication))
-> Bag Implication -> StateT Bool TcS (Bag Implication)
forall (m :: * -> *) a b.
Monad m =>
(a -> m (Maybe b)) -> Bag a -> m (Bag b)
mapMaybeBagM Implication -> StateT Bool TcS (Maybe Implication)
go_impl Bag Implication
impls
WantedConstraints -> StateT Bool TcS WantedConstraints
forall a. a -> StateT Bool TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints -> StateT Bool TcS WantedConstraints)
-> WantedConstraints -> StateT Bool TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$ WC { wc_simple :: Cts
wc_simple = Cts
wtds, wc_impl :: Bag Implication
wc_impl = Bag Implication
impls', wc_errors :: Bag DelayedError
wc_errors = Bag DelayedError
errs }
go_impl :: Implication -> StateT Bool TcS (Maybe Implication)
go_impl Implication
impl
| ImplicStatus -> Bool
isSolvedStatus (Implication -> ImplicStatus
ic_status Implication
impl)
= Maybe Implication -> StateT Bool TcS (Maybe Implication)
forall a. a -> StateT Bool TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Implication -> StateT Bool TcS (Maybe Implication))
-> Maybe Implication -> StateT Bool TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
impl
| (TcTyVar, Type)
unsat_given:[(TcTyVar, Type)]
_ <- (TcTyVar -> Maybe (TcTyVar, Type))
-> [TcTyVar] -> [(TcTyVar, Type)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe TcTyVar -> Maybe (TcTyVar, Type)
unsatisfiableEv_maybe (Implication -> [TcTyVar]
ic_given Implication
impl)
= do { Bool -> StateT Bool TcS ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put Bool
True
; TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication)
forall (m :: * -> *) a. Monad m => m a -> StateT Bool m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication))
-> TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ (TcTyVar, Type) -> Implication -> TcS (Maybe Implication)
solveImplicationUsingUnsatGiven (TcTyVar, Type)
unsat_given Implication
impl }
| Bool
otherwise
= do { WantedConstraints
wcs' <- WantedConstraints -> StateT Bool TcS WantedConstraints
go_wc (Implication -> WantedConstraints
ic_wanted Implication
impl)
; TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication)
forall (m :: * -> *) a. Monad m => m a -> StateT Bool m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication))
-> TcS (Maybe Implication) -> StateT Bool TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ Implication -> TcS (Maybe Implication)
setImplicationStatus (Implication -> TcS (Maybe Implication))
-> Implication -> TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ Implication
impl { ic_wanted = wcs' } }
unsatisfiableEv_maybe :: EvVar -> Maybe (EvVar, Type)
unsatisfiableEv_maybe :: TcTyVar -> Maybe (TcTyVar, Type)
unsatisfiableEv_maybe TcTyVar
v = (TcTyVar
v,) (Type -> (TcTyVar, Type)) -> Maybe Type -> Maybe (TcTyVar, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> Maybe Type
isUnsatisfiableCt_maybe (TcTyVar -> Type
idType TcTyVar
v)
solveImplicationUsingUnsatGiven :: (EvVar, Type) -> Implication -> TcS (Maybe Implication)
solveImplicationUsingUnsatGiven :: (TcTyVar, Type) -> Implication -> TcS (Maybe Implication)
solveImplicationUsingUnsatGiven
unsat_given :: (TcTyVar, Type)
unsat_given@(TcTyVar
given_ev,Type
_)
impl :: Implication
impl@(Implic { ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wtd, ic_tclvl :: Implication -> TcLevel
ic_tclvl = TcLevel
tclvl, ic_binds :: Implication -> EvBindsVar
ic_binds = EvBindsVar
ev_binds_var, ic_need_inner :: Implication -> VarSet
ic_need_inner = VarSet
inner })
| EvBindsVar -> Bool
isCoEvBindsVar EvBindsVar
ev_binds_var
= Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Implication -> TcS (Maybe Implication))
-> Maybe Implication -> TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
impl
| Bool
otherwise
= do { WantedConstraints
wcs <- EvBindsVar
-> TcLevel -> TcS WantedConstraints -> TcS WantedConstraints
forall a. EvBindsVar -> TcLevel -> TcS a -> TcS a
nestImplicTcS EvBindsVar
ev_binds_var TcLevel
tclvl (TcS WantedConstraints -> TcS WantedConstraints)
-> TcS WantedConstraints -> TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> TcS WantedConstraints
go_wc WantedConstraints
wtd
; Implication -> TcS (Maybe Implication)
setImplicationStatus (Implication -> TcS (Maybe Implication))
-> Implication -> TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$
Implication
impl { ic_wanted = wcs
, ic_need_inner = inner `extendVarSet` given_ev } }
where
go_wc :: WantedConstraints -> TcS WantedConstraints
go_wc :: WantedConstraints -> TcS WantedConstraints
go_wc wc :: WantedConstraints
wc@(WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
wtds, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
impls })
= do { (Ct -> TcS ()) -> Cts -> TcS ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> Bag a -> m ()
mapBagM_ Ct -> TcS ()
go_simple Cts
wtds
; Bag Implication
impls <- (Implication -> TcS (Maybe Implication))
-> Bag Implication -> TcS (Bag Implication)
forall (m :: * -> *) a b.
Monad m =>
(a -> m (Maybe b)) -> Bag a -> m (Bag b)
mapMaybeBagM ((TcTyVar, Type) -> Implication -> TcS (Maybe Implication)
solveImplicationUsingUnsatGiven (TcTyVar, Type)
unsat_given) Bag Implication
impls
; WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints -> TcS WantedConstraints)
-> WantedConstraints -> TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$ WantedConstraints
wc { wc_simple = emptyBag, wc_impl = impls } }
go_simple :: Ct -> TcS ()
go_simple :: Ct -> TcS ()
go_simple Ct
ct = case Ct -> CtEvidence
ctEvidence Ct
ct of
CtWanted { ctev_pred :: CtEvidence -> Type
ctev_pred = Type
pty, ctev_dest :: CtEvidence -> TcEvDest
ctev_dest = TcEvDest
dst }
-> do { EvExpr
ev_expr <- (TcTyVar, Type) -> Type -> TcS EvExpr
unsatisfiableEvExpr (TcTyVar, Type)
unsat_given Type
pty
; TcEvDest -> Bool -> EvTerm -> TcS ()
setWantedEvTerm TcEvDest
dst Bool
True (EvTerm -> TcS ()) -> EvTerm -> TcS ()
forall a b. (a -> b) -> a -> b
$ EvExpr -> EvTerm
EvExpr EvExpr
ev_expr }
CtEvidence
_ -> () -> TcS ()
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
unsatisfiableEvExpr :: (EvVar, ErrorMsgType) -> PredType -> TcS EvExpr
unsatisfiableEvExpr :: (TcTyVar, Type) -> Type -> TcS EvExpr
unsatisfiableEvExpr (TcTyVar
unsat_ev, Type
given_msg) Type
wtd_ty
= do { Module
mod <- TcS Module
forall (m :: * -> *). HasModule m => m Module
getModule
; if Module
mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
gHC_TYPEERROR then EvExpr -> TcS EvExpr
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (TcTyVar -> EvExpr
forall b. TcTyVar -> Expr b
Var TcTyVar
unsat_ev) else
do { TcTyVar
unsatisfiable_id <- Name -> TcS TcTyVar
tcLookupId Name
unsatisfiableIdName
; let
fun_ty :: Type
fun_ty = HasDebugCallStack => FunTyFlag -> Type -> Type -> Type -> Type
FunTyFlag -> Type -> Type -> Type -> Type
mkFunTy FunTyFlag
visArgConstraintLike Type
ManyTy Type
unboxedUnitTy Type
wtd_ty
mkDictBox :: DataCon
mkDictBox = case Type -> BoxingInfo Any
forall b. Type -> BoxingInfo b
boxingDataCon Type
fun_ty of
BI_Box { bi_data_con :: forall b. BoxingInfo b -> DataCon
bi_data_con = DataCon
mkDictBox } -> DataCon
mkDictBox
BoxingInfo Any
_ -> String -> SDoc -> DataCon
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"unsatisfiableEvExpr: no DictBox!" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
wtd_ty)
dictBox :: TyCon
dictBox = DataCon -> TyCon
dataConTyCon DataCon
mkDictBox
; TcTyVar
ev_bndr <- FastString -> Type -> Type -> TcS TcTyVar
forall (m :: * -> *).
MonadUnique m =>
FastString -> Type -> Type -> m TcTyVar
mkSysLocalM (String -> FastString
fsLit String
"ct") Type
ManyTy Type
fun_ty
; let scrut_ty :: Type
scrut_ty = TyCon -> [Type] -> Type
mkTyConApp TyCon
dictBox [Type
fun_ty]
scrut :: EvExpr
scrut =
EvExpr -> [EvExpr] -> EvExpr
mkCoreApps (TcTyVar -> EvExpr
forall b. TcTyVar -> Expr b
Var TcTyVar
unsatisfiable_id)
[ Type -> EvExpr
forall b. Type -> Expr b
Type Type
liftedRepTy
, Type -> EvExpr
forall b. Type -> Expr b
Type Type
given_msg
, Type -> EvExpr
forall b. Type -> Expr b
Type Type
scrut_ty
, TcTyVar -> EvExpr
forall b. TcTyVar -> Expr b
Var TcTyVar
unsat_ev ]
ev_expr :: EvExpr
ev_expr =
EvExpr -> Scaled Type -> Type -> [CoreAlt] -> EvExpr
mkWildCase EvExpr
scrut (Type -> Scaled Type
forall a. a -> Scaled a
unrestricted (Type -> Scaled Type) -> Type -> Scaled Type
forall a b. (a -> b) -> a -> b
$ Type
scrut_ty) Type
wtd_ty
[ AltCon -> [TcTyVar] -> EvExpr -> CoreAlt
forall b. AltCon -> [b] -> Expr b -> Alt b
Alt (DataCon -> AltCon
DataAlt DataCon
mkDictBox) [TcTyVar
ev_bndr] (EvExpr -> CoreAlt) -> EvExpr -> CoreAlt
forall a b. (a -> b) -> a -> b
$
EvExpr -> [EvExpr] -> EvExpr
mkCoreApps (TcTyVar -> EvExpr
forall b. TcTyVar -> Expr b
Var TcTyVar
ev_bndr) [EvExpr
unboxedUnitExpr]
]
; EvExpr -> TcS EvExpr
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return EvExpr
ev_expr } }
defaultCallStacks :: WantedConstraints -> TcS WantedConstraints
defaultCallStacks :: WantedConstraints -> TcS WantedConstraints
defaultCallStacks WantedConstraints
wanteds
= do Cts
simples <- Cts -> TcS Cts
handle_simples (WantedConstraints -> Cts
wc_simple WantedConstraints
wanteds)
Bag (Maybe Implication)
mb_implics <- (Implication -> TcS (Maybe Implication))
-> Bag Implication -> TcS (Bag (Maybe Implication))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Implication -> TcS (Maybe Implication)
handle_implic (WantedConstraints -> Bag Implication
wc_impl WantedConstraints
wanteds)
WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanteds { wc_simple = simples
, wc_impl = catBagMaybes mb_implics })
where
handle_simples :: Cts -> TcS Cts
handle_simples Cts
simples
= Bag (Maybe Ct) -> Cts
forall a. Bag (Maybe a) -> Bag a
catBagMaybes (Bag (Maybe Ct) -> Cts) -> TcS (Bag (Maybe Ct)) -> TcS Cts
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ct -> TcS (Maybe Ct)) -> Cts -> TcS (Bag (Maybe Ct))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Ct -> TcS (Maybe Ct)
defaultCallStack Cts
simples
handle_implic :: Implication -> TcS (Maybe Implication)
handle_implic :: Implication -> TcS (Maybe Implication)
handle_implic Implication
implic
| ImplicStatus -> Bool
isSolvedStatus (Implication -> ImplicStatus
ic_status Implication
implic)
= Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
implic)
| Bool
otherwise
= do { WantedConstraints
wanteds <- EvBindsVar -> TcS WantedConstraints -> TcS WantedConstraints
forall a. EvBindsVar -> TcS a -> TcS a
setEvBindsTcS (Implication -> EvBindsVar
ic_binds Implication
implic) (TcS WantedConstraints -> TcS WantedConstraints)
-> TcS WantedConstraints -> TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$
WantedConstraints -> TcS WantedConstraints
defaultCallStacks (Implication -> WantedConstraints
ic_wanted Implication
implic)
; Implication -> TcS (Maybe Implication)
setImplicationStatus (Implication
implic { ic_wanted = wanteds }) }
defaultCallStack :: Ct -> TcS (Maybe Ct)
defaultCallStack Ct
ct
| ClassPred Class
cls [Type]
tys <- Type -> Pred
classifyPredType (Ct -> Type
ctPred Ct
ct)
, Just {} <- Class -> [Type] -> Maybe FastString
isCallStackPred Class
cls [Type]
tys
= do { CtEvidence -> EvCallStack -> TcS ()
solveCallStack (Ct -> CtEvidence
ctEvidence Ct
ct) EvCallStack
EvCsEmpty
; Maybe Ct -> TcS (Maybe Ct)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Ct
forall a. Maybe a
Nothing }
defaultCallStack Ct
ct
= Maybe Ct -> TcS (Maybe Ct)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ct -> Maybe Ct
forall a. a -> Maybe a
Just Ct
ct)
simplifyAmbiguityCheck :: Type -> WantedConstraints -> TcM ()
simplifyAmbiguityCheck :: Type -> WantedConstraints -> TcM ()
simplifyAmbiguityCheck Type
ty WantedConstraints
wanteds
= do { String -> SDoc -> TcM ()
traceTc String
"simplifyAmbiguityCheck {" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type = " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wanted = " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanteds
; (WantedConstraints
final_wc, EvBindMap
_) <- TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a. TcS a -> TcM (a, EvBindMap)
runTcS (TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap))
-> TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> TcS WantedConstraints
useUnsatisfiableGivens (WantedConstraints -> TcS WantedConstraints)
-> TcS WantedConstraints -> TcS WantedConstraints
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wanteds
; TcM (Bag EvBind) -> TcM ()
forall a. TcM a -> TcM ()
discardResult (WantedConstraints -> TcM (Bag EvBind)
reportUnsolved WantedConstraints
final_wc)
; String -> SDoc -> TcM ()
traceTc String
"End simplifyAmbiguityCheck }" SDoc
forall doc. IsOutput doc => doc
empty }
simplifyInteractive :: WantedConstraints -> TcM (Bag EvBind)
simplifyInteractive :: WantedConstraints -> TcM (Bag EvBind)
simplifyInteractive WantedConstraints
wanteds
= String -> SDoc -> TcM ()
traceTc String
"simplifyInteractive" SDoc
forall doc. IsOutput doc => doc
empty TcM () -> TcM (Bag EvBind) -> TcM (Bag EvBind)
forall a b.
IOEnv (Env TcGblEnv TcLclEnv) a
-> IOEnv (Env TcGblEnv TcLclEnv) b
-> IOEnv (Env TcGblEnv TcLclEnv) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
WantedConstraints -> TcM (Bag EvBind)
simplifyTop WantedConstraints
wanteds
simplifyDefault :: ThetaType
-> TcM Bool
simplifyDefault :: [Type] -> TcM Bool
simplifyDefault [Type]
theta
= do { String -> SDoc -> TcM ()
traceTc String
"simplifyDefault" SDoc
forall doc. IsOutput doc => doc
empty
; [CtEvidence]
wanteds <- CtOrigin -> [Type] -> TcM [CtEvidence]
newWanteds CtOrigin
DefaultOrigin [Type]
theta
; (WantedConstraints
unsolved, EvBindMap
_) <- TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a. TcS a -> TcM (a, EvBindMap)
runTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds ([CtEvidence] -> WantedConstraints
mkSimpleWC [CtEvidence]
wanteds))
; Bool -> TcM Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints -> Bool
isEmptyWC WantedConstraints
unsolved) }
tcCheckGivens :: InertSet -> Bag EvVar -> TcM (Maybe InertSet)
tcCheckGivens :: InertSet -> Bag TcTyVar -> TcM (Maybe InertSet)
tcCheckGivens InertSet
inerts Bag TcTyVar
given_ids = do
(Bool
sat, InertSet
new_inerts) <- InertSet -> TcS Bool -> TcM (Bool, InertSet)
forall a. InertSet -> TcS a -> TcM (a, InertSet)
runTcSInerts InertSet
inerts (TcS Bool -> TcM (Bool, InertSet))
-> TcS Bool -> TcM (Bool, InertSet)
forall a b. (a -> b) -> a -> b
$ do
String -> SDoc -> TcS ()
traceTcS String
"checkGivens {" (InertSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr InertSet
inerts SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bag TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bag TcTyVar
given_ids)
TcLclEnv
lcl_env <- TcS TcLclEnv
TcS.getLclEnv
let given_loc :: CtLoc
given_loc = TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc TcLevel
topTcLevel (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
HasCallStack => SkolemInfo
unkSkol) (TcLclEnv -> CtLocEnv
mkCtLocEnv TcLclEnv
lcl_env)
let given_cts :: [Ct]
given_cts = CtLoc -> [TcTyVar] -> [Ct]
mkGivens CtLoc
given_loc (Bag TcTyVar -> [TcTyVar]
forall a. Bag a -> [a]
bagToList Bag TcTyVar
given_ids)
[Ct] -> TcS ()
solveSimpleGivens [Ct]
given_cts
Cts
insols <- TcS Cts
getInertInsols
Cts
insols <- Cts -> TcS Cts
try_harder Cts
insols
String -> SDoc -> TcS ()
traceTcS String
"checkGivens }" (Cts -> SDoc
forall a. Outputable a => a -> SDoc
ppr Cts
insols)
Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Cts -> Bool
forall a. Bag a -> Bool
isEmptyBag Cts
insols)
Maybe InertSet -> TcM (Maybe InertSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe InertSet -> TcM (Maybe InertSet))
-> Maybe InertSet -> TcM (Maybe InertSet)
forall a b. (a -> b) -> a -> b
$ if Bool
sat then InertSet -> Maybe InertSet
forall a. a -> Maybe a
Just InertSet
new_inerts else Maybe InertSet
forall a. Maybe a
Nothing
where
try_harder :: Cts -> TcS Cts
try_harder :: Cts -> TcS Cts
try_harder Cts
insols
| Bool -> Bool
not (Cts -> Bool
forall a. Bag a -> Bool
isEmptyBag Cts
insols)
= Cts -> TcS Cts
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Cts
insols
| Bool
otherwise
= do { [Ct]
pending_given <- TcS [Ct]
getPendingGivenScs
; [Ct]
new_given <- [Ct] -> TcS [Ct]
makeSuperClasses [Ct]
pending_given
; [Ct] -> TcS ()
solveSimpleGivens [Ct]
new_given
; TcS Cts
getInertInsols }
tcCheckWanteds :: InertSet -> ThetaType -> TcM Bool
tcCheckWanteds :: InertSet -> [Type] -> TcM Bool
tcCheckWanteds InertSet
inerts [Type]
wanteds = do
[CtEvidence]
cts <- CtOrigin -> [Type] -> TcM [CtEvidence]
newWanteds CtOrigin
PatCheckOrigin [Type]
wanteds
(Bool
sat, InertSet
_new_inerts) <- InertSet -> TcS Bool -> TcM (Bool, InertSet)
forall a. InertSet -> TcS a -> TcM (a, InertSet)
runTcSInerts InertSet
inerts (TcS Bool -> TcM (Bool, InertSet))
-> TcS Bool -> TcM (Bool, InertSet)
forall a b. (a -> b) -> a -> b
$ do
String -> SDoc -> TcS ()
traceTcS String
"checkWanteds {" (InertSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr InertSet
inerts SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
wanteds)
WantedConstraints
wcs <- WantedConstraints -> TcS WantedConstraints
solveWanteds ([CtEvidence] -> WantedConstraints
mkSimpleWC [CtEvidence]
cts)
String -> SDoc -> TcS ()
traceTcS String
"checkWanteds }" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wcs)
Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints -> Bool
isSolvedWC WantedConstraints
wcs)
Bool -> TcM Bool
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
sat
tcNormalise :: InertSet -> Type -> TcM Type
tcNormalise :: InertSet -> Type -> TcM Type
tcNormalise InertSet
inerts Type
ty
= do { CtLoc
norm_loc <- CtOrigin -> Maybe TypeOrKind -> TcM CtLoc
getCtLocM CtOrigin
PatCheckOrigin Maybe TypeOrKind
forall a. Maybe a
Nothing
; (Type
res, InertSet
_new_inerts) <- InertSet -> TcS Type -> TcM (Type, InertSet)
forall a. InertSet -> TcS a -> TcM (a, InertSet)
runTcSInerts InertSet
inerts (TcS Type -> TcM (Type, InertSet))
-> TcS Type -> TcM (Type, InertSet)
forall a b. (a -> b) -> a -> b
$
do { String -> SDoc -> TcS ()
traceTcS String
"tcNormalise {" (InertSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr InertSet
inerts)
; Type
ty' <- CtLoc -> Type -> TcS Type
rewriteType CtLoc
norm_loc Type
ty
; String -> SDoc -> TcS ()
traceTcS String
"tcNormalise }" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty')
; Type -> TcS Type
forall a. a -> TcS a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type
ty' }
; Type -> TcM Type
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Type
res }
data InferMode = ApplyMR
| EagerDefaulting
| NoRestrictions
instance Outputable InferMode where
ppr :: InferMode -> SDoc
ppr InferMode
ApplyMR = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ApplyMR"
ppr InferMode
EagerDefaulting = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"EagerDefaulting"
ppr InferMode
NoRestrictions = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NoRestrictions"
simplifyInfer :: TcLevel
-> InferMode
-> [TcIdSigInst]
-> [(Name, TcTauType)]
-> WantedConstraints
-> TcM ([TcTyVar],
[EvVar],
TcEvBinds,
Bool)
simplifyInfer :: TcLevel
-> InferMode
-> [TcIdSigInst]
-> [(Name, Type)]
-> WantedConstraints
-> TcM ([TcTyVar], [TcTyVar], TcEvBinds, Bool)
simplifyInfer TcLevel
rhs_tclvl InferMode
infer_mode [TcIdSigInst]
sigs [(Name, Type)]
name_taus WantedConstraints
wanteds
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanteds
= do {
let psig_tv_tys :: [Type]
psig_tv_tys = [ TcTyVar -> Type
mkTyVarTy TcTyVar
tv | TcIdSigInst
sig <- [TcIdSigInst]
partial_sigs
, (Name
_,Bndr TcTyVar
tv Specificity
_) <- TcIdSigInst -> [(Name, InvisTVBinder)]
sig_inst_skols TcIdSigInst
sig ]
psig_theta :: [Type]
psig_theta = [ Type
pred | TcIdSigInst
sig <- [TcIdSigInst]
partial_sigs
, Type
pred <- TcIdSigInst -> [Type]
sig_inst_theta TcIdSigInst
sig ]
; CandidatesQTvs
dep_vars <- [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes ([Type]
psig_tv_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
psig_theta [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ ((Name, Type) -> Type) -> [(Name, Type)] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Type) -> Type
forall a b. (a, b) -> b
snd [(Name, Type)]
name_taus)
; SkolemInfo
skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo ([(Name, Type)] -> SkolemInfoAnon
InferSkol [(Name, Type)]
name_taus)
; [TcTyVar]
qtkvs <- SkolemInfo
-> NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
quantifyTyVars SkolemInfo
skol_info NonStandardDefaultingStrategy
DefaultNonStandardTyVars CandidatesQTvs
dep_vars
; String -> SDoc -> TcM ()
traceTc String
"simplifyInfer: empty WC" ([(Name, Type)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(Name, Type)]
name_taus SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [TcTyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcTyVar]
qtkvs)
; ([TcTyVar], [TcTyVar], TcEvBinds, Bool)
-> TcM ([TcTyVar], [TcTyVar], TcEvBinds, Bool)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TcTyVar]
qtkvs, [], TcEvBinds
emptyTcEvBinds, Bool
False) }
| Bool
otherwise
= do { String -> SDoc -> TcM ()
traceTc String
"simplifyInfer {" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"sigs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcIdSigInst] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcIdSigInst]
sigs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"binds =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [(Name, Type)] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(Name, Type)]
name_taus
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"rhs_tclvl =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
rhs_tclvl
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infer_mode =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> InferMode -> SDoc
forall a. Outputable a => a -> SDoc
ppr InferMode
infer_mode
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(unzonked) wanted =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanteds
]
; let psig_theta :: [Type]
psig_theta = (TcIdSigInst -> [Type]) -> [TcIdSigInst] -> [Type]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TcIdSigInst -> [Type]
sig_inst_theta [TcIdSigInst]
partial_sigs
; EvBindsVar
ev_binds_var <- TcM EvBindsVar
TcM.newTcEvBinds
; [CtEvidence]
psig_evs <- CtOrigin -> [Type] -> TcM [CtEvidence]
newWanteds CtOrigin
AnnOrigin [Type]
psig_theta
; WantedConstraints
wanted_transformed
<- TcLevel
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. TcLevel -> TcM a -> TcM a
setTcLevel TcLevel
rhs_tclvl (IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$
EvBindsVar
-> TcS WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. EvBindsVar -> TcS a -> TcM a
runTcSWithEvBinds EvBindsVar
ev_binds_var (TcS WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> TcS WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$
WantedConstraints -> TcS WantedConstraints
solveWanteds ([CtEvidence] -> WantedConstraints
mkSimpleWC [CtEvidence]
psig_evs WantedConstraints -> WantedConstraints -> WantedConstraints
`andWC` WantedConstraints
wanteds)
; WantedConstraints
wanted_transformed <- ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> ZonkM WantedConstraints
TcM.zonkWC WantedConstraints
wanted_transformed
; let definite_error :: Bool
definite_error = WantedConstraints -> Bool
insolubleWC WantedConstraints
wanted_transformed
quant_pred_candidates :: [Type]
quant_pred_candidates
| Bool
definite_error = []
| Bool
otherwise = Cts -> [Type]
ctsPreds (Bool -> WantedConstraints -> Cts
approximateWC Bool
False WantedConstraints
wanted_transformed)
; rec { ([TcTyVar]
qtvs, [Type]
bound_theta, VarSet
co_vars) <- SkolemInfo
-> InferMode
-> TcLevel
-> [(Name, Type)]
-> [TcIdSigInst]
-> [Type]
-> TcM ([TcTyVar], [Type], VarSet)
decideQuantification SkolemInfo
skol_info InferMode
infer_mode TcLevel
rhs_tclvl
[(Name, Type)]
name_taus [TcIdSigInst]
partial_sigs
[Type]
quant_pred_candidates
; [TcTyVar]
bound_theta_vars <- (Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> [Type] -> 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 Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. Type -> TcRnIf gbl lcl TcTyVar
TcM.newEvVar [Type]
bound_theta
; let full_theta :: [Type]
full_theta = (TcTyVar -> Type) -> [TcTyVar] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TcTyVar -> Type
idType [TcTyVar]
bound_theta_vars
; SkolemInfo
skol_info <- SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfo
forall (m :: * -> *). MonadIO m => SkolemInfoAnon -> m SkolemInfo
mkSkolemInfo ([(Name, Type)] -> SkolemInfoAnon
InferSkol [ (Name
name, [ForAllTyBinder] -> [Type] -> Type -> Type
HasDebugCallStack => [ForAllTyBinder] -> [Type] -> Type -> Type
mkSigmaTy [] [Type]
full_theta Type
ty)
| (Name
name, Type
ty) <- [(Name, Type)]
name_taus ])
}
; TcLevel
-> EvBindsVar
-> [(Name, Type)]
-> VarSet
-> [TcTyVar]
-> [TcTyVar]
-> WantedConstraints
-> TcM ()
emitResidualConstraints TcLevel
rhs_tclvl EvBindsVar
ev_binds_var
[(Name, Type)]
name_taus VarSet
co_vars [TcTyVar]
qtvs [TcTyVar]
bound_theta_vars
WantedConstraints
wanted_transformed
; String -> SDoc -> TcM ()
traceTc String
"} simplifyInfer/produced residual implication for quantification" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"quant_pred_candidates =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
quant_pred_candidates
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"psig_theta =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
psig_theta
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bound_theta =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
pprCoreBinders [TcTyVar]
bound_theta_vars
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"qtvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcTyVar]
qtvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"definite_error =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
definite_error ]
; ([TcTyVar], [TcTyVar], TcEvBinds, Bool)
-> TcM ([TcTyVar], [TcTyVar], TcEvBinds, Bool)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ( [TcTyVar]
qtvs, [TcTyVar]
bound_theta_vars, EvBindsVar -> TcEvBinds
TcEvBinds EvBindsVar
ev_binds_var, Bool
definite_error ) }
where
partial_sigs :: [TcIdSigInst]
partial_sigs = (TcIdSigInst -> Bool) -> [TcIdSigInst] -> [TcIdSigInst]
forall a. (a -> Bool) -> [a] -> [a]
filter TcIdSigInst -> Bool
isPartialSig [TcIdSigInst]
sigs
emitResidualConstraints :: TcLevel -> EvBindsVar
-> [(Name, TcTauType)]
-> CoVarSet -> [TcTyVar] -> [EvVar]
-> WantedConstraints -> TcM ()
emitResidualConstraints :: TcLevel
-> EvBindsVar
-> [(Name, Type)]
-> VarSet
-> [TcTyVar]
-> [TcTyVar]
-> WantedConstraints
-> TcM ()
emitResidualConstraints TcLevel
rhs_tclvl EvBindsVar
ev_binds_var
[(Name, Type)]
name_taus VarSet
co_vars [TcTyVar]
qtvs [TcTyVar]
full_theta_vars WantedConstraints
wanteds
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanteds
= () -> TcM ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { Cts
wanted_simple <- ZonkM Cts -> TcM Cts
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM Cts -> TcM Cts) -> ZonkM Cts -> TcM Cts
forall a b. (a -> b) -> a -> b
$ Cts -> ZonkM Cts
TcM.zonkSimples (WantedConstraints -> Cts
wc_simple WantedConstraints
wanteds)
; let (Cts
outer_simple, Cts
inner_simple) = (Ct -> Bool) -> Cts -> (Cts, Cts)
forall a. (a -> Bool) -> Bag a -> (Bag a, Bag a)
partitionBag Ct -> Bool
is_mono Cts
wanted_simple
is_mono :: Ct -> Bool
is_mono Ct
ct
| Just TcTyVar
ct_ev_id <- Ct -> Maybe TcTyVar
wantedEvId_maybe Ct
ct
= TcTyVar
ct_ev_id TcTyVar -> VarSet -> Bool
`elemVarSet` VarSet
co_vars
| Bool
otherwise
= Bool
False
; let inner_wanted :: WantedConstraints
inner_wanted = WantedConstraints
wanteds { wc_simple = inner_simple }
; Bag Implication
implics <- if WantedConstraints -> Bool
isEmptyWC WantedConstraints
inner_wanted
then Bag Implication -> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return Bag Implication
forall a. Bag a
emptyBag
else do Implication
implic1 <- TcM Implication
newImplication
Bag Implication -> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bag Implication
-> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication))
-> Bag Implication
-> IOEnv (Env TcGblEnv TcLclEnv) (Bag Implication)
forall a b. (a -> b) -> a -> b
$ Implication -> Bag Implication
forall a. a -> Bag a
unitBag (Implication -> Bag Implication) -> Implication -> Bag Implication
forall a b. (a -> b) -> a -> b
$
Implication
implic1 { ic_tclvl = rhs_tclvl
, ic_skols = qtvs
, ic_given = full_theta_vars
, ic_wanted = inner_wanted
, ic_binds = ev_binds_var
, ic_given_eqs = MaybeGivenEqs
, ic_info = skol_info }
; WantedConstraints -> TcM ()
emitConstraints (WantedConstraints
emptyWC { wc_simple = outer_simple
, wc_impl = implics }) }
where
full_theta :: [Type]
full_theta = (TcTyVar -> Type) -> [TcTyVar] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TcTyVar -> Type
idType [TcTyVar]
full_theta_vars
skol_info :: SkolemInfoAnon
skol_info = [(Name, Type)] -> SkolemInfoAnon
InferSkol [ (Name
name, [ForAllTyBinder] -> [Type] -> Type -> Type
HasDebugCallStack => [ForAllTyBinder] -> [Type] -> Type -> Type
mkSigmaTy [] [Type]
full_theta Type
ty)
| (Name
name, Type
ty) <- [(Name, Type)]
name_taus ]
findInferredDiff :: TcThetaType -> TcThetaType -> TcM TcThetaType
findInferredDiff :: [Type] -> [Type] -> TcM [Type]
findInferredDiff [Type]
annotated_theta [Type]
inferred_theta
| [Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
annotated_theta
= [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [Type]
inferred_theta
| Bool
otherwise
= TcM [Type] -> TcM [Type]
forall r. TcM r -> TcM r
pushTcLevelM_ (TcM [Type] -> TcM [Type]) -> TcM [Type] -> TcM [Type]
forall a b. (a -> b) -> a -> b
$
do { TcLclEnv
lcl_env <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
TcM.getLclEnv
; [TcTyVar]
given_ids <- (Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-> [Type] -> 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 Type -> IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. Type -> TcRnIf gbl lcl TcTyVar
TcM.newEvVar [Type]
annotated_theta
; [CtEvidence]
wanteds <- CtOrigin -> [Type] -> TcM [CtEvidence]
newWanteds CtOrigin
AnnOrigin [Type]
inferred_theta
; let given_loc :: CtLoc
given_loc = TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc TcLevel
topTcLevel (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
HasCallStack => SkolemInfo
unkSkol) (TcLclEnv -> CtLocEnv
mkCtLocEnv TcLclEnv
lcl_env)
given_cts :: [Ct]
given_cts = CtLoc -> [TcTyVar] -> [Ct]
mkGivens CtLoc
given_loc [TcTyVar]
given_ids
; (WantedConstraints
residual, EvBindMap
_) <- TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a. TcS a -> TcM (a, EvBindMap)
runTcS (TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap))
-> TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a b. (a -> b) -> a -> b
$
do { ()
_ <- [Ct] -> TcS ()
solveSimpleGivens [Ct]
given_cts
; Cts -> TcS WantedConstraints
solveSimpleWanteds ([Ct] -> Cts
forall a. [a] -> Bag a
listToBag ((CtEvidence -> Ct) -> [CtEvidence] -> [Ct]
forall a b. (a -> b) -> [a] -> [b]
map CtEvidence -> Ct
mkNonCanonical [CtEvidence]
wanteds)) }
; [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Ct -> Type) -> [Ct] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Type
box_pred (Type -> Type) -> (Ct -> Type) -> Ct -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ct -> Type
ctPred) ([Ct] -> [Type]) -> [Ct] -> [Type]
forall a b. (a -> b) -> a -> b
$
Cts -> [Ct]
forall a. Bag a -> [a]
bagToList (Cts -> [Ct]) -> Cts -> [Ct]
forall a b. (a -> b) -> a -> b
$
WantedConstraints -> Cts
wc_simple WantedConstraints
residual) }
where
box_pred :: PredType -> PredType
box_pred :: Type -> Type
box_pred Type
pred = case Type -> Pred
classifyPredType Type
pred of
EqPred EqRel
rel Type
ty1 Type
ty2
| Just (Class
cls,[Type]
tys) <- EqRel -> Type -> Type -> Maybe (Class, [Type])
boxEqPred EqRel
rel Type
ty1 Type
ty2
-> Class -> [Type] -> Type
mkClassPred Class
cls [Type]
tys
| Bool
otherwise
-> String -> SDoc -> Type
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"findInferredDiff" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
pred)
Pred
_other -> Type
pred
decideQuantification
:: SkolemInfo
-> InferMode
-> TcLevel
-> [(Name, TcTauType)]
-> [TcIdSigInst]
-> [PredType]
-> TcM ( [TcTyVar]
, [PredType]
, CoVarSet)
decideQuantification :: SkolemInfo
-> InferMode
-> TcLevel
-> [(Name, Type)]
-> [TcIdSigInst]
-> [Type]
-> TcM ([TcTyVar], [Type], VarSet)
decideQuantification SkolemInfo
skol_info InferMode
infer_mode TcLevel
rhs_tclvl [(Name, Type)]
name_taus [TcIdSigInst]
psigs [Type]
candidates
= do {
; ([Type]
candidates, VarSet
co_vars, VarSet
mono_tvs0)
<- InferMode
-> [(Name, Type)]
-> [TcIdSigInst]
-> [Type]
-> TcM ([Type], VarSet, VarSet)
decidePromotedTyVars InferMode
infer_mode [(Name, Type)]
name_taus [TcIdSigInst]
psigs [Type]
candidates
; [Type]
candidates <- TcLevel -> [Type] -> TcM [Type]
defaultTyVarsAndSimplify TcLevel
rhs_tclvl [Type]
candidates
; [TcTyVar]
qtvs <- SkolemInfo
-> [(Name, Type)] -> [TcIdSigInst] -> [Type] -> TcM [TcTyVar]
decideQuantifiedTyVars SkolemInfo
skol_info [(Name, Type)]
name_taus [TcIdSigInst]
psigs [Type]
candidates
; ([Type]
candidates, [Type]
psig_theta) <- ZonkM ([Type], [Type]) -> TcM ([Type], [Type])
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM ([Type], [Type]) -> TcM ([Type], [Type]))
-> ZonkM ([Type], [Type]) -> TcM ([Type], [Type])
forall a b. (a -> b) -> a -> b
$
do { [Type]
candidates <- [Type] -> ZonkM [Type]
TcM.zonkTcTypes [Type]
candidates
; [Type]
psig_theta <- [Type] -> ZonkM [Type]
TcM.zonkTcTypes ((TcIdSigInst -> [Type]) -> [TcIdSigInst] -> [Type]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TcIdSigInst -> [Type]
sig_inst_theta [TcIdSigInst]
psigs)
; ([Type], [Type]) -> ZonkM ([Type], [Type])
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Type]
candidates, [Type]
psig_theta) }
; [Type]
min_theta <- VarSet -> VarSet -> [Type] -> TcM [Type]
pickQuantifiablePreds ([TcTyVar] -> VarSet
mkVarSet [TcTyVar]
qtvs) VarSet
mono_tvs0 [Type]
candidates
; let min_psig_theta :: [Type]
min_psig_theta = (Type -> Type) -> [Type] -> [Type]
forall a. (a -> Type) -> [a] -> [a]
mkMinimalBySCs Type -> Type
forall a. a -> a
id [Type]
psig_theta
; [Type]
theta <- if
| [TcIdSigInst] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcIdSigInst]
psigs -> [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [Type]
min_theta
| Bool -> Bool
not ((TcIdSigInst -> Bool) -> [TcIdSigInst] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all TcIdSigInst -> Bool
has_extra_constraints_wildcard [TcIdSigInst]
psigs)
-> [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [Type]
min_psig_theta
| Bool
otherwise
-> do { [Type]
diff <- [Type] -> [Type] -> TcM [Type]
findInferredDiff [Type]
min_psig_theta [Type]
min_theta
; [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Type]
min_psig_theta [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
diff) }
; String -> SDoc -> TcM ()
traceTc String
"decideQuantification"
([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infer_mode:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> InferMode -> SDoc
forall a. Outputable a => a -> SDoc
ppr InferMode
infer_mode
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"candidates:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
candidates
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"psig_theta:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
psig_theta
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"co_vars:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
co_vars
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"qtvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcTyVar]
qtvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"theta:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
theta ])
; ([TcTyVar], [Type], VarSet) -> TcM ([TcTyVar], [Type], VarSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TcTyVar]
qtvs, [Type]
theta, VarSet
co_vars) }
where
has_extra_constraints_wildcard :: TcIdSigInst -> Bool
has_extra_constraints_wildcard (TISI { sig_inst_wcx :: TcIdSigInst -> Maybe Type
sig_inst_wcx = Just {} }) = Bool
True
has_extra_constraints_wildcard TcIdSigInst
_ = Bool
False
decidePromotedTyVars :: InferMode
-> [(Name,TcType)]
-> [TcIdSigInst]
-> [PredType]
-> TcM ([PredType], CoVarSet, TcTyVarSet)
decidePromotedTyVars :: InferMode
-> [(Name, Type)]
-> [TcIdSigInst]
-> [Type]
-> TcM ([Type], VarSet, VarSet)
decidePromotedTyVars InferMode
infer_mode [(Name, Type)]
name_taus [TcIdSigInst]
psigs [Type]
candidates
= do { TcLevel
tc_lvl <- TcM TcLevel
TcM.getTcLevel
; ([Type]
no_quant, [Type]
maybe_quant) <- InferMode -> [Type] -> TcM ([Type], [Type])
pick InferMode
infer_mode [Type]
candidates
; ([TcTyVar]
psig_qtvs, [Type]
psig_theta, [Type]
taus) <- ZonkM ([TcTyVar], [Type], [Type])
-> TcM ([TcTyVar], [Type], [Type])
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM ([TcTyVar], [Type], [Type])
-> TcM ([TcTyVar], [Type], [Type]))
-> ZonkM ([TcTyVar], [Type], [Type])
-> TcM ([TcTyVar], [Type], [Type])
forall a b. (a -> b) -> a -> b
$
do { [TcTyVar]
psig_qtvs <- [TcTyVar] -> ZonkM [TcTyVar]
HasDebugCallStack => [TcTyVar] -> ZonkM [TcTyVar]
zonkTcTyVarsToTcTyVars ([TcTyVar] -> ZonkM [TcTyVar]) -> [TcTyVar] -> ZonkM [TcTyVar]
forall a b. (a -> b) -> a -> b
$ [InvisTVBinder] -> [TcTyVar]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars ([InvisTVBinder] -> [TcTyVar]) -> [InvisTVBinder] -> [TcTyVar]
forall a b. (a -> b) -> a -> b
$
(TcIdSigInst -> [InvisTVBinder])
-> [TcIdSigInst] -> [InvisTVBinder]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((Name, InvisTVBinder) -> InvisTVBinder)
-> [(Name, InvisTVBinder)] -> [InvisTVBinder]
forall a b. (a -> b) -> [a] -> [b]
map (Name, InvisTVBinder) -> InvisTVBinder
forall a b. (a, b) -> b
snd ([(Name, InvisTVBinder)] -> [InvisTVBinder])
-> (TcIdSigInst -> [(Name, InvisTVBinder)])
-> TcIdSigInst
-> [InvisTVBinder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcIdSigInst -> [(Name, InvisTVBinder)]
sig_inst_skols) [TcIdSigInst]
psigs
; [Type]
psig_theta <- (Type -> ZonkM Type) -> [Type] -> ZonkM [Type]
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 Type -> ZonkM Type
TcM.zonkTcType ([Type] -> ZonkM [Type]) -> [Type] -> ZonkM [Type]
forall a b. (a -> b) -> a -> b
$
(TcIdSigInst -> [Type]) -> [TcIdSigInst] -> [Type]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TcIdSigInst -> [Type]
sig_inst_theta [TcIdSigInst]
psigs
; [Type]
taus <- ((Name, Type) -> ZonkM Type) -> [(Name, Type)] -> ZonkM [Type]
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 (Type -> ZonkM Type
TcM.zonkTcType (Type -> ZonkM Type)
-> ((Name, Type) -> Type) -> (Name, Type) -> ZonkM Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, Type) -> Type
forall a b. (a, b) -> b
snd) [(Name, Type)]
name_taus
; ([TcTyVar], [Type], [Type]) -> ZonkM ([TcTyVar], [Type], [Type])
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return ([TcTyVar]
psig_qtvs, [Type]
psig_theta, [Type]
taus) }
; let psig_tys :: [Type]
psig_tys = [TcTyVar] -> [Type]
mkTyVarTys [TcTyVar]
psig_qtvs [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
psig_theta
co_vars :: VarSet
co_vars = [Type] -> VarSet
coVarsOfTypes ([Type]
psig_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
taus [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
candidates)
co_var_tvs :: VarSet
co_var_tvs = VarSet -> VarSet
closeOverKinds VarSet
co_vars
mono_tvs0 :: VarSet
mono_tvs0 = (TcTyVar -> Bool) -> VarSet -> VarSet
filterVarSet (Bool -> Bool
not (Bool -> Bool) -> (TcTyVar -> Bool) -> TcTyVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcLevel -> TcTyVar -> Bool
isQuantifiableTv TcLevel
tc_lvl) (VarSet -> VarSet) -> VarSet -> VarSet
forall a b. (a -> b) -> a -> b
$
[Type] -> VarSet
tyCoVarsOfTypes [Type]
candidates
mono_tvs1 :: VarSet
mono_tvs1 = VarSet
mono_tvs0 VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
co_var_tvs
non_ip_candidates :: [Type]
non_ip_candidates = (Type -> Bool) -> [Type] -> [Type]
forall a. (a -> Bool) -> [a] -> [a]
filterOut Type -> Bool
isIPLikePred [Type]
candidates
mono_tvs2 :: VarSet
mono_tvs2 = [Type] -> VarSet -> VarSet
closeWrtFunDeps [Type]
non_ip_candidates VarSet
mono_tvs1
constrained_tvs :: VarSet
constrained_tvs = (TcTyVar -> Bool) -> VarSet -> VarSet
filterVarSet (TcLevel -> TcTyVar -> Bool
isQuantifiableTv TcLevel
tc_lvl) (VarSet -> VarSet) -> VarSet -> VarSet
forall a b. (a -> b) -> a -> b
$
[Type] -> VarSet -> VarSet
closeWrtFunDeps [Type]
non_ip_candidates ([Type] -> VarSet
tyCoVarsOfTypes [Type]
no_quant)
VarSet -> VarSet -> VarSet
`minusVarSet` VarSet
mono_tvs2
mono_tvs :: VarSet
mono_tvs = (VarSet
mono_tvs2 VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
constrained_tvs)
VarSet -> [TcTyVar] -> VarSet
`delVarSetList` [TcTyVar]
psig_qtvs
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (case InferMode
infer_mode of { InferMode
ApplyMR -> Bool
True; InferMode
_ -> Bool
False}) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ do
let dia :: TcRnMessage
dia = [Name] -> TcRnMessage
TcRnMonomorphicBindings (((Name, Type) -> Name) -> [(Name, Type)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Type) -> Name
forall a b. (a, b) -> a
fst [(Name, Type)]
name_taus)
Bool -> TcRnMessage -> TcM ()
diagnosticTc (VarSet
constrained_tvs VarSet -> VarSet -> Bool
`intersectsVarSet` [Type] -> VarSet
tyCoVarsOfTypes [Type]
taus) TcRnMessage
dia
; Bool
_ <- HasDebugCallStack => VarSet -> TcM Bool
VarSet -> TcM Bool
promoteTyVarSet VarSet
mono_tvs
; String -> SDoc -> TcM ()
traceTc String
"decidePromotedTyVars" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"infer_mode =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> InferMode -> SDoc
forall a. Outputable a => a -> SDoc
ppr InferMode
infer_mode
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"psigs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcIdSigInst] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcIdSigInst]
psigs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"psig_qtvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [TcTyVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TcTyVar]
psig_qtvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"mono_tvs0 =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
mono_tvs0
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"no_quant =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
no_quant
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"maybe_quant =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
maybe_quant
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"mono_tvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
mono_tvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"co_vars =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
co_vars ]
; ([Type], VarSet, VarSet) -> TcM ([Type], VarSet, VarSet)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Type]
maybe_quant, VarSet
co_vars, VarSet
mono_tvs0) }
where
pick :: InferMode -> [PredType] -> TcM ([PredType], [PredType])
pick :: InferMode -> [Type] -> TcM ([Type], [Type])
pick InferMode
ApplyMR [Type]
cand = ([Type], [Type]) -> TcM ([Type], [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Type]
cand, [])
pick InferMode
NoRestrictions [Type]
cand = ([Type], [Type]) -> TcM ([Type], [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [Type]
cand)
pick InferMode
EagerDefaulting [Type]
cand = do { Bool
os <- Extension -> TcM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.OverloadedStrings
; ([Type], [Type]) -> TcM ([Type], [Type])
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Type -> Bool) -> [Type] -> ([Type], [Type])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Bool -> Type -> Bool
is_int_ct Bool
os) [Type]
cand) }
is_int_ct :: Bool -> Type -> Bool
is_int_ct Bool
ovl_strings Type
pred
= case Type -> Pred
classifyPredType Type
pred of
ClassPred Class
cls [Type]
_ -> Bool -> Class -> Bool
isInteractiveClass Bool
ovl_strings Class
cls
Pred
_ -> Bool
False
defaultTyVarsAndSimplify :: TcLevel
-> [PredType]
-> TcM [PredType]
defaultTyVarsAndSimplify :: TcLevel -> [Type] -> TcM [Type]
defaultTyVarsAndSimplify TcLevel
rhs_tclvl [Type]
candidates
= do {
; DV {dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
cand_kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
cand_tvs}
<- [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes [Type]
candidates
; Bool
poly_kinds <- Extension -> TcM Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PolyKinds
; let default_kv :: TcTyVar -> TcM Bool
default_kv | Bool
poly_kinds = TcTyVar -> TcM Bool
default_tv
| Bool
otherwise = DefaultingStrategy -> TcTyVar -> TcM Bool
defaultTyVar DefaultingStrategy
DefaultKindVars
default_tv :: TcTyVar -> TcM Bool
default_tv = DefaultingStrategy -> TcTyVar -> TcM Bool
defaultTyVar (NonStandardDefaultingStrategy -> DefaultingStrategy
NonStandardDefaulting NonStandardDefaultingStrategy
DefaultNonStandardTyVars)
; (TcTyVar -> TcM Bool) -> [TcTyVar] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ TcTyVar -> TcM Bool
default_kv (DTyVarSet -> [TcTyVar]
dVarSetElems DTyVarSet
cand_kvs)
; (TcTyVar -> TcM Bool) -> [TcTyVar] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ TcTyVar -> TcM Bool
default_tv (DTyVarSet -> [TcTyVar]
dVarSetElems (DTyVarSet
cand_tvs DTyVarSet -> DTyVarSet -> DTyVarSet
`minusDVarSet` DTyVarSet
cand_kvs))
; [Type] -> TcM [Type]
simplify_cand [Type]
candidates
}
where
simplify_cand :: [Type] -> TcM [Type]
simplify_cand [] = [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return []
simplify_cand [Type]
candidates
= do { [CtEvidence]
clone_wanteds <- CtOrigin -> [Type] -> TcM [CtEvidence]
newWanteds CtOrigin
DefaultOrigin [Type]
candidates
; WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples } <- TcLevel
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. TcLevel -> TcM a -> TcM a
setTcLevel TcLevel
rhs_tclvl (IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$
[CtEvidence] -> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
simplifyWantedsTcM [CtEvidence]
clone_wanteds
; let new_candidates :: [Type]
new_candidates = Cts -> [Type]
ctsPreds Cts
simples
; String -> SDoc -> TcM ()
traceTc String
"Simplified after defaulting" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Before:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
candidates
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"After:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
new_candidates ]
; [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return [Type]
new_candidates }
decideQuantifiedTyVars
:: SkolemInfo
-> [(Name,TcType)]
-> [TcIdSigInst]
-> [PredType]
-> TcM [TyVar]
decideQuantifiedTyVars :: SkolemInfo
-> [(Name, Type)] -> [TcIdSigInst] -> [Type] -> TcM [TcTyVar]
decideQuantifiedTyVars SkolemInfo
skol_info [(Name, Type)]
name_taus [TcIdSigInst]
psigs [Type]
candidates
= do {
; ([Type]
psig_tv_tys, [Type]
psig_theta, [Type]
tau_tys) <- ZonkM ([Type], [Type], [Type]) -> TcM ([Type], [Type], [Type])
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM ([Type], [Type], [Type]) -> TcM ([Type], [Type], [Type]))
-> ZonkM ([Type], [Type], [Type]) -> TcM ([Type], [Type], [Type])
forall a b. (a -> b) -> a -> b
$
do { [Type]
psig_tv_tys <- (TcTyVar -> ZonkM Type) -> [TcTyVar] -> ZonkM [Type]
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 TcTyVar -> ZonkM Type
TcM.zonkTcTyVar [ TcTyVar
tv | TcIdSigInst
sig <- [TcIdSigInst]
psigs
, (Name
_,Bndr TcTyVar
tv Specificity
_) <- TcIdSigInst -> [(Name, InvisTVBinder)]
sig_inst_skols TcIdSigInst
sig ]
; [Type]
psig_theta <- (Type -> ZonkM Type) -> [Type] -> ZonkM [Type]
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 Type -> ZonkM Type
TcM.zonkTcType [ Type
pred | TcIdSigInst
sig <- [TcIdSigInst]
psigs
, Type
pred <- TcIdSigInst -> [Type]
sig_inst_theta TcIdSigInst
sig ]
; [Type]
tau_tys <- ((Name, Type) -> ZonkM Type) -> [(Name, Type)] -> ZonkM [Type]
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 (Type -> ZonkM Type
TcM.zonkTcType (Type -> ZonkM Type)
-> ((Name, Type) -> Type) -> (Name, Type) -> ZonkM Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, Type) -> Type
forall a b. (a, b) -> b
snd) [(Name, Type)]
name_taus
; ([Type], [Type], [Type]) -> ZonkM ([Type], [Type], [Type])
forall a. a -> ZonkM a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Type]
psig_tv_tys, [Type]
psig_theta, [Type]
tau_tys) }
; let
psig_tys :: [Type]
psig_tys = [Type]
psig_tv_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
psig_theta
seed_tys :: [Type]
seed_tys = [Type]
psig_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
tau_tys
grown_tcvs :: VarSet
grown_tcvs = [Type] -> VarSet -> VarSet
growThetaTyVars [Type]
candidates ([Type] -> VarSet
tyCoVarsOfTypes [Type]
seed_tys)
; dv :: CandidatesQTvs
dv@DV {dv_kvs :: CandidatesQTvs -> DTyVarSet
dv_kvs = DTyVarSet
cand_kvs, dv_tvs :: CandidatesQTvs -> DTyVarSet
dv_tvs = DTyVarSet
cand_tvs} <- [Type] -> TcM CandidatesQTvs
candidateQTyVarsOfTypes ([Type] -> TcM CandidatesQTvs) -> [Type] -> TcM CandidatesQTvs
forall a b. (a -> b) -> a -> b
$
[Type]
psig_tys [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
candidates [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
tau_tys
; let pick :: DTyVarSet -> DTyVarSet
pick = (DTyVarSet -> VarSet -> DTyVarSet
`dVarSetIntersectVarSet` VarSet
grown_tcvs)
dvs_plus :: CandidatesQTvs
dvs_plus = CandidatesQTvs
dv { dv_kvs = pick cand_kvs, dv_tvs = pick cand_tvs }
; String -> SDoc -> TcM ()
traceTc String
"decideQuantifiedTyVars" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tau_tys =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
tau_tys
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"candidates =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
candidates
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"cand_kvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
cand_kvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"cand_tvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> DTyVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DTyVarSet
cand_tvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tau_tys =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
tau_tys
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"seed_tys =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Type] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Type]
seed_tys
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"seed_tcvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([Type] -> VarSet
tyCoVarsOfTypes [Type]
seed_tys)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"grown_tcvs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
grown_tcvs
, 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_plus])
; SkolemInfo
-> NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
quantifyTyVars SkolemInfo
skol_info NonStandardDefaultingStrategy
DefaultNonStandardTyVars CandidatesQTvs
dvs_plus }
pickQuantifiablePreds
:: TyVarSet
-> TcTyVarSet
-> TcThetaType
-> TcM TcThetaType
pickQuantifiablePreds :: VarSet -> VarSet -> [Type] -> TcM [Type]
pickQuantifiablePreds VarSet
qtvs VarSet
mono_tvs0 [Type]
theta
= do { TcLevel
tc_lvl <- TcM TcLevel
TcM.getTcLevel
; let is_nested :: Bool
is_nested = Bool -> Bool
not (TcLevel -> Bool
isTopTcLevel TcLevel
tc_lvl)
; [Type] -> TcM [Type]
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Type -> Type) -> [Type] -> [Type]
forall a. (a -> Type) -> [a] -> [a]
mkMinimalBySCs Type -> Type
forall a. a -> a
id ([Type] -> [Type]) -> [Type] -> [Type]
forall a b. (a -> b) -> a -> b
$
(Type -> Maybe Type) -> [Type] -> [Type]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Bool -> Type -> Maybe Type
pick_me Bool
is_nested) [Type]
theta) }
where
pick_me :: Bool -> Type -> Maybe Type
pick_me Bool
is_nested Type
pred
= let pred_tvs :: VarSet
pred_tvs = Type -> VarSet
tyCoVarsOfType Type
pred
mentions_qtvs :: Bool
mentions_qtvs = VarSet
pred_tvs VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
qtvs
in case Type -> Pred
classifyPredType Type
pred of
ClassPred Class
cls [Type]
tys
| Just {} <- Class -> [Type] -> Maybe FastString
isCallStackPred Class
cls [Type]
tys
-> Maybe Type
forall a. Maybe a
Nothing
| Class -> Bool
isIPClass Class
cls
-> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
pred
| Bool -> Bool
not Bool
mentions_qtvs
-> Maybe Type
forall a. Maybe a
Nothing
| Bool
is_nested
-> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
pred
| VarSet
pred_tvs VarSet -> VarSet -> Bool
`subVarSet` (VarSet
qtvs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
mono_tvs0)
-> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
pred
| Bool
otherwise
-> Maybe Type
forall a. Maybe a
Nothing
EqPred EqRel
eq_rel Type
ty1 Type
ty2
| Bool
mentions_qtvs
, EqRel -> Type -> Type -> Bool
quantify_equality EqRel
eq_rel Type
ty1 Type
ty2
, Just (Class
cls, [Type]
tys) <- EqRel -> Type -> Type -> Maybe (Class, [Type])
boxEqPred EqRel
eq_rel Type
ty1 Type
ty2
-> Type -> Maybe Type
forall a. a -> Maybe a
Just (Class -> [Type] -> Type
mkClassPred Class
cls [Type]
tys)
| Bool
otherwise
-> Maybe Type
forall a. Maybe a
Nothing
IrredPred {} | Bool
mentions_qtvs -> Type -> Maybe Type
forall a. a -> Maybe a
Just Type
pred
| Bool
otherwise -> Maybe Type
forall a. Maybe a
Nothing
ForAllPred {} -> Maybe Type
forall a. Maybe a
Nothing
quantify_equality :: EqRel -> Type -> Type -> Bool
quantify_equality EqRel
NomEq Type
ty1 Type
ty2 = Type -> Bool
quant_fun Type
ty1 Bool -> Bool -> Bool
|| Type -> Bool
quant_fun Type
ty2
quantify_equality EqRel
ReprEq Type
_ Type
_ = Bool
True
quant_fun :: Type -> Bool
quant_fun Type
ty
= case HasCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
tcSplitTyConApp_maybe Type
ty of
Just (TyCon
tc, [Type]
tys) | TyCon -> Bool
isTypeFamilyTyCon TyCon
tc
-> [Type] -> VarSet
tyCoVarsOfTypes [Type]
tys VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
qtvs
Maybe (TyCon, [Type])
_ -> Bool
False
growThetaTyVars :: ThetaType -> TyCoVarSet -> TyCoVarSet
growThetaTyVars :: [Type] -> VarSet -> VarSet
growThetaTyVars [Type]
theta VarSet
tcvs
| [Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
theta = VarSet
tcvs
| Bool
otherwise = (VarSet -> VarSet) -> VarSet -> VarSet
transCloVarSet VarSet -> VarSet
mk_next VarSet
seed_tcvs
where
seed_tcvs :: VarSet
seed_tcvs = VarSet
tcvs VarSet -> VarSet -> VarSet
`unionVarSet` [Type] -> VarSet
tyCoVarsOfTypes [Type]
ips
([Type]
ips, [Type]
non_ips) = (Type -> Bool) -> [Type] -> ([Type], [Type])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Type -> Bool
isIPLikePred [Type]
theta
mk_next :: VarSet -> VarSet
mk_next :: VarSet -> VarSet
mk_next VarSet
so_far = (Type -> VarSet -> VarSet) -> VarSet -> [Type] -> VarSet
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (VarSet -> Type -> VarSet -> VarSet
grow_one VarSet
so_far) VarSet
emptyVarSet [Type]
non_ips
grow_one :: VarSet -> Type -> VarSet -> VarSet
grow_one VarSet
so_far Type
pred VarSet
tcvs
| VarSet
pred_tcvs VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
so_far = VarSet
tcvs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
pred_tcvs
| Bool
otherwise = VarSet
tcvs
where
pred_tcvs :: VarSet
pred_tcvs = Type -> VarSet
tyCoVarsOfType Type
pred
simplifyWantedsTcM :: [CtEvidence] -> TcM WantedConstraints
simplifyWantedsTcM :: [CtEvidence] -> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
simplifyWantedsTcM [CtEvidence]
wanted
= do { String -> SDoc -> TcM ()
traceTc String
"simplifyWantedsTcM {" ([CtEvidence] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [CtEvidence]
wanted)
; (WantedConstraints
result, EvBindMap
_) <- TcS WantedConstraints -> TcM (WantedConstraints, EvBindMap)
forall a. TcS a -> TcM (a, EvBindMap)
runTcS (WantedConstraints -> TcS WantedConstraints
solveWanteds ([CtEvidence] -> WantedConstraints
mkSimpleWC [CtEvidence]
wanted))
; WantedConstraints
result <- ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. ZonkM a -> TcM a
TcM.liftZonkM (ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints)
-> ZonkM WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a b. (a -> b) -> a -> b
$ WantedConstraints -> ZonkM WantedConstraints
TcM.zonkWC WantedConstraints
result
; String -> SDoc -> TcM ()
traceTc String
"simplifyWantedsTcM }" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
result)
; WantedConstraints
-> IOEnv (Env TcGblEnv TcLclEnv) WantedConstraints
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
result }
solveWanteds :: WantedConstraints -> TcS WantedConstraints
solveWanteds :: WantedConstraints -> TcS WantedConstraints
solveWanteds wc :: WantedConstraints
wc@(WC { wc_errors :: WantedConstraints -> Bag DelayedError
wc_errors = Bag DelayedError
errs })
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wc
= WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc
| Bool
otherwise
= do { TcLevel
cur_lvl <- TcS TcLevel
TcS.getTcLevel
; String -> SDoc -> TcS ()
traceTcS String
"solveWanteds {" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Level =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
cur_lvl
, WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wc ]
; DynFlags
dflags <- TcS DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; WantedConstraints
solved_wc <- Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
simplify_loop Int
0 (DynFlags -> IntWithInf
solverIterations DynFlags
dflags) Bool
True WantedConstraints
wc
; Bag DelayedError
errs' <- Bag DelayedError -> TcS (Bag DelayedError)
simplifyDelayedErrors Bag DelayedError
errs
; let final_wc :: WantedConstraints
final_wc = WantedConstraints
solved_wc { wc_errors = errs' }
; EvBindsVar
ev_binds_var <- TcS EvBindsVar
getTcEvBindsVar
; EvBindMap
bb <- EvBindsVar -> TcS EvBindMap
TcS.getTcEvBindsMap EvBindsVar
ev_binds_var
; String -> SDoc -> TcS ()
traceTcS String
"solveWanteds }" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"final wc =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
final_wc
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"current evbinds =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bag EvBind -> SDoc
forall a. Outputable a => a -> SDoc
ppr (EvBindMap -> Bag EvBind
evBindMapBinds EvBindMap
bb) ]
; WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
final_wc }
simplify_loop :: Int -> IntWithInf -> Bool
-> WantedConstraints -> TcS WantedConstraints
simplify_loop :: Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
simplify_loop Int
n IntWithInf
limit Bool
definitely_redo_implications
wc :: WantedConstraints
wc@(WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics })
= do { SDoc -> TcS ()
csTraceTcS (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"simplify_loop iteration=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
n
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"definitely_redo =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
definitely_redo_implications SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma
, Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (Cts -> Int
forall a. Bag a -> Int
lengthBag Cts
simples) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"simples to solve" ])
; String -> SDoc -> TcS ()
traceTcS String
"simplify_loop: wc =" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wc)
; (Int
unifs1, WantedConstraints
wc1) <- TcS WantedConstraints -> TcS (Int, WantedConstraints)
forall a. TcS a -> TcS (Int, a)
reportUnifications (TcS WantedConstraints -> TcS (Int, WantedConstraints))
-> TcS WantedConstraints -> TcS (Int, WantedConstraints)
forall a b. (a -> b) -> a -> b
$
Cts -> TcS WantedConstraints
solveSimpleWanteds Cts
simples
; WantedConstraints
wc2 <- if Bool -> Bool
not Bool
definitely_redo_implications
Bool -> Bool -> Bool
&& Int
unifs1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
Bool -> Bool -> Bool
&& Bag Implication -> Bool
forall a. Bag a -> Bool
isEmptyBag (WantedConstraints -> Bag Implication
wc_impl WantedConstraints
wc1)
then WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wc { wc_simple = wc_simple wc1 })
else do { Bag Implication
implics2 <- Bag Implication -> TcS (Bag Implication)
solveNestedImplications (Bag Implication -> TcS (Bag Implication))
-> Bag Implication -> TcS (Bag Implication)
forall a b. (a -> b) -> a -> b
$
Bag Implication
implics Bag Implication -> Bag Implication -> Bag Implication
forall a. Bag a -> Bag a -> Bag a
`unionBags` (WantedConstraints -> Bag Implication
wc_impl WantedConstraints
wc1)
; WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wc { wc_simple = wc_simple wc1
, wc_impl = implics2 }) }
; Bool
unif_happened <- TcS Bool
resetUnificationFlag
; SDoc -> TcS ()
csTraceTcS (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"unif_happened" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
unif_happened
; Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
maybe_simplify_again (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) IntWithInf
limit Bool
unif_happened WantedConstraints
wc2 }
maybe_simplify_again :: Int -> IntWithInf -> Bool
-> WantedConstraints -> TcS WantedConstraints
maybe_simplify_again :: Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
maybe_simplify_again Int
n IntWithInf
limit Bool
unif_happened wc :: WantedConstraints
wc@(WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples })
| Int
n Int -> IntWithInf -> Bool
`intGtLimit` IntWithInf
limit
= do {
TcRnMessage -> TcS ()
addErrTcS (TcRnMessage -> TcS ()) -> TcRnMessage -> TcS ()
forall a b. (a -> b) -> a -> b
$ Cts -> IntWithInf -> WantedConstraints -> TcRnMessage
TcRnSimplifierTooManyIterations Cts
simples IntWithInf
limit WantedConstraints
wc
; WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc }
| Bool
unif_happened
= Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
simplify_loop Int
n IntWithInf
limit Bool
True WantedConstraints
wc
| WantedConstraints -> Bool
superClassesMightHelp WantedConstraints
wc
=
do { [Ct]
pending_given <- TcS [Ct]
getPendingGivenScs
; let ([Ct]
pending_wanted, Cts
simples1) = Cts -> ([Ct], Cts)
getPendingWantedScs Cts
simples
; if [Ct] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Ct]
pending_given Bool -> Bool -> Bool
&& [Ct] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Ct]
pending_wanted
then WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc
else
do { [Ct]
new_given <- [Ct] -> TcS [Ct]
makeSuperClasses [Ct]
pending_given
; [Ct]
new_wanted <- [Ct] -> TcS [Ct]
makeSuperClasses [Ct]
pending_wanted
; [Ct] -> TcS ()
solveSimpleGivens [Ct]
new_given
; String -> SDoc -> TcS ()
traceTcS String
"maybe_simplify_again" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pending_given" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
pending_given
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"new_given" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
new_given
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pending_wanted" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
pending_wanted
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"new_wanted" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
new_wanted ])
; Int
-> IntWithInf -> Bool -> WantedConstraints -> TcS WantedConstraints
simplify_loop Int
n IntWithInf
limit (Bool -> Bool
not ([Ct] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Ct]
pending_given)) (WantedConstraints -> TcS WantedConstraints)
-> WantedConstraints -> TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$
WantedConstraints
wc { wc_simple = simples1 `unionBags` listToBag new_wanted } } }
| Bool
otherwise
= WantedConstraints -> TcS WantedConstraints
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return WantedConstraints
wc
solveNestedImplications :: Bag Implication
-> TcS (Bag Implication)
solveNestedImplications :: Bag Implication -> TcS (Bag Implication)
solveNestedImplications Bag Implication
implics
| Bag Implication -> Bool
forall a. Bag a -> Bool
isEmptyBag Bag Implication
implics
= Bag Implication -> TcS (Bag Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bag Implication
forall a. Bag a
emptyBag)
| Bool
otherwise
= do { String -> SDoc -> TcS ()
traceTcS String
"solveNestedImplications starting {" SDoc
forall doc. IsOutput doc => doc
empty
; Bag (Maybe Implication)
unsolved_implics <- (Implication -> TcS (Maybe Implication))
-> Bag Implication -> TcS (Bag (Maybe Implication))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM Implication -> TcS (Maybe Implication)
solveImplication Bag Implication
implics
; String -> SDoc -> TcS ()
traceTcS String
"solveNestedImplications end }" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"unsolved_implics =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bag (Maybe Implication) -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bag (Maybe Implication)
unsolved_implics ]
; Bag Implication -> TcS (Bag Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bag (Maybe Implication) -> Bag Implication
forall a. Bag (Maybe a) -> Bag a
catBagMaybes Bag (Maybe Implication)
unsolved_implics) }
solveImplication :: Implication
-> TcS (Maybe Implication)
solveImplication :: Implication -> TcS (Maybe Implication)
solveImplication imp :: Implication
imp@(Implic { ic_tclvl :: Implication -> TcLevel
ic_tclvl = TcLevel
tclvl
, ic_binds :: Implication -> EvBindsVar
ic_binds = EvBindsVar
ev_binds_var
, ic_given :: Implication -> [TcTyVar]
ic_given = [TcTyVar]
given_ids
, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wanteds
, ic_info :: Implication -> SkolemInfoAnon
ic_info = SkolemInfoAnon
info
, ic_status :: Implication -> ImplicStatus
ic_status = ImplicStatus
status })
| ImplicStatus -> Bool
isSolvedStatus ImplicStatus
status
= Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
imp)
| Bool
otherwise
= do { InertSet
inerts <- TcS InertSet
getInertSet
; String -> SDoc -> TcS ()
traceTcS String
"solveImplication {" (Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Implication
imp SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Inerts" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> InertSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr InertSet
inerts)
; (HasGivenEqs
has_given_eqs, InertIrreds
given_insols, WantedConstraints
residual_wanted)
<- EvBindsVar
-> TcLevel
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints)
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints)
forall a. EvBindsVar -> TcLevel -> TcS a -> TcS a
nestImplicTcS EvBindsVar
ev_binds_var TcLevel
tclvl (TcS (HasGivenEqs, InertIrreds, WantedConstraints)
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints))
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints)
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints)
forall a b. (a -> b) -> a -> b
$
do { let loc :: CtLoc
loc = TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc TcLevel
tclvl SkolemInfoAnon
info (Implication -> CtLocEnv
ic_env Implication
imp)
givens :: [Ct]
givens = CtLoc -> [TcTyVar] -> [Ct]
mkGivens CtLoc
loc [TcTyVar]
given_ids
; [Ct] -> TcS ()
solveSimpleGivens [Ct]
givens
; WantedConstraints
residual_wanted <- WantedConstraints -> TcS WantedConstraints
solveWanteds WantedConstraints
wanteds
; (HasGivenEqs
has_eqs, InertIrreds
given_insols) <- TcLevel -> TcS (HasGivenEqs, InertIrreds)
getHasGivenEqs TcLevel
tclvl
; (HasGivenEqs, InertIrreds, WantedConstraints)
-> TcS (HasGivenEqs, InertIrreds, WantedConstraints)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (HasGivenEqs
has_eqs, InertIrreds
given_insols, WantedConstraints
residual_wanted) }
; String -> SDoc -> TcS ()
traceTcS String
"solveImplication 2"
(InertIrreds -> SDoc
forall a. Outputable a => a -> SDoc
ppr InertIrreds
given_insols SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
residual_wanted)
; let final_wanted :: WantedConstraints
final_wanted = WantedConstraints
residual_wanted WantedConstraints -> InertIrreds -> WantedConstraints
`addInsols` InertIrreds
given_insols
; Maybe Implication
res_implic <- Implication -> TcS (Maybe Implication)
setImplicationStatus (Implication
imp { ic_given_eqs = has_given_eqs
, ic_wanted = final_wanted })
; EvBindMap
evbinds <- EvBindsVar -> TcS EvBindMap
TcS.getTcEvBindsMap EvBindsVar
ev_binds_var
; VarSet
tcvs <- EvBindsVar -> TcS VarSet
TcS.getTcEvTyCoVars EvBindsVar
ev_binds_var
; String -> SDoc -> TcS ()
traceTcS String
"solveImplication end }" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"has_given_eqs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HasGivenEqs -> SDoc
forall a. Outputable a => a -> SDoc
ppr HasGivenEqs
has_given_eqs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"res_implic =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Maybe Implication
res_implic
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"implication evbinds =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bag EvBind -> SDoc
forall a. Outputable a => a -> SDoc
ppr (EvBindMap -> Bag EvBind
evBindMapBinds EvBindMap
evbinds)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"implication tvcs =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
tcvs ]
; Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Implication
res_implic }
setImplicationStatus :: Implication -> TcS (Maybe Implication)
setImplicationStatus :: Implication -> TcS (Maybe Implication)
setImplicationStatus implic :: Implication
implic@(Implic { ic_status :: Implication -> ImplicStatus
ic_status = ImplicStatus
status
, ic_info :: Implication -> SkolemInfoAnon
ic_info = SkolemInfoAnon
info
, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wc
, ic_given :: Implication -> [TcTyVar]
ic_given = [TcTyVar]
givens })
| Bool -> SDoc -> Bool -> Bool
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Bool -> Bool
not (ImplicStatus -> Bool
isSolvedStatus ImplicStatus
status)) (SkolemInfoAnon -> SDoc
forall a. Outputable a => a -> SDoc
ppr SkolemInfoAnon
info) (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
Bool -> Bool
not (WantedConstraints -> Bool
isSolvedWC WantedConstraints
pruned_wc)
= do { String -> SDoc -> TcS ()
traceTcS String
"setImplicationStatus(not-all-solved) {" (Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Implication
implic)
; Implication
implic <- Implication -> TcS Implication
neededEvVars Implication
implic
; let new_status :: ImplicStatus
new_status | WantedConstraints -> Bool
insolubleWC WantedConstraints
pruned_wc = ImplicStatus
IC_Insoluble
| Bool
otherwise = ImplicStatus
IC_Unsolved
new_implic :: Implication
new_implic = Implication
implic { ic_status = new_status
, ic_wanted = pruned_wc }
; String -> SDoc -> TcS ()
traceTcS String
"setImplicationStatus(not-all-solved) }" (Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Implication
new_implic)
; Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Implication -> TcS (Maybe Implication))
-> Maybe Implication -> TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
new_implic }
| Bool
otherwise
= do { String -> SDoc -> TcS ()
traceTcS String
"setImplicationStatus(all-solved) {" (Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Implication
implic)
; implic :: Implication
implic@(Implic { ic_need_inner :: Implication -> VarSet
ic_need_inner = VarSet
need_inner
, ic_need_outer :: Implication -> VarSet
ic_need_outer = VarSet
need_outer }) <- Implication -> TcS Implication
neededEvVars Implication
implic
; Bool
bad_telescope <- Implication -> TcS Bool
checkBadTelescope Implication
implic
; let warn_givens :: [TcTyVar]
warn_givens = SkolemInfoAnon -> VarSet -> [TcTyVar] -> [TcTyVar]
findUnnecessaryGivens SkolemInfoAnon
info VarSet
need_inner [TcTyVar]
givens
discard_entire_implication :: Bool
discard_entire_implication
= [TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
warn_givens
Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
bad_telescope
Bool -> Bool -> Bool
&& WantedConstraints -> Bool
isEmptyWC WantedConstraints
pruned_wc
Bool -> Bool -> Bool
&& VarSet -> Bool
isEmptyVarSet VarSet
need_outer
final_status :: ImplicStatus
final_status
| Bool
bad_telescope = ImplicStatus
IC_BadTelescope
| Bool
otherwise = IC_Solved { ics_dead :: [TcTyVar]
ics_dead = [TcTyVar]
warn_givens }
final_implic :: Implication
final_implic = Implication
implic { ic_status = final_status
, ic_wanted = pruned_wc }
; String -> SDoc -> TcS ()
traceTcS String
"setImplicationStatus(all-solved) }" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"discard:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
discard_entire_implication
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"new_implic:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Implication -> SDoc
forall a. Outputable a => a -> SDoc
ppr Implication
final_implic ]
; Maybe Implication -> TcS (Maybe Implication)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Implication -> TcS (Maybe Implication))
-> Maybe Implication -> TcS (Maybe Implication)
forall a b. (a -> b) -> a -> b
$ if Bool
discard_entire_implication
then Maybe Implication
forall a. Maybe a
Nothing
else Implication -> Maybe Implication
forall a. a -> Maybe a
Just Implication
final_implic }
where
WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics, wc_errors :: WantedConstraints -> Bag DelayedError
wc_errors = Bag DelayedError
errs } = WantedConstraints
wc
pruned_implics :: Bag Implication
pruned_implics = (Implication -> Bool) -> Bag Implication -> Bag Implication
forall a. (a -> Bool) -> Bag a -> Bag a
filterBag Implication -> Bool
keep_me Bag Implication
implics
pruned_wc :: WantedConstraints
pruned_wc = WC { wc_simple :: Cts
wc_simple = Cts
simples
, wc_impl :: Bag Implication
wc_impl = Bag Implication
pruned_implics
, wc_errors :: Bag DelayedError
wc_errors = Bag DelayedError
errs }
keep_me :: Implication -> Bool
keep_me :: Implication -> Bool
keep_me Implication
ic
| IC_Solved { ics_dead :: ImplicStatus -> [TcTyVar]
ics_dead = [TcTyVar]
dead_givens } <- Implication -> ImplicStatus
ic_status Implication
ic
, [TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
dead_givens
, Bag Implication -> Bool
forall a. Bag a -> Bool
isEmptyBag (WantedConstraints -> Bag Implication
wc_impl (Implication -> WantedConstraints
ic_wanted Implication
ic))
= Bool
False
| Bool
otherwise
= Bool
True
findUnnecessaryGivens :: SkolemInfoAnon -> VarSet -> [EvVar] -> [EvVar]
findUnnecessaryGivens :: SkolemInfoAnon -> VarSet -> [TcTyVar] -> [TcTyVar]
findUnnecessaryGivens SkolemInfoAnon
info VarSet
need_inner [TcTyVar]
givens
| Bool -> Bool
not (SkolemInfoAnon -> Bool
warnRedundantGivens SkolemInfoAnon
info)
= []
| Bool -> Bool
not ([TcTyVar] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TcTyVar]
unused_givens)
= [TcTyVar]
unused_givens
| Bool
otherwise
= [TcTyVar]
redundant_givens
where
in_instance_decl :: Bool
in_instance_decl = case SkolemInfoAnon
info of { InstSkol {} -> Bool
True; SkolemInfoAnon
_ -> Bool
False }
unused_givens :: [TcTyVar]
unused_givens = (TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filterOut TcTyVar -> Bool
is_used [TcTyVar]
givens
is_used :: TcTyVar -> Bool
is_used TcTyVar
given = TcTyVar -> Bool
is_type_error TcTyVar
given
Bool -> Bool -> Bool
|| TcTyVar
given TcTyVar -> VarSet -> Bool
`elemVarSet` VarSet
need_inner
Bool -> Bool -> Bool
|| (Bool
in_instance_decl Bool -> Bool -> Bool
&& Type -> Bool
is_improving (TcTyVar -> Type
idType TcTyVar
given))
minimal_givens :: [TcTyVar]
minimal_givens = (TcTyVar -> Type) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Type) -> [a] -> [a]
mkMinimalBySCs TcTyVar -> Type
evVarPred [TcTyVar]
givens
is_minimal :: TcTyVar -> Bool
is_minimal = (TcTyVar -> VarSet -> Bool
`elemVarSet` [TcTyVar] -> VarSet
mkVarSet [TcTyVar]
minimal_givens)
redundant_givens :: [TcTyVar]
redundant_givens
| Bool
in_instance_decl = []
| Bool
otherwise = (TcTyVar -> Bool) -> [TcTyVar] -> [TcTyVar]
forall a. (a -> Bool) -> [a] -> [a]
filterOut TcTyVar -> Bool
is_minimal [TcTyVar]
givens
is_type_error :: TcTyVar -> Bool
is_type_error TcTyVar
id = Type -> Bool
isTopLevelUserTypeError (TcTyVar -> Type
idType TcTyVar
id)
is_improving :: Type -> Bool
is_improving Type
pred
= (Type -> Bool) -> [Type] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Type -> Bool
isImprovementPred (Type
pred Type -> [Type] -> [Type]
forall a. a -> [a] -> [a]
: Type -> [Type]
transSuperClasses Type
pred)
checkBadTelescope :: Implication -> TcS Bool
checkBadTelescope :: Implication -> TcS Bool
checkBadTelescope (Implic { ic_info :: Implication -> SkolemInfoAnon
ic_info = SkolemInfoAnon
info
, ic_skols :: Implication -> [TcTyVar]
ic_skols = [TcTyVar]
skols })
| SkolemInfoAnon -> Bool
checkTelescopeSkol SkolemInfoAnon
info
= do{ [TcTyVar]
skols <- (TcTyVar -> TcS TcTyVar) -> [TcTyVar] -> TcS [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 TcTyVar -> TcS TcTyVar
TcS.zonkTyCoVarKind [TcTyVar]
skols
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (VarSet -> [TcTyVar] -> Bool
go VarSet
emptyVarSet ([TcTyVar] -> [TcTyVar]
forall a. [a] -> [a]
reverse [TcTyVar]
skols))}
| Bool
otherwise
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
where
go :: TyVarSet
-> [TcTyVar]
-> Bool
go :: VarSet -> [TcTyVar] -> Bool
go VarSet
_ [] = Bool
False
go VarSet
later_skols (TcTyVar
one_skol : [TcTyVar]
earlier_skols)
| Type -> VarSet
tyCoVarsOfType (TcTyVar -> Type
tyVarKind TcTyVar
one_skol) VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
later_skols
= Bool
True
| Bool
otherwise
= VarSet -> [TcTyVar] -> Bool
go (VarSet
later_skols VarSet -> TcTyVar -> VarSet
`extendVarSet` TcTyVar
one_skol) [TcTyVar]
earlier_skols
warnRedundantGivens :: SkolemInfoAnon -> Bool
warnRedundantGivens :: SkolemInfoAnon -> Bool
warnRedundantGivens (SigSkol UserTypeCtxt
ctxt Type
_ [(Name, TcTyVar)]
_)
= case UserTypeCtxt
ctxt of
FunSigCtxt Name
_ ReportRedundantConstraints
rrc -> ReportRedundantConstraints -> Bool
reportRedundantConstraints ReportRedundantConstraints
rrc
ExprSigCtxt ReportRedundantConstraints
rrc -> ReportRedundantConstraints -> Bool
reportRedundantConstraints ReportRedundantConstraints
rrc
UserTypeCtxt
_ -> Bool
False
warnRedundantGivens (InstSkol {}) = Bool
True
warnRedundantGivens SkolemInfoAnon
_ = Bool
False
neededEvVars :: Implication -> TcS Implication
neededEvVars :: Implication -> TcS Implication
neededEvVars implic :: Implication
implic@(Implic { ic_given :: Implication -> [TcTyVar]
ic_given = [TcTyVar]
givens
, ic_binds :: Implication -> EvBindsVar
ic_binds = EvBindsVar
ev_binds_var
, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WC { wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics }
, ic_need_inner :: Implication -> VarSet
ic_need_inner = VarSet
old_needs })
= do { EvBindMap
ev_binds <- EvBindsVar -> TcS EvBindMap
TcS.getTcEvBindsMap EvBindsVar
ev_binds_var
; VarSet
tcvs <- EvBindsVar -> TcS VarSet
TcS.getTcEvTyCoVars EvBindsVar
ev_binds_var
; let seeds1 :: VarSet
seeds1 = (Implication -> VarSet -> VarSet)
-> VarSet -> Bag Implication -> VarSet
forall a b. (a -> b -> b) -> b -> Bag a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Implication -> VarSet -> VarSet
add_implic_seeds VarSet
old_needs Bag Implication
implics
seeds2 :: VarSet
seeds2 = (EvBind -> VarSet -> VarSet) -> VarSet -> EvBindMap -> VarSet
forall a. (EvBind -> a -> a) -> a -> EvBindMap -> a
nonDetStrictFoldEvBindMap EvBind -> VarSet -> VarSet
add_wanted VarSet
seeds1 EvBindMap
ev_binds
seeds3 :: VarSet
seeds3 = VarSet
seeds2 VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
tcvs
need_inner :: VarSet
need_inner = EvBindMap -> VarSet -> VarSet
findNeededEvVars EvBindMap
ev_binds VarSet
seeds3
live_ev_binds :: EvBindMap
live_ev_binds = (EvBind -> Bool) -> EvBindMap -> EvBindMap
filterEvBindMap (VarSet -> EvBind -> Bool
needed_ev_bind VarSet
need_inner) EvBindMap
ev_binds
need_outer :: VarSet
need_outer = VarSet -> EvBindMap -> VarSet
varSetMinusEvBindMap VarSet
need_inner EvBindMap
live_ev_binds
VarSet -> [TcTyVar] -> VarSet
`delVarSetList` [TcTyVar]
givens
; EvBindsVar -> EvBindMap -> TcS ()
TcS.setTcEvBindsMap EvBindsVar
ev_binds_var EvBindMap
live_ev_binds
; String -> SDoc -> TcS ()
traceTcS String
"neededEvVars" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"old_needs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
old_needs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"seeds3:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
seeds3
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tcvs:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> VarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr VarSet
tcvs
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ev_binds:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> EvBindMap -> SDoc
forall a. Outputable a => a -> SDoc
ppr EvBindMap
ev_binds
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"live_ev_binds:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> EvBindMap -> SDoc
forall a. Outputable a => a -> SDoc
ppr EvBindMap
live_ev_binds ]
; Implication -> TcS Implication
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Implication
implic { ic_need_inner = need_inner
, ic_need_outer = need_outer }) }
where
add_implic_seeds :: Implication -> VarSet -> VarSet
add_implic_seeds (Implic { ic_need_outer :: Implication -> VarSet
ic_need_outer = VarSet
needs }) VarSet
acc
= VarSet
needs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
acc
needed_ev_bind :: VarSet -> EvBind -> Bool
needed_ev_bind VarSet
needed (EvBind { eb_lhs :: EvBind -> TcTyVar
eb_lhs = TcTyVar
ev_var
, eb_info :: EvBind -> EvBindInfo
eb_info = EvBindInfo
info })
| EvBindGiven{} <- EvBindInfo
info = TcTyVar
ev_var TcTyVar -> VarSet -> Bool
`elemVarSet` VarSet
needed
| Bool
otherwise = Bool
True
add_wanted :: EvBind -> VarSet -> VarSet
add_wanted :: EvBind -> VarSet -> VarSet
add_wanted (EvBind { eb_info :: EvBind -> EvBindInfo
eb_info = EvBindInfo
info, eb_rhs :: EvBind -> EvTerm
eb_rhs = EvTerm
rhs }) VarSet
needs
| EvBindGiven{} <- EvBindInfo
info = VarSet
needs
| Bool
otherwise = EvTerm -> VarSet
evVarsOfTerm EvTerm
rhs VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
needs
simplifyDelayedErrors :: Bag DelayedError -> TcS (Bag DelayedError)
simplifyDelayedErrors :: Bag DelayedError -> TcS (Bag DelayedError)
simplifyDelayedErrors = (DelayedError -> TcS DelayedError)
-> Bag DelayedError -> TcS (Bag DelayedError)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bag a -> m (Bag b)
mapBagM DelayedError -> TcS DelayedError
simpl_err
where
simpl_err :: DelayedError -> TcS DelayedError
simpl_err :: DelayedError -> TcS DelayedError
simpl_err (DE_Hole Hole
hole) = Hole -> DelayedError
DE_Hole (Hole -> DelayedError) -> TcS Hole -> TcS DelayedError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Hole -> TcS Hole
simpl_hole Hole
hole
simpl_err err :: DelayedError
err@(DE_NotConcrete {}) = DelayedError -> TcS DelayedError
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return DelayedError
err
simpl_hole :: Hole -> TcS Hole
simpl_hole :: Hole -> TcS Hole
simpl_hole h :: Hole
h@(Hole { hole_sort :: Hole -> HoleSort
hole_sort = HoleSort
ConstraintHole }) = Hole -> TcS Hole
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Hole
h
simpl_hole h :: Hole
h@(Hole { hole_ty :: Hole -> Type
hole_ty = Type
ty, hole_loc :: Hole -> CtLoc
hole_loc = CtLoc
loc })
= do { Type
ty' <- CtLoc -> Type -> TcS Type
rewriteType CtLoc
loc Type
ty
; String -> SDoc -> TcS ()
traceTcS String
"simpl_hole" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty')
; Hole -> TcS Hole
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Hole
h { hole_ty = ty' }) }
defaultTyVarTcS :: TcTyVar -> TcS Bool
defaultTyVarTcS :: TcTyVar -> TcS Bool
defaultTyVarTcS TcTyVar
the_tv
| TcTyVar -> Bool
isTyVarTyVar TcTyVar
the_tv
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| TcTyVar -> Bool
isRuntimeRepVar TcTyVar
the_tv
= do { String -> SDoc -> TcS ()
traceTcS String
"defaultTyVarTcS RuntimeRep" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
the_tv)
; TcTyVar -> Type -> TcS ()
unifyTyVar TcTyVar
the_tv Type
liftedRepTy
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| TcTyVar -> Bool
isLevityVar TcTyVar
the_tv
= do { String -> SDoc -> TcS ()
traceTcS String
"defaultTyVarTcS Levity" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
the_tv)
; TcTyVar -> Type -> TcS ()
unifyTyVar TcTyVar
the_tv Type
liftedDataConTy
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| TcTyVar -> Bool
isMultiplicityVar TcTyVar
the_tv
= do { String -> SDoc -> TcS ()
traceTcS String
"defaultTyVarTcS Multiplicity" (TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
the_tv)
; TcTyVar -> Type -> TcS ()
unifyTyVar TcTyVar
the_tv Type
ManyTy
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
| Bool
otherwise
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
approximateWC :: Bool
-> WantedConstraints
-> Cts
approximateWC :: Bool -> WantedConstraints -> Cts
approximateWC Bool
float_past_equalities WantedConstraints
wc
= Bool -> VarSet -> WantedConstraints -> Cts
float_wc Bool
False VarSet
emptyVarSet WantedConstraints
wc
where
float_wc :: Bool
-> TcTyCoVarSet
-> WantedConstraints -> Cts
float_wc :: Bool -> VarSet -> WantedConstraints -> Cts
float_wc Bool
encl_eqs VarSet
trapping_tvs (WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics })
= (Ct -> Bool) -> Cts -> Cts
forall a. (a -> Bool) -> Bag a -> Bag a
filterBag (Bool -> VarSet -> Ct -> Bool
is_floatable Bool
encl_eqs VarSet
trapping_tvs) Cts
simples Cts -> Cts -> Cts
forall a. Bag a -> Bag a -> Bag a
`unionBags`
(Implication -> Cts) -> Bag Implication -> Cts
forall a b. (a -> Bag b) -> Bag a -> Bag b
concatMapBag (Bool -> VarSet -> Implication -> Cts
float_implic Bool
encl_eqs VarSet
trapping_tvs) Bag Implication
implics
float_implic :: Bool -> TcTyCoVarSet -> Implication -> Cts
float_implic :: Bool -> VarSet -> Implication -> Cts
float_implic Bool
encl_eqs VarSet
trapping_tvs Implication
imp
= Bool -> VarSet -> WantedConstraints -> Cts
float_wc Bool
new_encl_eqs VarSet
new_trapping_tvs (Implication -> WantedConstraints
ic_wanted Implication
imp)
where
new_trapping_tvs :: VarSet
new_trapping_tvs = VarSet
trapping_tvs VarSet -> [TcTyVar] -> VarSet
`extendVarSetList` Implication -> [TcTyVar]
ic_skols Implication
imp
new_encl_eqs :: Bool
new_encl_eqs = Bool
encl_eqs Bool -> Bool -> Bool
|| Implication -> HasGivenEqs
ic_given_eqs Implication
imp HasGivenEqs -> HasGivenEqs -> Bool
forall a. Eq a => a -> a -> Bool
== HasGivenEqs
MaybeGivenEqs
is_floatable :: Bool -> VarSet -> Ct -> Bool
is_floatable Bool
encl_eqs VarSet
skol_tvs Ct
ct
| Ct -> Bool
isGivenCt Ct
ct = Bool
False
| Ct -> Bool
insolubleCt Ct
ct = Bool
False
| Ct -> VarSet
tyCoVarsOfCt Ct
ct VarSet -> VarSet -> Bool
`intersectsVarSet` VarSet
skol_tvs = Bool
False
| Bool
otherwise
= case Type -> Pred
classifyPredType (Ct -> Type
ctPred Ct
ct) of
EqPred {} -> Bool
float_past_equalities Bool -> Bool -> Bool
|| Bool -> Bool
not Bool
encl_eqs
ClassPred {} -> Bool
True
IrredPred {} -> Bool
True
ForAllPred {} -> Bool
False
applyDefaultingRules :: WantedConstraints -> TcS Bool
applyDefaultingRules :: WantedConstraints -> TcS Bool
applyDefaultingRules WantedConstraints
wanteds
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanteds
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| Bool
otherwise
= do { info :: ([Type], (Bool, Bool))
info@([Type]
default_tys, (Bool, Bool)
_) <- TcS ([Type], (Bool, Bool))
getDefaultInfo
; WantedConstraints
wanteds <- WantedConstraints -> TcS WantedConstraints
TcS.zonkWC WantedConstraints
wanteds
; TcGblEnv
tcg_env <- TcS TcGblEnv
TcS.getGblEnv
; let plugins :: [FillDefaulting]
plugins = TcGblEnv -> [FillDefaulting]
tcg_defaulting_plugins TcGblEnv
tcg_env
; (WantedConstraints
wanteds, [Bool]
plugin_defaulted) <- if [FillDefaulting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FillDefaulting]
plugins then (WantedConstraints, [Bool]) -> TcS (WantedConstraints, [Bool])
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanteds, []) else
do {
; String -> SDoc -> TcS ()
traceTcS String
"defaultingPlugins {" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanteds)
; (WantedConstraints
wanteds, [Bool]
defaultedGroups) <- (WantedConstraints
-> FillDefaulting -> TcS (WantedConstraints, Bool))
-> WantedConstraints
-> [FillDefaulting]
-> TcS (WantedConstraints, [Bool])
forall (m :: * -> *) (t :: * -> *) acc x y.
(Monad m, Traversable t) =>
(acc -> x -> m (acc, y)) -> acc -> t x -> m (acc, t y)
mapAccumLM WantedConstraints
-> FillDefaulting -> TcS (WantedConstraints, Bool)
run_defaulting_plugin WantedConstraints
wanteds [FillDefaulting]
plugins
; String -> SDoc -> TcS ()
traceTcS String
"defaultingPlugins }" ([Bool] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Bool]
defaultedGroups)
; (WantedConstraints, [Bool]) -> TcS (WantedConstraints, [Bool])
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanteds, [Bool]
defaultedGroups)
}
; let groups :: [(TcTyVar, [Ct])]
groups = ([Type], (Bool, Bool)) -> WantedConstraints -> [(TcTyVar, [Ct])]
findDefaultableGroups ([Type], (Bool, Bool))
info WantedConstraints
wanteds
; String -> SDoc -> TcS ()
traceTcS String
"applyDefaultingRules {" (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wanteds =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanteds
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"groups =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [(TcTyVar, [Ct])] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(TcTyVar, [Ct])]
groups
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"info =" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ([Type], (Bool, Bool)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([Type], (Bool, Bool))
info ]
; [Bool]
something_happeneds <- ((TcTyVar, [Ct]) -> TcS Bool) -> [(TcTyVar, [Ct])] -> TcS [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 ([Type] -> (TcTyVar, [Ct]) -> TcS Bool
disambigGroup [Type]
default_tys) [(TcTyVar, [Ct])]
groups
; String -> SDoc -> TcS ()
traceTcS String
"applyDefaultingRules }" ([Bool] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Bool]
something_happeneds)
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> TcS Bool) -> Bool -> TcS Bool
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
something_happeneds Bool -> Bool -> Bool
|| [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
plugin_defaulted }
where run_defaulting_plugin :: WantedConstraints
-> FillDefaulting -> TcS (WantedConstraints, Bool)
run_defaulting_plugin WantedConstraints
wanteds FillDefaulting
p =
do { [DefaultingProposal]
groups <- TcPluginM [DefaultingProposal] -> TcS [DefaultingProposal]
forall a. TcPluginM a -> TcS a
runTcPluginTcS (FillDefaulting
p WantedConstraints
wanteds)
; [DefaultingProposal]
defaultedGroups <-
(DefaultingProposal -> TcS Bool)
-> [DefaultingProposal] -> TcS [DefaultingProposal]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM (\DefaultingProposal
g -> [Type] -> (TcTyVar, [Ct]) -> TcS Bool
disambigGroup
(DefaultingProposal -> [Type]
deProposalCandidates DefaultingProposal
g)
(DefaultingProposal -> TcTyVar
deProposalTyVar DefaultingProposal
g, DefaultingProposal -> [Ct]
deProposalCts DefaultingProposal
g))
[DefaultingProposal]
groups
; String -> SDoc -> TcS ()
traceTcS String
"defaultingPlugin " (SDoc -> TcS ()) -> SDoc -> TcS ()
forall a b. (a -> b) -> a -> b
$ [DefaultingProposal] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [DefaultingProposal]
defaultedGroups
; case [DefaultingProposal]
defaultedGroups of
[] -> (WantedConstraints, Bool) -> TcS (WantedConstraints, Bool)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanteds, Bool
False)
[DefaultingProposal]
_ -> do
WantedConstraints
wanteds' <- WantedConstraints -> TcS WantedConstraints
TcS.zonkWC WantedConstraints
wanteds
(WantedConstraints, Bool) -> TcS (WantedConstraints, Bool)
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return (WantedConstraints
wanteds', Bool
True)
}
findDefaultableGroups
:: ( [Type]
, (Bool,Bool) )
-> WantedConstraints
-> [(TyVar, [Ct])]
findDefaultableGroups :: ([Type], (Bool, Bool)) -> WantedConstraints -> [(TcTyVar, [Ct])]
findDefaultableGroups ([Type]
default_tys, (Bool
ovl_strings, Bool
extended_defaults)) WantedConstraints
wanteds
| [Type] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Type]
default_tys
= []
| Bool
otherwise
= [ (TcTyVar
tv, ((Ct, Class, TcTyVar) -> Ct) -> [(Ct, Class, TcTyVar)] -> [Ct]
forall a b. (a -> b) -> [a] -> [b]
map (Ct, Class, TcTyVar) -> Ct
forall a b c. (a, b, c) -> a
fstOf3 [(Ct, Class, TcTyVar)]
group)
| group' :: NonEmpty (Ct, Class, TcTyVar)
group'@((Ct
_,Class
_,TcTyVar
tv) :| [(Ct, Class, TcTyVar)]
_) <- [NonEmpty (Ct, Class, TcTyVar)]
unary_groups
, let group :: [(Ct, Class, TcTyVar)]
group = NonEmpty (Ct, Class, TcTyVar) -> [(Ct, Class, TcTyVar)]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (Ct, Class, TcTyVar)
group'
, TcTyVar -> Bool
defaultable_tyvar TcTyVar
tv
, [Class] -> Bool
defaultable_classes (((Ct, Class, TcTyVar) -> Class)
-> [(Ct, Class, TcTyVar)] -> [Class]
forall a b. (a -> b) -> [a] -> [b]
map (Ct, Class, TcTyVar) -> Class
forall a b c. (a, b, c) -> b
sndOf3 [(Ct, Class, TcTyVar)]
group) ]
where
simples :: Cts
simples = Bool -> WantedConstraints -> Cts
approximateWC Bool
True WantedConstraints
wanteds
([(Ct, Class, TcTyVar)]
unaries, [Ct]
non_unaries) = (Ct -> Either (Ct, Class, TcTyVar) Ct)
-> [Ct] -> ([(Ct, Class, TcTyVar)], [Ct])
forall a b c. (a -> Either b c) -> [a] -> ([b], [c])
partitionWith Ct -> Either (Ct, Class, TcTyVar) Ct
find_unary (Cts -> [Ct]
forall a. Bag a -> [a]
bagToList Cts
simples)
unary_groups :: [NonEmpty (Ct, Class, TcTyVar)]
unary_groups = ((Ct, Class, TcTyVar) -> (Ct, Class, TcTyVar) -> Ordering)
-> [(Ct, Class, TcTyVar)] -> [NonEmpty (Ct, Class, TcTyVar)]
forall a. (a -> a -> Ordering) -> [a] -> [NonEmpty a]
equivClasses (Ct, Class, TcTyVar) -> (Ct, Class, TcTyVar) -> Ordering
forall {a} {a} {b} {a} {b}.
Ord a =>
(a, b, a) -> (a, b, a) -> Ordering
cmp_tv [(Ct, Class, TcTyVar)]
unaries
unary_groups :: [NonEmpty (Ct, Class, TcTyVar)]
unaries :: [(Ct, Class, TcTyVar)]
non_unaries :: [Ct]
find_unary :: Ct -> Either (Ct, Class, TyVar) Ct
find_unary :: Ct -> Either (Ct, Class, TcTyVar) Ct
find_unary Ct
cc
| Just (Class
cls,[Type]
tys) <- Type -> Maybe (Class, [Type])
getClassPredTys_maybe (Ct -> Type
ctPred Ct
cc)
, [Type
ty] <- TyCon -> [Type] -> [Type]
filterOutInvisibleTypes (Class -> TyCon
classTyCon Class
cls) [Type]
tys
, Just TcTyVar
tv <- Type -> Maybe TcTyVar
getTyVar_maybe Type
ty
, TcTyVar -> Bool
isMetaTyVar TcTyVar
tv
= (Ct, Class, TcTyVar) -> Either (Ct, Class, TcTyVar) Ct
forall a b. a -> Either a b
Left (Ct
cc, Class
cls, TcTyVar
tv)
find_unary Ct
cc = Ct -> Either (Ct, Class, TcTyVar) Ct
forall a b. b -> Either a b
Right Ct
cc
bad_tvs :: TcTyCoVarSet
bad_tvs :: VarSet
bad_tvs = (Ct -> VarSet) -> [Ct] -> VarSet
forall a. (a -> VarSet) -> [a] -> VarSet
mapUnionVarSet Ct -> VarSet
tyCoVarsOfCt [Ct]
non_unaries
cmp_tv :: (a, b, a) -> (a, b, a) -> Ordering
cmp_tv (a
_,b
_,a
tv1) (a
_,b
_,a
tv2) = a
tv1 a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` a
tv2
defaultable_tyvar :: TcTyVar -> Bool
defaultable_tyvar :: TcTyVar -> Bool
defaultable_tyvar TcTyVar
tv
= let b1 :: Bool
b1 = TcTyVar -> Bool
isTyConableTyVar TcTyVar
tv
b2 :: Bool
b2 = Bool -> Bool
not (TcTyVar
tv TcTyVar -> VarSet -> Bool
`elemVarSet` VarSet
bad_tvs)
in Bool
b1 Bool -> Bool -> Bool
&& (Bool
b2 Bool -> Bool -> Bool
|| Bool
extended_defaults)
defaultable_classes :: [Class] -> Bool
defaultable_classes :: [Class] -> Bool
defaultable_classes [Class]
clss
| Bool
extended_defaults = (Class -> Bool) -> [Class] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Bool -> Class -> Bool
isInteractiveClass Bool
ovl_strings) [Class]
clss
| Bool
otherwise = (Class -> Bool) -> [Class] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Class -> Bool
is_std_class [Class]
clss Bool -> Bool -> Bool
&& ((Class -> Bool) -> [Class] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Bool -> Class -> Bool
isNumClass Bool
ovl_strings) [Class]
clss)
is_std_class :: Class -> Bool
is_std_class Class
cls = Class -> Bool
isStandardClass Class
cls Bool -> Bool -> Bool
||
(Bool
ovl_strings Bool -> Bool -> Bool
&& (Class
cls Class -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
isStringClassKey))
disambigGroup :: [Type]
-> (TcTyVar, [Ct])
-> TcS Bool
disambigGroup :: [Type] -> (TcTyVar, [Ct]) -> TcS Bool
disambigGroup [] (TcTyVar, [Ct])
_
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
disambigGroup (Type
default_ty:[Type]
default_tys) group :: (TcTyVar, [Ct])
group@(TcTyVar
the_tv, [Ct]
wanteds)
= do { String -> SDoc -> TcS ()
traceTcS String
"disambigGroup {" ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
default_ty, TcTyVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcTyVar
the_tv, [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
wanteds ])
; EvBindsVar
fake_ev_binds_var <- TcS EvBindsVar
TcS.newTcEvBinds
; TcLevel
tclvl <- TcS TcLevel
TcS.getTcLevel
; Bool
success <- EvBindsVar -> TcLevel -> TcS Bool -> TcS Bool
forall a. EvBindsVar -> TcLevel -> TcS a -> TcS a
nestImplicTcS EvBindsVar
fake_ev_binds_var (TcLevel -> TcLevel
pushTcLevel TcLevel
tclvl) TcS Bool
try_group
; if Bool
success then
do { TcTyVar -> Type -> TcS ()
unifyTyVar TcTyVar
the_tv Type
default_ty
; TcM () -> TcS ()
forall a. TcM a -> TcS a
wrapWarnTcS (TcM () -> TcS ()) -> TcM () -> TcS ()
forall a b. (a -> b) -> a -> b
$ TcTyVar -> [Ct] -> Type -> TcM ()
warnDefaulting TcTyVar
the_tv [Ct]
wanteds Type
default_ty
; String -> SDoc -> TcS ()
traceTcS String
"disambigGroup succeeded }" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
default_ty)
; Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True }
else
do { String -> SDoc -> TcS ()
traceTcS String
"disambigGroup failed, will try other default types }"
(Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
default_ty)
; [Type] -> (TcTyVar, [Ct]) -> TcS Bool
disambigGroup [Type]
default_tys (TcTyVar, [Ct])
group } }
where
try_group :: TcS Bool
try_group
| Just Subst
subst <- Maybe Subst
mb_subst
= do { TcLclEnv
lcl_env <- TcS TcLclEnv
TcS.getLclEnv
; TcLevel
tc_lvl <- TcS TcLevel
TcS.getTcLevel
; let loc :: CtLoc
loc = TcLevel -> SkolemInfoAnon -> CtLocEnv -> CtLoc
mkGivenLoc TcLevel
tc_lvl (SkolemInfo -> SkolemInfoAnon
getSkolemInfo SkolemInfo
HasCallStack => SkolemInfo
unkSkol) (TcLclEnv -> CtLocEnv
mkCtLocEnv TcLclEnv
lcl_env)
; [CtEvidence]
wanted_evs <- [TcS CtEvidence] -> TcS [CtEvidence]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [ CtLoc -> RewriterSet -> Type -> TcS CtEvidence
newWantedNC CtLoc
loc RewriterSet
rewriters Type
pred'
| Ct
wanted <- [Ct]
wanteds
, CtWanted { ctev_pred :: CtEvidence -> Type
ctev_pred = Type
pred
, ctev_rewriters :: CtEvidence -> RewriterSet
ctev_rewriters = RewriterSet
rewriters }
<- CtEvidence -> [CtEvidence]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (Ct -> CtEvidence
ctEvidence Ct
wanted)
, let pred' :: Type
pred' = HasDebugCallStack => Subst -> Type -> Type
Subst -> Type -> Type
substTy Subst
subst Type
pred ]
; (WantedConstraints -> Bool) -> TcS WantedConstraints -> TcS Bool
forall a b. (a -> b) -> TcS a -> TcS b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WantedConstraints -> Bool
isEmptyWC (TcS WantedConstraints -> TcS Bool)
-> TcS WantedConstraints -> TcS Bool
forall a b. (a -> b) -> a -> b
$
Cts -> TcS WantedConstraints
solveSimpleWanteds (Cts -> TcS WantedConstraints) -> Cts -> TcS WantedConstraints
forall a b. (a -> b) -> a -> b
$ [Ct] -> Cts
forall a. [a] -> Bag a
listToBag ([Ct] -> Cts) -> [Ct] -> Cts
forall a b. (a -> b) -> a -> b
$
(CtEvidence -> Ct) -> [CtEvidence] -> [Ct]
forall a b. (a -> b) -> [a] -> [b]
map CtEvidence -> Ct
mkNonCanonical [CtEvidence]
wanted_evs }
| Bool
otherwise
= Bool -> TcS Bool
forall a. a -> TcS a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
the_ty :: Type
the_ty = TcTyVar -> Type
mkTyVarTy TcTyVar
the_tv
mb_subst :: Maybe Subst
mb_subst = Type -> Type -> Maybe Subst
tcMatchTyKi Type
the_ty Type
default_ty
isInteractiveClass :: Bool
-> Class -> Bool
isInteractiveClass :: Bool -> Class -> Bool
isInteractiveClass Bool
ovl_strings Class
cls
= Bool -> Class -> Bool
isNumClass Bool
ovl_strings Class
cls Bool -> Bool -> Bool
|| (Class -> Unique
classKey Class
cls Unique -> [Unique] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Unique]
interactiveClassKeys)
isNumClass :: Bool
-> Class -> Bool
isNumClass :: Bool -> Class -> Bool
isNumClass Bool
ovl_strings Class
cls
= Class -> Bool
isNumericClass Class
cls Bool -> Bool -> Bool
|| (Bool
ovl_strings Bool -> Bool -> Bool
&& (Class
cls Class -> Unique -> Bool
forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
isStringClassKey))