Also, same thing now applies for adding superclasses.
else setDictBind v' (EvCast v (mkSymCoercion dict_co))
; return v' }
else setDictBind v' (EvCast v (mkSymCoercion dict_co))
; return v' }
- -- Add the superclasses of this one here, See Note [Adding superclasses]
- ; sc_cts <- newSCWorkFromFlavored v_new fl cn xis
+ -- Add the superclasses of this one here, See Note [Adding superclasses].
+ -- But only if we are not simplifying the LHS of a rule.
+ ; sctx <- getTcSContext
+ ; sc_cts <- if simplEqsOnly sctx then return emptyCCan
+ else newSCWorkFromFlavored v_new fl cn xis
; return (sc_cts `andCCan` ccs `extendCCans` CDictCan { cc_id = v_new
, cc_flavor = fl
; return (sc_cts `andCCan` ccs `extendCCans` CDictCan { cc_id = v_new
, cc_flavor = fl
solveInteract :: InertSet -> Bag (CtFlavor,EvVar) -> TcS InertSet
solveInteract inert ws
= do { dyn_flags <- getDynFlags
solveInteract :: InertSet -> Bag (CtFlavor,EvVar) -> TcS InertSet
solveInteract inert ws
= do { dyn_flags <- getDynFlags
- ; can_ws <- foldlBagM (tryPreSolveAndCanon inert) emptyCCan ws
+ ; sctx <- getTcSContext
+
+ ; traceTcS "solveInteract, before clever canonicalization:" $
+ ppr (mapBag (\(ct,ev) -> (ct,evVarPred ev)) ws)
+
+ ; can_ws <- foldlBagM (tryPreSolveAndCanon sctx inert) emptyCCan ws
+
+ ; traceTcS "solveInteract, after clever canonicalization:" $
+ ppr can_ws
+
; solveInteractWithDepth (ctxtStkDepth dyn_flags,0,[]) inert can_ws }
; solveInteractWithDepth (ctxtStkDepth dyn_flags,0,[]) inert can_ws }
-tryPreSolveAndCanon :: InertSet -> CanonicalCts -> (CtFlavor, EvVar) -> TcS CanonicalCts
+tryPreSolveAndCanon :: SimplContext -> InertSet -> CanonicalCts -> (CtFlavor, EvVar) -> TcS CanonicalCts
-- Checks if this constraint can be immediately solved from a constraint in the
-- inert set or in the previously encountered CanonicalCts and only then
-- canonicalise it. See Note [Avoiding the superclass explosion]
-- Checks if this constraint can be immediately solved from a constraint in the
-- inert set or in the previously encountered CanonicalCts and only then
-- canonicalise it. See Note [Avoiding the superclass explosion]
-tryPreSolveAndCanon is cts_acc (fl,ev_var)
+tryPreSolveAndCanon sctx is cts_acc (fl,ev_var)
| ClassP clas tys <- evVarPred ev_var
| ClassP clas tys <- evVarPred ev_var
+ , not $ simplEqsOnly sctx -- And we *can* discharge constraints from other constraints
= do { let (relevant_inert_dicts,_) = getRelevantCts clas (inert_dicts is)
; b <- dischargeFromCans (cts_acc `unionBags` relevant_inert_dicts)
(fl,ev_var,clas,tys)
= do { let (relevant_inert_dicts,_) = getRelevantCts clas (inert_dicts is)
; b <- dischargeFromCans (cts_acc `unionBags` relevant_inert_dicts)
(fl,ev_var,clas,tys)
| SimplRuleLhs -- Inferring type of a RULE lhs
| SimplInteractive -- Inferring type at GHCi prompt
| SimplCheck -- Checking a type signature or RULE rhs
| SimplRuleLhs -- Inferring type of a RULE lhs
| SimplInteractive -- Inferring type at GHCi prompt
| SimplCheck -- Checking a type signature or RULE rhs
instance Outputable SimplContext where
ppr SimplInfer = ptext (sLit "SimplInfer")
instance Outputable SimplContext where
ppr SimplInfer = ptext (sLit "SimplInfer")