[commit: ghc] wip/T14880-2-step2-c123: Close over kinds exactly once per var (#14880) (0c994c4)
git at git.haskell.org
git at git.haskell.org
Thu Sep 13 20:06:55 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/T14880-2-step2-c123
Link : http://ghc.haskell.org/trac/ghc/changeset/0c994c47a7cbf30e5ec7a46f955117b2ea360067/ghc
>---------------------------------------------------------------
commit 0c994c47a7cbf30e5ec7a46f955117b2ea360067
Author: Tobias Dammers <tdammers at gmail.com>
Date: Thu Sep 13 09:56:02 2018 +0200
Close over kinds exactly once per var (#14880)
Summary:
As discussed in Trac:14880, comment:123, we have the issue that we want to
avoid processing the same var more than once. The original plan was to move
closing over kinds to the very end of the `tyCoVarsOfType` function, however,
this turns out to be inefficient and unnecessary.
Instead, we simply change the code in `ty_co_vars_of_type` such that
closing over kinds doesn't happen if we've already seen the var in question.
Test Plan: ./validate, nofib
Reviewers: simonpj, goldfire, bgamari
Subscribers: rwbarton, carter
GHC Trac Issues: #14880
Differential Revision: https://phabricator.haskell.org/D5147
>---------------------------------------------------------------
0c994c47a7cbf30e5ec7a46f955117b2ea360067
compiler/types/TyCoRep.hs | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/compiler/types/TyCoRep.hs b/compiler/types/TyCoRep.hs
index 7f470ea..7d08fd0 100644
--- a/compiler/types/TyCoRep.hs
+++ b/compiler/types/TyCoRep.hs
@@ -1650,7 +1650,7 @@ ty_co_vars_of_type :: Type -> TyCoVarSet -> TyCoVarSet -> TyCoVarSet
ty_co_vars_of_type (TyVarTy v) is acc
| v `elemVarSet` is = acc
| v `elemVarSet` acc = acc
- | otherwise = ty_co_vars_of_type (tyVarKind v) is (extendVarSet acc v)
+ | otherwise = ty_co_vars_of_type (tyVarKind v) emptyVarSet (extendVarSet acc v)
ty_co_vars_of_type (TyConApp _ tys) is acc = ty_co_vars_of_types tys is acc
ty_co_vars_of_type (LitTy {}) _ acc = acc
ty_co_vars_of_type (AppTy fun arg) is acc = ty_co_vars_of_type fun is (ty_co_vars_of_type arg is acc)
@@ -1782,14 +1782,18 @@ tyCoVarsOfTypesList tys = fvVarList $ tyCoFVsOfTypes tys
-- See Note [FV eta expansion] in FV for explanation.
tyCoFVsOfType :: Type -> FV
-- See Note [Free variables of types]
-tyCoFVsOfType (TyVarTy v) a b c = (unitFV v `unionFV` tyCoFVsOfType (tyVarKind v)) a b c
-tyCoFVsOfType (TyConApp _ tys) a b c = tyCoFVsOfTypes tys a b c
-tyCoFVsOfType (LitTy {}) a b c = emptyFV a b c
-tyCoFVsOfType (AppTy fun arg) a b c = (tyCoFVsOfType fun `unionFV` tyCoFVsOfType arg) a b c
-tyCoFVsOfType (FunTy arg res) a b c = (tyCoFVsOfType arg `unionFV` tyCoFVsOfType res) a b c
-tyCoFVsOfType (ForAllTy bndr ty) a b c = tyCoFVsBndr bndr (tyCoFVsOfType ty) a b c
-tyCoFVsOfType (CastTy ty co) a b c = (tyCoFVsOfType ty `unionFV` tyCoFVsOfCo co) a b c
-tyCoFVsOfType (CoercionTy co) a b c = tyCoFVsOfCo co a b c
+tyCoFVsOfType (TyVarTy v) f bound_vars (acc_list, acc_set)
+ | not (f v) = (acc_list, acc_set)
+ | v `elemVarSet` bound_vars = (acc_list, acc_set)
+ | v `elemVarSet` acc_set = (acc_list, acc_set)
+ | otherwise = tyCoFVsOfType (tyVarKind v) f emptyVarSet (v:acc_list, extendVarSet acc_set v)
+tyCoFVsOfType (TyConApp _ tys) f bound_vars acc = tyCoFVsOfTypes tys f bound_vars acc
+tyCoFVsOfType (LitTy {}) f bound_vars acc = emptyFV f bound_vars acc
+tyCoFVsOfType (AppTy fun arg) f bound_vars acc = (tyCoFVsOfType fun `unionFV` tyCoFVsOfType arg) f bound_vars acc
+tyCoFVsOfType (FunTy arg res) f bound_vars acc = (tyCoFVsOfType arg `unionFV` tyCoFVsOfType res) f bound_vars acc
+tyCoFVsOfType (ForAllTy bndr ty) f bound_vars acc = tyCoFVsBndr bndr (tyCoFVsOfType ty) f bound_vars acc
+tyCoFVsOfType (CastTy ty co) f bound_vars acc = (tyCoFVsOfType ty `unionFV` tyCoFVsOfCo co) f bound_vars acc
+tyCoFVsOfType (CoercionTy co) f bound_vars acc = tyCoFVsOfCo co f bound_vars acc
tyCoFVsBndr :: TyVarBinder -> FV -> FV
-- Free vars of (forall b. <thing with fvs>)
More information about the ghc-commits
mailing list