summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2022-01-13 15:58:52 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-01-18 16:13:25 -0500
commit2d205154d3fd565c7f88e07c4c307f48c5ade902 (patch)
tree4394debadcfff5520da4184a5b4a33508a4a2497
parent7ec783de6ba9e380da6737dad78d9a82cf56002a (diff)
downloadhaskell-2d205154d3fd565c7f88e07c4c307f48c5ade902.tar.gz
Stricten the Strict State monad
I found it weird that most of the combinators weren't actually strict. Making `pure` strict in the state should hopefully give Nested CPR an easier time to unbox the nested state.
-rw-r--r--compiler/GHC/Utils/Monad/State/Strict.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/compiler/GHC/Utils/Monad/State/Strict.hs b/compiler/GHC/Utils/Monad/State/Strict.hs
index 27a2755067..d5298955a5 100644
--- a/compiler/GHC/Utils/Monad/State/Strict.hs
+++ b/compiler/GHC/Utils/Monad/State/Strict.hs
@@ -37,10 +37,10 @@ pattern State m <- State' m
State m = State' (oneShot $ \s -> m s)
instance Applicative (State s) where
- pure x = State $ \s -> (# x, s #)
+ pure x = State $ \(!s) -> (# x, s #)
m <*> n = State $ \s -> case runState' m s of
(# f, !s' #) -> case runState' n s' of
- (# x, s'' #) -> (# f x, s'' #)
+ (# x, !s'' #) -> (# f x, s'' #)
instance Monad (State s) where
m >>= n = State $ \s -> case runState' m s of
@@ -48,19 +48,19 @@ instance Monad (State s) where
state :: (s -> (a, s)) -> State s a
state f = State $ \s -> case f s of
- (r, s') -> (# r, s' #)
+ (r, !s') -> (# r, s' #)
get :: State s s
-get = State $ \s -> (# s, s #)
+get = State $ \(!s) -> (# s, s #)
gets :: (s -> a) -> State s a
-gets f = State $ \s -> (# f s, s #)
+gets f = State $ \(!s) -> (# f s, s #)
put :: s -> State s ()
-put s' = State $ \_ -> (# (), s' #)
+put !s' = State $ \_ -> (# (), s' #)
modify :: (s -> s) -> State s ()
-modify f = State $ \s -> (# (), f s #)
+modify f = State $ \s -> let !s' = f s in (# (), s' #)
evalState :: State s a -> s -> a
@@ -75,4 +75,4 @@ execState s i = case runState' s i of
runState :: State s a -> s -> (a, s)
runState s i = case runState' s i of
- (# a, s' #) -> (a, s')
+ (# a, !s' #) -> (a, s')