| ... |
... |
@@ -2935,8 +2935,7 @@ lookup_eq_in_qcis :: CtEvidence -> EqRel -> TcType -> TcType -> SolverStage () |
|
2935
|
2935
|
-- [W] t1 ~# t2
|
|
2936
|
2936
|
-- and a Given quantified contraint like (forall a b. blah => a ~ b)
|
|
2937
|
2937
|
-- Why? See Note [Looking up primitive equalities in quantified constraints]
|
|
2938
|
|
--- See also GHC.Tc.Solver.Dict
|
|
2939
|
|
--- Note [Equality superclasses in quantified constraints]
|
|
|
2938
|
+-- See also GHC.Tc.Solver.Dict Note [Equality superclasses in quantified constraints]
|
|
2940
|
2939
|
lookup_eq_in_qcis (CtGiven {}) _ _ _
|
|
2941
|
2940
|
= nopStage ()
|
|
2942
|
2941
|
|
| ... |
... |
@@ -2952,10 +2951,18 @@ lookup_eq_in_qcis ev@(CtWanted (WantedCt { ctev_dest = dest, ctev_loc = loc })) |
|
2952
|
2951
|
where
|
|
2953
|
2952
|
hole = case dest of
|
|
2954
|
2953
|
HoleDest hole -> hole -- Equality constraints have HoleDest
|
|
2955
|
|
- _ -> pprPanic "lookup_eq_in_qcis" (ppr dest)
|
|
|
2954
|
+ _ -> pprPanic "lookup_eq_in_qcis" (ppr dest)
|
|
2956
|
2955
|
|
|
2957
|
2956
|
try :: SwapFlag -> SolverStage ()
|
|
2958
|
|
- try swap -- First try looking for (lhs ~ rhs)
|
|
|
2957
|
+ -- E.g. We are trying to solve (say)
|
|
|
2958
|
+ -- [W] g : [Int] ~# b)
|
|
|
2959
|
+ -- from [G] forall x. blah => b ~ [x] -- A quantified constraint
|
|
|
2960
|
+ -- We can solve it like this
|
|
|
2961
|
+ -- d::b~[Int] := $df @Int blah -- Apply the quantified constraint
|
|
|
2962
|
+ -- g'::b~#[Int] := sc_sel d -- Binding, extract the coercion from d
|
|
|
2963
|
+ -- g(co-hole) := sym g' -- Fill the original coercion hole
|
|
|
2964
|
+ -- Here g' is a fresh coercion variable.
|
|
|
2965
|
+ try swap
|
|
2959
|
2966
|
| Just (cls, tys) <- unSwap swap (boxEqPred eq_rel) lhs rhs
|
|
2960
|
2967
|
= Stage $
|
|
2961
|
2968
|
do { let cls_pred = mkClassPred cls tys
|
| ... |
... |
@@ -2965,7 +2972,7 @@ lookup_eq_in_qcis ev@(CtWanted (WantedCt { ctev_dest = dest, ctev_loc = loc })) |
|
2965
|
2972
|
OneInst {}
|
|
2966
|
2973
|
-> do { dict_ev <- newWantedEvVarNC loc emptyCoHoleSet cls_pred
|
|
2967
|
2974
|
; chooseInstance dict_ev res
|
|
2968
|
|
- ; let co_var = coHoleCoVar hole
|
|
|
2975
|
+ ; co_var <- newEvVar (unSwap swap (mkEqPred eq_rel) lhs rhs)
|
|
2969
|
2976
|
; setEvBind (mkWantedEvBind co_var EvCanonical (mk_sc_sel cls tys dict_ev))
|
|
2970
|
2977
|
; fillCoercionHole hole emptyCoHoleSet $
|
|
2971
|
2978
|
maybeSymCo swap (mkCoVarCo co_var)
|