Skip to content

Commit 36e205f

Browse files
committed
Improve fullModuleGraph code path
1 parent 1fe8e80 commit 36e205f

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
@@ -88,6 +88,7 @@ import Control.Concurrent.STM.TVar
8888
import Data.IntMap.Strict (IntMap)
8989
import qualified Data.IntMap.Strict as IntMap
9090
import Data.List
91+
import Data.List.Extra (nubOrdOn)
9192
import qualified Data.Map as M
9293
import Data.Maybe
9394
import Data.Proxy
@@ -166,6 +167,7 @@ import GHC.Unit.Env
166167
#if MIN_VERSION_ghc(9,5,0)
167168
import GHC.Unit.Home.ModInfo
168169
#endif
170+
import GHC (mgModSummaries)
169171

170172
data Log
171173
= LogShake Shake.Log
@@ -798,10 +800,31 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
798800
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
799801
ifaces <- uses_ GetModIface deps
800802
let inLoadOrder = map (\HiFileResult{..} -> HomeModInfo hirModIface hirModDetails emptyHomeModInfoLinkable) ifaces
801-
mg <- depModuleGraph <$>
803+
mg <- do
802804
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
805828
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions
806829

807830
-- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new

0 commit comments

Comments
 (0)