[commit: ghc] master: TH: Use atomicModifyIORef' for fresh names (f897b74)

git at git.haskell.org git at git.haskell.org
Tue Sep 27 21:38:44 UTC 2016


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

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

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

commit f897b7427a4804e3285144f57676574d338be1f5
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Wed Sep 28 07:37:33 2016 +1000

    TH: Use atomicModifyIORef' for fresh names
    
    This prevents the possibility of race conditions when creating fresh
    names.
    
    Test Plan: validate
    
    Reviewers: goldfire, austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2548


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

f897b7427a4804e3285144f57676574d338be1f5
 libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 20c2396..00ac0b3 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -112,9 +112,8 @@ class Monad m => Quasi m where
 -----------------------------------------------------
 
 instance Quasi IO where
-  qNewName s = do { n <- readIORef counter
-                 ; writeIORef counter (n+1)
-                 ; return (mkNameU s n) }
+  qNewName s = do { n <- atomicModifyIORef' counter (\x -> (x + 1, x))
+                  ; pure (mkNameU s n) }
 
   qReport True  msg = hPutStrLn stderr ("Template Haskell error: " ++ msg)
   qReport False msg = hPutStrLn stderr ("Template Haskell error: " ++ msg)



More information about the ghc-commits mailing list