Skip to content

Commit faa2d8b

Browse files
committed
WIP fix: do not check for file existance when added to the context and
add all alternate file to knownFiles This need to be investigated. The different `-boot` tests are flaky / failing in this MR because of this.
1 parent 8a1f3d4 commit faa2d8b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ import GHC.Driver.Errors.Types
124124
import GHC.Types.Error (errMsgDiagnostic,
125125
singleMessage)
126126
import GHC.Unit.State
127+
import Debug.Trace (traceShow)
128+
import Text.Pretty.Simple (pPrint)
129+
import Debug.Pretty.Simple (pTraceShow, pTraceShowId)
127130

128131
#if MIN_VERSION_ghc(9,13,0)
129132
import GHC.Driver.Make (checkHomeUnitsClosed)
@@ -476,11 +479,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
476479
-- If we don't generate a TargetFile for each potential location, we will only have
477480
-- 'TargetFile Foo.hs' in the 'knownTargetsVar', thus not find 'TargetFile Foo.hs-boot'
478481
-- and also not find 'TargetModule Foo'.
479-
fs <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
480-
pure $ map (\fp -> (TargetFile fp, Set.singleton fp)) (nubOrd (f:fs))
482+
pure $ do
483+
file <- nubOrd (f:targetLocations)
484+
pure $ (TargetFile file, Set.singleton file)
481485
TargetModule _ -> do
482-
found <- filterM (IO.doesFileExist . fromNormalizedFilePath) targetLocations
483-
return [(targetTarget, Set.fromList found)]
486+
pure [(targetTarget, Set.fromList targetLocations)]
484487
hasUpdate <- atomically $ do
485488
known <- readTVar knownTargetsVar
486489
let known' = flip mapHashed known $ \k -> unionKnownTargets k (mkKnownTargets knownTargets)
@@ -544,9 +547,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
544547
pure (Map.insert hieYaml (NE.toList all_deps) m, (new,old))
545548

546549

547-
let session :: (Maybe FilePath, NormalizedFilePath, ComponentOptions, FilePath)
550+
let sessionTortue :: (Maybe FilePath, NormalizedFilePath, ComponentOptions, FilePath)
548551
-> IO (IdeResult HscEnvEq,[FilePath])
549-
session args@(hieYaml, _cfp, _opts, _libDir) = do
552+
sessionTortue args@(hieYaml, _cfp, _opts, _libDir) = do
550553
(new_deps, old_deps) <- packageSetup args
551554

552555
-- For each component, now make a new HscEnvEq which contains the
@@ -574,13 +577,13 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
574577
])
575578
Nothing
576579

577-
void $ modifyVar' fileToFlags $ Map.insert hieYaml this_flags_map
580+
void $ modifyVar' fileToFlags $ pTraceShow ("this_flags_map", this_flags_map) $ Map.insert hieYaml this_flags_map
578581
void $ modifyVar' filesMap $ flip HM.union (HM.fromList (map ((,hieYaml) . fst) $ concatMap toFlagsMap all_targets))
579582
-- The VFS doesn't change on cradle edits, re-use the old one.
580583
-- Invalidate all the existing GhcSession build nodes by restarting the Shake session
581584
keys2 <- invalidateShakeCache
582585
restartShakeSession VFSUnmodified "new component" [] $ do
583-
keys1 <- extendKnownTargets all_targets
586+
keys1 <- extendKnownTargets $ pTraceShow ("all_targets", all_targets) all_targets
584587
return [keys1, keys2]
585588

586589
-- Typecheck all files in the project on startup
@@ -630,15 +633,15 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
630633
((runTime, _):_)
631634
| compileTime == runTime -> do
632635
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))
633-
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
636+
sessionTortue (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
634637
| otherwise -> return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
635638
-- Failure case, either a cradle error or the none cradle
636639
Left err -> do
637640
dep_info <- getDependencyInfo (maybeToList hieYaml)
638641
let ncfp = toNormalizedFilePath' cfp
639642
let res = (map (\err' -> renderCradleError err' cradle ncfp) err, Nothing)
640643
void $ modifyVar' fileToFlags $
641-
Map.insertWith HM.union hieYaml (HM.singleton ncfp (res, dep_info))
644+
Map.insertWith HM.union hieYaml (pTraceShow ("ncfp", ncfp) $ HM.singleton ncfp (res, dep_info))
642645
void $ modifyVar' filesMap $ HM.insert ncfp hieYaml
643646
return (res, maybe [] pure hieYaml ++ concatMap cradleErrorDependencies err)
644647

@@ -676,9 +679,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
676679

677680
v <- Map.findWithDefault HM.empty hieYaml <$> readVar fileToFlags
678681
let cfp = toAbsolutePath file
682+
pPrint ("sessionOpts", cfp)
679683
case HM.lookup (toNormalizedFilePath' cfp) v of
680684
Just (opts, old_di) -> do
681685
deps_ok <- checkDependencyInfo old_di
686+
pPrint ("deps_ok", deps_ok, old_di)
682687
if not deps_ok
683688
then do
684689
-- If the dependencies are out of date then clear both caches and start
@@ -687,9 +692,12 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
687692
modifyVar_ filesMap (const (return HM.empty))
688693
-- Keep the same name cache
689694
modifyVar_ hscEnvs (return . Map.adjust (const []) hieYaml )
695+
pPrint ("consultCradle not deps_ok", cfp)
690696
consultCradle hieYaml cfp
691697
else return (opts, Map.keys old_di)
692-
Nothing -> consultCradle hieYaml cfp
698+
Nothing -> do
699+
pPrint ("consultCradle Nothing", cfp)
700+
consultCradle hieYaml cfp
693701

694702
-- The main function which gets options for a file. We only want one of these running
695703
-- at a time. Therefore the IORef contains the currently running cradle, if we try
@@ -764,6 +772,7 @@ data TargetDetails = TargetDetails
764772
targetDepends :: !DependencyInfo,
765773
targetLocations :: ![NormalizedFilePath]
766774
}
775+
deriving (Show)
767776

768777
fromTargetId :: [FilePath] -- ^ import paths
769778
-> [String] -- ^ extensions to consider

0 commit comments

Comments
 (0)