Skip to content

Commit 0b64655

Browse files
committed
Improve fullModuleGraph code path
1 parent 948c7dd commit 0b64655

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import Control.Concurrent.STM.TVar
8686
import Data.IntMap.Strict (IntMap)
8787
import qualified Data.IntMap.Strict as IntMap
8888
import Data.List
89+
import Data.List.Extra (nubOrdOn)
8990
import qualified Data.Map as M
9091
import Data.Maybe
9192
import qualified Data.Text.Utf16.Rope as Rope
@@ -159,6 +160,7 @@ import qualified Data.IntMap as IM
159160
import GHC.Unit.Module.Graph
160161
import GHC.Unit.Env
161162
#endif
163+
import GHC (mgModSummaries)
162164

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

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

0 commit comments

Comments
 (0)