Skip to content

Commit

Permalink
Improve fullModuleGraph code path
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Dec 20, 2022
1 parent 113b214 commit 616d328
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import Control.Concurrent.STM.TVar
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import Data.List
import Data.List.Extra (nubOrdOn)
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Text.Utf16.Rope as Rope
Expand Down Expand Up @@ -159,6 +160,7 @@ import qualified Data.IntMap as IM
import GHC.Unit.Module.Graph
import GHC.Unit.Env
#endif
import GHC (mgModSummaries)

data Log
= LogShake Shake.Log
Expand Down Expand Up @@ -792,10 +794,31 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
ifaces <- uses_ GetModIface deps
let inLoadOrder = map (\HiFileResult{..} -> HomeModInfo hirModIface hirModDetails Nothing) ifaces
mg <- depModuleGraph <$>
mg <- do
if fullModuleGraph
then useNoFile_ GetModuleGraph
else dependencyInfoForFiles [file]
then depModuleGraph <$> useNoFile_ GetModuleGraph
else do
let mgs = map hsc_mod_graph depSessions
#if MIN_VERSION_ghc(9,3,0)
-- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
-- also points to all the direct descendants of the current module. To get the keys for the descendants
-- we must get their `ModSummary`s
!final_deps <- do
dep_mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
return $!! map (NodeKey_Module . msKey) dep_mss
let module_graph_nodes =
nubOrdOn mkNodeKey (ModuleNode final_deps ms : concatMap mgModSummaries' mgs)
#else
let module_graph_nodes =
#if MIN_VERSION_ghc(9,2,0)
-- We don't do any instantiation for backpack at this point of time, so it is OK to use
-- 'extendModSummaryNoDeps'.
-- This may have to change in the future.
map extendModSummaryNoDeps $
#endif
nubOrdOn ms_mod (ms : concatMap mgModSummaries mgs)
#endif
pure $ mkModuleGraph module_graph_nodes
session' <- liftIO $ mergeEnvs hsc mg ms inLoadOrder depSessions

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

0 comments on commit 616d328

Please sign in to comment.