Skip to content

Commit 60cdccd

Browse files
committed
move deleteValue and recordDirtyKeys to STM
1 parent 67a14f5 commit 60cdccd

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
247247
} <- getShakeExtras
248248
let invalidateShakeCache = do
249249
void $ modifyVar' version succ
250-
recordDirtyKeys extras GhcSessionIO [emptyFilePath]
250+
atomically $ recordDirtyKeys extras GhcSessionIO [emptyFilePath]
251251

252252
IdeOptions{ optTesting = IdeTesting optTesting
253253
, optCheckProject = getCheckProject
@@ -264,7 +264,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
264264
TargetModule _ -> do
265265
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
266266
return (targetTarget, found)
267-
recordDirtyKeys extras GetKnownTargets [emptyFilePath]
267+
atomically $ recordDirtyKeys extras GetKnownTargets [emptyFilePath]
268268
modifyVarIO' knownTargetsVar $ traverseHashed $ \known -> do
269269
let known' = HM.unionWith (<>) known $ HM.fromList $ map (second Set.fromList) knownTargets
270270
when (known /= known') $

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Development.IDE.Core.FileExists
1010
)
1111
where
1212

13+
import Control.Concurrent.STM.Stats
1314
import Control.Concurrent.Strict
1415
import Control.Exception
1516
import Control.Monad.Extra
@@ -100,9 +101,11 @@ modifyFileExists state changes = do
100101
-- flush previous values
101102
let (fileModifChanges, fileExistChanges) =
102103
partition ((== FcChanged) . snd) (HashMap.toList changesMap)
103-
mapM_ (deleteValue (shakeExtras state) GetFileExists . fst) fileExistChanges
104-
recordDirtyKeys (shakeExtras state) GetFileExists $ map fst fileExistChanges
105-
recordDirtyKeys (shakeExtras state) GetModificationTime $ map fst fileModifChanges
104+
join $ atomically $ do
105+
mapM_ (deleteValue (shakeExtras state) GetFileExists . fst) fileExistChanges
106+
io1 <- recordDirtyKeys (shakeExtras state) GetFileExists $ map fst fileExistChanges
107+
io2 <- recordDirtyKeys (shakeExtras state) GetModificationTime $ map fst fileModifChanges
108+
return (io1 <> io2)
106109

107110
fromChange :: FileChangeType -> Maybe Bool
108111
fromChange FcCreated = Just True

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Development.IDE.Core.FileStore(
2424
registerFileWatches
2525
) where
2626

27-
import Control.Concurrent.STM (atomically,
27+
import Control.Concurrent.STM.Stats (STM, atomically,
2828
modifyTVar')
2929
import Control.Concurrent.STM.TQueue (writeTQueue)
3030
import Control.Concurrent.Strict
@@ -160,7 +160,7 @@ isInterface :: NormalizedFilePath -> Bool
160160
isInterface f = takeExtension (fromNormalizedFilePath f) `elem` [".hi", ".hi-boot"]
161161

162162
-- | Reset the GetModificationTime state of interface files
163-
resetInterfaceStore :: ShakeExtras -> NormalizedFilePath -> IO ()
163+
resetInterfaceStore :: ShakeExtras -> NormalizedFilePath -> STM ()
164164
resetInterfaceStore state f = do
165165
deleteValue state GetModificationTime f
166166

@@ -175,7 +175,8 @@ resetFileStore ideState changes = mask $ \_ -> do
175175
case c of
176176
FcChanged
177177
-- already checked elsewhere | not $ HM.member nfp fois
178-
-> deleteValue (shakeExtras ideState) GetModificationTime nfp
178+
-> atomically $
179+
deleteValue (shakeExtras ideState) GetModificationTime nfp
179180
_ -> pure ()
180181

181182

@@ -262,7 +263,7 @@ setFileModified state saved nfp = do
262263
VFSHandle{..} <- getIdeGlobalState state
263264
when (isJust setVirtualFileContents) $
264265
fail "setFileModified can't be called on this type of VFSHandle"
265-
recordDirtyKeys (shakeExtras state) GetModificationTime [nfp]
266+
atomically $ recordDirtyKeys (shakeExtras state) GetModificationTime [nfp]
266267
restartShakeSession (shakeExtras state) (fromNormalizedFilePath nfp ++ " (modified)") []
267268
when checkParents $
268269
typecheckParents state nfp

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import qualified Data.HashMap.Strict as HashMap
2525
import qualified Data.Text as T
2626
import Development.IDE.Graph
2727

28+
import Control.Concurrent.STM.Stats (atomically)
2829
import qualified Data.ByteString as BS
2930
import Data.Maybe (catMaybes)
3031
import Development.IDE.Core.ProgressReporting
@@ -86,15 +87,15 @@ addFileOfInterest state f v = do
8687
let (prev, new) = HashMap.alterF (, Just v) f dict
8788
pure (new, (prev, new))
8889
when (prev /= Just v) $
89-
recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
90+
join $ atomically $ recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
9091
logDebug (ideLogger state) $
9192
"Set files of interest to: " <> T.pack (show files)
9293

9394
deleteFileOfInterest :: IdeState -> NormalizedFilePath -> IO ()
9495
deleteFileOfInterest state f = do
9596
OfInterestVar var <- getIdeGlobalState state
9697
files <- modifyVar' var $ HashMap.delete f
97-
recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
98+
join $ atomically $ recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
9899
logDebug (ideLogger state) $ "Set files of interest to: " <> T.pack (show files)
99100

100101
scheduleGarbageCollection :: IdeState -> IO ()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ import Ide.Plugin.Properties (HasProperty,
148148
import Ide.PluginUtils (configForPlugin)
149149
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser),
150150
PluginId)
151+
import Control.Concurrent.STM.Stats (atomically)
151152

152153
-- | This is useful for rules to convert rules that can only produce errors or
153154
-- a result into the more general IdeResult type that supports producing
@@ -1061,7 +1062,7 @@ writeHiFileAction hsc hiFile = do
10611062
extras <- getShakeExtras
10621063
let targetPath = Compat.ml_hi_file $ ms_location $ hirModSummary hiFile
10631064
liftIO $ do
1064-
resetInterfaceStore extras $ toNormalizedFilePath' targetPath
1065+
atomically $ resetInterfaceStore extras $ toNormalizedFilePath' targetPath
10651066
writeHiFile hsc hiFile
10661067

10671068
data RulesConfig = RulesConfig

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ deleteValue
437437
=> ShakeExtras
438438
-> k
439439
-> NormalizedFilePath
440-
-> IO ()
441-
deleteValue ShakeExtras{dirtyKeys, state} key file = atomically $ do
440+
-> STM ()
441+
deleteValue ShakeExtras{dirtyKeys, state} key file = do
442442
STM.delete (toKey key file) state
443443
modifyTVar' dirtyKeys $ HSet.insert (toKey key file)
444444

@@ -447,10 +447,11 @@ recordDirtyKeys
447447
=> ShakeExtras
448448
-> k
449449
-> [NormalizedFilePath]
450-
-> IO ()
451-
recordDirtyKeys ShakeExtras{dirtyKeys} key file = withEventTrace "recordDirtyKeys" $ \addEvent -> do
452-
atomically $ modifyTVar' dirtyKeys $ \x -> foldl' (flip HSet.insert) x (toKey key <$> file)
453-
addEvent (fromString $ "dirty " <> show key) (fromString $ unlines $ map fromNormalizedFilePath file)
450+
-> STM (IO ())
451+
recordDirtyKeys ShakeExtras{dirtyKeys} key file = do
452+
modifyTVar' dirtyKeys $ \x -> foldl' (flip HSet.insert) x (toKey key <$> file)
453+
return $ withEventTrace "recordDirtyKeys" $ \addEvent -> do
454+
addEvent (fromString $ "dirty " <> show key) (fromString $ unlines $ map fromNormalizedFilePath file)
454455

455456

456457
-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.

0 commit comments

Comments
 (0)