@@ -155,10 +155,12 @@ data Log
155
155
| LogSessionReloadOnError FilePath ! [FilePath ]
156
156
| LogGetOptionsLoop ! FilePath
157
157
| LogLookupSessionCache ! FilePath
158
+ | LogTime ! String
158
159
deriving instance Show Log
159
160
160
161
instance Pretty Log where
161
162
pretty = \ case
163
+ LogTime s -> " Time:" <+> pretty s
162
164
LogLookupSessionCache path -> " Looking up session cache for" <+> pretty path
163
165
LogGetOptionsLoop fp -> " Loop: getOptions for" <+> pretty fp
164
166
LogSessionReloadOnError path files ->
@@ -582,7 +584,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
582
584
583
585
let flags_map' = HM. fromList (concatMap toFlagsMap all_targets')
584
586
all_targets' = concat all_target_details
585
- newLoaded = HM. keys flags_map'
586
587
this_dep_info <- getDependencyInfo $ maybeToList hieYaml
587
588
let (all_targets, this_flags_map, this_options)
588
589
= case HM. lookup _cfp flags_map' of
@@ -599,9 +600,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
599
600
]
600
601
601
602
let insertAll m xs = mapM_ (flip (uncurry STM. insert) m) xs
603
+ newLoaded = Set. fromList $ fromNormalizedFilePath <$> HM. keys this_flags_map
602
604
atomically $ do
603
605
STM. insert this_flags_map hieYaml fileToFlags
604
606
insertAll filesMap $ map ((hieYaml,) . fst ) $ concatMap toFlagsMap all_targets
607
+ forM_ newLoaded $ flip S. delete pendingFileSet
605
608
606
609
-- Typecheck all files in the project on startup
607
610
checkProject <- getCheckProject
@@ -621,9 +624,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
621
624
let ! exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces
622
625
liftIO $ atomically $ modifyTVar' (exportsMap shakeExtras) (exportsMap' <> )
623
626
return [keys1, keys2]
624
- return $ (this_options, Set. fromList $ fromNormalizedFilePath <$> newLoaded)
627
+ return $ (this_options, newLoaded)
625
628
626
- let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq , DependencyInfo )
629
+ let consultCradle :: Maybe FilePath -> FilePath -> IO ()
627
630
consultCradle hieYaml cfp = do
628
631
let lfpLog = makeRelative rootDir cfp
629
632
logWith recorder Info $ LogCradlePath lfpLog
@@ -658,32 +661,36 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
658
661
-- The cradle gave us some options so get to work turning them
659
662
-- into and HscEnv.
660
663
Right (opts, libDir, version) -> do
664
+ let ncfp = toNormalizedFilePath' cfp
661
665
let compileTime = fullCompilerVersion
662
666
case reverse $ readP_to_S parseVersion version of
663
667
[] -> error $ " GHC version could not be parsed: " <> version
664
668
((runTime, _): _)
665
669
| compileTime == runTime -> do
666
- (results, allNewLoaded) <- session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
667
- -- delete cfp even if we report No cradle target found for the cfp
670
+ (_results, allNewLoaded) <- session (hieYaml, ncfp, opts, libDir)
668
671
let newLoaded = pendingFiles `Set.intersection` allNewLoaded
669
- -- delete all new loaded
670
- atomically $ forM_ allNewLoaded $ flip S. delete pendingFileSet
671
672
-- log new loaded files
672
673
logWith recorder Info $ LogSessionNewLoadedFiles $ Set. toList newLoaded
673
674
-- remove all new loaded file from error loading files
674
675
atomicModifyIORef' error_loading_files (\ old -> (old `Set.difference` allNewLoaded, () ))
675
676
atomicModifyIORef' cradle_files (\ xs -> (newLoaded <> xs,() ))
676
- return results
677
677
| otherwise -> do
678
678
-- delete cfp from pending files
679
- atomically $ S. delete cfp pendingFileSet
680
- return (([renderPackageSetupException cfp GhcVersionMismatch {.. }], Nothing ),Map. empty)
679
+ atomically $ do
680
+ STM. focus (Focus. insertOrMerge HM. union
681
+ (HM. singleton ncfp (([renderPackageSetupException cfp GhcVersionMismatch {.. }], Nothing ), mempty )))
682
+ hieYaml fileToFlags
683
+ STM. insert hieYaml ncfp filesMap
684
+ S. delete cfp pendingFileSet
681
685
-- Failure case, either a cradle error or the none cradle
682
686
Left err -> do
683
687
let attemptToLoadFiles = (Set. delete cfp $ Set. fromList $ concatMap cradleErrorLoadingFiles err)
684
688
`Set.difference` old_files
685
689
if (not $ null attemptToLoadFiles)
690
+
686
691
then do
692
+ -- we are loading more files and failed, we need to retry
693
+
687
694
-- mark as less loaded files as failedLoadingFiles as possible
688
695
-- limitation is that when we are loading files, and the dependencies of old_files
689
696
-- are changed, and old_files are not valid anymore.
@@ -695,16 +702,16 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
695
702
logWith recorder Info $ LogSessionReloadOnError cfp (Set. toList attemptToLoadFiles)
696
703
consultCradle hieYaml cfp
697
704
else do
705
+ -- we are only loading this file and it failed
698
706
dep_info <- getDependencyInfo ((maybeToList hieYaml) ++ concatMap cradleErrorDependencies err)
699
707
let ncfp = toNormalizedFilePath' cfp
700
708
let res = (map (\ err' -> renderCradleError err' cradle ncfp) err, Nothing )
701
709
-- remove cfp from pending files
702
- atomically $ S. delete cfp pendingFileSet
710
+ atomicModifyIORef' error_loading_files ( \ xs -> ( Set. insert cfp xs, () ))
703
711
atomically $ do
704
712
STM. focus (Focus. insertOrMerge HM. union (HM. singleton ncfp (res, dep_info))) hieYaml fileToFlags
705
- STM. insert hieYaml ncfp filesMap
706
- atomicModifyIORef' error_loading_files (\ xs -> (Set. insert cfp xs,() ))
707
- return (res, dep_info)
713
+ STM. insert hieYaml ncfp filesMap
714
+ S. delete cfp pendingFileSet
708
715
709
716
let
710
717
-- | We allow users to specify a loading strategy.
@@ -727,7 +734,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
727
734
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
728
735
-- Returns the Ghc session and the cradle dependencies
729
736
let sessionOpts :: (Maybe FilePath , FilePath )
730
- -> IO (IdeResult HscEnvEq , DependencyInfo )
737
+ -> IO ()
731
738
sessionOpts (hieYaml, file) = do
732
739
Extra. whenM didSessionLoadingPreferenceConfigChange $ do
733
740
logWith recorder Info LogSessionLoadingChanged
@@ -744,10 +751,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
744
751
745
752
v <- atomically $ fromMaybe HM. empty <$> STM. lookup hieYaml fileToFlags
746
753
case HM. lookup (toNormalizedFilePath' file) v of
747
- Just (opts , old_di) -> do
754
+ Just (_opts , old_di) -> do
748
755
deps_ok <- checkDependencyInfo old_di
749
- if not deps_ok
750
- then do
756
+ when (not deps_ok) $ do
751
757
-- if deps are old, we can try to load the error files again
752
758
atomicModifyIORef' error_loading_files (\ xs -> (Set. delete file xs,() ))
753
759
atomicModifyIORef' cradle_files (\ xs -> (Set. delete file xs,() ))
@@ -759,7 +765,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
759
765
-- Keep the same name cache
760
766
modifyVar_ hscEnvs (return . Map. adjust (const [] ) hieYaml )
761
767
consultCradle hieYaml file
762
- else return (opts, old_di)
763
768
Nothing -> consultCradle hieYaml file
764
769
765
770
let checkInCache :: NormalizedFilePath -> STM (Maybe (IdeResult HscEnvEq , DependencyInfo ))
@@ -772,24 +777,27 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
772
777
-- at a time. Therefore the IORef contains the currently running cradle, if we try
773
778
-- to get some more options then we wait for the currently running action to finish
774
779
-- before attempting to do so.
775
- let getOptions :: FilePath -> IO (IdeResult HscEnvEq , DependencyInfo )
780
+ let getOptions :: FilePath -> IO ()
776
781
getOptions file = do
777
782
let ncfp = toNormalizedFilePath' file
778
783
cachedHieYamlLocation <- atomically $ STM. lookup ncfp filesMap
779
784
hieYaml <- cradleLoc file
780
785
let hieLoc = join cachedHieYamlLocation <|> hieYaml
781
- result <- sessionOpts (hieLoc, file) `Safe.catch` \ e -> do
786
+ sessionOpts (hieLoc, file) `Safe.catch` \ e -> do
782
787
dep <- getDependencyInfo $ maybe [] pure hieYaml
783
- return (([renderPackageSetupException file e], Nothing ), dep)
784
- atomically $ STM. focus (Focus. insertOrMerge HM. union (HM. singleton ncfp result)) hieLoc fileToFlags
785
- return result
788
+ let errorResult = (([renderPackageSetupException file e], Nothing ), dep)
789
+ atomically $ do
790
+ STM. focus (Focus. insertOrMerge HM. union (HM. singleton ncfp errorResult)) hieLoc fileToFlags
791
+ STM. insert hieYaml ncfp filesMap
792
+ -- delete file from pending files
793
+ S. delete file pendingFileSet
786
794
787
795
let getOptionsLoop :: IO ()
788
796
getOptionsLoop = do
789
797
-- Get the next file to load
790
798
absFile <- atomically $ S. readQueue pendingFileSet
791
799
logWith recorder Info (LogGetOptionsLoop absFile)
792
- void $ getOptions absFile
800
+ getOptions absFile
793
801
getOptionsLoop
794
802
795
803
-- | Given a file, this function will return the HscEnv and the dependencies
0 commit comments