[commit: base] master: Change a use of atomicModifyIORef to atomicModifyIORef' (ddbe37f)

Ian Lynagh igloo at earth.li
Sat Jun 8 20:14:16 CEST 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/base

On branch  : master

https://github.com/ghc/packages-base/commit/ddbe37f3484a0c0b4da272d9ddd7be9caf78933e

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

commit ddbe37f3484a0c0b4da272d9ddd7be9caf78933e
Author: Ian Lynagh <ian at well-typed.com>
Date:   Sat Jun 8 17:06:13 2013 +0100

    Change a use of atomicModifyIORef to atomicModifyIORef'
    
    Resulting core is unchanged.

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

 Data/Unique.hs |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Data/Unique.hs b/Data/Unique.hs
index b8aa6cd..ffd45f9 100644
--- a/Data/Unique.hs
+++ b/Data/Unique.hs
@@ -55,8 +55,8 @@ uniqSource = unsafePerformIO (newIORef 0)
 -- times 'newUnique' may be called.
 newUnique :: IO Unique
 newUnique = do
-  r <- atomicModifyIORef uniqSource $ \x -> let z = x+1 in (z,z)
-  r `seq` return (Unique r)
+  r <- atomicModifyIORef' uniqSource $ \x -> let z = x+1 in (z,z)
+  return (Unique r)
 
 -- SDM (18/3/2010): changed from MVar to STM.  This fixes
 --  1. there was no async exception protection
@@ -73,6 +73,10 @@ newUnique = do
 --     Unique.
 --  3. IORef version is very slightly faster.
 
+-- IGL (08/06/2013): changed to using atomicModifyIORef' instead.
+--  This feels a little safer, from the point of view of not leaking
+--  memory, but the resulting core is identical.
+
 -- | Hashes a 'Unique' into an 'Int'.  Two 'Unique's may hash to the
 -- same value, although in practice this is unlikely.  The 'Int'
 -- returned makes a good hash key.





More information about the ghc-commits mailing list