@@ -88,6 +88,7 @@ import Control.Concurrent.STM.TVar
88
88
import Data.IntMap.Strict (IntMap )
89
89
import qualified Data.IntMap.Strict as IntMap
90
90
import Data.List
91
+ import Data.List.Extra (nubOrdOn )
91
92
import qualified Data.Map as M
92
93
import Data.Maybe
93
94
import Data.Proxy
@@ -166,6 +167,7 @@ import GHC.Unit.Env
166
167
#if MIN_VERSION_ghc(9,5,0)
167
168
import GHC.Unit.Home.ModInfo
168
169
#endif
170
+ import GHC (mgModSummaries )
169
171
170
172
data Log
171
173
= LogShake Shake. Log
@@ -798,10 +800,31 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
798
800
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
799
801
ifaces <- uses_ GetModIface deps
800
802
let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails emptyHomeModInfoLinkable) ifaces
801
- mg <- depModuleGraph <$>
803
+ mg <- do
802
804
if fullModuleGraph
803
- then useNoFile_ GetModuleGraph
804
- else dependencyInfoForFiles [file]
805
+ then depModuleGraph <$> useNoFile_ GetModuleGraph
806
+ else do
807
+ let mgs = map hsc_mod_graph depSessions
808
+ #if MIN_VERSION_ghc(9,3,0)
809
+ -- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
810
+ -- also points to all the direct descendants of the current module. To get the keys for the descendants
811
+ -- we must get their `ModSummary`s
812
+ ! final_deps <- do
813
+ dep_mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
814
+ return $!! map (NodeKey_Module . msKey) dep_mss
815
+ let module_graph_nodes =
816
+ nubOrdOn mkNodeKey (ModuleNode final_deps ms : concatMap mgModSummaries' mgs)
817
+ #else
818
+ let module_graph_nodes =
819
+ #if MIN_VERSION_ghc(9,2,0)
820
+ -- We don't do any instantiation for backpack at this point of time, so it is OK to use
821
+ -- 'extendModSummaryNoDeps'.
822
+ -- This may have to change in the future.
823
+ map extendModSummaryNoDeps $
824
+ #endif
825
+ nubOrdOn ms_mod (ms : concatMap mgModSummaries mgs)
826
+ #endif
827
+ pure $ mkModuleGraph module_graph_nodes
805
828
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
806
829
807
830
-- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new
0 commit comments