summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2016-07-05 03:37:06 -0700
committerBartosz Nitka <niteria@gmail.com>2016-07-05 04:41:25 -0700
commite10497b9a3622265b88caa60590ed620ff3d33e2 (patch)
treeffc3415e4294dfe4a24364950ad28161ee9e1d43
parent890ec98cdf144ed7e1efd53c528187deee27b783 (diff)
downloadhaskell-e10497b9a3622265b88caa60590ed620ff3d33e2.tar.gz
Kill some varEnvElts
I was able to hide the nondeterminism in some specialized function, which I believe will be useful in other places. GHC Trac: #4012
-rw-r--r--compiler/types/TyCoRep.hs28
1 files changed, 21 insertions, 7 deletions
diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs
index d4106c8ea3..08ac9c9978 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -1427,6 +1427,15 @@ tyCoVarsOfTypes :: [Type] -> TyCoVarSet
tyCoVarsOfTypes tys = fvVarSet $ tyCoFVsOfTypes tys
-- | Returns free variables of types, including kind variables as
+-- a non-deterministic set. For type synonyms it does /not/ expand the
+-- synonym.
+tyCoVarsOfTypesSet :: TyVarEnv Type -> TyCoVarSet
+-- See Note [Free variables of types]
+tyCoVarsOfTypesSet tys = fvVarSet $ tyCoFVsOfTypes $ nonDetEltsUFM tys
+ -- It's OK to use nonDetEltsUFM here because we immediately forget the
+ -- ordering by returning a set
+
+-- | Returns free variables of types, including kind variables as
-- a deterministic set. For type synonyms it does /not/ expand the
-- synonym.
tyCoVarsOfTypesDSet :: [Type] -> DTyCoVarSet
@@ -1496,6 +1505,11 @@ tyCoFVsOfProv (HoleProv _) fv_cand in_scope acc = emptyFV fv_cand in_scop
tyCoVarsOfCos :: [Coercion] -> TyCoVarSet
tyCoVarsOfCos cos = fvVarSet $ tyCoFVsOfCos cos
+tyCoVarsOfCosSet :: CoVarEnv Coercion -> TyCoVarSet
+tyCoVarsOfCosSet cos = fvVarSet $ tyCoFVsOfCos $ nonDetEltsUFM cos
+ -- It's OK to use nonDetEltsUFM here because we immediately forget the
+ -- ordering by returning a set
+
tyCoFVsOfCos :: [Coercion] -> FV
tyCoFVsOfCos [] fv_cand in_scope acc = emptyFV fv_cand in_scope acc
tyCoFVsOfCos (co:cos) fv_cand in_scope acc = (tyCoFVsOfCo co `unionFV` tyCoFVsOfCos cos) fv_cand in_scope acc
@@ -1755,8 +1769,8 @@ getTCvSubstRangeFVs :: TCvSubst -> VarSet
getTCvSubstRangeFVs (TCvSubst _ tenv cenv)
= unionVarSet tenvFVs cenvFVs
where
- tenvFVs = tyCoVarsOfTypes $ varEnvElts tenv
- cenvFVs = tyCoVarsOfCos $ varEnvElts cenv
+ tenvFVs = tyCoVarsOfTypesSet tenv
+ cenvFVs = tyCoVarsOfCosSet cenv
isInScope :: Var -> TCvSubst -> Bool
isInScope v (TCvSubst in_scope _ _) = v `elemInScopeSet` in_scope
@@ -2056,8 +2070,8 @@ isValidTCvSubst (TCvSubst in_scope tenv cenv) =
(tenvFVs `varSetInScope` in_scope) &&
(cenvFVs `varSetInScope` in_scope)
where
- tenvFVs = tyCoVarsOfTypes $ varEnvElts tenv
- cenvFVs = tyCoVarsOfCos $ varEnvElts cenv
+ tenvFVs = tyCoVarsOfTypesSet tenv
+ cenvFVs = tyCoVarsOfCosSet cenv
-- | This checks if the substitution satisfies the invariant from
-- Note [The substitution invariant].
@@ -2071,10 +2085,10 @@ checkValidSubst subst@(TCvSubst in_scope tenv cenv) tys cos a
text "in_scope" <+> ppr in_scope $$
text "tenv" <+> ppr tenv $$
text "tenvFVs"
- <+> ppr (tyCoVarsOfTypes $ varEnvElts tenv) $$
+ <+> ppr (tyCoVarsOfTypesSet tenv) $$
text "cenv" <+> ppr cenv $$
text "cenvFVs"
- <+> ppr (tyCoVarsOfCos $ varEnvElts cenv) $$
+ <+> ppr (tyCoVarsOfCosSet cenv) $$
text "tys" <+> ppr tys $$
text "cos" <+> ppr cos )
ASSERT2( tysCosFVsInScope,
@@ -2355,7 +2369,7 @@ substTyVarBndrCallback subst_fn subst@(TCvSubst in_scope tenv cenv) old_var
new_env | no_change = delVarEnv tenv old_var
| otherwise = extendVarEnv tenv old_var (TyVarTy new_var)
- _no_capture = not (new_var `elemVarSet` tyCoVarsOfTypes (varEnvElts tenv))
+ _no_capture = not (new_var `elemVarSet` tyCoVarsOfTypesSet tenv)
-- Assertion check that we are not capturing something in the substitution
old_ki = tyVarKind old_var