@@ -21,8 +21,9 @@ import Control.Concurrent.STM.Stats (atomicallyNamed)
2121import Control.DeepSeq (force )
2222import Control.Exception
2323import Control.Monad.IO.Class
24+ import Control.Monad.RWS (MonadReader (ask ),
25+ asks )
2426import Control.Monad.Trans.Class
25- import Control.Monad.Trans.Reader
2627import Data.Foldable (toList )
2728import Data.Functor.Identity
2829import Data.IORef
@@ -41,13 +42,13 @@ type ShakeValue a = (Show a, Typeable a, Eq a, Hashable a, NFData a)
4142-- | Always rerun this rule when dirty, regardless of the dependencies.
4243alwaysRerun :: Action ()
4344alwaysRerun = do
44- ref <- Action $ asks actionDeps
45+ ref <- asks actionDeps
4546 liftIO $ modifyIORef' ref (AlwaysRerunDeps mempty <> )
4647
4748parallel :: [Action a ] -> Action [Either SomeException a ]
4849parallel [] = return []
4950parallel xs = do
50- a <- Action ask
51+ a <- ask
5152 deps <- liftIO $ readIORef $ actionDeps a
5253 case deps of
5354 UnknownDeps ->
@@ -61,15 +62,15 @@ parallel xs = do
6162-- non-blocking version of runActionInDb
6263runActionInDbCb :: (a -> String ) -> (a -> Action result ) -> STM a -> (Either SomeException result -> IO () ) -> Action a
6364runActionInDbCb getTitle work getAct handler = do
64- a <- Action ask
65+ a <- ask
6566 liftIO $ atomicallyNamed " action queue - pop" $ do
6667 act <- getAct
6768 runInDataBase (getTitle act) (actionDatabase a) [(ignoreState a $ work act, handler)]
6869 return act
6970
7071runActionInDb :: String -> [Action a ] -> Action [Either SomeException a ]
7172runActionInDb title acts = do
72- a <- Action ask
73+ a <- ask
7374 xs <- mapM (\ x -> do
7475 barrier <- newEmptyTMVarIO
7576 return (x, barrier)) acts
@@ -81,7 +82,7 @@ runActionInDb title acts = do
8182ignoreState :: SAction -> Action b -> IO b
8283ignoreState a x = do
8384 ref <- newIORef mempty
84- runReaderT (fromAction x) a{actionDeps= ref}
85+ runActionMonad x a{actionDeps= ref}
8586
8687isAsyncException :: SomeException -> Bool
8788isAsyncException e
@@ -95,8 +96,8 @@ isAsyncException e
9596
9697actionCatch :: Exception e => Action a -> (e -> Action a ) -> Action a
9798actionCatch a b = do
98- v <- Action ask
99- Action $ lift $ catchJust f (runReaderT (fromAction a) v) (\ x -> runReaderT (fromAction ( b x) ) v)
99+ v <- ask
100+ liftIO $ catchJust f (runActionMonad a v) (\ x -> runActionMonad ( b x) v)
100101 where
101102 -- Catch only catches exceptions that were caused by this code, not those that
102103 -- are a result of program termination
@@ -105,41 +106,41 @@ actionCatch a b = do
105106
106107actionBracket :: IO a -> (a -> IO b ) -> (a -> Action c ) -> Action c
107108actionBracket a b c = do
108- v <- Action ask
109- Action $ lift $ bracket a b (\ x -> runReaderT (fromAction ( c x) ) v)
109+ v <- ask
110+ liftIO $ bracket a b (\ x -> runActionMonad ( c x) v)
110111
111112actionFinally :: Action a -> IO b -> Action a
112113actionFinally a b = do
113114 v <- Action ask
114- Action $ lift $ finally (runReaderT (fromAction a) v) b
115+ Action $ lift $ finally (runActionMonad a v) b
115116
116117apply1 :: (RuleResult key ~ value , ShakeValue key , Typeable value ) => key -> Action value
117118apply1 k = runIdentity <$> apply (Identity k)
118119
119120apply :: (Traversable f , RuleResult key ~ value , ShakeValue key , Typeable value ) => f key -> Action (f value )
120121apply ks = do
121- db <- Action $ asks actionDatabase
122- stack <- Action $ asks actionStack
122+ db <- asks actionDatabase
123+ stack <- asks actionStack
123124 pk <- getActionKey
124125 (is, vs) <- liftIO $ build pk db stack ks
125- ref <- Action $ asks actionDeps
126+ ref <- asks actionDeps
126127 let ! ks = force $ fromListKeySet $ toList is
127128 liftIO $ modifyIORef' ref (ResultDeps [ks] <> )
128129 pure vs
129130
130131-- | Evaluate a list of keys without recording any dependencies.
131132applyWithoutDependency :: (Traversable f , RuleResult key ~ value , ShakeValue key , Typeable value ) => f key -> Action (f value )
132133applyWithoutDependency ks = do
133- db <- Action $ asks actionDatabase
134- stack <- Action $ asks actionStack
134+ db <- asks actionDatabase
135+ stack <- asks actionStack
135136 pk <- getActionKey
136137 (_, vs) <- liftIO $ build pk db stack ks
137138 pure vs
138139
139140runActions :: Key -> Database -> [Action a ] -> IO [Either SomeException a ]
140141runActions pk db xs = do
141142 deps <- newIORef mempty
142- runReaderT (fromAction $ parallel xs) $ SAction pk db deps emptyStack
143+ runActionMonad ( parallel xs) $ SAction pk db deps emptyStack
143144
144145-- | Returns the set of dirty keys annotated with their age (in # of builds)
145146getDirtySet :: Action [(Key , Int )]
0 commit comments