1313module Main (main ) where
1414
1515import Arguments
16+ import Control.Concurrent.Async
1617import Control.Concurrent.Extra
1718import Control.Exception
1819import Control.Monad.Extra
@@ -190,8 +191,8 @@ main = do
190191 { optReportProgress = clientSupportsProgress caps
191192 , optShakeProfiling = argsShakeProfiling
192193 , optTesting = argsTesting
194+ , optThreads = argsThreads
193195 , optInterfaceLoadingDiagnostics = argsTesting
194- , optThreads = argsThread
195196 }
196197 debouncer <- newAsyncDebouncer
197198 initialise caps (mainRule >> pluginRules plugins >> action kick)
@@ -408,7 +409,6 @@ loadSession dir = liftIO $ do
408409 return res
409410
410411 lock <- newLock
411- cradle_lock <- newLock
412412
413413 -- This caches the mapping from hie.yaml + Mod.hs -> [String]
414414 sessionOpts <- return $ \ (hieYaml, file) -> do
@@ -435,17 +435,39 @@ loadSession dir = liftIO $ do
435435 finished_barrier <- newBarrier
436436 -- fork a new thread here which won't be killed by shake
437437 -- throwing an async exception
438- void $ forkIO $ withLock cradle_lock $ do
439- putStrLn $ " Shelling out to cabal " <> show file
438+ void $ forkIO $ do
439+ putStrLn $ " Consulting the cradle for " <> show file
440440 cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
441441 opts <- cradleToSessionOpts cradle cfp
442442 print opts
443443 res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
444444 signalBarrier finished_barrier res
445445 waitBarrier finished_barrier
446- return $ \ file -> liftIO $ mask_ $ withLock lock $ do
447- hieYaml <- cradleLoc file
448- sessionOpts (hieYaml, file)
446+
447+ dummyAs <- async $ return (error " Uninitialised" )
448+ runningCradle <- newIORef dummyAs
449+ -- The main function which gets options for a file. We only want one of these running
450+ -- at a time.
451+ let getOptions file = do
452+ hieYaml <- cradleLoc file
453+ sessionOpts (hieYaml, file)
454+ -- The lock is on the `runningCradle` resource
455+ return $ \ file -> liftIO $ withLock lock $ do
456+ as <- readIORef runningCradle
457+ finished <- poll as
458+ case finished of
459+ Just {} -> do
460+ as <- async $ getOptions file
461+ writeIORef runningCradle as
462+ wait as
463+ -- If it's not finished then wait and then get options, this could of course be killed still
464+ Nothing -> do
465+ _ <- wait as
466+ getOptions file
467+
468+
469+
470+
449471
450472checkDependencyInfo :: Map. Map FilePath (Maybe UTCTime ) -> IO Bool
451473checkDependencyInfo old_di = do
0 commit comments