@@ -455,8 +455,8 @@ handleLoadingFailureSingle sessionState file = do
455
455
removeCradleFile sessionState file
456
456
457
457
data SessionState = SessionState
458
- { loadedFiles :: ! (IORef (HashSet FilePath )),
459
- failedFiles :: ! (IORef (HashSet FilePath )),
458
+ { loadedFiles :: ! (Var (HashSet FilePath )),
459
+ failedFiles :: ! (Var (HashSet FilePath )),
460
460
pendingFiles :: ! (S. OrderedSet FilePath ),
461
461
hscEnvs :: ! (Var HieMap ),
462
462
fileToFlags :: ! FlagsMap ,
@@ -471,34 +471,34 @@ data SessionState = SessionState
471
471
-- | Add a file to the set of files with errors during loading
472
472
addErrorLoadingFile :: SessionState -> FilePath -> IO ()
473
473
addErrorLoadingFile state file =
474
- atomicModifyIORef ' (failedFiles state) (\ xs -> ( Set. insert file xs, () ) )
474
+ modifyVar_ ' (failedFiles state) (\ xs -> return $ Set. insert file xs)
475
475
476
476
addErrorLoadingFiles :: SessionState -> [FilePath ] -> IO ()
477
477
addErrorLoadingFiles = mapM_ . addErrorLoadingFile
478
478
479
479
-- | Remove a file from the set of files with errors during loading
480
480
removeErrorLoadingFile :: SessionState -> FilePath -> IO ()
481
481
removeErrorLoadingFile state file =
482
- atomicModifyIORef ' (failedFiles state) (\ xs -> ( Set. delete file xs, () ) )
482
+ modifyVar_ ' (failedFiles state) (\ xs -> return $ Set. delete file xs)
483
483
484
484
addCradleFiles :: SessionState -> HashSet FilePath -> IO ()
485
485
addCradleFiles state files =
486
- atomicModifyIORef ' (loadedFiles state) (\ xs -> ( files <> xs, () ) )
486
+ modifyVar_ ' (loadedFiles state) (\ xs -> return $ files <> xs)
487
487
488
488
-- | Remove a file from the cradle files set
489
489
removeCradleFile :: SessionState -> FilePath -> IO ()
490
490
removeCradleFile state file =
491
- atomicModifyIORef ' (loadedFiles state) (\ xs -> ( Set. delete file xs, () ) )
491
+ modifyVar_ ' (loadedFiles state) (\ xs -> return $ Set. delete file xs)
492
492
493
493
-- | Clear error loading files and reset to empty set
494
494
clearErrorLoadingFiles :: SessionState -> IO ()
495
495
clearErrorLoadingFiles state =
496
- atomicModifyIORef ' (failedFiles state) (\ _ -> ( Set. empty, () ) )
496
+ modifyVar_ ' (failedFiles state) (const $ return Set. empty)
497
497
498
498
-- | Clear cradle files and reset to empty set
499
499
clearCradleFiles :: SessionState -> IO ()
500
500
clearCradleFiles state =
501
- atomicModifyIORef ' (loadedFiles state) (\ _ -> ( Set. empty, () ) )
501
+ modifyVar_ ' (loadedFiles state) (const $ return Set. empty)
502
502
503
503
-- | Reset the file maps in the session state
504
504
resetFileMaps :: SessionState -> STM ()
@@ -562,8 +562,8 @@ handleFileProcessingError state hieYaml file diags extraDepFiles = do
562
562
getExtraFilesToLoad :: SessionState -> FilePath -> IO [FilePath ]
563
563
getExtraFilesToLoad state cfp = do
564
564
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)
567
567
-- if the file is in error loading files, we fall back to single loading mode
568
568
return $
569
569
Set. toList $
@@ -594,8 +594,8 @@ newSessionState :: IO SessionState
594
594
newSessionState = do
595
595
-- Initialize SessionState
596
596
sessionState <- SessionState
597
- <$> newIORef (Set. fromList [] ) -- loadedFiles
598
- <*> newIORef (Set. fromList [] ) -- failedFiles
597
+ <$> newVar (Set. fromList [] ) -- loadedFiles
598
+ <*> newVar (Set. fromList [] ) -- failedFiles
599
599
<*> S. newIO -- pendingFiles
600
600
<*> newVar Map. empty -- hscEnvs
601
601
<*> STM. newIO -- fileToFlags
@@ -835,7 +835,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
835
835
Left err -> do
836
836
-- what if the error to load file is one of old_files ?
837
837
let attemptToLoadFiles = Set. delete cfp $ Set. fromList $ concatMap cradleErrorLoadingFiles err
838
- old_files <- readIORef (loadedFiles sessionState)
838
+ old_files <- readVar (loadedFiles sessionState)
839
839
let errorToLoadNewFiles = cfp : Set. toList (attemptToLoadFiles `Set.difference` old_files)
840
840
if length errorToLoadNewFiles > 1
841
841
then do
0 commit comments