Skip to content

Commit f3c1cdd

Browse files
committed
io-sim: strict TVar operations
1 parent db8a525 commit f3c1cdd

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

io-sim/src/Control/Monad/IOSim/Internal.hs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,26 +1308,23 @@ execTryPutTMVar (TMVar var) a = do
13081308
saveTVar :: TVar s a -> ST s ()
13091309
saveTVar TVar{tvarCurrent, tvarUndo} = do
13101310
-- push the current value onto the undo stack
1311-
v <- readSTRef tvarCurrent
1312-
vs <- readSTRef tvarUndo
1313-
!_ <- writeSTRef tvarUndo (v:vs)
1314-
return ()
1311+
v <- readSTRef tvarCurrent
1312+
!vs <- readSTRef tvarUndo
1313+
writeSTRef tvarUndo $! v:vs
13151314

13161315
revertTVar :: TVar s a -> ST s ()
13171316
revertTVar TVar{tvarCurrent, tvarUndo} = do
13181317
-- pop the undo stack, and revert the current value
1319-
vs <- readSTRef tvarUndo
1320-
!_ <- writeSTRef tvarCurrent (head vs)
1321-
!_ <- writeSTRef tvarUndo (tail vs)
1322-
return ()
1318+
!vs <- readSTRef tvarUndo
1319+
!_ <- writeSTRef tvarCurrent (head vs)
1320+
writeSTRef tvarUndo $! tail vs
13231321
{-# INLINE revertTVar #-}
13241322

13251323
commitTVar :: TVar s a -> ST s ()
13261324
commitTVar TVar{tvarUndo} = do
1327-
vs <- readSTRef tvarUndo
1325+
!vs <- readSTRef tvarUndo
13281326
-- pop the undo stack, leaving the current value unchanged
1329-
!_ <- writeSTRef tvarUndo (tail vs)
1330-
return ()
1327+
writeSTRef tvarUndo $! tail vs
13311328
{-# INLINE commitTVar #-}
13321329

13331330
readTVarUndos :: TVar s a -> ST s [a]
@@ -1344,8 +1341,8 @@ traceTVarST TVar{tvarId, tvarCurrent, tvarUndo, tvarTrace} new = do
13441341
Nothing -> return TraceValue { traceDynamic = (Nothing :: Maybe ())
13451342
, traceString = Nothing }
13461343
Just f -> do
1347-
vs <- readSTRef tvarUndo
1348-
v <- readSTRef tvarCurrent
1344+
!vs <- readSTRef tvarUndo
1345+
v <- readSTRef tvarCurrent
13491346
case (new, vs) of
13501347
(True, _) -> f Nothing v
13511348
(_, _:_) -> f (Just $ last vs) v

io-sim/src/Control/Monad/IOSimPOR/Internal.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,23 +1598,23 @@ execTryPutTMVar (TMVar var) a = do
15981598
saveTVar :: TVar s a -> ST s ()
15991599
saveTVar TVar{tvarCurrent, tvarUndo} = do
16001600
-- push the current value onto the undo stack
1601-
v <- readSTRef tvarCurrent
1602-
vs <- readSTRef tvarUndo
1603-
writeSTRef tvarUndo (v:vs)
1601+
v <- readSTRef tvarCurrent
1602+
!vs <- readSTRef tvarUndo
1603+
writeSTRef tvarUndo $! v:vs
16041604

16051605
revertTVar :: TVar s a -> ST s ()
16061606
revertTVar TVar{tvarCurrent, tvarUndo} = do
16071607
-- pop the undo stack, and revert the current value
1608-
vs <- readSTRef tvarUndo
1609-
writeSTRef tvarCurrent (head vs)
1610-
writeSTRef tvarUndo (tail vs)
1608+
!vs <- readSTRef tvarUndo
1609+
!_ <- writeSTRef tvarCurrent (head vs)
1610+
writeSTRef tvarUndo $! tail vs
16111611
{-# INLINE revertTVar #-}
16121612

16131613
commitTVar :: TVar s a -> ST s ()
16141614
commitTVar TVar{tvarUndo} = do
1615-
vs <- readSTRef tvarUndo
1615+
!vs <- readSTRef tvarUndo
16161616
-- pop the undo stack, leaving the current value unchanged
1617-
writeSTRef tvarUndo (tail vs)
1617+
writeSTRef tvarUndo $! tail vs
16181618
{-# INLINE commitTVar #-}
16191619

16201620
readTVarUndos :: TVar s a -> ST s [a]
@@ -1630,8 +1630,8 @@ traceTVarST TVar{tvarCurrent, tvarUndo, tvarTrace} new = do
16301630
case mf of
16311631
Nothing -> return TraceValue { traceDynamic = (Nothing :: Maybe ()), traceString = Nothing }
16321632
Just f -> do
1633-
vs <- readSTRef tvarUndo
1634-
v <- readSTRef tvarCurrent
1633+
!vs <- readSTRef tvarUndo
1634+
v <- readSTRef tvarCurrent
16351635
case (new, vs) of
16361636
(True, _) -> f Nothing v
16371637
(_, _:_) -> f (Just $ last vs) v

0 commit comments

Comments
 (0)