@@ -772,9 +772,8 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
772772 -- at a time. Therefore the IORef contains the currently running cradle, if we try
773773 -- to get some more options then we wait for the currently running action to finish
774774 -- before attempting to do so.
775- let getOptionsWorker :: FilePath -> IO ()
776- getOptionsWorker file = do
777- logWith recorder Debug (LogGetOptionsLoop file)
775+ let getOptions :: FilePath -> IO ()
776+ getOptions file = do
778777 let ncfp = toNormalizedFilePath' file
779778 cachedHieYamlLocation <- atomically $ STM. lookup ncfp filesMap
780779 hieYaml <- cradleLoc file
@@ -788,6 +787,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
788787 -- delete file from pending files
789788 S. delete file pendingFileSet
790789
790+ let getOptionsLoop :: IO ()
791+ getOptionsLoop = do
792+ -- Get the next file to load
793+ absFile <- atomically $ S. readQueue pendingFileSet
794+ logWith recorder Debug (LogGetOptionsLoop absFile)
795+ getOptions absFile
796+ getOptionsLoop
797+
791798 -- | Given a file, this function will return the HscEnv and the dependencies
792799 -- it would look up the cache first, if the cache is not available, it would
793800 -- submit a request to the getOptionsLoop to get the options for the file
@@ -813,12 +820,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
813820 Nothing -> do
814821 -- if not ok, we need to reload the session
815822 atomically $ S. insert absFile pendingFileSet
816- -- line up the session to load
817- atomically $ writeTQueue que (getOptionsWorker absFile)
818823 lookupOrWaitCache absFile
819824
820825 -- see Note [Serializing runs in separate thread]
821826 -- Start the getOptionsLoop if the queue is empty
827+ liftIO $ atomically $ Extra. whenM (isEmptyTQueue que) $ writeTQueue que getOptionsLoop
822828 returnWithVersion $ \ file -> do
823829 let absFile = toAbsolutePath file
824830 second Map. keys <$> lookupOrWaitCache absFile
0 commit comments