Simon Peyton Jones pushed to branch wip/T26004 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Tc/Solver.hs
    ... ... @@ -1433,6 +1433,8 @@ decideAndPromoteTyVars top_lvl rhs_tclvl infer_mode name_taus psigs wanted
    1433 1433
                  (can_quant_cts, no_quant_cts) = approximateWCX wanted
    
    1434 1434
                  can_quant = ctsPreds can_quant_cts
    
    1435 1435
                  no_quant  = ctsPreds no_quant_cts
    
    1436
    +             can_quant_tvs = tyCoVarsOfTypes can_quant
    
    1437
    +             no_quant_tvs  = tyCoVarsOfTypes no_quant
    
    1436 1438
     
    
    1437 1439
                  -- Step 2 of Note [decideAndPromoteTyVars]
    
    1438 1440
                  -- Apply the monomorphism restriction
    
    ... ... @@ -1448,19 +1450,19 @@ decideAndPromoteTyVars top_lvl rhs_tclvl infer_mode name_taus psigs wanted
    1448 1450
                                              ++ tau_tys ++ post_mr_quant)
    
    1449 1451
                  co_var_tvs = closeOverKinds co_vars
    
    1450 1452
     
    
    1451
    -             -- outer_tvs are mentioned in `wanted, and belong to some outer level.
    
    1453
    +             -- outer_tvs are mentioned in `wanted`, and belong to some outer level.
    
    1452 1454
                  -- We definitely can't quantify over them
    
    1453 1455
                  outer_tvs = outerLevelTyVars rhs_tclvl $
    
    1454
    -                         tyCoVarsOfTypes can_quant `unionVarSet` tyCoVarsOfTypes no_quant
    
    1456
    +                         can_quant_tvs `unionVarSet` no_quant_tvs
    
    1455 1457
     
    
    1456 1458
                  -- Step 3 of Note [decideAndPromoteTyVars], (a-c)
    
    1457 1459
                  -- Identify mono_tvs: the type variables that we must not quantify over
    
    1458 1460
                  mono_tvs_without_mr
    
    1459 1461
     -- This does not work well (#26004)
    
    1460 1462
     --               | is_top_level = outer_tvs
    
    1461
    -               | otherwise    = outer_tvs                                 -- (a)
    
    1462
    -                                `unionVarSet` tyCoVarsOfTypes no_quant    -- (b)
    
    1463
    -                                `unionVarSet` co_var_tvs                  -- (c)
    
    1463
    +               | otherwise    = outer_tvs                    -- (a)
    
    1464
    +                                `unionVarSet` no_quant_tvs   -- (b)
    
    1465
    +                                `unionVarSet` co_var_tvs     -- (c)
    
    1464 1466
     
    
    1465 1467
                  -- Step 3 of Note [decideAndPromoteTyVars], (d)
    
    1466 1468
                  mono_tvs_with_mr
    

  • compiler/GHC/Tc/Types/Constraint.hs
    ... ... @@ -1792,11 +1792,11 @@ approximateWCX wc
    1792 1792
            = case classifyPredType (ctPred ct) of
    
    1793 1793
                -- See the classification in Note [ApproximateWC]
    
    1794 1794
                EqPred eq_rel ty1 ty2
    
    1795
    -             | not encl_eqs      -- See Wrinkle (W1)
    
    1796
    -             , quantify_equality eq_rel ty1 ty2
    
    1797
    -             -> add_to_quant
    
    1798
    -             | otherwise
    
    1799
    -             -> acc  -- add_to_no_quant    ToDo: never return equalities under an equality
    
    1795
    +             | encl_eqs                         -> acc
    
    1796
    +             | quantify_equality eq_rel ty1 ty2 -> add_to_quant
    
    1797
    +             | otherwise                        -> add_to_no_quant
    
    1798
    +               -- encl_eqs: See Wrinkle (W1)
    
    1799
    +               -- ToDo: explain acc
    
    1800 1800
     
    
    1801 1801
                ClassPred cls tys
    
    1802 1802
                  | Just {} <- isCallStackPred cls tys
    
    ... ... @@ -1852,7 +1852,7 @@ We proceed by classifying the constraint:
    1852 1852
     
    
    1853 1853
     Wrinkle (W1)
    
    1854 1854
       When inferring most-general types (in simplifyInfer), we
    
    1855
    -  do *not* float an equality constraint if the implication binds
    
    1855
    +  do *not* quantify over equality constraint if the implication binds
    
    1856 1856
       equality constraints, because that defeats the OutsideIn story.
    
    1857 1857
       Consider data T a where { TInt :: T Int; MkT :: T a }
    
    1858 1858
              f TInt = 3::Int