Skip to content

Commit 5a9f3fd

Browse files
committed
lock-less KnownTargets
1 parent 1b69975 commit 5a9f3fd

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ import Data.Void
7878

7979
import Control.Concurrent.STM (atomically)
8080
import Control.Concurrent.STM.TQueue
81+
import Data.Foldable (for_)
8182
import qualified Data.HashSet as Set
83+
import Data.Tuple (swap)
8284
import Database.SQLite.Simple
8385
import Development.IDE.Core.Tracing (withTrace)
8486
import HieDb.Create
@@ -265,12 +267,13 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
265267
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
266268
return (targetTarget, found)
267269
atomically $ recordDirtyKeys extras GetKnownTargets [emptyFilePath]
268-
modifyVarIO' knownTargetsVar $ traverseHashed $ \known -> do
270+
hasUpdate <- atomicModifyIORef' knownTargetsVar $ (swap .) $ traverseHashed $ \known -> do
269271
let known' = HM.unionWith (<>) known $ HM.fromList $ map (second Set.fromList) knownTargets
270-
when (known /= known') $
272+
hasUpdate = if known /= known' then Just known' else Nothing
273+
(hasUpdate, known')
274+
for_ hasUpdate $ \x ->
271275
logDebug logger $ "Known files updated: " <>
272-
T.pack(show $ (HM.map . Set.map) fromNormalizedFilePath known')
273-
pure known'
276+
T.pack(show $ (HM.map . Set.map) fromNormalizedFilePath x)
274277

275278
-- Create a new HscEnv from a hieYaml root and a set of options
276279
-- If the hieYaml file already has an HscEnv, the new component is

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ data ShakeExtras = ShakeExtras
210210
-> IO ()
211211
,ideNc :: IORef NameCache
212212
-- | A mapping of module name to known target (or candidate targets, if missing)
213-
,knownTargetsVar :: Var (Hashed KnownTargets)
213+
,knownTargetsVar :: IORef (Hashed KnownTargets)
214214
-- | A mapping of exported identifiers for local modules. Updated on kick
215215
,exportsMap :: Var ExportsMap
216216
-- | A work queue for actions added via 'runInShakeSession'
@@ -477,7 +477,7 @@ getValues state key file = do
477477
knownTargets :: Action (Hashed KnownTargets)
478478
knownTargets = do
479479
ShakeExtras{knownTargetsVar} <- getShakeExtras
480-
liftIO $ readVar knownTargetsVar
480+
liftIO $ readIORef knownTargetsVar
481481

482482
-- | Seq the result stored in the Shake value. This only
483483
-- evaluates the value to WHNF not NF. We take care of the latter
@@ -514,7 +514,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
514514
hiddenDiagnostics <- STM.newIO
515515
publishedDiagnostics <- STM.newIO
516516
positionMapping <- STM.newIO
517-
knownTargetsVar <- newVar $ hashed HMap.empty
517+
knownTargetsVar <- newIORef $ hashed HMap.empty
518518
let restartShakeSession = shakeRestart ideState
519519
persistentKeys <- newVar HMap.empty
520520
indexPending <- newTVarIO HMap.empty

plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ callRetrie ::
356356
Bool ->
357357
IO ([CallRetrieError], WorkspaceEdit)
358358
callRetrie state session rewrites origin restrictToOriginatingFile = do
359-
knownFiles <- toKnownFiles . unhashed <$> readVar (knownTargetsVar $ shakeExtras state)
359+
knownFiles <- toKnownFiles . unhashed <$> readIORef (knownTargetsVar $ shakeExtras state)
360360
let reuseParsedModule f = do
361361
pm <-
362362
useOrFail "GetParsedModule" NoParse GetParsedModule f

0 commit comments

Comments
 (0)