@@ -86,6 +86,7 @@ import Control.Concurrent.STM.TVar
86
86
import Data.IntMap.Strict (IntMap )
87
87
import qualified Data.IntMap.Strict as IntMap
88
88
import Data.List
89
+ import Data.List.Extra (nubOrdOn )
89
90
import qualified Data.Map as M
90
91
import Data.Maybe
91
92
import qualified Data.Text.Utf16.Rope as Rope
@@ -159,6 +160,7 @@ import qualified Data.IntMap as IM
159
160
import GHC.Unit.Module.Graph
160
161
import GHC.Unit.Env
161
162
#endif
163
+ import GHC (mgModSummaries )
162
164
163
165
data Log
164
166
= LogShake Shake. Log
@@ -792,10 +794,31 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
792
794
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
793
795
ifaces <- uses_ GetModIface deps
794
796
let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails Nothing ) ifaces
795
- mg <- depModuleGraph <$>
797
+ mg <- do
796
798
if fullModuleGraph
797
- then useNoFile_ GetModuleGraph
798
- else dependencyInfoForFiles [file]
799
+ then depModuleGraph <$> useNoFile_ GetModuleGraph
800
+ else do
801
+ let mgs = map hsc_mod_graph depSessions
802
+ #if MIN_VERSION_ghc(9,3,0)
803
+ -- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
804
+ -- also points to all the direct descendants of the current module. To get the keys for the descendants
805
+ -- we must get their `ModSummary`s
806
+ ! final_deps <- do
807
+ dep_mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
808
+ return $!! map (NodeKey_Module . msKey) dep_mss
809
+ let module_graph_nodes =
810
+ nubOrdOn mkNodeKey (ModuleNode final_deps ms : concatMap mgModSummaries' mgs)
811
+ #else
812
+ let module_graph_nodes =
813
+ #if MIN_VERSION_ghc(9,2,0)
814
+ -- We don't do any instantiation for backpack at this point of time, so it is OK to use
815
+ -- 'extendModSummaryNoDeps'.
816
+ -- This may have to change in the future.
817
+ map extendModSummaryNoDeps $
818
+ #endif
819
+ nubOrdOn ms_mod (ms : concatMap mgModSummaries mgs)
820
+ #endif
821
+ pure $ mkModuleGraph module_graph_nodes
799
822
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
800
823
801
824
Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [] )
0 commit comments