Skip to content

Commit

Permalink
Don't use typecheck rule for non FOIs in refine imports plugin
Browse files Browse the repository at this point in the history
Also add an assertion to check that we never use non-FOI rules

Fixes #2962
  • Loading branch information
wz1000 committed Jul 20, 2022
1 parent 100b53a commit b710651
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ data Log
| LogLoadingHieFileFail !FilePath !SomeException
| LogLoadingHieFileSuccess !FilePath
| LogExactPrint ExactPrint.Log
| LogTypecheckedFOI !NormalizedFilePath
deriving Show

instance Pretty Log where
Expand All @@ -182,6 +183,14 @@ instance Pretty Log where
LogLoadingHieFileSuccess path ->
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
LogExactPrint log -> pretty log
LogTypecheckedFOI path -> vcat
[ "WARNING: Typechecked a file which is not currently open in the editor:" <+> pretty path
, "This can indicate a bug which results in excessive memory usage."
, "This may be a spurious warning if you have recently closed the file."
, "If you haven't opened this file recently, please file a report on the issue tracker mentioning"
<+> "the HLS version being used, the plugins enabled, and if possible the codebase and file which"
<+> "triggered this warning."
]

templateHaskellInstructions :: T.Text
templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries"
Expand Down Expand Up @@ -650,7 +659,13 @@ typeCheckRule :: Recorder (WithPriority Log) -> Rules ()
typeCheckRule recorder = define (cmapWithPrio LogShake recorder) $ \TypeCheck file -> do
pm <- use_ GetParsedModule file
hsc <- hscEnv <$> use_ GhcSessionDeps file
typeCheckRuleDefinition hsc pm
foi <- use_ IsFileOfInterest file
-- We should only call the typecheck rule for files of interest.
-- Keeping typechecked modules in memory for other files is
-- very expensive.
case foi of
NotFOI -> logWith recorder Logger.Info $ LogTypecheckedFOI f
IsFOI {} -> typeCheckRuleDefinition hsc pm

knownFilesRule :: Recorder (WithPriority Log) -> Rules ()
knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorder) $ \GetKnownTargets -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm
-- second layer is from the imports of first layer to their imports
ImportMap importIm <- use_ GetImportMap path
forM importIm $ \imp_path -> do
imp_tmr <- use_ TypeCheck imp_path
return $ tcg_exports $ tmrTypechecked imp_tmr
imp_hir <- use_ GetModIface imp_path
return $ mi_exports $ hirModIface imp_hir

-- Use the GHC api to extract the "minimal" imports
-- We shouldn't blindly refine imports
Expand Down

0 comments on commit b710651

Please sign in to comment.