@@ -67,6 +67,7 @@ import Control.Applicative (liftA2)
67
67
#endif
68
68
import Control.Concurrent.Async (concurrently )
69
69
import Control.Concurrent.Strict
70
+ import Control.DeepSeq
70
71
import Control.Exception.Safe
71
72
import Control.Monad.Extra
72
73
import Control.Monad.Reader
@@ -668,7 +669,7 @@ typeCheckRule recorder = define (cmapWithPrio LogShake recorder) $ \TypeCheck fi
668
669
-- very expensive.
669
670
when (foi == NotFOI ) $
670
671
logWith recorder Logger. Warning $ LogTypecheckedFOI file
671
- typeCheckRuleDefinition hsc pm file
672
+ typeCheckRuleDefinition hsc pm
672
673
673
674
knownFilesRule :: Recorder (WithPriority Log ) -> Rules ()
674
675
knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorder) $ \ GetKnownTargets -> do
@@ -689,9 +690,8 @@ getModuleGraphRule recorder = defineNoFile (cmapWithPrio LogShake recorder) $ \G
689
690
typeCheckRuleDefinition
690
691
:: HscEnv
691
692
-> ParsedModule
692
- -> NormalizedFilePath
693
693
-> Action (IdeResult TcModuleResult )
694
- typeCheckRuleDefinition hsc pm file = do
694
+ typeCheckRuleDefinition hsc pm = do
695
695
setPriority priorityTypeCheck
696
696
IdeOptions { optDefer = defer } <- getIdeOptions
697
697
@@ -759,6 +759,11 @@ instance Default GhcSessionDepsConfig where
759
759
{ checkForImportCycles = True
760
760
}
761
761
762
+ -- | Note [GhcSessionDeps]
763
+ -- For a file 'Foo', GhcSessionDeps "Foo.hs" results in an HscEnv which includes
764
+ -- 1. HomeModInfo's (in the HUG/HPT) for all modules in the transitive closure of "Foo", **NOT** including "Foo" itself.
765
+ -- 2. ModSummary's (in the ModuleGraph) for all modules in the transitive closure of "Foo", including "Foo" itself.
766
+ -- 3. ModLocation's (in the FinderCache) all modules in the transitive closure of "Foo", including "Foo" itself.
762
767
ghcSessionDepsDefinition
763
768
:: -- | full mod summary
764
769
Bool ->
@@ -771,27 +776,25 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
771
776
Nothing -> return Nothing
772
777
Just deps -> do
773
778
when checkForImportCycles $ void $ uses_ ReportImportCycles deps
774
- mss <- map msrModSummary <$> if fullModSummary
775
- then uses_ GetModSummary deps
776
- else uses_ GetModSummaryWithoutTimestamps deps
779
+ ms <- msrModSummary <$> if fullModSummary
780
+ then use_ GetModSummary file
781
+ else use_ GetModSummaryWithoutTimestamps file
777
782
778
783
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
779
784
ifaces <- uses_ GetModIface deps
780
785
let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails Nothing ) ifaces
781
786
#if MIN_VERSION_ghc(9,3,0)
782
- mss_imports <- uses_ GetLocatedImports (file : deps)
783
- final_deps <- forM mss_imports $ \ imports -> do
784
- let fs = mapMaybe (fmap artifactFilePath . snd ) imports
785
- dep_mss <- map msrModSummary <$> if fullModSummary
786
- then uses_ GetModSummary fs
787
- else uses_ GetModSummaryWithoutTimestamps fs
788
- return (map (NodeKey_Module . msKey) dep_mss)
789
- ms <- msrModSummary <$> use_ GetModSummary file
790
- let moduleNodes = zipWith ModuleNode final_deps (ms : mss)
787
+ -- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
788
+ -- also points to all the direct descendents of the current module. To get the keys for the descendents
789
+ -- we must get their `ModSummary`s
790
+ ! final_deps <- do
791
+ dep_mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
792
+ return $!! map (NodeKey_Module . msKey) dep_mss
793
+ let moduleNode = (ms, final_deps)
791
794
#else
792
- let moduleNodes = mss
795
+ let moduleNode = ms
793
796
#endif
794
- session' <- liftIO $ mergeEnvs hsc moduleNodes inLoadOrder depSessions
797
+ session' <- liftIO $ mergeEnvs hsc moduleNode inLoadOrder depSessions
795
798
796
799
Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [] )
797
800
@@ -996,7 +999,7 @@ regenerateHiFile sess f ms compNeeded = do
996
999
Just pm -> do
997
1000
-- Invoke typechecking directly to update it without incurring a dependency
998
1001
-- on the parsed module and the typecheck rules
999
- (diags', mtmr) <- typeCheckRuleDefinition hsc pm f
1002
+ (diags', mtmr) <- typeCheckRuleDefinition hsc pm
1000
1003
case mtmr of
1001
1004
Nothing -> pure (diags', Nothing )
1002
1005
Just tmr -> do
0 commit comments