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

Commits:

17 changed files:

Changes:

  • compiler/GHC/Core/TyCo/Rep.hs
    ... ... @@ -42,10 +42,10 @@ module GHC.Core.TyCo.Rep (
    42 42
             CoercionN, CoercionR, CoercionP, KindCoercion,
    
    43 43
             MCoercion(..), MCoercionR, MCoercionN, KindMCoercion,
    
    44 44
     
    
    45
    -        -- RewriterSet
    
    46
    -        --   RewriterSet(..) is exported concretely only for zonkRewriterSet
    
    47
    -        RewriterSet(..), emptyRewriterSet, isEmptyRewriterSet, elemRewriterSet,
    
    48
    -        addRewriter, unitRewriterSet, unionRewriterSet, delRewriterSet,
    
    45
    +        -- CoHoleSet
    
    46
    +        --   CoHoleSet(..) is exported concretely only for zonkCoHoleSet
    
    47
    +        CoHoleSet(..), emptyCoHoleSet, isEmptyCoHoleSet, elemCoHoleSet,
    
    48
    +        addRewriter, unitCoHoleSet, unionCoHoleSet, delCoHoleSet,
    
    49 49
     
    
    50 50
             -- * Functions over types
    
    51 51
             mkNakedTyConTy, mkTyVarTy, mkTyVarTys,
    
    ... ... @@ -1680,7 +1680,7 @@ holes `HoleCo`, which get filled in later.
    1680 1680
     
    
    1681 1681
     {- **********************************************************************
    
    1682 1682
     %*                                                                      *
    
    1683
    -                Coercion holes and RewriterSets
    
    1683
    +                Coercion holes and CoHoleSets
    
    1684 1684
     %*                                                                      *
    
    1685 1685
     %********************************************************************* -}
    
    1686 1686
     
    
    ... ... @@ -1689,9 +1689,10 @@ data CoercionHole
    1689 1689
       = CoercionHole { ch_co_var  :: CoVar
    
    1690 1690
                            -- See Note [CoercionHoles and coercion free variables]
    
    1691 1691
     
    
    1692
    -                 , ch_ref :: IORef (Maybe (Coercion, RewriterSet))
    
    1693
    -                       -- The RewriterSet is (possibly a superset of)
    
    1692
    +                 , ch_ref :: IORef (Maybe (Coercion, CoHoleSet))
    
    1693
    +                       -- The CoHoleSet is (possibly a superset of)
    
    1694 1694
                            -- the free coercion holes of the coercion
    
    1695
    +                       -- See Note [Want
    
    1695 1696
                      }
    
    1696 1697
     
    
    1697 1698
     coHoleCoVar :: CoercionHole -> CoVar
    
    ... ... @@ -1713,30 +1714,30 @@ instance Uniquable CoercionHole where
    1713 1714
       getUnique (CoercionHole { ch_co_var = cv }) = getUnique cv
    
    1714 1715
     
    
    1715 1716
     
    
    1716
    --- | A RewriterSet stores a set of CoercionHoles that have been used to rewrite
    
    1717
    +-- | A CoHoleSet stores a set of CoercionHoles that have been used to rewrite
    
    1717 1718
     -- a constraint.  See Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint
    
    1718
    -newtype RewriterSet = RewriterSet (UniqSet CoercionHole)
    
    1719
    +newtype CoHoleSet = CoHoleSet (UniqSet CoercionHole)
    
    1719 1720
       deriving newtype (Outputable, Semigroup, Monoid)
    
    1720 1721
     
    
    1721
    -emptyRewriterSet :: RewriterSet
    
    1722
    -emptyRewriterSet = RewriterSet emptyUniqSet
    
    1722
    +emptyCoHoleSet :: CoHoleSet
    
    1723
    +emptyCoHoleSet = CoHoleSet emptyUniqSet
    
    1723 1724
     
    
    1724
    -unitRewriterSet :: CoercionHole -> RewriterSet
    
    1725
    -unitRewriterSet = coerce (unitUniqSet @CoercionHole)
    
    1725
    +unitCoHoleSet :: CoercionHole -> CoHoleSet
    
    1726
    +unitCoHoleSet = coerce (unitUniqSet @CoercionHole)
    
    1726 1727
     
    
    1727
    -elemRewriterSet :: CoercionHole -> RewriterSet -> Bool
    
    1728
    -elemRewriterSet = coerce (elementOfUniqSet @CoercionHole)
    
    1728
    +elemCoHoleSet :: CoercionHole -> CoHoleSet -> Bool
    
    1729
    +elemCoHoleSet = coerce (elementOfUniqSet @CoercionHole)
    
    1729 1730
     
    
    1730
    -delRewriterSet :: RewriterSet -> CoercionHole -> RewriterSet
    
    1731
    -delRewriterSet = coerce (delOneFromUniqSet @CoercionHole)
    
    1731
    +delCoHoleSet :: CoHoleSet -> CoercionHole -> CoHoleSet
    
    1732
    +delCoHoleSet = coerce (delOneFromUniqSet @CoercionHole)
    
    1732 1733
     
    
    1733
    -unionRewriterSet :: RewriterSet -> RewriterSet -> RewriterSet
    
    1734
    -unionRewriterSet = coerce (unionUniqSets @CoercionHole)
    
    1734
    +unionCoHoleSet :: CoHoleSet -> CoHoleSet -> CoHoleSet
    
    1735
    +unionCoHoleSet = coerce (unionUniqSets @CoercionHole)
    
    1735 1736
     
    
    1736
    -isEmptyRewriterSet :: RewriterSet -> Bool
    
    1737
    -isEmptyRewriterSet = coerce (isEmptyUniqSet @CoercionHole)
    
    1737
    +isEmptyCoHoleSet :: CoHoleSet -> Bool
    
    1738
    +isEmptyCoHoleSet = coerce (isEmptyUniqSet @CoercionHole)
    
    1738 1739
     
    
    1739
    -addRewriter :: RewriterSet -> CoercionHole -> RewriterSet
    
    1740
    +addRewriter :: CoHoleSet -> CoercionHole -> CoHoleSet
    
    1740 1741
     addRewriter = coerce (addOneToUniqSet @CoercionHole)
    
    1741 1742
     
    
    1742 1743
     {- Note [Coercion holes]
    
    ... ... @@ -1821,14 +1822,14 @@ Why does a CoercionHole contain a CoVar, as well as reference to fill in?
    1821 1822
     
    
    1822 1823
        But nowadays this is all irrelevant because we don't float constraints.
    
    1823 1824
     
    
    1824
    -Note [CoercionHoles and RewriterSets]
    
    1825
    -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    1825
    +Note [CoercionHoles and CoHoleSets]
    
    1826
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    1826 1827
     A constraint C carries a set of "rewriters", a set of Wanted CoercionHoles that have been
    
    1827 1828
     used to rewrite C; see Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint.
    
    1828 1829
     
    
    1829
    -If C is an equality constraint and is solved, we track its RewriterSet in the filled
    
    1830
    +If C is an equality constraint and is solved, we track its CoHoleSet in the filled
    
    1830 1831
     CoercionHole, so that it can be inherited by other constraints that have C in /their/
    
    1831
    -rewriters.  See zonkRewriterSet.
    
    1832
    +rewriters.  See zonkCoHoleSet.
    
    1832 1833
     -}
    
    1833 1834
     
    
    1834 1835
     
    

  • compiler/GHC/Runtime/Eval.hs
    ... ... @@ -1118,7 +1118,7 @@ getDictionaryBindings theta = do
    1118 1118
         ctev_pred = varType dict_var,
    
    1119 1119
         ctev_dest = EvVarDest dict_var,
    
    1120 1120
         ctev_loc = loc,
    
    1121
    -    ctev_rewriters = emptyRewriterSet
    
    1121
    +    ctev_rewriters = emptyCoHoleSet
    
    1122 1122
       }
    
    1123 1123
     
    
    1124 1124
     -- Find instances where the head unifies with the provided type
    

  • compiler/GHC/Tc/Errors.hs
    ... ... @@ -462,7 +462,7 @@ mkErrorItem ct
    462 462
                        -- see Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint
    
    463 463
                          CtGiven {} -> (False, Nothing)
    
    464 464
                          CtWanted (WantedCt { ctev_rewriters = rws, ctev_dest = dest })
    
    465
    -                                -> (not (isEmptyRewriterSet rws), Just dest)
    
    465
    +                                -> (not (isEmptyCoHoleSet rws), Just dest)
    
    466 466
     
    
    467 467
            ; let m_reason = case ct of
    
    468 468
                     CIrredCan (IrredCt { ir_reason = reason }) -> Just reason
    
    ... ... @@ -494,7 +494,7 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics
    494 494
     
    
    495 495
              -- Catch an awkward (and probably rare) case in which /all/ errors are
    
    496 496
              -- suppressed: see Wrinkle (PER2) in Note [Prioritise Wanteds with empty
    
    497
    -         -- RewriterSet] in GHC.Tc.Types.Constraint.
    
    497
    +         -- CoHoleSet] in GHC.Tc.Types.Constraint.
    
    498 498
              --
    
    499 499
              -- Unless we are sure that an error will be reported some other way
    
    500 500
              -- (details in the defn of tidy_items) un-suppress the lot. This makes
    
    ... ... @@ -1327,7 +1327,7 @@ addDeferredBinding ctxt supp hints msg (EI { ei_evdest = Just dest
    1327 1327
                  -> do { -- See Note [Deferred errors for coercion holes]
    
    1328 1328
                          let co_var = coHoleCoVar hole
    
    1329 1329
                        ; addTcEvBind ev_binds_var $ mkWantedEvBind co_var EvNonCanonical err_tm
    
    1330
    -                   ; fillCoercionHole hole (mkCoVarCo co_var, emptyRewriterSet) } }
    
    1330
    +                   ; fillCoercionHole hole (mkCoVarCo co_var, emptyCoHoleSet) } }
    
    1331 1331
     addDeferredBinding _ _ _ _ _ = return ()    -- Do not set any evidence for Given
    
    1332 1332
     
    
    1333 1333
     mkSolverErrorTerm :: CtLoc -> Type  -- of the error term
    
    ... ... @@ -1650,7 +1650,7 @@ validHoleFits ctxt@(CEC { cec_encl = implics
    1650 1650
               WantedCt { ctev_pred      = pred
    
    1651 1651
                        , ctev_dest      = dest
    
    1652 1652
                        , ctev_loc       = loc
    
    1653
    -                   , ctev_rewriters = emptyRewriterSet }
    
    1653
    +                   , ctev_rewriters = emptyCoHoleSet }
    
    1654 1654
           | otherwise
    
    1655 1655
           = Nothing   -- The ErrorItem was a Given
    
    1656 1656
     
    

  • compiler/GHC/Tc/Solver/Default.hs
    ... ... @@ -541,7 +541,7 @@ defaultEquality encl_eqs ct
    541 541
               = do { traceTcS "defaultEquality success:" (ppr rhs_ty)
    
    542 542
                    ; unifyTyVar lhs_tv rhs_ty  -- NB: unifyTyVar adds to the
    
    543 543
                                                -- TcS unification counter
    
    544
    -               ; setEqIfWanted (ctEvidence ct) emptyRewriterSet (mkReflCo Nominal rhs_ty)
    
    544
    +               ; setEqIfWanted (ctEvidence ct) emptyCoHoleSet (mkReflCo Nominal rhs_ty)
    
    545 545
                    ; return True
    
    546 546
                    }
    
    547 547
     
    
    ... ... @@ -566,7 +566,7 @@ defaultEquality encl_eqs ct
    566 566
                 -- See Note [Defaulting representational equalities].
    
    567 567
                ; if null new_eqs
    
    568 568
                  then do { traceTcS "defaultEquality ReprEq } (yes)" empty
    
    569
    -                     ; setEqIfWanted (ctEvidence ct) emptyRewriterSet (mkSubCo co)
    
    569
    +                     ; setEqIfWanted (ctEvidence ct) emptyCoHoleSet (mkSubCo co)
    
    570 570
                          ; return True }
    
    571 571
                  else do { traceTcS "defaultEquality ReprEq } (no)" empty
    
    572 572
                          ; return False } }
    

  • compiler/GHC/Tc/Solver/Dict.hs
    ... ... @@ -796,12 +796,15 @@ tryInstances dict_ct
    796 796
     
    
    797 797
     try_instances :: InertSet -> DictCt -> TcS (StopOrContinue ())
    
    798 798
     -- Try to use type-class instance declarations to simplify the constraint
    
    799
    -try_instances inerts work_item@(DictCt { di_ev = ev, di_cls = cls
    
    800
    -                                       , di_tys = xis })
    
    801
    -  | isGiven ev   -- Never use instances for Given constraints
    
    802
    -  = continueWith ()
    
    803
    -     -- See Note [No Given/Given fundeps]
    
    804 799
     
    
    800
    +-- Case for Givens
    
    801
    +-- Never use instances for Given constraints
    
    802
    +try_instances _ (DictCt { di_ev = CtGiven {} })
    
    803
    +  = -- See Note [No Given/Given fundeps]
    
    804
    +    continueWith ()
    
    805
    +
    
    806
    +-- Case for Wanteds
    
    807
    +try_instances inerts work_item@(DictCt { di_ev = ev@(CtWanted wev), di_cls = cls, di_tys = xis })
    
    805 808
       | Just solved_ev <- lookupSolvedDict inerts cls xis   -- Cached
    
    806 809
       = do { setDictIfWanted ev EvCanonical (ctEvTerm solved_ev)
    
    807 810
            ; stopWith ev "Dict/Top (cached)" }
    
    ... ... @@ -817,14 +820,16 @@ try_instances inerts work_item@(DictCt { di_ev = ev, di_cls = cls
    817 820
                               then stopWith ev "shortCutSolver worked(2)"
    
    818 821
                               else do { insertSafeOverlapFailureTcS what work_item
    
    819 822
                                       ; updSolvedDicts what work_item
    
    820
    -                                  ; chooseInstance ev lkup_res } }
    
    823
    +                                  ; chooseInstance wev lkup_res
    
    824
    +                                  ; stopWith ev "Dict/Top (solved wanted)" } }
    
    821 825
                    _  -> -- NoInstance or NotSure: we didn't solve it
    
    822 826
                          continueWith () }
    
    823 827
        where
    
    824 828
          dict_loc = ctEvLoc ev
    
    825 829
     
    
    826
    -chooseInstance :: CtEvidence -> ClsInstResult -> TcS (StopOrContinue a)
    
    827
    -chooseInstance work_item
    
    830
    +chooseInstance :: WantedCtEvidence -> ClsInstResult -> TcS ()
    
    831
    +chooseInstance work_item@(WantedCt { ctev_dest = dest, ctev_rewriters = rws
    
    832
    +                                   , ctev_loc = loc, ctev_pred = pred })
    
    828 833
                    (OneInst { cir_new_theta   = theta
    
    829 834
                             , cir_what        = what
    
    830 835
                             , cir_mk_ev       = mk_ev
    
    ... ... @@ -834,13 +839,9 @@ chooseInstance work_item
    834 839
            ; checkReductionDepth deeper_loc pred
    
    835 840
            ; assertPprM (getTcEvBindsVar >>= return . not . isCoEvBindsVar)
    
    836 841
                         (ppr work_item)
    
    837
    -       ; evc_vars <- mapM (newWanted deeper_loc (ctEvRewriters work_item)) theta
    
    838
    -       ; setDictIfWanted work_item canonical (mk_ev (map getEvExpr evc_vars))
    
    839
    -       ; emitWorkNC (map CtWanted $ freshGoals evc_vars)
    
    840
    -       ; stopWith work_item "Dict/Top (solved wanted)" }
    
    841
    -  where
    
    842
    -     pred = ctEvPred work_item
    
    843
    -     loc  = ctEvLoc work_item
    
    842
    +       ; evc_vars <- mapM (newWanted deeper_loc rws) theta
    
    843
    +       ; setWantedDict dest canonical (mk_ev (map getEvExpr evc_vars))
    
    844
    +       ; emitWorkNC (map CtWanted $ freshGoals evc_vars) }
    
    844 845
     
    
    845 846
     chooseInstance work_item lookup_res
    
    846 847
       = pprPanic "chooseInstance" (ppr work_item $$ ppr lookup_res)
    

  • compiler/GHC/Tc/Solver/Equality.hs
    ... ... @@ -372,7 +372,7 @@ can_eq_nc rewritten rdr_env envs ev eq_rel ty1 ps_ty1 (CastTy ty2 co2) _
    372 372
     -- Literals
    
    373 373
     can_eq_nc _rewritten _rdr_env _envs ev eq_rel ty1@(LitTy l1) _ (LitTy l2) _
    
    374 374
      | l1 == l2
    
    375
    -  = do { setEqIfWanted ev emptyRewriterSet (mkReflCo (eqRelRole eq_rel) ty1)
    
    375
    +  = do { setEqIfWanted ev emptyCoHoleSet (mkReflCo (eqRelRole eq_rel) ty1)
    
    376 376
            ; stopWith ev "Equal LitTy" }
    
    377 377
     
    
    378 378
     -- Decompose FunTy: (s -> t) and (c => t)
    
    ... ... @@ -571,8 +571,8 @@ can_eq_nc_forall ev eq_rel s1 s2
    571 571
                          -- CoercionHoles, from the nested solve, and we may miss the
    
    572 572
                          -- use of CoVars.  Test T7196 showed this up
    
    573 573
     
    
    574
    -                ; setWantedEq orig_dest emptyRewriterSet all_co
    
    575
    -                     -- emptyRewriterSet: fully solved, so all_co has no holes
    
    574
    +                ; setWantedEq orig_dest emptyCoHoleSet all_co
    
    575
    +                     -- emptyCoHoleSet: fully solved, so all_co has no holes
    
    576 576
                     ; stopWith ev "Polytype equality: solved" }
    
    577 577
     
    
    578 578
             else canEqSoftFailure IrredShapeReason ev s1 s2 } }
    
    ... ... @@ -792,7 +792,7 @@ can_eq_newtype_nc rdr_env envs ev swapped ty1 ((gres, co1), ty1') ty2 ps_ty2
    792 792
     
    
    793 793
            ; let redn1 = mkReduction co1 ty1'
    
    794 794
     
    
    795
    -       ; new_ev <- rewriteEqEvidence emptyRewriterSet ev' swapped
    
    795
    +       ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev' swapped
    
    796 796
                          redn1 (mkReflRedn Representational ps_ty2)
    
    797 797
     
    
    798 798
            ; can_eq_nc False rdr_env envs new_ev ReprEq ty1' ty1' ty2 ps_ty2 }
    
    ... ... @@ -872,7 +872,7 @@ canEqCast rewritten rdr_env envs ev eq_rel swapped ty1 co1 ty2 ps_ty2
    872 872
       = do { traceTcS "Decomposing cast" (vcat [ ppr ev
    
    873 873
                                                , ppr ty1 <+> text "|>" <+> ppr co1
    
    874 874
                                                , ppr ps_ty2 ])
    
    875
    -       ; new_ev <- rewriteEqEvidence emptyRewriterSet ev swapped
    
    875
    +       ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev swapped
    
    876 876
                           (mkGReflLeftRedn role ty1 co1)
    
    877 877
                           (mkReflRedn role ps_ty2)
    
    878 878
            ; can_eq_nc rewritten rdr_env envs new_ev eq_rel ty1 ty1 ty2 ps_ty2 }
    
    ... ... @@ -1678,7 +1678,7 @@ canEqCanLHSHetero ev eq_rel swapped lhs1 ps_xi1 ki1 xi2 ps_xi2 ki2
    1678 1678
                         kind_loc = mkKindEqLoc xi1 xi2 loc
    
    1679 1679
                   ; kind_ev <- newGivenEv kind_loc (pred_ty, evCoercion kind_co)
    
    1680 1680
                   ; emitWorkNC [CtGiven kind_ev]
    
    1681
    -              ; finish emptyRewriterSet (givenCtEvCoercion kind_ev) }
    
    1681
    +              ; finish emptyCoHoleSet (givenCtEvCoercion kind_ev) }
    
    1682 1682
     
    
    1683 1683
           CtWanted {}
    
    1684 1684
              -> do { (unifs, (kind_co, eqs)) <- reportFineGrainUnifications $
    
    ... ... @@ -1830,7 +1830,7 @@ canEqCanLHS2 ev eq_rel swapped lhs1 ps_xi1 lhs2 ps_xi2 mco
    1830 1830
         finish_with_swapping
    
    1831 1831
           = do { let lhs1_redn = mkGReflRightMRedn role lhs1_ty sym_mco
    
    1832 1832
                      lhs2_redn = mkGReflLeftMRedn  role lhs2_ty mco
    
    1833
    -           ; new_ev <-rewriteEqEvidence emptyRewriterSet ev swapped lhs1_redn lhs2_redn
    
    1833
    +           ; new_ev <-rewriteEqEvidence emptyCoHoleSet ev swapped lhs1_redn lhs2_redn
    
    1834 1834
                ; canEqCanLHSFinish new_ev eq_rel IsSwapped lhs2 (ps_xi1 `mkCastTyMCo` sym_mco) }
    
    1835 1835
     
    
    1836 1836
         put_tyvar_on_lhs = isWanted ev && eq_rel == NomEq
    
    ... ... @@ -1967,7 +1967,7 @@ canEqCanLHSFinish_try_unification ev eq_rel swapped lhs rhs
    1967 1967
                               -- ContinueWith, to allow using this constraint for
    
    1968 1968
                               -- rewriting (e.g. alpha[2] ~ beta[3]).
    
    1969 1969
                               do { let role = eqRelRole eq_rel
    
    1970
    -                             ; new_ev <- rewriteEqEvidence emptyRewriterSet ev swapped
    
    1970
    +                             ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev swapped
    
    1971 1971
                                      (mkReflRedn role (canEqLHSType lhs))
    
    1972 1972
                                      (mkReflRedn role rhs)
    
    1973 1973
                                  ; continueWith $ Right $
    
    ... ... @@ -2010,9 +2010,9 @@ canEqCanLHSFinish_try_unification ev eq_rel swapped lhs rhs
    2010 2010
                --           co' = <Int>
    
    2011 2011
                new_ev <- if isReflCo (reductionCoercion rhs_redn)
    
    2012 2012
                          then return ev
    
    2013
    -                     else rewriteEqEvidence emptyRewriterSet ev swapped
    
    2013
    +                     else rewriteEqEvidence emptyCoHoleSet ev swapped
    
    2014 2014
                                   (mkReflRedn Nominal (mkTyVarTy tv)) rhs_redn
    
    2015
    -                          -- emptyRewriterSet: rhs_redn has no CoercionHoles
    
    2015
    +                          -- emptyCoHoleSet: rhs_redn has no CoercionHoles
    
    2016 2016
     
    
    2017 2017
              ; let tv_ty     = mkTyVarTy tv
    
    2018 2018
                    final_rhs = reductionReducedType rhs_redn
    
    ... ... @@ -2028,7 +2028,7 @@ canEqCanLHSFinish_try_unification ev eq_rel swapped lhs rhs
    2028 2028
     
    
    2029 2029
              -- Provide Refl evidence for the constraint
    
    2030 2030
              -- Ignore 'swapped' because it's Refl!
    
    2031
    -         ; setEqIfWanted new_ev emptyRewriterSet (mkNomReflCo final_rhs)
    
    2031
    +         ; setEqIfWanted new_ev emptyCoHoleSet (mkNomReflCo final_rhs)
    
    2032 2032
     
    
    2033 2033
              -- Kick out any constraints that can now be rewritten
    
    2034 2034
              ; kickOutAfterUnification (unitVarSet tv)
    
    ... ... @@ -2062,7 +2062,7 @@ canEqCanLHSFinish_no_unification ev eq_rel swapped lhs rhs
    2062 2062
     
    
    2063 2063
                   | reason `cterHasOnlyProblems` do_not_prevent_rewriting
    
    2064 2064
                   -> do { let role = eqRelRole eq_rel
    
    2065
    -                    ; new_ev <- rewriteEqEvidence emptyRewriterSet ev swapped
    
    2065
    +                    ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev swapped
    
    2066 2066
                             (mkReflRedn role (canEqLHSType lhs))
    
    2067 2067
                             (mkReflRedn role rhs)
    
    2068 2068
                         ; continueWith $ Right $
    
    ... ... @@ -2074,7 +2074,7 @@ canEqCanLHSFinish_no_unification ev eq_rel swapped lhs rhs
    2074 2074
                   -> tryIrredInstead reason ev eq_rel swapped lhs rhs
    
    2075 2075
     
    
    2076 2076
                 PuOK _ rhs_redn
    
    2077
    -              -> do { new_ev <- rewriteEqEvidence emptyRewriterSet ev swapped
    
    2077
    +              -> do { new_ev <- rewriteEqEvidence emptyCoHoleSet ev swapped
    
    2078 2078
                                        (mkReflRedn (eqRelRole eq_rel) lhs_ty)
    
    2079 2079
                                        rhs_redn
    
    2080 2080
     
    
    ... ... @@ -2108,7 +2108,7 @@ swapAndFinish :: CtEvidence -> EqRel -> SwapFlag
    2108 2108
     -- We want to flip it to (F tys ~ a), whereupon it is canonical
    
    2109 2109
     swapAndFinish ev eq_rel swapped lhs_ty can_rhs
    
    2110 2110
       = do { let role = eqRelRole eq_rel
    
    2111
    -       ; new_ev <- rewriteEqEvidence emptyRewriterSet ev (flipSwap swapped)
    
    2111
    +       ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev (flipSwap swapped)
    
    2112 2112
                            (mkReflRedn role (canEqLHSType can_rhs))
    
    2113 2113
                            (mkReflRedn role lhs_ty)
    
    2114 2114
            ; continueWith $ Right $
    
    ... ... @@ -2127,7 +2127,7 @@ tryIrredInstead :: CheckTyEqResult -> CtEvidence
    2127 2127
     tryIrredInstead reason ev eq_rel swapped lhs rhs
    
    2128 2128
       = do { traceTcS "cantMakeCanonical" (ppr reason $$ ppr lhs $$ ppr rhs)
    
    2129 2129
            ; let role = eqRelRole eq_rel
    
    2130
    -       ; new_ev <- rewriteEqEvidence emptyRewriterSet ev swapped
    
    2130
    +       ; new_ev <- rewriteEqEvidence emptyCoHoleSet ev swapped
    
    2131 2131
                            (mkReflRedn role (canEqLHSType lhs))
    
    2132 2132
                            (mkReflRedn role rhs)
    
    2133 2133
            ; finishCanWithIrred (NonCanonicalReason reason) new_ev }
    
    ... ... @@ -2148,7 +2148,7 @@ canEqReflexive :: CtEvidence -- ty ~ ty
    2148 2148
                    -> TcType        -- ty
    
    2149 2149
                    -> TcS (StopOrContinue a)   -- always Stop
    
    2150 2150
     canEqReflexive ev eq_rel ty
    
    2151
    -  = do { setEqIfWanted ev emptyRewriterSet (mkReflCo (eqRelRole eq_rel) ty)
    
    2151
    +  = do { setEqIfWanted ev emptyCoHoleSet (mkReflCo (eqRelRole eq_rel) ty)
    
    2152 2152
            ; stopWith ev "Solved by reflexivity" }
    
    2153 2153
     
    
    2154 2154
     {- Note [Equalities with heterogeneous kinds]
    
    ... ... @@ -2171,7 +2171,7 @@ k2 and use this to cast. To wit, from
    2171 2171
     Wrinkles:
    
    2172 2172
     
    
    2173 2173
     (EIK1) When X=Wanted, the new type-level wanted for `co` is effectively rewritten by
    
    2174
    -     the kind-level one. We thus include the kind-level wanted in the RewriterSet
    
    2174
    +     the kind-level one. We thus include the kind-level wanted in the CoHoleSet
    
    2175 2175
          for the type-level one. See Note [Wanteds rewrite Wanteds] in
    
    2176 2176
          GHC.Tc.Types.Constraint.  This is done in canEqCanLHSHetero.
    
    2177 2177
     
    
    ... ... @@ -2199,7 +2199,7 @@ Wrinkles:
    2199 2199
            the kind of the parent type-equality.  See the calls to `mkKindEqLoc`
    
    2200 2200
            in `canEqCanLHSHetero`.
    
    2201 2201
     
    
    2202
    -     * We /also/ add these unsolved kind equalities to the `RewriterSet` of the
    
    2202
    +     * We /also/ add these unsolved kind equalities to the `CoHoleSet` of the
    
    2203 2203
            parent constraint; see the call to `rewriteEqEvidence` in `finish` in
    
    2204 2204
            `canEqCanLHSHetero`.
    
    2205 2205
     
    
    ... ... @@ -2611,7 +2611,7 @@ More details:
    2611 2611
     **********************************************************************
    
    2612 2612
     -}
    
    2613 2613
     
    
    2614
    -rewriteEqEvidence :: RewriterSet        -- New rewriters
    
    2614
    +rewriteEqEvidence :: CoHoleSet        -- New rewriters
    
    2615 2615
                                             -- See GHC.Tc.Types.Constraint
    
    2616 2616
                                             -- Note [Wanteds rewrite Wanteds]
    
    2617 2617
                       -> CtEvidence         -- Old evidence :: olhs ~ orhs (not swapped)
    
    ... ... @@ -2653,7 +2653,7 @@ rewriteEqEvidence new_rewriters old_ev swapped (Reduction lhs_co nlhs) (Reductio
    2653 2653
            ; let co = maybeSymCo swapped $
    
    2654 2654
                       lhs_co `mkTransCo` mkHoleCo hole `mkTransCo` mkSymCo rhs_co
    
    2655 2655
                  -- new_rewriters has all the holes from lhs_co and rhs_co
    
    2656
    -       ; setWantedEq dest (new_rewriters `mappend` unitRewriterSet hole) co
    
    2656
    +       ; setWantedEq dest (new_rewriters `mappend` unitCoHoleSet hole) co
    
    2657 2657
            ; traceTcS "rewriteEqEvidence" (vcat [ ppr old_ev
    
    2658 2658
                                                 , ppr nlhs
    
    2659 2659
                                                 , ppr nrhs
    
    ... ... @@ -2723,7 +2723,7 @@ But it's not so simple:
    2723 2723
        TL;DR: Better to hang on to `g1` (with no rewriters), in preference
    
    2724 2724
        to `g2` (which has a rewriter).
    
    2725 2725
     
    
    2726
    -   See (WRW1) in Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint.
    
    2726
    +   See (WRW11) in Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint.
    
    2727 2727
     -}
    
    2728 2728
     
    
    2729 2729
     tryInertEqs :: EqCt -> SolverStage ()
    
    ... ... @@ -2731,7 +2731,7 @@ tryInertEqs work_item@(EqCt { eq_ev = ev, eq_eq_rel = eq_rel })
    2731 2731
       = Stage $
    
    2732 2732
         do { inerts <- getInertCans
    
    2733 2733
            ; if | Just (ev_i, swapped) <- inertsEqsCanDischarge inerts work_item
    
    2734
    -            -> do { setEqIfWanted ev (ctEvRewriterSet ev_i) $
    
    2734
    +            -> do { setEqIfWanted ev (ctEvCoHoleSet ev_i) $
    
    2735 2735
                         maybeSymCo swapped $
    
    2736 2736
                         downgradeRole (eqRelRole eq_rel)
    
    2737 2737
                                       (ctEvRewriteRole ev_i)
    
    ... ... @@ -2769,7 +2769,7 @@ inertsEqsCanDischarge inerts (EqCt { eq_lhs = lhs_w, eq_rhs = rhs_w
    2769 2769
         loc_w  = ctEvLoc ev_w
    
    2770 2770
         flav_w = ctEvFlavour ev_w
    
    2771 2771
         fr_w   = (flav_w, eq_rel)
    
    2772
    -    empty_rw_w = isEmptyRewriterSet (ctEvRewriters ev_w)
    
    2772
    +    empty_rw_w = isEmptyCoHoleSet (ctEvRewriters ev_w)
    
    2773 2773
     
    
    2774 2774
         inert_beats_wanted ev_i eq_rel
    
    2775 2775
           = -- eqCanRewriteFR:        see second bullet of Note [Combining equalities]
    
    ... ... @@ -2786,7 +2786,7 @@ inertsEqsCanDischarge inerts (EqCt { eq_lhs = lhs_w, eq_rhs = rhs_w
    2786 2786
         prefer_wanted ev_i
    
    2787 2787
           =  (loc_w `strictly_more_visible` ctEvLoc ev_i)
    
    2788 2788
                  -- strictly_more_visible: see (CE3) in Note [Combining equalities]
    
    2789
    -      || (empty_rw_w && not (isEmptyRewriterSet (ctEvRewriters ev_i)))
    
    2789
    +      || (empty_rw_w && not (isEmptyCoHoleSet (ctEvRewriters ev_i)))
    
    2790 2790
                  -- Prefer the one that has no rewriters
    
    2791 2791
                  -- See (CE4) in Note [Combining equalities]
    
    2792 2792
     
    
    ... ... @@ -2862,7 +2862,7 @@ Wrinkles:
    2862 2862
     
    
    2863 2863
        However the solver prioritises equalities with an empty rewriter
    
    2864 2864
        set, to try to avoid unnecessary kick-out.  See GHC.Tc.Types.Constraint
    
    2865
    -   Note [Prioritise Wanteds with empty RewriterSet] esp (PER1)
    
    2865
    +   Note [Prioritise Wanteds with empty CoHoleSet] esp (PER1)
    
    2866 2866
     
    
    2867 2867
     Note [Solve by unification]
    
    2868 2868
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -2914,9 +2914,9 @@ See
    2914 2914
     
    
    2915 2915
     --------------------
    
    2916 2916
     tryQCsIrredEqCt :: IrredCt -> SolverStage ()
    
    2917
    -tryQCsIrredEqCt irred@(IrredCt { ir_ev = ev })
    
    2917
    +tryQCsIrredEqCt (IrredCt { ir_ev = ev })
    
    2918 2918
       | EqPred eq_rel t1 t2 <- classifyPredType (ctEvPred ev)
    
    2919
    -  = lookup_eq_in_qcis (CIrredCan irred) eq_rel t1 t2
    
    2919
    +  = lookup_eq_in_qcis ev eq_rel t1 t2
    
    2920 2920
     
    
    2921 2921
       | otherwise  -- All the calls come from in this module, where we deal only with
    
    2922 2922
                    -- equalities, so ctEvPred ev) must be an equality. Indeed, we could
    
    ... ... @@ -2926,62 +2926,61 @@ tryQCsIrredEqCt irred@(IrredCt { ir_ev = ev })
    2926 2926
     
    
    2927 2927
     --------------------
    
    2928 2928
     tryQCsEqCt :: EqCt -> SolverStage ()
    
    2929
    -tryQCsEqCt work_item@(EqCt { eq_lhs = lhs, eq_rhs = rhs, eq_eq_rel = eq_rel })
    
    2930
    -  = lookup_eq_in_qcis (CEqCan work_item) eq_rel (canEqLHSType lhs) rhs
    
    2929
    +tryQCsEqCt (EqCt { eq_ev = ev, eq_lhs = lhs, eq_rhs = rhs, eq_eq_rel = eq_rel })
    
    2930
    +  = lookup_eq_in_qcis ev eq_rel (canEqLHSType lhs) rhs
    
    2931 2931
     
    
    2932 2932
     --------------------
    
    2933
    -lookup_eq_in_qcis :: Ct -> EqRel -> TcType -> TcType -> SolverStage ()
    
    2933
    +lookup_eq_in_qcis :: CtEvidence -> EqRel -> TcType -> TcType -> SolverStage ()
    
    2934 2934
     -- The "final QCI check" checks to see if we have
    
    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 2938
     -- See also GHC.Tc.Solver.Dict
    
    2939 2939
     -- Note [Equality superclasses in quantified constraints]
    
    2940
    -lookup_eq_in_qcis work_ct eq_rel lhs rhs
    
    2941
    -  = Stage $
    
    2942
    -    do { ev_binds_var <- getTcEvBindsVar
    
    2943
    -       ; ics <- getInertCans
    
    2944
    -       ; if isWanted ev                       -- Never look up Givens in quantified constraints
    
    2945
    -         && not (null (inert_qcis ics))       -- Shortcut common case
    
    2946
    -         && not (isCoEvBindsVar ev_binds_var) -- See Note [Instances in no-evidence implications]
    
    2947
    -         then try_for_qci
    
    2948
    -         else continueWith () }
    
    2940
    +lookup_eq_in_qcis (CtGiven {}) _ _ _
    
    2941
    +  = nopStage ()
    
    2942
    +
    
    2943
    +lookup_eq_in_qcis ev@(CtWanted (WantedCt { ctev_dest = dest, ctev_loc = loc })) eq_rel lhs rhs
    
    2944
    +  = do { ev_binds_var <- simpleStage getTcEvBindsVar
    
    2945
    +       ; ics          <- simpleStage getInertCans
    
    2946
    +       ; if null (inert_qcis ics)
    
    2947
    +            || isCoEvBindsVar ev_binds_var -- See Note [Instances in no-evidence implications]
    
    2948
    +         then -- Shortcut common case
    
    2949
    +              nopStage ()
    
    2950
    +         else -- Try looking for both (lhs~rhs) anr (rhs~lhs); see #23333
    
    2951
    +              do { try NotSwapped; try IsSwapped } }
    
    2949 2952
       where
    
    2950
    -    ev  = ctEvidence work_ct
    
    2951
    -    loc = ctEvLoc ev
    
    2952
    -    role = eqRelRole eq_rel
    
    2953
    -
    
    2954
    -    try_for_qci  -- First try looking for (lhs ~ rhs)
    
    2955
    -       | Just (cls, tys) <- boxEqPred eq_rel lhs rhs
    
    2956
    -       = do { res <- matchLocalInst (mkClassPred cls tys) loc
    
    2957
    -            ; traceTcS "lookup_irred_in_qcis:1" (ppr (mkClassPred cls tys))
    
    2953
    +    hole = case dest of
    
    2954
    +             HoleDest hole -> hole   -- Equality constraints have HoleDest
    
    2955
    +             _ -> pprPanic "lookup_eq_in_qcis" (ppr dest) 
    
    2956
    +
    
    2957
    +    try :: SwapFlag -> SolverStage ()
    
    2958
    +    try swap -- First try looking for (lhs ~ rhs)
    
    2959
    +       | Just (cls, tys) <- unSwap swap (boxEqPred eq_rel) lhs rhs
    
    2960
    +       = Stage $
    
    2961
    +         do { let cls_pred = mkClassPred cls tys
    
    2962
    +            ; res <- matchLocalInst cls_pred loc
    
    2963
    +            ; traceTcS "lookup_eq_in_qcis:1" (ppr cls_pred)
    
    2958 2964
                 ; case res of
    
    2959
    -                OneInst { cir_mk_ev = mk_ev }
    
    2960
    -                  -> chooseInstance ev (res { cir_mk_ev = mk_eq_ev cls tys mk_ev })
    
    2961
    -                _ -> try_swapping }
    
    2962
    -       | otherwise
    
    2963
    -       = continueWith ()
    
    2965
    +                OneInst {}
    
    2966
    +                  -> do { dict_ev <- newWantedEvVarNC loc emptyCoHoleSet cls_pred
    
    2967
    +                        ; chooseInstance dict_ev res
    
    2968
    +                        ; let co_var = coHoleCoVar hole
    
    2969
    +                        ; setEvBind (mkWantedEvBind co_var EvCanonical (mk_sc_sel cls tys dict_ev))
    
    2970
    +                        ; fillCoercionHole hole emptyCoHoleSet $
    
    2971
    +                          maybeSymCo swap (mkCoVarCo co_var)
    
    2972
    +                        ; stopWith ev "lookup_eq_in_qcis" }
    
    2973
    +                _ -> continueWith () }
    
    2964 2974
     
    
    2965
    -    try_swapping  -- Now try looking for (rhs ~ lhs)  (see #23333)
    
    2966
    -       | Just (cls, tys) <- boxEqPred eq_rel rhs lhs
    
    2967
    -       = do { res <- matchLocalInst (mkClassPred cls tys) loc
    
    2968
    -            ; traceTcS "lookup_irred_in_qcis:2" (ppr (mkClassPred cls tys))
    
    2969
    -            ; case res of
    
    2970
    -                OneInst { cir_mk_ev = mk_ev }
    
    2971
    -                  -> do { ev' <- rewriteEqEvidence emptyRewriterSet ev IsSwapped
    
    2972
    -                                      (mkReflRedn role rhs) (mkReflRedn role lhs)
    
    2973
    -                        ; chooseInstance ev' (res { cir_mk_ev = mk_eq_ev cls tys mk_ev }) }
    
    2974
    -                _ -> do { traceTcS "lookup_irred_in_qcis:3" (ppr work_ct)
    
    2975
    -                        ; continueWith () }}
    
    2976 2975
            | otherwise
    
    2977
    -       = continueWith ()
    
    2978
    -
    
    2979
    -    mk_eq_ev cls tys mk_ev evs
    
    2980
    -      | sc_id : rest <- classSCSelIds cls  -- Just one superclass for this
    
    2981
    -      = assert (null rest) $ case (mk_ev evs) of
    
    2982
    -          EvExpr e -> EvExpr (Var sc_id `mkTyApps` tys `App` e)
    
    2983
    -          ev       -> pprPanic "mk_eq_ev" (ppr ev)
    
    2984
    -      | otherwise = pprPanic "finishEqCt" (ppr work_ct)
    
    2976
    +       = nopStage ()
    
    2977
    +
    
    2978
    +    mk_sc_sel cls tys dict_ev
    
    2979
    +      | [sc_id] <- classSCSelIds cls  -- Just one superclass for this
    
    2980
    +      = EvExpr (Var sc_id `mkTyApps` tys `App` Var (wantedCtEvEvId dict_ev))
    
    2981
    +      | otherwise
    
    2982
    +      = pprPanic "looup_eq_in_qcis" (ppr dict_ev)
    
    2983
    +
    
    2985 2984
     
    
    2986 2985
     {- Note [Instances in no-evidence implications]
    
    2987 2986
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

  • compiler/GHC/Tc/Solver/InertSet.hs
    ... ... @@ -171,7 +171,7 @@ data WorkList
    171 171
            , wl_rw_eqs  :: [Ct]  -- Like wl_eqs, but ones that may have a non-empty
    
    172 172
                                  -- rewriter set
    
    173 173
              -- We prioritise wl_eqs over wl_rw_eqs;
    
    174
    -         -- see Note [Prioritise Wanteds with empty RewriterSet]
    
    174
    +         -- see Note [Prioritise Wanteds with empty CoHoleSet]
    
    175 175
              -- in GHC.Tc.Types.Constraint for more details.
    
    176 176
     
    
    177 177
            , wl_rest :: [Ct]
    
    ... ... @@ -200,11 +200,11 @@ workListSize :: WorkList -> Int
    200 200
     workListSize (WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs, wl_rest = rest })
    
    201 201
       = length eqs_N + length eqs_X + length rw_eqs + length rest
    
    202 202
     
    
    203
    -extendWorkListEq :: RewriterSet -> Ct -> WorkList -> WorkList
    
    203
    +extendWorkListEq :: CoHoleSet -> Ct -> WorkList -> WorkList
    
    204 204
     extendWorkListEq rewriters ct
    
    205 205
         wl@(WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs })
    
    206
    -  | isEmptyRewriterSet rewriters      -- A wanted that has not been rewritten
    
    207
    -    -- isEmptyRewriterSet: see Note [Prioritise Wanteds with empty RewriterSet]
    
    206
    +  | isEmptyCoHoleSet rewriters      -- A wanted that has not been rewritten
    
    207
    +    -- isEmptyCoHoleSet: see Note [Prioritise Wanteds with empty CoHoleSet]
    
    208 208
         --                         in GHC.Tc.Types.Constraint
    
    209 209
       = if isNominalEqualityCt ct
    
    210 210
         then wl { wl_eqs_N = ct : eqs_N }
    
    ... ... @@ -223,8 +223,8 @@ extendWorkListChildEqs :: CtEvidence -> Bag Ct -> WorkList -> WorkList
    223 223
     -- Precondition: new_eqs is non-empty
    
    224 224
     extendWorkListChildEqs parent_ev new_eqs
    
    225 225
         wl@(WL { wl_eqs_N = eqs_N, wl_eqs_X = eqs_X, wl_rw_eqs = rw_eqs })
    
    226
    -  | isEmptyRewriterSet (ctEvRewriters parent_ev)
    
    227
    -    -- isEmptyRewriterSet: see Note [Prioritise Wanteds with empty RewriterSet]
    
    226
    +  | isEmptyCoHoleSet (ctEvRewriters parent_ev)
    
    227
    +    -- isEmptyCoHoleSet: see Note [Prioritise Wanteds with empty CoHoleSet]
    
    228 228
         --                         in GHC.Tc.Types.Constraint
    
    229 229
         -- If the rewriter set is empty, add to wl_eqs_X and wl_eqs_N
    
    230 230
       = case partitionBag isNominalEqualityCt new_eqs of
    
    ... ... @@ -244,7 +244,7 @@ extendWorkListChildEqs parent_ev new_eqs
    244 244
         push_on_front new_eqs eqs = foldr (:) eqs new_eqs
    
    245 245
     
    
    246 246
     extendWorkListRewrittenEqs :: [EqCt] -> WorkList -> WorkList
    
    247
    --- Don't bother checking the RewriterSet: just pop them into wl_rw_eqs
    
    247
    +-- Don't bother checking the CoHoleSet: just pop them into wl_rw_eqs
    
    248 248
     extendWorkListRewrittenEqs new_eqs wl@(WL { wl_rw_eqs = rw_eqs })
    
    249 249
       = wl { wl_rw_eqs = foldr ((:) . CEqCan) rw_eqs new_eqs }
    
    250 250
     
    
    ... ... @@ -2007,7 +2007,7 @@ solveOneFromTheOther ct_i ct_w
    2007 2007
             -- If only one has an empty rewriter set, use it
    
    2008 2008
             -- c.f. GHC.Tc.Solver.Equality.inertsCanDischarge, and especially
    
    2009 2009
             --      (CE4) in Note [Combining equalities]
    
    2010
    -        | Just res <- better (isEmptyRewriterSet rw_i) (isEmptyRewriterSet rw_w)
    
    2010
    +        | Just res <- better (isEmptyCoHoleSet rw_i) (isEmptyCoHoleSet rw_w)
    
    2011 2011
             -> res
    
    2012 2012
     
    
    2013 2013
             -- If only one is a WantedSuperclassOrigin (arising from expanding
    

  • compiler/GHC/Tc/Solver/Irred.hs
    1
    +{-# LANGUAGE DuplicateRecordFields #-}
    
    1 2
     {-# LANGUAGE DeriveFunctor #-}
    
    2 3
     {-# LANGUAGE MultiWayIf #-}
    
    3 4
     {-# LANGUAGE RecursiveDo #-}
    
    ... ... @@ -85,7 +86,7 @@ setIrredIfWanted :: CtEvidence -> SwapFlag -> CtEvidence -> TcS ()
    85 86
     setIrredIfWanted ev_dest swap ev_source
    
    86 87
       | CtWanted (WantedCt { ctev_dest = dest }) <- ev_dest
    
    87 88
       = case dest of
    
    88
    -      HoleDest {}  -> setWantedEq dest (ctEvRewriterSet ev_source)
    
    89
    +      HoleDest {}  -> setWantedEq dest (ctEvCoHoleSet ev_source)
    
    89 90
                                       (maybeSymCo swap (ctEvCoercion ev_source))
    
    90 91
     
    
    91 92
           EvVarDest {} -> assertPpr (swap==NotSwapped) (ppr ev_dest $$ ppr ev_source) $
    
    ... ... @@ -133,14 +134,12 @@ tryQCsIrredCt :: IrredCt -> SolverStage ()
    133 134
     -- Try local quantified constraints for
    
    134 135
     -- and CIrredCan e.g.  (c a)
    
    135 136
     tryQCsIrredCt (IrredCt { ir_ev = ev })
    
    136
    -  | isGiven ev
    
    137
    -  = Stage $ continueWith ()
    
    138
    -
    
    139
    -  | otherwise
    
    140
    -  = Stage $ do { res <- matchLocalInst pred loc
    
    141
    -               ; case res of
    
    142
    -                    OneInst {} -> chooseInstance ev res
    
    143
    -                    _          -> continueWith () }
    
    144
    -  where
    
    145
    -    loc  = ctEvLoc ev
    
    146
    -    pred = ctEvPred ev
    137
    +  = Stage $ case ev of
    
    138
    +      CtGiven {}
    
    139
    +        -> continueWith ()
    
    140
    +      CtWanted wev@(WantedCt { ctev_loc = loc, ctev_pred = pred })
    
    141
    +        -> do { res <- matchLocalInst pred loc
    
    142
    +              ; case res of
    
    143
    +                  OneInst {} -> do { chooseInstance wev res
    
    144
    +                                   ; stopWith ev "Irred (solved wanted)" }
    
    145
    +                  _          -> continueWith () }

  • compiler/GHC/Tc/Solver/Monad.hs
    ... ... @@ -56,6 +56,7 @@ module GHC.Tc.Solver.Monad (
    56 56
         newBoundEvVarId,
    
    57 57
         unifyTyVar, reportFineGrainUnifications, reportCoarseGrainUnifications,
    
    58 58
         setEvBind, setWantedEq, setWantedDict, setEqIfWanted, setDictIfWanted,
    
    59
    +    fillCoercionHole,
    
    59 60
         newEvVar, newGivenEv, emitNewGivens,
    
    60 61
         emitChildEqs, checkReductionDepth,
    
    61 62
     
    
    ... ... @@ -456,7 +457,7 @@ kickOutAfterUnification tv_set
    456 457
            ; traceTcS "kickOutAfterUnification" (ppr tv_set $$ text "n_kicked =" <+> ppr n_kicked)
    
    457 458
            ; return n_kicked }
    
    458 459
     
    
    459
    -kickOutAfterFillingCoercionHole :: CoercionHole -> RewriterSet -> TcS ()
    
    460
    +kickOutAfterFillingCoercionHole :: CoercionHole -> CoHoleSet -> TcS ()
    
    460 461
     -- See Wrinkle (URW2) in Note [Unify only if the rewriter set is empty]
    
    461 462
     -- in GHC.Tc.Solver.Equality
    
    462 463
     --
    
    ... ... @@ -488,10 +489,10 @@ kickOutAfterFillingCoercionHole hole new_holes
    488 489
           | CtWanted (wev@(WantedCt { ctev_rewriters = rewriters })) <- ev
    
    489 490
           , TyVarLHS tv <- lhs
    
    490 491
           , isMetaTyVar tv
    
    491
    -      , hole `elemRewriterSet` rewriters
    
    492
    -      , let holes' = (rewriters `delRewriterSet` hole) `mappend` new_holes
    
    492
    +      , hole `elemCoHoleSet` rewriters
    
    493
    +      , let holes' = (rewriters `delCoHoleSet` hole) `mappend` new_holes
    
    493 494
                 eq_ct' = eq_ct { eq_ev = CtWanted (wev { ctev_rewriters = holes' }) }
    
    494
    -      = if isEmptyRewriterSet holes'
    
    495
    +      = if isEmptyCoHoleSet holes'
    
    495 496
             then Left eq_ct'    -- Kick out
    
    496 497
             else Right eq_ct'   -- Keep, but with trimmed holes
    
    497 498
           | otherwise
    
    ... ... @@ -1736,7 +1737,7 @@ selectNextWorkItem :: TcS (Maybe Ct)
    1736 1737
     --
    
    1737 1738
     -- Suppose a constraint c1 is rewritten by another, c2.  When c2
    
    1738 1739
     -- gets solved, c1 has no rewriters, and can be prioritised; see
    
    1739
    --- Note [Prioritise Wanteds with empty RewriterSet] in
    
    1740
    +-- Note [Prioritise Wanteds with empty CoHoleSet] in
    
    1740 1741
     -- GHC.Tc.Types.Constraint wrinkle (PER1)
    
    1741 1742
     
    
    1742 1743
     -- ToDo: if wl_rw_eqs is long, we'll re-zonk it each time we pick
    
    ... ... @@ -1761,7 +1762,7 @@ selectNextWorkItem
    1761 1762
                  -- try_rws looks through rw_eqs to find one that has an empty
    
    1762 1763
                  -- rewriter set, after zonking.  If none such, call try_rest.
    
    1763 1764
                  try_rws acc (ct:cts)
    
    1764
    -                = do { ct' <- liftZonkTcS (TcM.zonkCtRewriterSet ct)
    
    1765
    +                = do { ct' <- liftZonkTcS (TcM.zonkCtCoHoleSet ct)
    
    1765 1766
                          ; if ctHasNoRewriters ct'
    
    1766 1767
                            then pick_me ct' (wl { wl_rw_eqs = cts ++ acc })
    
    1767 1768
                            else try_rws (ct':acc) cts }
    
    ... ... @@ -1959,14 +1960,14 @@ addUsedCoercion co
    1959 1960
       = do { ev_binds_var <- getTcEvBindsVar
    
    1960 1961
            ; wrapTcS (TcM.updTcRef (ebv_tcvs ev_binds_var) (co :)) }
    
    1961 1962
     
    
    1962
    -setEqIfWanted :: CtEvidence -> RewriterSet -> TcCoercion -> TcS ()
    
    1963
    +setEqIfWanted :: CtEvidence -> CoHoleSet -> TcCoercion -> TcS ()
    
    1963 1964
     setEqIfWanted ev rewriters co
    
    1964 1965
       = case ev of
    
    1965 1966
           CtWanted (WantedCt { ctev_dest = dest })
    
    1966 1967
              -> setWantedEq dest rewriters co
    
    1967 1968
           _  -> return ()
    
    1968 1969
     
    
    1969
    -setWantedEq :: HasDebugCallStack => TcEvDest -> RewriterSet -> TcCoercion -> TcS ()
    
    1970
    +setWantedEq :: HasDebugCallStack => TcEvDest -> CoHoleSet -> TcCoercion -> TcS ()
    
    1970 1971
     -- ^ Equalities only
    
    1971 1972
     setWantedEq dest rewriters co
    
    1972 1973
       = case dest of
    
    ... ... @@ -1987,7 +1988,7 @@ setWantedDict dest canonical tm
    1987 1988
           EvVarDest ev_id -> setEvBind (mkWantedEvBind ev_id canonical tm)
    
    1988 1989
           HoleDest h      -> pprPanic "setWantedEq: HoleDest" (ppr h)
    
    1989 1990
     
    
    1990
    -fillCoercionHole :: CoercionHole -> RewriterSet -> Coercion -> TcS ()
    
    1991
    +fillCoercionHole :: CoercionHole -> CoHoleSet -> Coercion -> TcS ()
    
    1991 1992
     fillCoercionHole hole rewriters co
    
    1992 1993
       = do { addUsedCoercion co
    
    1993 1994
            ; wrapTcS $ TcM.fillCoercionHole hole (co, rewriters)
    
    ... ... @@ -2046,7 +2047,7 @@ emitChildEqs ev eqs
    2046 2047
     
    
    2047 2048
     -- | Create a new Wanted constraint holding a coercion hole
    
    2048 2049
     -- for an equality between the two types at the given 'Role'.
    
    2049
    -newWantedEq :: CtLoc -> RewriterSet -> Role -> TcType -> TcType
    
    2050
    +newWantedEq :: CtLoc -> CoHoleSet -> Role -> TcType -> TcType
    
    2050 2051
                 -> TcS (WantedCtEvidence, CoercionHole)
    
    2051 2052
     newWantedEq loc rewriters role ty1 ty2
    
    2052 2053
       = do { hole <- wrapTcS $ TcM.newCoercionHole pty
    
    ... ... @@ -2061,7 +2062,7 @@ newWantedEq loc rewriters role ty1 ty2
    2061 2062
     -- | Create a new Wanted constraint holding an evidence variable.
    
    2062 2063
     --
    
    2063 2064
     -- Don't use this for equality constraints: use 'newWantedEq' instead.
    
    2064
    -newWantedEvVarNC :: CtLoc -> RewriterSet
    
    2065
    +newWantedEvVarNC :: CtLoc -> CoHoleSet
    
    2065 2066
                      -> TcPredType -> TcS WantedCtEvidence
    
    2066 2067
     -- Don't look up in the solved/inerts; we know it's not there
    
    2067 2068
     newWantedEvVarNC loc rewriters pty
    
    ... ... @@ -2085,7 +2086,7 @@ newWantedEvVarNC loc rewriters pty
    2085 2086
     --
    
    2086 2087
     -- Don't use this for equality constraints: this function is only for
    
    2087 2088
     -- constraints with 'EvVarDest'.
    
    2088
    -newWantedEvVar :: CtLoc -> RewriterSet
    
    2089
    +newWantedEvVar :: CtLoc -> CoHoleSet
    
    2089 2090
                    -> TcPredType -> TcS MaybeNew
    
    2090 2091
     newWantedEvVar loc rewriters pty
    
    2091 2092
       = case classifyPredType pty of
    
    ... ... @@ -2105,7 +2106,7 @@ newWantedEvVar loc rewriters pty
    2105 2106
     -- a new one from scratch.
    
    2106 2107
     --
    
    2107 2108
     -- Deals with both equality and non-equality constraints.
    
    2108
    -newWanted :: CtLoc -> RewriterSet -> PredType -> TcS MaybeNew
    
    2109
    +newWanted :: CtLoc -> CoHoleSet -> PredType -> TcS MaybeNew
    
    2109 2110
     newWanted loc rewriters pty
    
    2110 2111
       | Just (role, ty1, ty2) <- getEqPredTys_maybe pty
    
    2111 2112
       = Fresh . fst <$> newWantedEq loc rewriters role ty1 ty2
    
    ... ... @@ -2118,7 +2119,7 @@ newWanted loc rewriters pty
    2118 2119
     --
    
    2119 2120
     -- Does not attempt to re-use non-equality constraints that already
    
    2120 2121
     -- exist in the inert set.
    
    2121
    -newWantedNC :: CtLoc -> RewriterSet -> PredType -> TcS WantedCtEvidence
    
    2122
    +newWantedNC :: CtLoc -> CoHoleSet -> PredType -> TcS WantedCtEvidence
    
    2122 2123
     newWantedNC loc rewriters pty
    
    2123 2124
       | Just (role, ty1, ty2) <- getEqPredTys_maybe pty
    
    2124 2125
       = fst <$> newWantedEq loc rewriters role ty1 ty2
    
    ... ... @@ -2194,11 +2195,11 @@ uPairsTcM uenv eqns = mapM_ (\(Pair ty1 ty2) -> uType uenv ty1 ty2) eqns
    2194 2195
     
    
    2195 2196
     wrapUnifierAndEmit :: CtEvidence -> Role
    
    2196 2197
                        -> (UnifyEnv -> TcM a)  -- Some calls to uType
    
    2197
    -                   -> TcS (a, RewriterSet)
    
    2198
    +                   -> TcS (a, CoHoleSet)
    
    2198 2199
     -- Like wrapUnifier, but
    
    2199 2200
     --    emits any unsolved equalities into the work-list
    
    2200 2201
     --    kicks out any inert constraints that mention unified variables
    
    2201
    ---    returns a RewriterSet describing the new unsolved goals
    
    2202
    +--    returns a CoHoleSet describing the new unsolved goals
    
    2202 2203
     wrapUnifierAndEmit ev role do_unifications
    
    2203 2204
       = do { (unifs, (res, eqs)) <- reportFineGrainUnifications $
    
    2204 2205
                                     wrapUnifier ev role do_unifications
    

  • compiler/GHC/Tc/Solver/Rewrite.hs
    ... ... @@ -80,16 +80,16 @@ liftTcS thing_inside
    80 80
     
    
    81 81
     -- convenient wrapper when you have a CtEvidence describing
    
    82 82
     -- the rewriting operation
    
    83
    -runRewriteCtEv :: CtEvidence -> RewriteM a -> TcS (a, RewriterSet)
    
    83
    +runRewriteCtEv :: CtEvidence -> RewriteM a -> TcS (a, CoHoleSet)
    
    84 84
     runRewriteCtEv ev
    
    85 85
       = runRewrite (ctEvLoc ev) (ctEvFlavour ev) (ctEvRewriteEqRel ev)
    
    86 86
     
    
    87 87
     -- Run thing_inside (which does the rewriting)
    
    88 88
     -- Also returns the set of Wanteds which rewrote a Wanted;
    
    89 89
     -- See Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint
    
    90
    -runRewrite :: CtLoc -> CtFlavour -> EqRel -> RewriteM a -> TcS (a, RewriterSet)
    
    90
    +runRewrite :: CtLoc -> CtFlavour -> EqRel -> RewriteM a -> TcS (a, CoHoleSet)
    
    91 91
     runRewrite loc flav eq_rel thing_inside
    
    92
    -  = do { rewriters_ref <- newTcRef emptyRewriterSet
    
    92
    +  = do { rewriters_ref <- newTcRef emptyCoHoleSet
    
    93 93
            ; let fmode = RE { re_loc       = loc
    
    94 94
                             , re_flavour   = flav
    
    95 95
                             , re_eq_rel    = eq_rel
    
    ... ... @@ -226,7 +226,7 @@ a better error message anyway.)
    226 226
     -- `rewriters` is the set of coercion holes that have been used to rewrite
    
    227 227
     -- See Note [Wanteds rewrite Wanteds] in GHC.Tc.Types.Constraint
    
    228 228
     rewrite :: CtEvidence -> TcType
    
    229
    -        -> TcS (Reduction, RewriterSet)
    
    229
    +        -> TcS (Reduction, CoHoleSet)
    
    230 230
     rewrite ev ty
    
    231 231
       = do { traceTcS "rewrite {" (ppr ty)
    
    232 232
            ; result@(redn, _) <- runRewriteCtEv ev (rewrite_one ty)
    
    ... ... @@ -239,7 +239,7 @@ rewrite ev ty
    239 239
     -- for error messages. (This was important when we flirted with rewriting
    
    240 240
     -- newtypes but perhaps less so now.)
    
    241 241
     rewriteForErrors :: CtEvidence -> TcType
    
    242
    -                 -> TcS (Reduction, RewriterSet)
    
    242
    +                 -> TcS (Reduction, CoHoleSet)
    
    243 243
     rewriteForErrors ev ty
    
    244 244
       = do { traceTcS "rewriteForErrors {" (ppr ty)
    
    245 245
            ; result@(redn, rewriters) <-
    
    ... ... @@ -251,7 +251,7 @@ rewriteForErrors ev ty
    251 251
     
    
    252 252
     -- See Note [Rewriting]
    
    253 253
     rewriteArgsNom :: CtEvidence -> TyCon -> [TcType]
    
    254
    -               -> TcS (Reductions, RewriterSet)
    
    254
    +               -> TcS (Reductions, CoHoleSet)
    
    255 255
     -- Externally-callable, hence runRewrite
    
    256 256
     -- Rewrite a vector of types all at once; in fact they are
    
    257 257
     -- always the arguments of type family or class, so
    

  • compiler/GHC/Tc/Solver/Solve.hs
    ... ... @@ -1702,19 +1702,19 @@ rewriteDictEvidence ev
    1702 1702
     
    
    1703 1703
     finish_rewrite :: CtEvidence   -- ^ old evidence
    
    1704 1704
                    -> Reduction    -- ^ new predicate + coercion, of type <type of old evidence> ~ new predicate
    
    1705
    -               -> RewriterSet  -- ^ See Note [Wanteds rewrite Wanteds]
    
    1705
    +               -> CoHoleSet  -- ^ See Note [Wanteds rewrite Wanteds]
    
    1706 1706
                                    -- in GHC.Tc.Types.Constraint
    
    1707 1707
                    -> TcS (StopOrContinue CtEvidence)
    
    1708 1708
     finish_rewrite old_ev (Reduction co new_pred) rewriters
    
    1709 1709
       | isReflCo co -- See Note [Rewriting with Refl]
    
    1710
    -  = assert (isEmptyRewriterSet rewriters) $
    
    1710
    +  = assert (isEmptyCoHoleSet rewriters) $
    
    1711 1711
         continueWith (setCtEvPredType old_ev new_pred)
    
    1712 1712
     
    
    1713 1713
     finish_rewrite
    
    1714 1714
       ev@(CtGiven (GivenCt { ctev_evar = old_evar }))
    
    1715 1715
       (Reduction co new_pred)
    
    1716 1716
       rewriters
    
    1717
    -  = assert (isEmptyRewriterSet rewriters) $ -- this is a Given, not a wanted
    
    1717
    +  = assert (isEmptyCoHoleSet rewriters) $ -- this is a Given, not a wanted
    
    1718 1718
         do { let loc = ctEvLoc ev
    
    1719 1719
                  -- mkEvCast optimises ReflCo
    
    1720 1720
                  ev_rw_role = ctEvRewriteRole ev
    
    ... ... @@ -1810,7 +1810,7 @@ setPluginEv (tm,ct)
    1810 1810
             -> case dest of
    
    1811 1811
                   EvVarDest {} -> setWantedDict dest EvCanonical tm
    
    1812 1812
                                   -- TODO: plugins should be able to signal non-canonicity
    
    1813
    -              HoleDest {}  -> setWantedEq dest emptyRewriterSet (evTermCoercion tm)
    
    1813
    +              HoleDest {}  -> setWantedEq dest emptyCoHoleSet (evTermCoercion tm)
    
    1814 1814
                                   -- TODO: should we try to track rewriters?
    
    1815 1815
     
    
    1816 1816
           CtGiven {} -> panic "runTcPluginsWanted.setEv: attempt to solve non-wanted!"
    

  • compiler/GHC/Tc/Types.hs
    ... ... @@ -334,7 +334,7 @@ data RewriteEnv
    334 334
               -- ^ At what role are we rewriting?
    
    335 335
               -- See Note [Rewriter EqRels] in GHC.Tc.Solver.Rewrite
    
    336 336
     
    
    337
    -       , re_rewriters :: !(TcRef RewriterSet)  -- ^ See Note [Wanteds rewrite Wanteds]
    
    337
    +       , re_rewriters :: !(TcRef CoHoleSet)  -- ^ See Note [Wanteds rewrite Wanteds]
    
    338 338
            }
    
    339 339
     -- RewriteEnv is mostly used in @GHC.Tc.Solver.Rewrite@, but it is defined
    
    340 340
     -- here so that it can also be passed to rewriting plugins.
    

  • compiler/GHC/Tc/Types/Constraint.hs
    ... ... @@ -80,7 +80,7 @@ module GHC.Tc.Types.Constraint (
    80 80
             ctEvExpr, ctEvTerm,
    
    81 81
             ctEvCoercion, givenCtEvCoercion,
    
    82 82
             ctEvEvId, wantedCtEvEvId,
    
    83
    -        ctEvRewriters, ctEvRewriterSet, setWantedCtEvRewriters,
    
    83
    +        ctEvRewriters, ctEvCoHoleSet, setWantedCtEvRewriters,
    
    84 84
             ctEvUnique, tcEvDestUnique,
    
    85 85
             ctEvRewriteRole, ctEvRewriteEqRel, setCtEvPredType, setCtEvLoc,
    
    86 86
             tyCoVarsOfCtEvList, tyCoVarsOfCtEv, tyCoVarsOfCtEvsList,
    
    ... ... @@ -88,10 +88,10 @@ module GHC.Tc.Types.Constraint (
    88 88
             -- CtEvidence constructors
    
    89 89
             GivenCtEvidence(..), WantedCtEvidence(..),
    
    90 90
     
    
    91
    -        -- RewriterSet
    
    92
    -        --   RewriterSet(..) is exported concretely only for zonkRewriterSet
    
    93
    -        RewriterSet(..), emptyRewriterSet, isEmptyRewriterSet, elemRewriterSet,
    
    94
    -        addRewriter, unitRewriterSet, unionRewriterSet, delRewriterSet,
    
    91
    +        -- CoHoleSet
    
    92
    +        --   CoHoleSet(..) is exported concretely only for zonkCoHoleSet
    
    93
    +        CoHoleSet(..), emptyCoHoleSet, isEmptyCoHoleSet, elemCoHoleSet,
    
    94
    +        addRewriter, unitCoHoleSet, unionCoHoleSet, delCoHoleSet,
    
    95 95
             rewriterSetFromCts,
    
    96 96
     
    
    97 97
             wrapType,
    
    ... ... @@ -706,7 +706,7 @@ ctPred :: Ct -> PredType
    706 706
     -- See Note [Ct/evidence invariant]
    
    707 707
     ctPred ct = ctEvPred (ctEvidence ct)
    
    708 708
     
    
    709
    -ctRewriters :: Ct -> RewriterSet
    
    709
    +ctRewriters :: Ct -> CoHoleSet
    
    710 710
     ctRewriters = ctEvRewriters . ctEvidence
    
    711 711
     
    
    712 712
     ctEvId :: HasDebugCallStack => Ct -> EvVar
    
    ... ... @@ -1210,7 +1210,7 @@ insolubleWantedCt ct
    1210 1210
           -- It's a Wanted
    
    1211 1211
       , insolubleCt ct
    
    1212 1212
           -- It's insoluble
    
    1213
    -  , isEmptyRewriterSet rewriters
    
    1213
    +  , isEmptyCoHoleSet rewriters
    
    1214 1214
           -- It has no rewriters – see (IW1) in Note [Insoluble Wanteds]
    
    1215 1215
       , not (isGivenLoc loc)
    
    1216 1216
           -- isGivenLoc: see (IW2) in Note [Insoluble Wanteds]
    
    ... ... @@ -2341,7 +2341,7 @@ data WantedCtEvidence =
    2341 2341
         { ctev_pred      :: TcPredType     -- See Note [Ct/evidence invariant]
    
    2342 2342
         , ctev_dest      :: TcEvDest       -- See Note [CtEvidence invariants]
    
    2343 2343
         , ctev_loc       :: CtLoc
    
    2344
    -    , ctev_rewriters :: RewriterSet }  -- See Note [Wanteds rewrite Wanteds]
    
    2344
    +    , ctev_rewriters :: CoHoleSet }  -- See Note [Wanteds rewrite Wanteds]
    
    2345 2345
     
    
    2346 2346
     ctEvPred :: CtEvidence -> TcPredType
    
    2347 2347
     -- The predicate of a flavor
    
    ... ... @@ -2377,9 +2377,9 @@ ctEvTerm ev = EvExpr (ctEvExpr ev)
    2377 2377
     -- See Note [Wanteds rewrite Wanteds]
    
    2378 2378
     -- If the provided CtEvidence is not for a Wanted, just
    
    2379 2379
     -- return an empty set.
    
    2380
    -ctEvRewriters :: CtEvidence -> RewriterSet
    
    2380
    +ctEvRewriters :: CtEvidence -> CoHoleSet
    
    2381 2381
     ctEvRewriters (CtWanted (WantedCt { ctev_rewriters = rws })) = rws
    
    2382
    -ctEvRewriters (CtGiven {})  = emptyRewriterSet
    
    2382
    +ctEvRewriters (CtGiven {})  = emptyCoHoleSet
    
    2383 2383
     
    
    2384 2384
     ctHasNoRewriters :: Ct -> Bool
    
    2385 2385
     ctHasNoRewriters ev
    
    ... ... @@ -2389,22 +2389,22 @@ ctHasNoRewriters ev
    2389 2389
     
    
    2390 2390
     wantedCtHasNoRewriters :: WantedCtEvidence -> Bool
    
    2391 2391
     wantedCtHasNoRewriters (WantedCt { ctev_rewriters = rws })
    
    2392
    -  = isEmptyRewriterSet rws
    
    2392
    +  = isEmptyCoHoleSet rws
    
    2393 2393
     
    
    2394 2394
     -- | Set the rewriter set of a Wanted constraint.
    
    2395
    -setWantedCtEvRewriters :: WantedCtEvidence -> RewriterSet -> WantedCtEvidence
    
    2395
    +setWantedCtEvRewriters :: WantedCtEvidence -> CoHoleSet -> WantedCtEvidence
    
    2396 2396
     setWantedCtEvRewriters ev rs = ev { ctev_rewriters = rs }
    
    2397 2397
     
    
    2398
    -ctEvRewriterSet :: CtEvidence -> RewriterSet
    
    2398
    +ctEvCoHoleSet :: CtEvidence -> CoHoleSet
    
    2399 2399
     -- Returns the set of holes (empty or singleton) for the evidence itself
    
    2400 2400
     -- Note the difference from ctEvRewriters!
    
    2401
    -ctEvRewriterSet (CtWanted (WantedCt { ctev_dest = HoleDest hole })) = unitRewriterSet hole
    
    2402
    -ctEvRewriterSet _                                                   = emptyRewriterSet
    
    2401
    +ctEvCoHoleSet (CtWanted (WantedCt { ctev_dest = HoleDest hole })) = unitCoHoleSet hole
    
    2402
    +ctEvCoHoleSet _                                                   = emptyCoHoleSet
    
    2403 2403
     
    
    2404
    -rewriterSetFromCts :: Bag Ct -> RewriterSet
    
    2405
    --- Take a bag of Wanted equalities, and collect them as a RewriterSet
    
    2404
    +rewriterSetFromCts :: Bag Ct -> CoHoleSet
    
    2405
    +-- Take a bag of Wanted equalities, and collect them as a CoHoleSet
    
    2406 2406
     rewriterSetFromCts cts
    
    2407
    -  = foldr add emptyRewriterSet cts
    
    2407
    +  = foldr add emptyCoHoleSet cts
    
    2408 2408
       where
    
    2409 2409
         add ct rw_set =
    
    2410 2410
           case ctEvidence ct of
    
    ... ... @@ -2440,16 +2440,19 @@ ctEvEvId (CtWanted wtd) = wantedCtEvEvId wtd
    2440 2440
     ctEvEvId (CtGiven (GivenCt { ctev_evar = ev })) = ev
    
    2441 2441
     
    
    2442 2442
     wantedCtEvEvId :: WantedCtEvidence -> EvVar
    
    2443
    -wantedCtEvEvId (WantedCt { ctev_dest = EvVarDest ev }) = ev
    
    2444
    -wantedCtEvEvId (WantedCt { ctev_dest = HoleDest h })   = coHoleCoVar h
    
    2443
    +wantedCtEvEvId (WantedCt { ctev_dest = dest }) = tcEvDestVar dest
    
    2445 2444
     
    
    2446 2445
     ctEvUnique :: CtEvidence -> Unique
    
    2447 2446
     ctEvUnique (CtGiven (GivenCt { ctev_evar = ev }))     = varUnique ev
    
    2448 2447
     ctEvUnique (CtWanted (WantedCt { ctev_dest = dest })) = tcEvDestUnique dest
    
    2449 2448
     
    
    2449
    +tcEvDestVar :: TcEvDest -> EvVar
    
    2450
    +tcEvDestVar (EvVarDest ev_var) = ev_var
    
    2451
    +tcEvDestVar (HoleDest co_hole) = coHoleCoVar co_hole
    
    2452
    +
    
    2450 2453
     tcEvDestUnique :: TcEvDest -> Unique
    
    2451
    -tcEvDestUnique (EvVarDest ev_var) = varUnique ev_var
    
    2452
    -tcEvDestUnique (HoleDest co_hole) = varUnique (coHoleCoVar co_hole)
    
    2454
    +tcEvDestUnique dest = varUnique (tcEvDestVar dest)
    
    2455
    +
    
    2453 2456
     
    
    2454 2457
     setCtEvLoc :: CtEvidence -> CtLoc -> CtEvidence
    
    2455 2458
     setCtEvLoc (CtGiven (GivenCt pred evar _)) loc = CtGiven (GivenCt pred evar loc)
    
    ... ... @@ -2493,7 +2496,7 @@ instance Outputable CtEvidence where
    2493 2496
                  CtWanted ev -> ppr (ctev_dest ev)
    
    2494 2497
     
    
    2495 2498
           rewriters = ctEvRewriters ev
    
    2496
    -      pp_rewriters | isEmptyRewriterSet rewriters = empty
    
    2499
    +      pp_rewriters | isEmptyCoHoleSet rewriters = empty
    
    2497 2500
                        | otherwise                    = semi <> ppr rewriters
    
    2498 2501
     
    
    2499 2502
     isWanted :: CtEvidence -> Bool
    
    ... ... @@ -2593,39 +2596,52 @@ We thus want Wanteds to rewrite Wanteds in order to accept more programs,
    2593 2596
     but we don't want Wanteds to rewrite Wanteds because doing so can create
    
    2594 2597
     inscrutable error messages. To solve this dilemma:
    
    2595 2598
     
    
    2596
    -* We allow Wanteds to rewrite Wanteds, but each Wanted tracks the set of Wanteds
    
    2597
    -  it has been rewritten by, in its RewriterSet, stored in the ctev_rewriters
    
    2598
    -  field of the CtWanted constructor of CtEvidence.  (Only Wanteds have
    
    2599
    -  RewriterSets.)
    
    2599
    +(WRW1) The rewriters of a Wanted.  We do allow Wanteds to rewrite Wanteds, but each
    
    2600
    +  unsolved Wanted tracks
    
    2601
    +     the set of Wanteds that it has been rewritten by
    
    2602
    +  in its CoHoleSet, stored in the `ctev_rewriters` field of the CtWanted
    
    2603
    +  constructor of CtEvidence.  (Only Wanteds have CoHoleSets.)
    
    2600 2604
     
    
    2601
    -* A RewriterSet is just a set of unfilled CoercionHoles. This is sufficient
    
    2602
    -  because only equalities (evidenced by coercion holes) are used for rewriting;
    
    2603
    -  other (dictionary) constraints cannot ever rewrite.
    
    2605
    +  If the rewriter set is empty, then the constaint has been not been rewritten
    
    2606
    +  by any unsolved constraint.
    
    2604 2607
     
    
    2605
    -* The rewriter (in e.g. GHC.Tc.Solver.Rewrite.rewrite) tracks and returns a RewriterSet,
    
    2608
    +(WRW2) A CoHoleSet is just a set of CoercionHoles. This is sufficient because only
    
    2609
    +  equalities (evidenced by coercion holes) are used for rewriting; other
    
    2610
    +  (dictionary) constraints cannot ever rewrite.
    
    2611
    +
    
    2612
    +(WRW3) The rewriter (in e.g. GHC.Tc.Solver.Rewrite.rewrite) tracks and returns a CoHoleSet,
    
    2606 2613
       consisting of the evidence (a CoercionHole) for any Wanted equalities used in
    
    2607 2614
       rewriting.
    
    2608 2615
     
    
    2609
    -* Then GHC.Tc.Solver.Solve.rewriteEvidence and GHC.Tc.Solver.Equality.rewriteEqEvidence
    
    2610
    -  add this RewriterSet to the rewritten constraint's rewriter set.
    
    2616
    +(WRW4) Then GHC.Tc.Solver.Solve.rewriteEvidence and GHC.Tc.Solver.Equality.rewriteEqEvidence
    
    2617
    +  add this CoHoleSet to the rewritten constraint's rewriter set.
    
    2618
    +
    
    2619
    +(WRW5) We prevent the unifier from unifying any equality with a non-empty rewriter
    
    2620
    +  set; unification effectively turns a Wanted into a Given, and we lose all
    
    2621
    +  tracking.  See (REWRITERS) in Note [Unification preconditions] in
    
    2622
    +  GHC.Tc.Utils.Unify and Note [Unify only if the rewriter set is empty] in
    
    2623
    +  GHC.Solver.Equality.
    
    2611 2624
     
    
    2612
    -* We prevent the unifier from unifying any equality with a non-empty rewriter set;
    
    2613
    -  unification effectively turns a Wanted into a Given, and we lose all tracking.
    
    2614
    -  See (REWRITERS) in Note [Unification preconditions] in GHC.Tc.Utils.Unify and
    
    2615
    -  Note [Unify only if the rewriter set is empty] in GHC.Solver.Equality.
    
    2625
    +(WRW6) Filling a coercion hole.  When filling a coercion hole we store, in the filled
    
    2626
    +  hole `ch_ref`, a CoHoleSet that is a superset of the CoercionHoles in the coercion.  e.g.
    
    2627
    +  suppose we fill a coercion hole
    
    2628
    +      co_hole0 := co_hole1 ; Maybe co_hole2
    
    2629
    +   Another constraint D may have been written by this constraint, and thus have co_hole0
    
    2630
    +   in D's `ctev_rewriters`   When zonking the rewriters of D, we want to record that
    
    2631
    +   it has been rewritten by `co_hole1` and `co_hole2
    
    2616 2632
     
    
    2617
    -* In error reporting, we simply suppress any errors that have been rewritten
    
    2633
    +(WRW7) In error reporting, we simply suppress any errors that have been rewritten
    
    2618 2634
       by /unsolved/ wanteds. This suppression happens in GHC.Tc.Errors.mkErrorItem,
    
    2619
    -  which uses `GHC.Tc.Zonk.Type.zonkRewriterSet` to look through any filled
    
    2635
    +  which uses `GHC.Tc.Zonk.Type.zonkCoHoleSet` to look through any filled
    
    2620 2636
       coercion holes. The idea is that we wish to report the "root cause" -- the
    
    2621 2637
       error that rewrote all the others.
    
    2622 2638
     
    
    2623
    -* In `selectNextWorkItem`, priorities equalities with no rewiters.  See
    
    2624
    -  Note [Prioritise Wanteds with empty RewriterSet] in GHC.Tc.Types.Constraint
    
    2639
    +(WRW8) In `selectNextWorkItem`, priorities equalities with no rewiters.  See
    
    2640
    +  Note [Prioritise Wanteds with empty CoHoleSet] in GHC.Tc.Types.Constraint
    
    2625 2641
       wrinkle (PER1).
    
    2626 2642
     
    
    2627
    -* In error reporting, we prioritise Wanteds that have an empty RewriterSet:
    
    2628
    -  see Note [Prioritise Wanteds with empty RewriterSet].
    
    2643
    +(WRW9) In error reporting, we prioritise Wanteds that have an empty CoHoleSet:
    
    2644
    +  see Note [Prioritise Wanteds with empty CoHoleSet].
    
    2629 2645
     
    
    2630 2646
     Let's continue our first example above:
    
    2631 2647
     
    
    ... ... @@ -2637,25 +2653,25 @@ Because Wanteds can rewrite Wanteds, w1 will rewrite w2, yielding
    2637 2653
       inert: [W] w1 :: a ~ Char
    
    2638 2654
              [W] w2 {w1}:: Char ~ Bool
    
    2639 2655
     
    
    2640
    -The {w1} in the second line of output is the RewriterSet of w1.
    
    2656
    +The {w1} in the second line of output is the CoHoleSet of w1.
    
    2641 2657
     
    
    2642 2658
     Wrinkles:
    
    2643 2659
     
    
    2644
    -(WRW1) When we find a constraint identical to one already in the inert set,
    
    2660
    +(WRW10) When we find a constraint identical to one already in the inert set,
    
    2645 2661
        we solve one from the other. Other things being equal, keep the one
    
    2646 2662
        that has fewer (better still no) rewriters.
    
    2647 2663
        See (CE4) in Note [Combining equalities] in GHC.Tc.Solver.Equality.
    
    2648 2664
     
    
    2649
    -   To this accurately we should use `zonkRewriterSet` during canonicalisation,
    
    2665
    +   To do this accurately we should use `zonkCoHoleSet` during canonicalisation,
    
    2650 2666
        to eliminate rewriters that have now been solved.  Currently we only do so
    
    2651 2667
        during error reporting; but perhaps we should change that.
    
    2652 2668
     
    
    2653
    -(WRW2) When zonking a constraint (with `zonkCt` and `zonkCtEvidence`) we take
    
    2654
    -   the opportunity to zonk its `RewriterSet`, which eliminates solved ones.
    
    2655
    -   This doesn't guarantee that rewriter sets are always up to date -- see
    
    2656
    -   (WRW1) -- but it helps, and it de-clutters debug output.
    
    2669
    +(WRW11) When zonking a constraint (with `zonkCt` and `zonkCtEvidence`) we take
    
    2670
    +   the opportunity to zonk its `CoHoleSet`, which eliminates solved ones.
    
    2671
    +   This doesn't guarantee that rewriter sets are always up to date -- c.f.
    
    2672
    +   (WRW10) -- but it helps, and it de-clutters debug output.
    
    2657 2673
     
    
    2658
    -Note [Prioritise Wanteds with empty RewriterSet]
    
    2674
    +Note [Prioritise Wanteds with empty CoHoleSet]
    
    2659 2675
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2660 2676
     When extending the WorkList, in GHC.Tc.Solver.InertSet.extendWorkListEq,
    
    2661 2677
     we prioritise constraints that have no rewriters. Here's why.
    
    ... ... @@ -2702,8 +2718,8 @@ is done in `GHC.Tc.Solver.Monad.selectNextWorkItem`.
    2702 2718
     
    
    2703 2719
     Wrinkles
    
    2704 2720
     
    
    2705
    -(PER1) When picking the next work item, before checking for an empty RewriterSet
    
    2706
    -  in GHC.Tc.Solver.Monad.selectNextWorkItem, we zonk the RewriterSet, because
    
    2721
    +(PER1) When picking the next work item, before checking for an empty CoHoleSet
    
    2722
    +  in GHC.Tc.Solver.Monad.selectNextWorkItem, we zonk the CoHoleSet, because
    
    2707 2723
       some of those CoercionHoles may have been filled in since we last looked.
    
    2708 2724
     
    
    2709 2725
     (PER2) Despite the prioritisation, it is hard to be /certain/ that we can't end up
    

  • compiler/GHC/Tc/Utils/TcMType.hs
    ... ... @@ -202,7 +202,7 @@ newWantedWithLoc loc pty
    202 202
              WantedCt { ctev_dest      = dst
    
    203 203
                       , ctev_pred      = pty
    
    204 204
                       , ctev_loc       = loc
    
    205
    -                  , ctev_rewriters = emptyRewriterSet }
    
    205
    +                  , ctev_rewriters = emptyCoHoleSet }
    
    206 206
     
    
    207 207
     -- | Create a new Wanted constraint with the given 'CtOrigin', and
    
    208 208
     -- location information taken from the 'TcM' environment.
    
    ... ... @@ -278,7 +278,7 @@ emitWantedEq origin t_or_k role ty1 ty2
    278 278
                WantedCt { ctev_pred      = pty
    
    279 279
                         , ctev_dest      = HoleDest hole
    
    280 280
                         , ctev_loc       = loc
    
    281
    -                    , ctev_rewriters = emptyRewriterSet }
    
    281
    +                    , ctev_rewriters = emptyCoHoleSet }
    
    282 282
            ; return (HoleCo hole) }
    
    283 283
       where
    
    284 284
         pty = mkEqPredRole role ty1 ty2
    
    ... ... @@ -292,7 +292,7 @@ emitWantedEvVar origin ty
    292 292
            ; let ctev = WantedCt { ctev_pred      = ty
    
    293 293
                                  , ctev_dest      = EvVarDest new_cv
    
    294 294
                                  , ctev_loc       = loc
    
    295
    -                             , ctev_rewriters = emptyRewriterSet }
    
    295
    +                             , ctev_rewriters = emptyCoHoleSet }
    
    296 296
            ; emitSimple $ mkNonCanonical $ CtWanted ctev
    
    297 297
            ; return new_cv }
    
    298 298
     
    
    ... ... @@ -360,7 +360,7 @@ newCoercionHole pred_ty
    360 360
            ; return $ CoercionHole { ch_co_var = co_var, ch_ref = ref } }
    
    361 361
     
    
    362 362
     -- | Put a value in a coercion hole
    
    363
    -fillCoercionHole :: CoercionHole -> (Coercion, RewriterSet) -> TcM ()
    
    363
    +fillCoercionHole :: CoercionHole -> (Coercion, CoHoleSet) -> TcM ()
    
    364 364
     fillCoercionHole (CoercionHole { ch_ref = ref, ch_co_var = cv }) co
    
    365 365
       = do { when debugIsOn $
    
    366 366
              do { cts <- readTcRef ref
    

  • compiler/GHC/Tc/Utils/Unify.hs
    ... ... @@ -2297,7 +2297,7 @@ unifyTypeAndEmit t_or_k orig ty1 ty2
    2297 2297
                -- /any/ level outside this one as untouchable.  Hence cur_lvl.
    
    2298 2298
            ; let env = UE { u_loc = loc, u_role = Nominal
    
    2299 2299
                           , u_given_eq_lvl = cur_lvl
    
    2300
    -                      , u_rewriters = emptyRewriterSet  -- ToDo: check this
    
    2300
    +                      , u_rewriters = emptyCoHoleSet  -- ToDo: check this
    
    2301 2301
                           , u_defer = ref, u_what = WU_None }
    
    2302 2302
     
    
    2303 2303
            -- The hard work happens here
    
    ... ... @@ -2444,7 +2444,7 @@ A job for the future.
    2444 2444
     data UnifyEnv
    
    2445 2445
       = UE { u_role         :: Role
    
    2446 2446
            , u_loc          :: CtLoc
    
    2447
    -       , u_rewriters    :: RewriterSet
    
    2447
    +       , u_rewriters    :: CoHoleSet
    
    2448 2448
     
    
    2449 2449
            -- `u_given_eq_lvl` is just like the `inert_given_eq_lvl`
    
    2450 2450
            -- field of GHC.Tc.Solver.InertSet.InertCans
    
    ... ... @@ -4597,7 +4597,7 @@ makeTypeConcrete occ_fs conc_orig ty =
    4597 4597
                              $ WantedCt { ctev_pred      = pty
    
    4598 4598
                                         , ctev_dest      = HoleDest hole
    
    4599 4599
                                         , ctev_loc       = loc
    
    4600
    -                                    , ctev_rewriters = emptyRewriterSet }
    
    4600
    +                                    , ctev_rewriters = emptyCoHoleSet }
    
    4601 4601
                     ; return (kind_cts S.<> unitBag ct, HoleCo hole)
    
    4602 4602
                     }
    
    4603 4603
     
    

  • compiler/GHC/Tc/Zonk/TcType.hs
    ... ... @@ -39,7 +39,7 @@ module GHC.Tc.Zonk.TcType
    39 39
       , zonkCt, zonkWC, zonkSimples, zonkImplication
    
    40 40
     
    
    41 41
         -- * Rewriter sets
    
    42
    -  , zonkRewriterSet, zonkCtRewriterSet, zonkCtEvRewriterSet
    
    42
    +  , zonkCoHoleSet, zonkCtCoHoleSet, zonkCtEvCoHoleSet
    
    43 43
     
    
    44 44
         -- * Coercion holes
    
    45 45
       , isFilledCoercionHole, unpackCoercionHole, unpackCoercionHole_maybe
    
    ... ... @@ -507,13 +507,13 @@ zonkCt ct
    507 507
     
    
    508 508
     zonkCtEvidence :: CtEvidence -> ZonkM CtEvidence
    
    509 509
     -- Zonks the ctev_pred and the ctev_rewriters; but not ctev_evar
    
    510
    --- For ctev_rewriters, see (WRW2) in Note [Wanteds rewrite Wanteds]
    
    510
    +-- For ctev_rewriters, see (WRW11) in Note [Wanteds rewrite Wanteds]
    
    511 511
     zonkCtEvidence (CtGiven (GivenCt { ctev_pred = pred, ctev_evar = var, ctev_loc = loc }))
    
    512 512
       = do { pred' <- zonkTcType pred
    
    513 513
            ; return (CtGiven (GivenCt { ctev_pred = pred', ctev_evar = var, ctev_loc = loc })) }
    
    514 514
     zonkCtEvidence (CtWanted wanted@(WantedCt { ctev_pred = pred, ctev_rewriters = rws }))
    
    515 515
       = do { pred' <- zonkTcType pred
    
    516
    -       ; rws'  <- zonkRewriterSet rws
    
    516
    +       ; rws'  <- zonkCoHoleSet rws
    
    517 517
            ; return (CtWanted (wanted { ctev_pred = pred', ctev_rewriters = rws' })) }
    
    518 518
     
    
    519 519
     zonkSkolemInfo :: SkolemInfo -> ZonkM SkolemInfo
    
    ... ... @@ -555,33 +555,33 @@ But c.f Note [Sharing when zonking to Type] in GHC.Tc.Zonk.Type.
    555 555
     ************************************************************************
    
    556 556
     -}
    
    557 557
     
    
    558
    -zonkCtRewriterSet :: Ct -> ZonkM Ct
    
    559
    -zonkCtRewriterSet ct
    
    558
    +zonkCtCoHoleSet :: Ct -> ZonkM Ct
    
    559
    +zonkCtCoHoleSet ct
    
    560 560
       | isGivenCt ct
    
    561 561
       = return ct
    
    562 562
       | otherwise
    
    563 563
       = case ct of
    
    564
    -      CEqCan eq@(EqCt { eq_ev = ev })       -> do { ev' <- zonkCtEvRewriterSet ev
    
    564
    +      CEqCan eq@(EqCt { eq_ev = ev })       -> do { ev' <- zonkCtEvCoHoleSet ev
    
    565 565
                                                       ; return (CEqCan (eq { eq_ev = ev' })) }
    
    566
    -      CIrredCan ir@(IrredCt { ir_ev = ev }) -> do { ev' <- zonkCtEvRewriterSet ev
    
    566
    +      CIrredCan ir@(IrredCt { ir_ev = ev }) -> do { ev' <- zonkCtEvCoHoleSet ev
    
    567 567
                                                       ; return (CIrredCan (ir { ir_ev = ev' })) }
    
    568
    -      CDictCan di@(DictCt { di_ev = ev })   -> do { ev' <- zonkCtEvRewriterSet ev
    
    568
    +      CDictCan di@(DictCt { di_ev = ev })   -> do { ev' <- zonkCtEvCoHoleSet ev
    
    569 569
                                                       ; return (CDictCan (di { di_ev = ev' })) }
    
    570 570
           CQuantCan {}     -> return ct
    
    571
    -      CNonCanonical ev -> do { ev' <- zonkCtEvRewriterSet ev
    
    571
    +      CNonCanonical ev -> do { ev' <- zonkCtEvCoHoleSet ev
    
    572 572
                                  ; return (CNonCanonical ev') }
    
    573 573
     
    
    574
    -zonkCtEvRewriterSet :: CtEvidence -> ZonkM CtEvidence
    
    575
    -zonkCtEvRewriterSet ev@(CtGiven {})
    
    574
    +zonkCtEvCoHoleSet :: CtEvidence -> ZonkM CtEvidence
    
    575
    +zonkCtEvCoHoleSet ev@(CtGiven {})
    
    576 576
       = return ev
    
    577
    -zonkCtEvRewriterSet ev@(CtWanted wtd)
    
    578
    -  = do { rewriters' <- zonkRewriterSet (ctEvRewriters ev)
    
    577
    +zonkCtEvCoHoleSet ev@(CtWanted wtd)
    
    578
    +  = do { rewriters' <- zonkCoHoleSet (ctEvRewriters ev)
    
    579 579
            ; return (CtWanted $ setWantedCtEvRewriters wtd rewriters') }
    
    580 580
     
    
    581 581
     -- | Zonk a rewriter set; if a coercion hole in the set has been filled,
    
    582 582
     -- find all the free un-filled coercion holes in the coercion that fills it
    
    583
    -zonkRewriterSet :: RewriterSet -> ZonkM RewriterSet
    
    584
    -zonkRewriterSet (RewriterSet set)
    
    583
    +zonkCoHoleSet :: CoHoleSet -> ZonkM CoHoleSet
    
    584
    +zonkCoHoleSet (CoHoleSet set)
    
    585 585
       = unUCHM (nonDetStrictFoldUniqSet go mempty set)
    
    586 586
          -- This does not introduce non-determinism, because the only
    
    587 587
          -- monadic action is to read, and the combining function is
    
    ... ... @@ -594,16 +594,16 @@ freeHolesOfHole :: CoercionHole -> UnfilledCoercionHoleMonoid
    594 594
     freeHolesOfHole hole
    
    595 595
       = UCHM $ do { m_co <- unpackCoercionHole_maybe hole
    
    596 596
                   ; case m_co of
    
    597
    -                   Nothing -> return (unitRewriterSet hole)  -- Not filled
    
    598
    -                   Just (_co,holes) -> zonkRewriterSet holes }
    
    597
    +                   Nothing -> return (unitCoHoleSet hole)  -- Not filled
    
    598
    +                   Just (_co,holes) -> zonkCoHoleSet holes }
    
    599 599
     
    
    600
    -newtype UnfilledCoercionHoleMonoid = UCHM { unUCHM :: ZonkM RewriterSet }
    
    600
    +newtype UnfilledCoercionHoleMonoid = UCHM { unUCHM :: ZonkM CoHoleSet }
    
    601 601
     
    
    602 602
     instance Semigroup UnfilledCoercionHoleMonoid where
    
    603
    -  UCHM l <> UCHM r = UCHM (unionRewriterSet <$> l <*> r)
    
    603
    +  UCHM l <> UCHM r = UCHM (unionCoHoleSet <$> l <*> r)
    
    604 604
     
    
    605 605
     instance Monoid UnfilledCoercionHoleMonoid where
    
    606
    -  mempty = UCHM (return emptyRewriterSet)
    
    606
    +  mempty = UCHM (return emptyCoHoleSet)
    
    607 607
     
    
    608 608
     
    
    609 609
     {-
    
    ... ... @@ -629,7 +629,7 @@ unpackCoercionHole hole
    629 629
                Nothing -> pprPanic "Unfilled coercion hole" (ppr hole) }
    
    630 630
     
    
    631 631
     -- | Retrieve the contents of a coercion hole, if it is filled
    
    632
    -unpackCoercionHole_maybe :: CoercionHole -> ZonkM (Maybe (Coercion,RewriterSet))
    
    632
    +unpackCoercionHole_maybe :: CoercionHole -> ZonkM (Maybe (Coercion,CoHoleSet))
    
    633 633
     unpackCoercionHole_maybe (CoercionHole { ch_ref = ref }) = readTcRef ref
    
    634 634
     
    
    635 635
     
    

  • testsuite/tests/quantified-constraints/T15359.hs
    ... ... @@ -11,3 +11,10 @@ data Dict c where
    11 11
     
    
    12 12
     foo :: (forall a b. C a b => a ~ b) => Dict (C a b) -> a -> b
    
    13 13
     foo Dict x = x
    
    14
    +-- This is a terrible test.  If we are trying to solve
    
    15
    +--   [W] t1 ~ t2
    
    16
    +-- the quantified constraint will fire, producing
    
    17
    +--   [W] C t1 t2
    
    18
    +-- But it would also fire the other way round producing
    
    19
    +--   [W] C t2 t1
    
    20
    +-- So it's a coincidence whether or not it typechecks!