summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2016-06-02 10:34:57 -0700
committerBartosz Nitka <niteria@gmail.com>2016-06-02 10:34:57 -0700
commit3eac3a0e9f74ad936375e3ba65f5d8454ea9d408 (patch)
tree7080f4b51ee5d46cf88d1feedc63aa7cd7bfb077 /compiler
parentd348acd527548fc71a59e239a963e982c69af1f8 (diff)
downloadhaskell-3eac3a0e9f74ad936375e3ba65f5d8454ea9d408.tar.gz
Add nameSetElemsStable and fix the build
Diffstat (limited to 'compiler')
-rw-r--r--compiler/basicTypes/NameSet.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/basicTypes/NameSet.hs b/compiler/basicTypes/NameSet.hs
index 559f43933f..27a2c3b078 100644
--- a/compiler/basicTypes/NameSet.hs
+++ b/compiler/basicTypes/NameSet.hs
@@ -13,7 +13,7 @@ module NameSet (
minusNameSet, elemNameSet, nameSetElems, extendNameSet, extendNameSetList,
delFromNameSet, delListFromNameSet, isEmptyNameSet, filterNameSet,
intersectsNameSet, intersectNameSet,
- nameSetAny, nameSetAll,
+ nameSetAny, nameSetAll, nameSetElemsStable,
-- * Free variables
FreeVars,
@@ -35,6 +35,8 @@ module NameSet (
import Name
import UniqSet
+import UniqFM
+import Data.List (sortBy)
{-
************************************************************************
@@ -90,6 +92,14 @@ nameSetAny = uniqSetAny
nameSetAll :: (Name -> Bool) -> NameSet -> Bool
nameSetAll = uniqSetAll
+-- | Get the elements of a NameSet with some stable ordering.
+-- See Note [Deterministic UniqFM] to learn about nondeterminism
+nameSetElemsStable :: NameSet -> [Name]
+nameSetElemsStable ns =
+ sortBy stableNameCmp $ nonDetEltsUFM ns
+ -- It's OK to use nonDetEltsUFM here because we immediately sort
+ -- with stableNameCmp
+
{-
************************************************************************
* *