Skip to content

Commit 26aac1a

Browse files
committed
mark the keys dirty before we do async runs to start the database
1 parent e426e76 commit 26aac1a

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import Data.Default
9696
import Data.Dynamic
9797
import Data.EnumMap.Strict (EnumMap)
9898
import qualified Data.EnumMap.Strict as EM
99-
import Data.Foldable (find, for_)
99+
import Data.Foldable (find, for_, traverse_)
100100
import Data.Functor ((<&>))
101101
import Data.Functor.Identity
102102
import Data.Hashable
@@ -172,6 +172,7 @@ import qualified StmContainers.Map as STM
172172
import System.FilePath hiding (makeRelative)
173173
import System.IO.Unsafe (unsafePerformIO)
174174
import System.Time.Extra
175+
import Development.IDE.Graph.Database (shakeMarkDirtyKeys)
175176
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
176177

177178
#if !MIN_VERSION_ghc(9,3,0)
@@ -853,14 +854,15 @@ newSession recorder extras@ShakeExtras{..} vfsMod shakeDb acts reason = do
853854
whenJust allPendingKeys $ \kk -> setTag otSpan "keys" (BS8.pack $ unlines $ map show $ toListKeySet kk)
854855
let keysActs = pumpActionThread otSpan : map (run otSpan) (reenqueued ++ acts)
855856
res <- try @SomeException $
856-
restore $ shakeRunDatabaseForKeys (toListKeySet <$> allPendingKeys) shakeDb keysActs
857+
restore $ shakeRunDatabaseForKeys shakeDb keysActs
857858
return $ do
858859
let exception =
859860
case res of
860861
Left e -> Just e
861862
_ -> Nothing
862863
logWith recorder Debug $ LogBuildSessionFinish exception
863-
864+
-- mark the key as dirty in hls graph
865+
traverse_ (shakeMarkDirtyKeys shakeDb) allPendingKeys
864866
-- Do the work in a background thread
865867
workThread <- asyncWithUnmask workRun
866868

hls-graph/src/Development/IDE/Graph/Database.hs

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ module Development.IDE.Graph.Database(
88
shakeGetBuildStep,
99
shakeGetDatabaseKeys,
1010
shakeGetDirtySet,
11-
shakeGetCleanKeys
12-
,shakeGetBuildEdges) where
11+
shakeGetCleanKeys,
12+
shakeMarkDirtyKeys,
13+
shakeGetBuildEdges) where
1314
import Control.Concurrent.STM.Stats (readTVarIO)
1415
import Data.Dynamic
1516
import Data.Maybe
@@ -34,7 +35,7 @@ shakeNewDatabase opts rules = do
3435
pure $ ShakeDatabase (length actions) actions db
3536

3637
shakeRunDatabase :: ShakeDatabase -> [Action a] -> IO [a]
37-
shakeRunDatabase = shakeRunDatabaseForKeys Nothing
38+
shakeRunDatabase = shakeRunDatabaseForKeys
3839

3940
-- | Returns the set of dirty keys annotated with their age (in # of builds)
4041
shakeGetDirtySet :: ShakeDatabase -> IO [(Key, Int)]
@@ -52,16 +53,19 @@ unvoid :: Functor m => m () -> m a
5253
unvoid = fmap undefined
5354

5455
-- | Assumes that the database is not running a build
56+
-- dirty keys should be marked using `shakeMarkDirtyKeys`
57+
-- before calling this function
5558
shakeRunDatabaseForKeys
56-
:: Maybe [Key]
57-
-- ^ Set of keys changed since last run. 'Nothing' means everything has changed
58-
-> ShakeDatabase
59+
::
60+
ShakeDatabase
5961
-> [Action a]
6062
-> IO [a]
61-
shakeRunDatabaseForKeys keysChanged (ShakeDatabase lenAs1 as1 db) as2 = do
62-
incDatabase db keysChanged
63+
shakeRunDatabaseForKeys (ShakeDatabase lenAs1 as1 db) as2 = do
6364
fmap (drop lenAs1) $ runActions db $ map unvoid as1 ++ as2
6465

66+
shakeMarkDirtyKeys :: ShakeDatabase -> KeySet -> IO ()
67+
shakeMarkDirtyKeys (ShakeDatabase _ _ db) keys = incDatabase db $ Just (toListKeySet keys)
68+
6569
-- | Given a 'ShakeDatabase', write an HTML profile to the given file about the latest run.
6670
shakeProfileDatabase :: ShakeDatabase -> FilePath -> IO ()
6771
shakeProfileDatabase (ShakeDatabase _ _ s) file = writeProfile file s

0 commit comments

Comments
 (0)