summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/types/TyCoFVs.hs17
-rw-r--r--compiler/types/Type.hs2
-rw-r--r--compiler/utils/FV.hs33
3 files changed, 29 insertions, 23 deletions
diff --git a/compiler/types/TyCoFVs.hs b/compiler/types/TyCoFVs.hs
index 5a736739f4..3781d301eb 100644
--- a/compiler/types/TyCoFVs.hs
+++ b/compiler/types/TyCoFVs.hs
@@ -36,7 +36,7 @@ module TyCoFVs
tyCoVarsOfTypesWellScoped,
-- * Closing over kinds
- closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
+ closeOverKindsDSet, closeOverKindsList,
closeOverKinds,
) where
@@ -54,7 +54,6 @@ import Var
import FV
import UniqFM
-import UniqSet( nonDetEltsUniqSet )
import VarSet
import VarEnv
import Util
@@ -343,10 +342,18 @@ shallowTcvFolder = TyCoFolder { tcf_tyvar = do_tcv, tcf_covar = do_tcv
------------- Closing over kinds -----------------
-closeOverKinds :: TyVarSet -> TyVarSet
+closeOverKinds :: TyCoVarSet -> TyCoVarSet
+-- For each element of the input set,
+-- add the deep free variables of its kind
+closeOverKinds vs = nonDetFoldVarSet do_one vs vs
+ where
+ do_one v acc = appEndo (deep_ty (varType v)) acc
+
+{- --------------- Alternative version 1 (using FV) ------------
closeOverKinds = fvVarSet . closeOverKindsFV . nonDetEltsUniqSet
+-}
-{- ---------------- Alternative version 1 (preferred) -------------
+{- ---------------- Alternative version 2 -------------
-- | Add the kind variables free in the kinds of the tyvars in the given set.
-- Returns a non-deterministic set.
@@ -368,7 +375,7 @@ closeOverKinds vs
-}
-{- ---------------- Alternative version -------------
+{- ---------------- Alternative version 3 -------------
-- | Add the kind variables free in the kinds of the tyvars in the given set.
-- Returns a non-deterministic set.
closeOverKinds :: TyVarSet -> TyVarSet
diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs
index 3d2b90c2ed..7e469c988b 100644
--- a/compiler/types/Type.hs
+++ b/compiler/types/Type.hs
@@ -149,7 +149,7 @@ module Type (
typeSize, occCheckExpand,
-- ** Closing over kinds
- closeOverKindsDSet, closeOverKindsFV, closeOverKindsList,
+ closeOverKindsDSet, closeOverKindsList,
closeOverKinds,
-- * Well-scoped lists of variables
diff --git a/compiler/utils/FV.hs b/compiler/utils/FV.hs
index 6d0dc2b2ab..667d2a3966 100644
--- a/compiler/utils/FV.hs
+++ b/compiler/utils/FV.hs
@@ -12,7 +12,7 @@ module FV (
FV, InterestingVarFun,
-- * Running the computations
- fvVarListVarSet, fvVarList, fvVarSet, fvDVarSet,
+ fvVarList, fvVarSet, fvDVarSet,
-- ** Manipulating those computations
unitFV,
@@ -46,22 +46,21 @@ type InterestingVarFun = Var -> Bool
-- Merging costs O(n+m) for UniqFM and for UniqDFM there's an additional log
-- factor. It's cheaper to incrementally add to a list and use a set to check
-- for duplicates.
-type FV = InterestingVarFun
- -- Used for filtering sets as we build them
- -> VarSet
- -- Locally bound variables
- -> ([Var], VarSet)
- -- List to preserve ordering and set to check for membership,
- -- so that the list doesn't have duplicates
- -- For explanation of why using `VarSet` is not deterministic see
- -- Note [Deterministic UniqFM] in UniqDFM.
- -> ([Var], VarSet)
+type FV = InterestingVarFun -- Used for filtering sets as we build them
+ -> VarSet -- Locally bound variables
+ -> VarAcc -- Accumulator
+ -> VarAcc
+
+type VarAcc = ([Var], VarSet) -- List to preserve ordering and set to check for membership,
+ -- so that the list doesn't have duplicates
+ -- For explanation of why using `VarSet` is not deterministic see
+ -- Note [Deterministic UniqFM] in UniqDFM.
-- Note [FV naming conventions]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- To get the performance and determinism that FV provides, FV computations
-- need to built up from smaller FV computations and then evaluated with
--- one of `fvVarList`, `fvDVarSet`, `fvVarListVarSet`. That means the functions
+-- one of `fvVarList`, `fvDVarSet` That means the functions
-- returning FV need to be exported.
--
-- The conventions are:
@@ -84,26 +83,26 @@ type FV = InterestingVarFun
-- | Run a free variable computation, returning a list of distinct free
-- variables in deterministic order and a non-deterministic set containing
-- those variables.
-fvVarListVarSet :: FV -> ([Var], VarSet)
-fvVarListVarSet fv = fv (const True) emptyVarSet ([], emptyVarSet)
+fvVarAcc :: FV -> ([Var], VarSet)
+fvVarAcc fv = fv (const True) emptyVarSet ([], emptyVarSet)
-- | Run a free variable computation, returning a list of distinct free
-- variables in deterministic order.
fvVarList :: FV -> [Var]
-fvVarList = fst . fvVarListVarSet
+fvVarList = fst . fvVarAcc
-- | Run a free variable computation, returning a deterministic set of free
-- variables. Note that this is just a wrapper around the version that
-- returns a deterministic list. If you need a list you should use
-- `fvVarList`.
fvDVarSet :: FV -> DVarSet
-fvDVarSet = mkDVarSet . fst . fvVarListVarSet
+fvDVarSet = mkDVarSet . fvVarList
-- | Run a free variable computation, returning a non-deterministic set of
-- free variables. Don't use if the set will be later converted to a list
-- and the order of that list will impact the generated code.
fvVarSet :: FV -> VarSet
-fvVarSet = snd . fvVarListVarSet
+fvVarSet = snd . fvVarAcc
-- Note [FV eta expansion]
-- ~~~~~~~~~~~~~~~~~~~~~~~