| ... |
... |
@@ -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
|