Skip to content

Commit 702e367

Browse files
committed
refactor SessionState to use Var instead of IORef for loaded and failed files
1 parent 90e1df1 commit 702e367

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ handleLoadingFailureSingle sessionState file = do
455455
removeCradleFile sessionState file
456456

457457
data SessionState = SessionState
458-
{ loadedFiles :: !(IORef (HashSet FilePath)),
459-
failedFiles :: !(IORef (HashSet FilePath)),
458+
{ loadedFiles :: !(Var (HashSet FilePath)),
459+
failedFiles :: !(Var (HashSet FilePath)),
460460
pendingFiles :: !(S.OrderedSet FilePath),
461461
hscEnvs :: !(Var HieMap),
462462
fileToFlags :: !FlagsMap,
@@ -471,34 +471,34 @@ data SessionState = SessionState
471471
-- | Add a file to the set of files with errors during loading
472472
addErrorLoadingFile :: SessionState -> FilePath -> IO ()
473473
addErrorLoadingFile state file =
474-
atomicModifyIORef' (failedFiles state) (\xs -> (Set.insert file xs, ()))
474+
modifyVar_' (failedFiles state) (\xs -> return $ Set.insert file xs)
475475

476476
addErrorLoadingFiles :: SessionState -> [FilePath] -> IO ()
477477
addErrorLoadingFiles = mapM_ . addErrorLoadingFile
478478

479479
-- | Remove a file from the set of files with errors during loading
480480
removeErrorLoadingFile :: SessionState -> FilePath -> IO ()
481481
removeErrorLoadingFile state file =
482-
atomicModifyIORef' (failedFiles state) (\xs -> (Set.delete file xs, ()))
482+
modifyVar_' (failedFiles state) (\xs -> return $ Set.delete file xs)
483483

484484
addCradleFiles :: SessionState -> HashSet FilePath -> IO ()
485485
addCradleFiles state files =
486-
atomicModifyIORef' (loadedFiles state) (\xs -> (files <> xs, ()))
486+
modifyVar_' (loadedFiles state) (\xs -> return $ files <> xs)
487487

488488
-- | Remove a file from the cradle files set
489489
removeCradleFile :: SessionState -> FilePath -> IO ()
490490
removeCradleFile state file =
491-
atomicModifyIORef' (loadedFiles state) (\xs -> (Set.delete file xs, ()))
491+
modifyVar_' (loadedFiles state) (\xs -> return $ Set.delete file xs)
492492

493493
-- | Clear error loading files and reset to empty set
494494
clearErrorLoadingFiles :: SessionState -> IO ()
495495
clearErrorLoadingFiles state =
496-
atomicModifyIORef' (failedFiles state) (\_ -> (Set.empty, ()))
496+
modifyVar_' (failedFiles state) (const $ return Set.empty)
497497

498498
-- | Clear cradle files and reset to empty set
499499
clearCradleFiles :: SessionState -> IO ()
500500
clearCradleFiles state =
501-
atomicModifyIORef' (loadedFiles state) (\_ -> (Set.empty, ()))
501+
modifyVar_' (loadedFiles state) (const $ return Set.empty)
502502

503503
-- | Reset the file maps in the session state
504504
resetFileMaps :: SessionState -> STM ()
@@ -562,8 +562,8 @@ handleFileProcessingError state hieYaml file diags extraDepFiles = do
562562
getExtraFilesToLoad :: SessionState -> FilePath -> IO [FilePath]
563563
getExtraFilesToLoad state cfp = do
564564
pendingFiles <- getPendingFiles state
565-
errorFiles <- readIORef (failedFiles state)
566-
old_files <- readIORef (loadedFiles state)
565+
errorFiles <- readVar (failedFiles state)
566+
old_files <- readVar (loadedFiles state)
567567
-- if the file is in error loading files, we fall back to single loading mode
568568
return $
569569
Set.toList $
@@ -594,8 +594,8 @@ newSessionState :: IO SessionState
594594
newSessionState = do
595595
-- Initialize SessionState
596596
sessionState <- SessionState
597-
<$> newIORef (Set.fromList []) -- loadedFiles
598-
<*> newIORef (Set.fromList []) -- failedFiles
597+
<$> newVar (Set.fromList []) -- loadedFiles
598+
<*> newVar (Set.fromList []) -- failedFiles
599599
<*> S.newIO -- pendingFiles
600600
<*> newVar Map.empty -- hscEnvs
601601
<*> STM.newIO -- fileToFlags
@@ -835,7 +835,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
835835
Left err -> do
836836
-- what if the error to load file is one of old_files ?
837837
let attemptToLoadFiles = Set.delete cfp $ Set.fromList $ concatMap cradleErrorLoadingFiles err
838-
old_files <- readIORef (loadedFiles sessionState)
838+
old_files <- readVar (loadedFiles sessionState)
839839
let errorToLoadNewFiles = cfp : Set.toList (attemptToLoadFiles `Set.difference` old_files)
840840
if length errorToLoadNewFiles > 1
841841
then do

0 commit comments

Comments
 (0)