Skip to content

Commit beb1764

Browse files
committed
refactor session loading to wait for pending files before cache check
1 parent 79a43a0 commit beb1764

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
799799
let lookupOrWaitCache :: FilePath -> IO (IdeResult HscEnvEq, DependencyInfo)
800800
lookupOrWaitCache absFile = do
801801
let ncfp = toNormalizedFilePath' absFile
802-
-- check if in the cache
803-
res <- atomically $ checkInCache ncfp
802+
res <- atomically $ do
803+
-- wait until target file is not in pendingFiles
804+
Extra.whenM (S.lookup absFile pendingFileSet) STM.retry
805+
-- check if in the cache
806+
checkInCache ncfp
804807
logWith recorder Info $ LogLookupSessionCache absFile
805808
updateDateRes <- case res of
806809
Just r -> do
@@ -814,8 +817,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
814817
Nothing -> do
815818
-- if not ok, we need to reload the session
816819
atomically $ S.insert absFile pendingFileSet
817-
-- wait until pendingFiles is not in pendingFiles
818-
atomically $ Extra.whenM (S.lookup absFile pendingFileSet) STM.retry
819820
lookupOrWaitCache absFile
820821

821822
-- see Note [Serializing runs in separate thread]

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module Development.IDE.Session.OrderedSet where
22

33
import Control.Concurrent.STM (STM, TQueue, newTQueueIO)
44
import Control.Concurrent.STM.TQueue (readTQueue, writeTQueue)
5+
import Control.Monad (when)
56
import Data.Hashable (Hashable)
7+
import qualified Focus
68
import qualified ListT as LT
79
import qualified StmContainers.Set as S
810
import StmContainers.Set (Set)
@@ -12,9 +14,8 @@ type OrderedSet a = (TQueue a, Set a)
1214

1315
insert :: Hashable a => a -> OrderedSet a -> STM ()
1416
insert a (que, s) = do
15-
S.insert a s
16-
writeTQueue que a
17-
return ()
17+
(_, inserted) <- S.focus (Focus.testingIfInserts $ Focus.insert ()) a s
18+
when inserted $ writeTQueue que a
1819

1920
newIO :: Hashable a => IO (OrderedSet a)
2021
newIO = do

0 commit comments

Comments
 (0)