Commit c4e6b35d authored by Ben Gamari's avatar Ben Gamari 🐢

Move closeOverKinds and friends to TyCoFVs

parent 29b72c00
...@@ -20,9 +20,14 @@ module TyCoFVs ...@@ -20,9 +20,14 @@ module TyCoFVs
mkTyCoInScopeSet, mkTyCoInScopeSet,
-- * Welll-scoped free variables -- * Well-scoped free variables
scopedSort, tyCoVarsOfTypeWellScoped, scopedSort, tyCoVarsOfTypeWellScoped,
tyCoVarsOfTypesWellScoped, tyCoVarsOfTypesWellScoped,
-- * Closing over kinds
closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
closeOverKinds,
) where ) where
import GhcPrelude import GhcPrelude
...@@ -35,6 +40,7 @@ import Var ...@@ -35,6 +40,7 @@ import Var
import FV import FV
import UniqFM import UniqFM
import UniqSet (nonDetEltsUniqSet)
import VarSet import VarSet
import VarEnv import VarEnv
import Util import Util
...@@ -859,3 +865,29 @@ tyCoVarsOfTypeWellScoped = scopedSort . tyCoVarsOfTypeList ...@@ -859,3 +865,29 @@ tyCoVarsOfTypeWellScoped = scopedSort . tyCoVarsOfTypeList
-- | Get the free vars of types in scoped order -- | Get the free vars of types in scoped order
tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar] tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
tyCoVarsOfTypesWellScoped = scopedSort . tyCoVarsOfTypesList 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
...@@ -141,14 +141,16 @@ module Type ( ...@@ -141,14 +141,16 @@ module Type (
tyCoVarsOfTypeDSet, tyCoVarsOfTypeDSet,
coVarsOfType, coVarsOfType,
coVarsOfTypes, coVarsOfTypes,
closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
closeOverKinds,
noFreeVarsOfType, noFreeVarsOfType,
splitVisVarsOfType, splitVisVarsOfTypes, splitVisVarsOfType, splitVisVarsOfTypes,
expandTypeSynonyms, expandTypeSynonyms,
typeSize, occCheckExpand, typeSize, occCheckExpand,
-- ** Closing over kinds
closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
closeOverKinds,
-- * Well-scoped lists of variables -- * Well-scoped lists of variables
scopedSort, tyCoVarsOfTypeWellScoped, scopedSort, tyCoVarsOfTypeWellScoped,
tyCoVarsOfTypesWellScoped, tyCoVarsOfTypesWellScoped,
...@@ -1857,32 +1859,6 @@ binderRelevantType_maybe :: TyCoBinder -> Maybe Type ...@@ -1857,32 +1859,6 @@ binderRelevantType_maybe :: TyCoBinder -> Maybe Type
binderRelevantType_maybe (Named {}) = Nothing binderRelevantType_maybe (Named {}) = Nothing
binderRelevantType_maybe (Anon _ ty) = Just ty 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
{- {-
************************************************************************ ************************************************************************
* * * *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment