Skip to content

Commit 1fe8e80

Browse files
committed
Replace checkForImportCycles option with fullModuleGraph option that restores the old behaviour
1 parent 74d93cf commit 1fe8e80

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
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,
@@ -674,7 +670,11 @@ knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorde
674670
getModuleGraphRule :: Recorder (WithPriority Log) -> Rules ()
675671
getModuleGraphRule recorder = defineNoFile (cmapWithPrio LogShake recorder) $ \GetModuleGraph -> do
676672
fs <- toKnownFiles <$> useNoFile_ GetKnownTargets
677-
(rawDepInfo, bm) <- rawDependencyInformation (HashSet.toList fs)
673+
dependencyInfoForFiles (HashSet.toList fs)
674+
675+
dependencyInfoForFiles :: [NormalizedFilePath] -> Action DependencyInformation
676+
dependencyInfoForFiles fs = do
677+
(rawDepInfo, bm) <- rawDependencyInformation fs
678678
let (all_fs, _all_ids) = unzip $ HM.toList $ pathToIdMap $ rawPathIdMap rawDepInfo
679679
mss <- map (fmap msrModSummary) <$> uses GetModSummaryWithoutTimestamps all_fs
680680
#if MIN_VERSION_ghc(9,3,0)
@@ -767,11 +767,11 @@ loadGhcSession recorder ghcSessionDepsConfig = do
767767
ghcSessionDepsDefinition fullModSummary ghcSessionDepsConfig env file
768768

769769
newtype GhcSessionDepsConfig = GhcSessionDepsConfig
770-
{ checkForImportCycles :: Bool
770+
{ fullModuleGraph :: Bool
771771
}
772772
instance Default GhcSessionDepsConfig where
773773
def = GhcSessionDepsConfig
774-
{ checkForImportCycles = True
774+
{ fullModuleGraph = True
775775
}
776776

777777
-- | Note [GhcSessionDeps]
@@ -790,15 +790,18 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
790790
case mbdeps of
791791
Nothing -> return Nothing
792792
Just deps -> do
793-
when checkForImportCycles $ void $ uses_ ReportImportCycles deps
793+
when fullModuleGraph $ void $ uses_ ReportImportCycles deps
794794
ms <- msrModSummary <$> if fullModSummary
795795
then use_ GetModSummary file
796796
else use_ GetModSummaryWithoutTimestamps file
797797

798798
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
799799
ifaces <- uses_ GetModIface deps
800800
let inLoadOrder = map (\HiFileResult{..} -> HomeModInfo hirModIface hirModDetails emptyHomeModInfoLinkable) ifaces
801-
mg <- depModuleGraph <$> useNoFile_ GetModuleGraph
801+
mg <- depModuleGraph <$>
802+
if fullModuleGraph
803+
then useNoFile_ GetModuleGraph
804+
else dependencyInfoForFiles [file]
802805
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
803806

804807
-- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new
@@ -1203,8 +1206,16 @@ newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (Mod
12031206
instance IsIdeGlobal CompiledLinkables
12041207

12051208
data RulesConfig = RulesConfig
1206-
{ -- | Disable import cycle checking for improved performance in large codebases
1207-
checkForImportCycles :: Bool
1209+
{ -- | Share the computation for the entire module graph
1210+
-- We usually compute the full module graph for the project
1211+
-- and share it for all files.
1212+
-- However, in large projects it might not be desirable to wait
1213+
-- for computing the entire module graph before starting to
1214+
-- typecheck a particular file.
1215+
-- Disabling this drastically decreases sharing and is likely to
1216+
-- increase memory usage if you have multiple files open
1217+
-- Disabling this also disables checking for import cycles
1218+
fullModuleGraph :: Bool
12081219
-- | Disable TH for improved performance in large codebases
12091220
, enableTemplateHaskell :: Bool
12101221
-- | Warning to show when TH is not supported by the current HLS binary
@@ -1241,7 +1252,7 @@ mainRule recorder RulesConfig{..} = do
12411252
reportImportCyclesRule recorder
12421253
typeCheckRule recorder
12431254
getDocMapRule recorder
1244-
loadGhcSession recorder def{checkForImportCycles}
1255+
loadGhcSession recorder def{fullModuleGraph}
12451256
getModIfaceFromDiskRule recorder
12461257
getModIfaceFromDiskAndIndexRule recorder
12471258
getModIfaceRule recorder

0 commit comments

Comments
 (0)