Skip to content

Commit 2f059f8

Browse files
committed
Improve fullModuleGraph code path
1 parent 113b214 commit 2f059f8

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

‎ghcide/src/Development/IDE/Core/Rules.hs‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import Control.Concurrent.STM.TVar
8686
importData.IntMap.Strict (IntMap)
8787
importqualifiedData.IntMap.StrictasIntMap
8888
importData.List
89+
importData.List.Extra (nubOrdOn)
8990
importqualifiedData.MapasM
9091
importData.Maybe
9192
importqualifiedData.Text.Utf16.RopeasRope
@@ -159,6 +160,9 @@ import qualified Data.IntMap as IM
159160
importGHC.Unit.Module.Graph
160161
importGHC.Unit.Env
161162
#endif
163+
#if MIN_VERSION_ghc(9,2,0)
164+
importGHC (mgModSummaries)
165+
#endif
162166

163167
dataLog
164168
=LogShakeShake.Log
@@ -792,10 +796,31 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
792796
depSessions <-map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
793797
ifaces <- uses_ GetModIface deps
794798
let inLoadOrder =map (\HiFileResult{..} ->HomeModInfo hirModIface hirModDetails Nothing) ifaces
795-
mg <-depModuleGraph <$>
799+
mg <-do
796800
if fullModuleGraph
797-
then useNoFile_ GetModuleGraph
798-
else dependencyInfoForFiles [file]
801+
then depModuleGraph <$> useNoFile_ GetModuleGraph
802+
elsedo
803+
let mgs =map hsc_mod_graph depSessions
804+
#if MIN_VERSION_ghc(9,3,0)
805+
-- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
806+
-- also points to all the direct descendants of the current module. To get the keys for the descendants
807+
-- we must get their `ModSummary`s
808+
!final_deps <-do
809+
dep_mss <-map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
810+
return$!!map (NodeKey_Module. msKey) dep_mss
811+
let module_graph_nodes =
812+
nubOrdOn mkNodeKey (ModuleNode final_deps ms :concatMap mgModSummaries' mgs)
813+
#else
814+
let module_graph_nodes =
815+
#if MIN_VERSION_ghc(9,2,0)
816+
-- We don't do any instantiation for backpack at this point of time, so it is OK to use
817+
-- 'extendModSummaryNoDeps'.
818+
-- This may have to change in the future.
819+
map extendModSummaryNoDeps $
820+
#endif
821+
nubOrdOn ms_mod (ms :concatMap mgModSummaries mgs)
822+
#endif
823+
pure$ mkModuleGraph module_graph_nodes
799824
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
800825

801826
Just<$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [])

0 commit comments

Comments
(0)