Skip to content

Commit 52f85b2

Browse files
committed
Book keeping running keys
It can prevent the dirty keys being removed The old problem is that: Key is running Key is dirtied Key is finished and remove the dirtiness shake session restart and Key is in invalid clean state now we are going: Key is running and add itself to be running Key is dirtied, remove from runnning Key is finished seeing itself is not running and keep the dirtiness Or Key is dirtied, remove from runnning Key is running and add itself to be running Key is finished, seeing itself is running and remove the dirtiness
1 parent a6f0008 commit 52f85b2

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ setSomethingModified vfs state keys reason = do
249249
-- Update database to remove any files that might have been renamed/deleted
250250
atomically $ do
251251
writeTQueue (indexQueue $ hiedbWriter $ shakeExtras state) (\withHieDb -> withHieDb deleteMissingRealFiles)
252-
modifyTVar' (dirtyKeys $ shakeExtras state) $ \x ->
253-
foldl' (flip insertKeySet) x keys
252+
recordDirtyKeySet (shakeExtras state) keys
254253
void $ restartShakeSession (shakeExtras state) vfs reason []
255254

256255
registerFileWatches :: [String] -> LSP.LspT Config IO Bool

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module Development.IDE.Core.Shake(
5757
FileVersion(..),
5858
updatePositionMapping,
5959
updatePositionMappingHelper,
60-
deleteValue, recordDirtyKeys,
60+
deleteValue, recordDirtyKeys, recordDirtyKeySet,
6161
WithProgressFunc, WithIndefiniteProgressFunc,
6262
ProgressEvent(..),
6363
DelayedAction, mkDelayedAction,
@@ -137,6 +137,7 @@ import Development.IDE.Graph.Database (ShakeDatabase,
137137
shakeNewDatabase,
138138
shakeProfileDatabase,
139139
shakeRunDatabaseForKeys)
140+
import Development.IDE.Graph.Internal.Key (deleteKeySet)
140141
import Development.IDE.Graph.Rule
141142
import Development.IDE.Types.Action
142143
import Development.IDE.Types.Diagnostics
@@ -328,6 +329,8 @@ data ShakeExtras = ShakeExtras
328329
-- ^ Default HLS config, only relevant if the client does not provide any Config
329330
, dirtyKeys :: TVar KeySet
330331
-- ^ Set of dirty rule keys since the last Shake run
332+
, runningKeys:: TVar KeySet
333+
-- ^ Set of running rule keys since the last Shake run
331334
}
332335

333336
type WithProgressFunc = forall a.
@@ -573,11 +576,22 @@ recordDirtyKeys
573576
-> k
574577
-> [NormalizedFilePath]
575578
-> STM (IO ())
576-
recordDirtyKeys ShakeExtras{dirtyKeys} key file = do
579+
recordDirtyKeys ShakeExtras{dirtyKeys, runningKeys} key file = do
580+
modifyTVar' runningKeys $ \x -> foldl' (flip deleteKeySet) x (toKey key <$> file)
577581
modifyTVar' dirtyKeys $ \x -> foldl' (flip insertKeySet) x (toKey key <$> file)
578582
return $ withEventTrace "recordDirtyKeys" $ \addEvent -> do
579583
addEvent (fromString $ unlines $ "dirty " <> show key : map fromNormalizedFilePath file)
580584

585+
recordDirtyKeySet
586+
:: ShakeExtras
587+
-> [Key]
588+
-> STM (IO ())
589+
recordDirtyKeySet ShakeExtras{dirtyKeys, runningKeys} keys = do
590+
modifyTVar' runningKeys $ \x -> foldl' (flip deleteKeySet) x keys
591+
modifyTVar' dirtyKeys $ \x -> foldl' (flip insertKeySet) x keys
592+
return $ withEventTrace "recordDirtyKeys" $ \addEvent -> do
593+
addEvent (fromString $ unlines $ "dirty: ": map show keys)
594+
581595
-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.
582596
getValues ::
583597
forall k v.
@@ -672,6 +686,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins debouncer
672686

673687
let clientCapabilities = maybe def LSP.resClientCapabilities lspEnv
674688
dirtyKeys <- newTVarIO mempty
689+
runningKeys <- newTVarIO mempty
675690
-- Take one VFS snapshot at the start
676691
vfsVar <- newTVarIO =<< vfsSnapshot lspEnv
677692
pure ShakeExtras{shakeRecorder = recorder, ..}
@@ -925,6 +940,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
925940
ShakeExtras{state, dirtyKeys, lspEnv, shakeRecorder, ideTesting} <- getShakeExtras
926941
(n::Int, garbage) <- liftIO $
927942
foldM (removeDirtyKey dirtyKeys state) (0,[]) agedKeys
943+
928944
t <- liftIO start
929945
when (n>0) $ liftIO $ do
930946
logWith shakeRecorder Debug $ LogShakeGarbageCollection (T.pack label) n t
@@ -1186,9 +1202,11 @@ defineEarlyCutoff'
11861202
-> (Value v -> Action (Maybe BS.ByteString, IdeResult v))
11871203
-> Action (RunResult (A (RuleResult k)))
11881204
defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
1189-
ShakeExtras{state, progress, dirtyKeys} <- getShakeExtras
1205+
ShakeExtras{state, progress, dirtyKeys, runningKeys} <- getShakeExtras
11901206
options <- getIdeOptions
11911207
(if optSkipProgress options key then id else inProgress progress file) $ do
1208+
let theKey = toKey key file
1209+
liftIO $ atomicallyNamed "define - runningKeys" $ modifyTVar' runningKeys (insertKeySet theKey)
11921210
val <- case mbOld of
11931211
Just old | mode == RunDependenciesSame -> do
11941212
mbValue <- liftIO $ atomicallyNamed "define - read 1" $ getValues state key file
@@ -1234,7 +1252,9 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
12341252
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff)
12351253
(encodeShakeValue bs) $
12361254
A res
1237-
liftIO $ atomicallyNamed "define - dirtyKeys" $ modifyTVar' dirtyKeys (deleteKeySet $ toKey key file)
1255+
liftIO $ atomicallyNamed "define - (runningKeys, dirtyKeys)" $ do
1256+
running <- readTVar runningKeys
1257+
when (memberKeySet theKey running) $ return (deleteKeySet theKey running) >> modifyTVar' dirtyKeys (deleteKeySet theKey)
12381258
return res
12391259
where
12401260
-- Highly unsafe helper to compute the version of a file

0 commit comments

Comments
 (0)