@@ -156,8 +156,6 @@ import Data.Default
156
156
import Data.Foldable (toList )
157
157
import Data.HashSet (HashSet )
158
158
import qualified Data.HashSet as HSet
159
- import Data.IORef.Extra (atomicModifyIORef'_ ,
160
- atomicModifyIORef_ )
161
159
import Data.String (fromString )
162
160
import Data.Text (pack )
163
161
import Debug.Trace.Flags (userTracingEnabled )
@@ -226,7 +224,7 @@ data ShakeExtras = ShakeExtras
226
224
, vfs :: VFSHandle
227
225
, defaultConfig :: Config
228
226
-- ^ Default HLS config, only relevant if the client does not provide any Config
229
- , dirtyKeys :: IORef (HashSet Key )
227
+ , dirtyKeys :: TVar (HashSet Key )
230
228
-- ^ Set of dirty rule keys since the last Shake run
231
229
}
232
230
@@ -440,9 +438,9 @@ deleteValue
440
438
-> k
441
439
-> NormalizedFilePath
442
440
-> IO ()
443
- deleteValue ShakeExtras {dirtyKeys, state} key file = do
444
- atomically $ STM. delete (toKey key file) state
445
- atomicModifyIORef_ dirtyKeys $ HSet. insert (toKey key file)
441
+ deleteValue ShakeExtras {dirtyKeys, state} key file = atomically $ do
442
+ STM. delete (toKey key file) state
443
+ modifyTVar' dirtyKeys $ HSet. insert (toKey key file)
446
444
447
445
recordDirtyKeys
448
446
:: Shake. ShakeValue k
@@ -451,7 +449,7 @@ recordDirtyKeys
451
449
-> [NormalizedFilePath ]
452
450
-> IO ()
453
451
recordDirtyKeys ShakeExtras {dirtyKeys} key file = withEventTrace " recordDirtyKeys" $ \ addEvent -> do
454
- atomicModifyIORef_ dirtyKeys $ \ x -> foldl' (flip HSet. insert) x (toKey key <$> file)
452
+ atomically $ modifyTVar' dirtyKeys $ \ x -> foldl' (flip HSet. insert) x (toKey key <$> file)
455
453
addEvent (fromString $ " dirty " <> show key) (fromString $ unlines $ map fromNormalizedFilePath file)
456
454
457
455
@@ -538,7 +536,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
538
536
539
537
let clientCapabilities = maybe def LSP. resClientCapabilities lspEnv
540
538
541
- dirtyKeys <- newIORef mempty
539
+ dirtyKeys <- newTVarIO mempty
542
540
pure ShakeExtras {.. }
543
541
(shakeDbM, shakeClose) <-
544
542
shakeOpenDatabase
@@ -569,7 +567,7 @@ startTelemetry db extras@ShakeExtras{..}
569
567
checkParents <- optCheckParents
570
568
regularly 1 $ do
571
569
observe countKeys . countRelevantKeys checkParents . map fst =<< (atomically . ListT. toList . STM. listT) state
572
- readIORef dirtyKeys >>= observe countDirty . countRelevantKeys checkParents . HSet. toList
570
+ readTVarIO dirtyKeys >>= observe countDirty . countRelevantKeys checkParents . HSet. toList
573
571
shakeGetBuildStep db >>= observe countBuilds
574
572
575
573
| otherwise = async (pure () )
@@ -626,7 +624,7 @@ shakeRestart IdeState{..} reason acts =
626
624
(\ runner -> do
627
625
(stopTime,() ) <- duration (cancelShakeSession runner)
628
626
res <- shakeDatabaseProfile shakeDb
629
- backlog <- readIORef $ dirtyKeys shakeExtras
627
+ backlog <- readTVarIO ( dirtyKeys shakeExtras)
630
628
queue <- atomically $ peekInProgress $ actionQueue shakeExtras
631
629
let profile = case res of
632
630
Just fp -> " , profile saved at " <> fp
@@ -687,7 +685,7 @@ newSession extras@ShakeExtras{..} shakeDb acts reason = do
687
685
reenqueued <- atomically $ peekInProgress actionQueue
688
686
allPendingKeys <-
689
687
if optRunSubset
690
- then Just <$> readIORef dirtyKeys
688
+ then Just <$> readTVarIO dirtyKeys
691
689
else return Nothing
692
690
let
693
691
-- A daemon-like action used to inject additional work
@@ -787,28 +785,27 @@ garbageCollectDirtyKeysOlderThan maxAge checkParents = otTracedGarbageCollection
787
785
garbageCollectKeys :: String -> Int -> CheckParents -> [(Key , Int )] -> Action [Key ]
788
786
garbageCollectKeys label maxAge checkParents agedKeys = do
789
787
start <- liftIO offsetTime
790
- extras <- getShakeExtras
791
- let values = state extras
788
+ ShakeExtras {state, dirtyKeys, lspEnv, logger, ideTesting} <- getShakeExtras
792
789
(n:: Int , garbage ) <- liftIO $ atomically $
793
- foldM (removeDirtyKey values) (0 ,[] ) agedKeys
794
- liftIO $ atomicModifyIORef_ (dirtyKeys extras) $ \ x ->
795
- foldl' (flip HSet. insert) x garbage
790
+ foldM (removeDirtyKey dirtyKeys state) (0 ,[] ) agedKeys
796
791
t <- liftIO start
797
792
when (n> 0 ) $ liftIO $ do
798
- logDebug ( logger extras) $ T. pack $
793
+ logDebug logger $ T. pack $
799
794
label <> " of " <> show n <> " keys (took " <> showDuration t <> " )"
800
- when (coerce $ ideTesting extras ) $ liftIO $ mRunLspT ( lspEnv extras) $
795
+ when (coerce ideTesting) $ liftIO $ mRunLspT lspEnv $
801
796
LSP. sendNotification (SCustomMethod " ghcide/GC" )
802
797
(toJSON $ mapMaybe (fmap showKey . fromKeyType) garbage)
803
798
return garbage
804
799
805
800
where
806
801
showKey = show . Q
807
- removeDirtyKey m st@ (! counter, keys) (k, age)
802
+ removeDirtyKey dk values st@ (! counter, keys) (k, age)
808
803
| age > maxAge
809
804
, Just (kt,_) <- fromKeyType k
810
805
, not (kt `HSet.member` preservedKeys checkParents)
811
- = do gotIt <- STM. focus (Focus. member <* Focus. delete) k m
806
+ = do gotIt <- STM. focus (Focus. member <* Focus. delete) k values
807
+ when gotIt $
808
+ modifyTVar' dk (HSet. insert k)
812
809
return $ if gotIt then (counter+ 1 , k: keys) else st
813
810
| otherwise = pure st
814
811
@@ -1063,7 +1060,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1063
1060
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff )
1064
1061
(encodeShakeValue bs) $
1065
1062
A res
1066
- liftIO $ atomicModifyIORef'_ dirtyKeys (HSet. delete $ toKey key file)
1063
+ liftIO $ atomically $ modifyTVar' dirtyKeys (HSet. delete $ toKey key file)
1067
1064
return res
1068
1065
1069
1066
traceA :: A v -> String
0 commit comments