| ... |
... |
@@ -960,7 +960,8 @@ substTyVarBndrUsing subst_fn subst@(Subst in_scope idenv tenv cenv) old_var |
|
960
|
960
|
-- Assertion check that we are not capturing something in the substitution
|
|
961
|
961
|
|
|
962
|
962
|
old_ki = tyVarKind old_var
|
|
963
|
|
- no_kind_change = noFreeVarsOfType old_ki -- verify that kind is closed
|
|
|
963
|
+ no_kind_change = isEmptyTCvSubst subst || noFreeVarsOfType old_ki
|
|
|
964
|
+ -- isEmptyTCvSubst: see Note [Keeping the substitution empty]
|
|
964
|
965
|
no_change = no_kind_change && (new_var == old_var)
|
|
965
|
966
|
-- no_change means that the new_var is identical in
|
|
966
|
967
|
-- all respects to the old_var (same unique, same kind)
|
| ... |
... |
@@ -988,7 +989,8 @@ substCoVarBndrUsing subst_fn subst@(Subst in_scope idenv tenv cenv) old_var |
|
988
|
989
|
(Subst (in_scope `extendInScopeSet` new_var) idenv tenv new_cenv, new_var)
|
|
989
|
990
|
where
|
|
990
|
991
|
new_co = mkCoVarCo new_var
|
|
991
|
|
- no_kind_change = noFreeVarsOfTypes [t1, t2]
|
|
|
992
|
+ no_kind_change = isEmptyTCvSubst subst || noFreeVarsOfTypes [t1, t2]
|
|
|
993
|
+ -- isEmptyTCvSubst: see Note [Keeping the substitution empty]
|
|
992
|
994
|
no_change = new_var == old_var && no_kind_change
|
|
993
|
995
|
|
|
994
|
996
|
new_cenv | no_change = delVarEnv cenv old_var
|
| ... |
... |
@@ -1034,3 +1036,22 @@ substTyCoBndr subst (Anon ty af) = (subst, Anon (substScaledTy subst ty |
|
1034
|
1036
|
substTyCoBndr subst (Named (Bndr tv vis)) = (subst', Named (Bndr tv' vis))
|
|
1035
|
1037
|
where
|
|
1036
|
1038
|
(subst', tv') = substVarBndr subst tv
|
|
|
1039
|
+
|
|
|
1040
|
+{- Note [Keeping the substitution empty]
|
|
|
1041
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
1042
|
+A very common situation is where we run over a term doing no cloning,
|
|
|
1043
|
+no substitution, nothing. In that case the TCvSubst till be empty, and
|
|
|
1044
|
+it is /very/ valuable to /keep/ it empty:
|
|
|
1045
|
+
|
|
|
1046
|
+* It's wasted effort to build up an identity substitution mapping
|
|
|
1047
|
+ [x:->x, y:->y].
|
|
|
1048
|
+
|
|
|
1049
|
+* When we come to a binder, if the incoming substitution is empty,
|
|
|
1050
|
+ we can avoid substituting its type; and that in turn may mean that
|
|
|
1051
|
+ the binder itself does not change and we don't need to extend the
|
|
|
1052
|
+ substitution.
|
|
|
1053
|
+
|
|
|
1054
|
+* In the Simplifier we substitute over both types and coercions.
|
|
|
1055
|
+ If the substitution is empty, this is a no-op -- but only if it
|
|
|
1056
|
+ is empty!
|
|
|
1057
|
+-} |