@@ -67,6 +67,7 @@ import Control.Applicative (liftA2)
6767#endif
6868import Control.Concurrent.Async (concurrently )
6969import Control.Concurrent.Strict
70+ import Control.DeepSeq
7071import Control.Exception.Safe
7172import Control.Monad.Extra
7273import Control.Monad.Reader
@@ -668,7 +669,7 @@ typeCheckRule recorder = define (cmapWithPrio LogShake recorder) $ \TypeCheck fi
668669 -- very expensive.
669670 when (foi == NotFOI ) $
670671 logWith recorder Logger. Warning $ LogTypecheckedFOI file
671- typeCheckRuleDefinition hsc pm file
672+ typeCheckRuleDefinition hsc pm
672673
673674knownFilesRule :: Recorder (WithPriority Log ) -> Rules ()
674675knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorder) $ \ GetKnownTargets -> do
@@ -689,9 +690,8 @@ getModuleGraphRule recorder = defineNoFile (cmapWithPrio LogShake recorder) $ \G
689690typeCheckRuleDefinition
690691 :: HscEnv
691692 -> ParsedModule
692- -> NormalizedFilePath
693693 -> Action (IdeResult TcModuleResult )
694- typeCheckRuleDefinition hsc pm file = do
694+ typeCheckRuleDefinition hsc pm = do
695695 setPriority priorityTypeCheck
696696 IdeOptions { optDefer = defer } <- getIdeOptions
697697
@@ -759,6 +759,11 @@ instance Default GhcSessionDepsConfig where
759759 { checkForImportCycles = True
760760 }
761761
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.
762767ghcSessionDepsDefinition
763768 :: -- | full mod summary
764769 Bool ->
@@ -771,27 +776,25 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
771776 Nothing -> return Nothing
772777 Just deps -> do
773778 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
777782
778783 depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
779784 ifaces <- uses_ GetModIface deps
780785 let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails Nothing ) ifaces
781786#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)
791794#else
792- let moduleNodes = mss
795+ let moduleNode = ms
793796#endif
794- session' <- liftIO $ mergeEnvs hsc moduleNodes inLoadOrder depSessions
797+ session' <- liftIO $ mergeEnvs hsc moduleNode inLoadOrder depSessions
795798
796799 Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [] )
797800
@@ -996,7 +999,7 @@ regenerateHiFile sess f ms compNeeded = do
996999 Just pm -> do
9971000 -- Invoke typechecking directly to update it without incurring a dependency
9981001 -- on the parsed module and the typecheck rules
999- (diags', mtmr) <- typeCheckRuleDefinition hsc pm f
1002+ (diags', mtmr) <- typeCheckRuleDefinition hsc pm
10001003 case mtmr of
10011004 Nothing -> pure (diags', Nothing )
10021005 Just tmr -> do
0 commit comments