Skip to content

Commit 113b214

Browse files
committed
Replace checkForImportCycles option with fullModuleGraph option that restores the old behaviour
1 parent 7934342 commit 113b214

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ module Development.IDE.Core.Rules(
1414
IdeState, GetParsedModule(..), TransitiveDependencies(..),
1515
Priority(..), GhcSessionIO(..), GetClientSettings(..),
1616
-- * Functions
17-
--
18-
--
19-
--
20-
--
2117
priorityTypeCheck,
2218
priorityGenerateCore,
2319
priorityFilesOfInterest,
@@ -668,7 +664,11 @@ knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorde
668664
getModuleGraphRule :: Recorder (WithPriority Log) -> Rules ()
669665
getModuleGraphRule recorder = defineNoFile (cmapWithPrio LogShake recorder) $ \GetModuleGraph -> do
670666
fs <- toKnownFiles <$> useNoFile_ GetKnownTargets
671-
(rawDepInfo, bm) <- rawDependencyInformation (HashSet.toList fs)
667+
dependencyInfoForFiles (HashSet.toList fs)
668+
669+
dependencyInfoForFiles :: [NormalizedFilePath] -> Action DependencyInformation
670+
dependencyInfoForFiles fs = do
671+
(rawDepInfo, bm) <- rawDependencyInformation fs
672672
let (all_fs, _all_ids) = unzip $ HM.toList $ pathToIdMap $ rawPathIdMap rawDepInfo
673673
mss <- map (fmap msrModSummary) <$> uses GetModSummaryWithoutTimestamps all_fs
674674
#if MIN_VERSION_ghc(9,3,0)
@@ -761,11 +761,11 @@ loadGhcSession recorder ghcSessionDepsConfig = do
761761
ghcSessionDepsDefinition fullModSummary ghcSessionDepsConfig env file
762762

763763
newtype GhcSessionDepsConfig = GhcSessionDepsConfig
764-
{ checkForImportCycles :: Bool
764+
{ fullModuleGraph :: Bool
765765
}
766766
instance Default GhcSessionDepsConfig where
767767
def = GhcSessionDepsConfig
768-
{ checkForImportCycles = True
768+
{ fullModuleGraph = True
769769
}
770770

771771
-- | Note [GhcSessionDeps]
@@ -784,15 +784,18 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
784784
case mbdeps of
785785
Nothing -> return Nothing
786786
Just deps -> do
787-
when checkForImportCycles $ void $ uses_ ReportImportCycles deps
787+
when fullModuleGraph $ void $ uses_ ReportImportCycles deps
788788
ms <- msrModSummary <$> if fullModSummary
789789
then use_ GetModSummary file
790790
else use_ GetModSummaryWithoutTimestamps file
791791

792792
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
793793
ifaces <- uses_ GetModIface deps
794794
let inLoadOrder = map (\HiFileResult{..} -> HomeModInfo hirModIface hirModDetails Nothing) ifaces
795-
mg <- depModuleGraph <$> useNoFile_ GetModuleGraph
795+
mg <- depModuleGraph <$>
796+
if fullModuleGraph
797+
then useNoFile_ GetModuleGraph
798+
else dependencyInfoForFiles [file]
796799
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
797800

798801
Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [])
@@ -1192,8 +1195,16 @@ newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (Mod
11921195
instance IsIdeGlobal CompiledLinkables
11931196

11941197
data RulesConfig = RulesConfig
1195-
{ -- | Disable import cycle checking for improved performance in large codebases
1196-
checkForImportCycles :: Bool
1198+
{ -- | Share the computation for the entire module graph
1199+
-- We usually compute the full module graph for the project
1200+
-- and share it for all files.
1201+
-- However, in large projects it might not be desirable to wait
1202+
-- for computing the entire module graph before starting to
1203+
-- typecheck a particular file.
1204+
-- Disabling this drastically decreases sharing and is likely to
1205+
-- increase memory usage if you have multiple files open
1206+
-- Disabling this also disables checking for import cycles
1207+
fullModuleGraph :: Bool
11971208
-- | Disable TH for improved performance in large codebases
11981209
, enableTemplateHaskell :: Bool
11991210
-- | Warning to show when TH is not supported by the current HLS binary
@@ -1230,7 +1241,7 @@ mainRule recorder RulesConfig{..} = do
12301241
reportImportCyclesRule recorder
12311242
typeCheckRule recorder
12321243
getDocMapRule recorder
1233-
loadGhcSession recorder def{checkForImportCycles}
1244+
loadGhcSession recorder def{fullModuleGraph}
12341245
getModIfaceFromDiskRule recorder
12351246
getModIfaceFromDiskAndIndexRule recorder
12361247
getModIfaceRule recorder

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ import Development.IDE (GetModuleGraph (.
6767
useNoFile_,
6868
useWithStale_,
6969
use_, uses_)
70-
import Development.IDE.Core.Rules (GhcSessionDepsConfig (..),
71-
ghcSessionDepsDefinition)
70+
import Development.IDE.Core.Rules (ghcSessionDepsDefinition)
7271
import Development.IDE.GHC.Compat hiding (typeKind,
7372
unitState)
7473
import qualified Development.IDE.GHC.Compat as Compat
@@ -571,8 +570,6 @@ runGetSession st nfp = liftIO $ runAction "eval" st $ do
571570
((_, res),_) <- liftIO $ loadSessionFun fp
572571
let env = fromMaybe (error $ "Unknown file: " <> fp) res
573572
ghcSessionDepsConfig = def
574-
{ checkForImportCycles = False
575-
}
576573
res <- fmap hscEnvWithImportPaths <$> ghcSessionDepsDefinition True ghcSessionDepsConfig env nfp
577574
return $ fromMaybe (error $ "Unable to load file: " <> fp) res
578575

0 commit comments

Comments
 (0)