[commit: ghc] master: Kill varSetElems (7008515)

git at git.haskell.org git at git.haskell.org
Tue Jun 7 16:05:19 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/7008515be5863df46f7863ccb8b74df004ccf73e/ghc

>---------------------------------------------------------------

commit 7008515be5863df46f7863ccb8b74df004ccf73e
Author: Bartosz Nitka <niteria at gmail.com>
Date:   Tue Jun 7 07:47:42 2016 -0700

    Kill varSetElems
    
    This eradicates varSetElems from the codebase. This function
    used to introduce nondeterminism.
    I've also documented benign nondeterminism in three places.
    
    GHC Trac: #4012


>---------------------------------------------------------------

7008515be5863df46f7863ccb8b74df004ccf73e
 compiler/basicTypes/VarEnv.hs                    | 6 ++++--
 compiler/basicTypes/VarSet.hs                    | 8 +++-----
 compiler/typecheck/TcSimplify.hs                 | 4 +++-
 testsuite/tests/callarity/unittest/CallArity1.hs | 5 ++++-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/compiler/basicTypes/VarEnv.hs b/compiler/basicTypes/VarEnv.hs
index dd61257..5a852a3 100644
--- a/compiler/basicTypes/VarEnv.hs
+++ b/compiler/basicTypes/VarEnv.hs
@@ -109,8 +109,10 @@ data InScopeSet = InScope (VarEnv Var) {-# UNPACK #-} !Int
         -- INVARIANT: it's not zero; we use it as a multiplier in uniqAway
 
 instance Outputable InScopeSet where
-  ppr (InScope s _) = text "InScope"
-                      <+> braces (fsep (map (ppr . Var.varName) (varSetElems s)))
+  ppr (InScope s _) =
+    text "InScope" <+> braces (fsep (map (ppr . Var.varName) (nonDetEltsUFM s)))
+                      -- It's OK to use nonDetEltsUFM here because it's
+                      -- only for pretty printing
                       -- In-scope sets get big, and with -dppr-debug
                       -- the output is overwhelming
 
diff --git a/compiler/basicTypes/VarSet.hs b/compiler/basicTypes/VarSet.hs
index 4663a41..b0151d8 100644
--- a/compiler/basicTypes/VarSet.hs
+++ b/compiler/basicTypes/VarSet.hs
@@ -12,7 +12,7 @@ module VarSet (
         -- ** Manipulating these sets
         emptyVarSet, unitVarSet, mkVarSet,
         extendVarSet, extendVarSetList, extendVarSet_C,
-        elemVarSet, varSetElems, subVarSet,
+        elemVarSet, subVarSet,
         unionVarSet, unionVarSets, mapUnionVarSet,
         intersectVarSet, intersectsVarSet, disjointVarSet,
         isEmptyVarSet, delVarSet, delVarSetList, delVarSetByKey,
@@ -72,7 +72,6 @@ unionVarSets    :: [VarSet] -> VarSet
 mapUnionVarSet  :: (a -> VarSet) -> [a] -> VarSet
 -- ^ map the function over the list, and union the results
 
-varSetElems     :: VarSet -> [Var]
 unitVarSet      :: Var -> VarSet
 extendVarSet    :: VarSet -> Var -> VarSet
 extendVarSetList:: VarSet -> [Var] -> VarSet
@@ -108,7 +107,6 @@ subVarSet       :: VarSet -> VarSet -> Bool     -- True if first arg is subset o
 
 unionVarSet     = unionUniqSets
 unionVarSets    = unionManyUniqSets
-varSetElems     = uniqSetToList
 elemVarSet      = elementOfUniqSet
 minusVarSet     = minusUniqSet
 delVarSet       = delOneFromUniqSet
@@ -188,10 +186,10 @@ pluralVarSet = pluralUFM
 -- The order of variables is non-deterministic and for pretty-printing that
 -- shouldn't be a problem.
 -- Having this function helps contain the non-determinism created with
--- varSetElems.
+-- nonDetEltsUFM.
 -- Passing a list to the pretty-printing function allows the caller
 -- to decide on the order of Vars (eg. toposort them) without them having
--- to use varSetElems at the call site. This prevents from let-binding
+-- to use nonDetEltsUFM at the call site. This prevents from let-binding
 -- non-deterministically ordered lists and reusing them where determinism
 -- matters.
 pprVarSet :: VarSet          -- ^ The things to be pretty printed
diff --git a/compiler/typecheck/TcSimplify.hs b/compiler/typecheck/TcSimplify.hs
index 4c621dd..c889b4b 100644
--- a/compiler/typecheck/TcSimplify.hs
+++ b/compiler/typecheck/TcSimplify.hs
@@ -648,7 +648,9 @@ simplifyInfer rhs_tclvl apply_mr sigs name_taus wanteds
 
            -- promoteTyVar ignores coercion variables
        ; outer_tclvl <- TcM.getTcLevel
-       ; mapM_ (promoteTyVar outer_tclvl) (varSetElems promote_tkvs)
+       ; mapM_ (promoteTyVar outer_tclvl) (nonDetEltsUFM promote_tkvs)
+           -- It's OK to use nonDetEltsUFM here because promoteTyVar is
+           -- commutative
 
            -- Emit an implication constraint for the
            -- remaining constraints from the RHS
diff --git a/testsuite/tests/callarity/unittest/CallArity1.hs b/testsuite/tests/callarity/unittest/CallArity1.hs
index b889a2f..6873d32 100644
--- a/testsuite/tests/callarity/unittest/CallArity1.hs
+++ b/testsuite/tests/callarity/unittest/CallArity1.hs
@@ -19,6 +19,7 @@ import System.Environment( getArgs )
 import VarSet
 import PprCore
 import Unique
+import UniqFM
 import CoreLint
 import FastString
 
@@ -173,7 +174,9 @@ main = do
             putMsg dflags (text n <> char ':')
             -- liftIO $ putMsg dflags (ppr e)
             let e' = callArityRHS e
-            let bndrs = varSetElems (allBoundIds e')
+            let bndrs = nonDetEltsUFM (allBoundIds e')
+              -- It should be OK to use nonDetEltsUFM here, if it becomes a
+              -- problem we should use DVarSet
             -- liftIO $ putMsg dflags (ppr e')
             forM_ bndrs $ \v -> putMsg dflags $ nest 4 $ ppr v <+> ppr (idCallArity v)
 



More information about the ghc-commits mailing list