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

Commits:

2 changed files:

Changes:

  • compiler/GHC/Core/Unify.hs
    ... ... @@ -844,9 +844,10 @@ tcUnifyTysForInjectivity unif tys1 tys2
    844 844
                    -- in-scope set is never looked at, so this free-var stuff
    
    845 845
                    -- should never actually be done
    
    846 846
     
    
    847
    -    maybe_fix | unif      = niFixSubst in_scope
    
    848
    -              | otherwise = mkTvSubst in_scope -- when matching, don't confuse
    
    849
    -                                               -- domain with range
    
    847
    +    maybe_fix tv_subst
    
    848
    +      | unif      = niFixSubst in_scope tv_subst
    
    849
    +      | otherwise = mkTvSubst  in_scope tv_subst
    
    850
    +      -- When matching, don't confuse domain with range; no fixpoint!
    
    850 851
     
    
    851 852
     -----------------
    
    852 853
     tcUnifyTys :: BindTvFun
    
    ... ... @@ -1125,10 +1126,10 @@ So, we work as follows:
    1125 1126
            , rest :-> rest :: G b (z :: b) ]
    
    1126 1127
         Note that rest now has the right kind
    
    1127 1128
     
    
    1128
    - 7. Apply this extended substitution (once) to the range of
    
    1129
    -    the /original/ substitution.  (Note that we do the
    
    1130
    -    extended substitution would go on forever if you tried
    
    1131
    -    to find its fixpoint, because it maps z to z.)
    
    1129
    + 7. Apply this extended substitution (once) to the range of the
    
    1130
    +    /original/ substitution.  (Note that the extended substitution
    
    1131
    +    would go on forever if you tried to find its fixpoint, because it
    
    1132
    +    maps z to z.)
    
    1132 1133
     
    
    1133 1134
      8. And go back to step 1
    
    1134 1135
     
    
    ... ... @@ -1147,8 +1148,10 @@ niFixSubst :: InScopeSet -> TvSubstEnv -> Subst
    1147 1148
     -- ToDo: use laziness instead of iteration?
    
    1148 1149
     niFixSubst in_scope tenv
    
    1149 1150
       | not_fixpoint = niFixSubst in_scope (mapVarEnv (substTy subst) tenv)
    
    1150
    -  | otherwise    = subst
    
    1151
    +  | otherwise    = tenv_subst
    
    1151 1152
       where
    
    1153
    +    tenv_subst = mkTvSubst in_scope tenv   -- This is our starting point
    
    1154
    +
    
    1152 1155
         range_fvs :: FV
    
    1153 1156
         range_fvs = tyCoFVsOfTypes (nonDetEltsUFM tenv)
    
    1154 1157
               -- It's OK to use nonDetEltsUFM here because the
    
    ... ... @@ -1163,9 +1166,7 @@ niFixSubst in_scope tenv
    1163 1166
         free_tvs = scopedSort (filterOut in_domain range_tvs)
    
    1164 1167
     
    
    1165 1168
         -- See Note [Finding the substitution fixpoint], Step 6
    
    1166
    -    subst = foldl' add_free_tv
    
    1167
    -                  (mkTvSubst in_scope tenv)
    
    1168
    -                  free_tvs
    
    1169
    +    subst = foldl' add_free_tv tenv_subst free_tvs
    
    1169 1170
     
    
    1170 1171
         add_free_tv :: Subst -> TyVar -> Subst
    
    1171 1172
         add_free_tv subst tv
    

  • compiler/GHC/Tc/Solver/FunDeps.hs
    ... ... @@ -592,13 +592,12 @@ getRelevantBranches ax work_args work_rhs
    592 592
               Nothing  ->       go (branch:preceding) branches
    
    593 593
           where
    
    594 594
              is_relevant (CoAxBranch { cab_tvs = qtvs, cab_lhs = lhs_tys, cab_rhs = rhs_ty })
    
    595
    -            | Just subst <- tcUnifyTysForInjectivity True work_tys (rhs_ty:lhs_tys)
    
    595
    +            | Just subst <- tcUnifyTysForInjectivity True (rhs_ty:lhs_tys) work_tys
    
    596 596
                 , let (subst', qtvs') = trim_qtvs subst qtvs
    
    597 597
                       lhs_tys' = substTys subst' lhs_tys
    
    598 598
                       rhs_ty'  = substTy  subst' rhs_ty
    
    599 599
                 , all (no_match lhs_tys') preceding
    
    600
    -            = pprTrace "grb" (ppr qtvs $$ ppr subst $$ ppr qtvs' $$ ppr subst' $$ ppr lhs_tys $$ ppr lhs_tys') $
    
    601
    -              Just (FDEqns { fd_qtvs = qtvs'
    
    600
    +            = Just (FDEqns { fd_qtvs = qtvs'
    
    602 601
                                , fd_eqs = zipWith Pair (rhs_ty':lhs_tys') work_tys })
    
    603 602
                 | otherwise
    
    604 603
                 = Nothing