Simon Peyton Jones pushed to branch wip/T23162-spj at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Core/TyCo/FVs.hs
    ... ... @@ -338,9 +338,15 @@ deepTcvFolder = TyCoFolder { tcf_view = noView -- See Note [Free vars and synon
    338 338
                       | otherwise          = appEndo (deep_ty (varType v)) $
    
    339 339
                                              acc `extendVarSet` v
    
    340 340
     
    
    341
    +    do_bndr :: TyCoVarSet -> TyVar -> ForAllTyFlag -> TyCoVarSet
    
    341 342
         do_bndr is tcv _ = extendVarSet is tcv
    
    342
    -    do_hole _ _  = mempty  -- See (CHFV1) in Note [CoercionHoles and coercion free variables]
    
    343
    -                           -- in GHC.Core.TyCo.Rep
    
    343
    +
    
    344
    +    do_hole :: VarSet -> CoercionHole -> Endo TyCoVarSet
    
    345
    +    do_hole _ hole = deep_ty (varType (coHoleCoVar hole))
    
    346
    +                     -- We don't collect the CoercionHole itself, but we /do/
    
    347
    +                     -- need to collect the free variables of its /kind/
    
    348
    +                     -- See (CHFV1) in Note [CoercionHoles and coercion free variables]
    
    349
    +                     -- in GHC.Core.TyCo.Rep
    
    344 350
     
    
    345 351
     {- *********************************************************************
    
    346 352
     *                                                                      *
    

  • compiler/GHC/Tc/Solver/Equality.hs
    ... ... @@ -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)