summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-12-01 15:34:42 -0500
committerBen Gamari <ben@smart-cactus.org>2020-02-06 11:55:41 -0500
commitc4e6b35daef9336ea6b0922bab595cb02ac742b5 (patch)
treed5392ddb4a24e1e10661b43f10dc08c7ac8b344a
parent29b72c00a692b442605b022fcc15c4454ed1c3de (diff)
downloadhaskell-c4e6b35daef9336ea6b0922bab595cb02ac742b5.tar.gz
Move closeOverKinds and friends to TyCoFVs
-rw-r--r--compiler/types/TyCoFVs.hs34
-rw-r--r--compiler/types/Type.hs32
2 files changed, 37 insertions, 29 deletions
diff --git a/compiler/types/TyCoFVs.hs b/compiler/types/TyCoFVs.hs
index c81c009029..d4a0179f88 100644
--- a/compiler/types/TyCoFVs.hs
+++ b/compiler/types/TyCoFVs.hs
@@ -20,9 +20,14 @@ module TyCoFVs
mkTyCoInScopeSet,
- -- * Welll-scoped free variables
+ -- * Well-scoped free variables
scopedSort, tyCoVarsOfTypeWellScoped,
tyCoVarsOfTypesWellScoped,
+
+ -- * Closing over kinds
+ closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
+ closeOverKinds,
+
) where
import GhcPrelude
@@ -35,6 +40,7 @@ import Var
import FV
import UniqFM
+import UniqSet (nonDetEltsUniqSet)
import VarSet
import VarEnv
import Util
@@ -859,3 +865,29 @@ tyCoVarsOfTypeWellScoped = scopedSort . tyCoVarsOfTypeList
-- | Get the free vars of types in scoped order
tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
tyCoVarsOfTypesWellScoped = scopedSort . tyCoVarsOfTypesList
+
+------------- Closing over kinds -----------------
+
+-- | Add the kind variables free in the kinds of the tyvars in the given set.
+-- Returns a non-deterministic set.
+closeOverKinds :: TyVarSet -> TyVarSet
+closeOverKinds = fvVarSet . closeOverKindsFV . nonDetEltsUniqSet
+ -- It's OK to use nonDetEltsUniqSet here because we immediately forget
+ -- about the ordering by returning a set.
+
+-- | Given a list of tyvars returns a deterministic FV computation that
+-- returns the given tyvars with the kind variables free in the kinds of the
+-- given tyvars.
+closeOverKindsFV :: [TyVar] -> FV
+closeOverKindsFV tvs =
+ mapUnionFV (tyCoFVsOfType . tyVarKind) tvs `unionFV` mkFVs tvs
+
+-- | Add the kind variables free in the kinds of the tyvars in the given set.
+-- Returns a deterministically ordered list.
+closeOverKindsList :: [TyVar] -> [TyVar]
+closeOverKindsList tvs = fvVarList $ closeOverKindsFV tvs
+
+-- | Add the kind variables free in the kinds of the tyvars in the given set.
+-- Returns a deterministic set.
+closeOverKindsDSet :: DTyVarSet -> DTyVarSet
+closeOverKindsDSet = fvDVarSet . closeOverKindsFV . dVarSetElems
diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs
index a318725f3b..e5859b2f4b 100644
--- a/compiler/types/Type.hs
+++ b/compiler/types/Type.hs
@@ -141,14 +141,16 @@ module Type (
tyCoVarsOfTypeDSet,
coVarsOfType,
coVarsOfTypes,
- closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
- closeOverKinds,
noFreeVarsOfType,
splitVisVarsOfType, splitVisVarsOfTypes,
expandTypeSynonyms,
typeSize, occCheckExpand,
+ -- ** Closing over kinds
+ closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
+ closeOverKinds,
+
-- * Well-scoped lists of variables
scopedSort, tyCoVarsOfTypeWellScoped,
tyCoVarsOfTypesWellScoped,
@@ -1857,32 +1859,6 @@ binderRelevantType_maybe :: TyCoBinder -> Maybe Type
binderRelevantType_maybe (Named {}) = Nothing
binderRelevantType_maybe (Anon _ ty) = Just ty
-------------- Closing over kinds -----------------
-
--- | Add the kind variables free in the kinds of the tyvars in the given set.
--- Returns a non-deterministic set.
-closeOverKinds :: TyVarSet -> TyVarSet
-closeOverKinds = fvVarSet . closeOverKindsFV . nonDetEltsUniqSet
- -- It's OK to use nonDetEltsUniqSet here because we immediately forget
- -- about the ordering by returning a set.
-
--- | Given a list of tyvars returns a deterministic FV computation that
--- returns the given tyvars with the kind variables free in the kinds of the
--- given tyvars.
-closeOverKindsFV :: [TyVar] -> FV
-closeOverKindsFV tvs =
- mapUnionFV (tyCoFVsOfType . tyVarKind) tvs `unionFV` mkFVs tvs
-
--- | Add the kind variables free in the kinds of the tyvars in the given set.
--- Returns a deterministically ordered list.
-closeOverKindsList :: [TyVar] -> [TyVar]
-closeOverKindsList tvs = fvVarList $ closeOverKindsFV tvs
-
--- | Add the kind variables free in the kinds of the tyvars in the given set.
--- Returns a deterministic set.
-closeOverKindsDSet :: DTyVarSet -> DTyVarSet
-closeOverKindsDSet = fvDVarSet . closeOverKindsFV . dVarSetElems
-
{-
************************************************************************
* *