@@ -14,6 +14,10 @@ module Development.IDE.Core.Rules(
1414 IdeState , GetParsedModule (.. ), TransitiveDependencies (.. ),
1515 Priority (.. ), GhcSessionIO (.. ), GetClientSettings (.. ),
1616 -- * Functions
17+ --
18+ --
19+ --
20+ --
1721 priorityTypeCheck ,
1822 priorityGenerateCore ,
1923 priorityFilesOfInterest ,
@@ -23,7 +27,6 @@ module Development.IDE.Core.Rules(
2327 defineEarlyCutOffNoFile ,
2428 mainRule ,
2529 RulesConfig (.. ),
26- getDependencies ,
2730 getParsedModule ,
2831 getParsedModuleWithComments ,
2932 getClientConfigAction ,
@@ -155,6 +158,7 @@ import qualified Development.IDE.Types.Shake as Shake
155158import Development.IDE.GHC.CoreFile
156159import Data.Time.Clock.POSIX (posixSecondsToUTCTime , utcTimeToPOSIXSeconds )
157160import Control.Monad.IO.Unlift
161+ import qualified Data.IntMap as IM
158162#if MIN_VERSION_ghc(9,3,0)
159163import GHC.Unit.Module.Graph
160164import GHC.Unit.Env
@@ -204,12 +208,6 @@ toIdeResult = either (, Nothing) (([],) . Just)
204208------------------------------------------------------------
205209-- Exposed API
206210------------------------------------------------------------
207- -- | Get all transitive file dependencies of a given module.
208- -- Does not include the file itself.
209- getDependencies :: NormalizedFilePath -> Action (Maybe [NormalizedFilePath ])
210- getDependencies file =
211- fmap transitiveModuleDeps . (`transitiveDeps` file) <$> useNoFile_ GetModuleGraph
212-
213211getSourceFileSource :: NormalizedFilePath -> Action BS. ByteString
214212getSourceFileSource nfp = do
215213 (_, msource) <- getFileContents nfp
@@ -417,17 +415,17 @@ type RawDepM a = StateT (RawDependencyInformation, IntMap ArtifactsLocation) Act
417415execRawDepM :: Monad m => StateT (RawDependencyInformation , IntMap a1 ) m a2 -> m (RawDependencyInformation , IntMap a1 )
418416execRawDepM act =
419417 execStateT act
420- ( RawDependencyInformation IntMap. empty emptyPathIdMap IntMap. empty IntMap. empty
418+ ( RawDependencyInformation IntMap. empty emptyPathIdMap IntMap. empty
421419 , IntMap. empty
422420 )
423421
424422-- | Given a target file path, construct the raw dependency results by following
425423-- imports recursively.
426- rawDependencyInformation :: [NormalizedFilePath ] -> Action RawDependencyInformation
424+ rawDependencyInformation :: [NormalizedFilePath ] -> Action ( RawDependencyInformation , BootIdMap )
427425rawDependencyInformation fs = do
428426 (rdi, ss) <- execRawDepM (goPlural fs)
429427 let bm = IntMap. foldrWithKey (updateBootMap rdi) IntMap. empty ss
430- return (rdi { rawBootMap = bm } )
428+ return (rdi, bm )
431429 where
432430 goPlural ff = do
433431 mss <- lift $ (fmap . fmap ) msrModSummary <$> uses GetModSummaryWithoutTimestamps ff
@@ -446,9 +444,9 @@ rawDependencyInformation fs = do
446444 fId <- getFreshFid al
447445 -- Record this module and its location
448446 whenJust msum $ \ ms ->
449- modifyRawDepInfo (\ rd -> rd { rawModuleNameMap = IntMap. insert (getFilePathId fId)
450- (ShowableModuleName (moduleName $ ms_mod ms) )
451- (rawModuleNameMap rd)})
447+ modifyRawDepInfo (\ rd -> rd { rawModuleMap = IntMap. insert (getFilePathId fId)
448+ (ShowableModule $ ms_mod ms)
449+ (rawModuleMap rd)})
452450 -- Adding an edge to the bootmap so we can make sure to
453451 -- insert boot nodes before the real files.
454452 addBootMap al fId
@@ -670,8 +668,30 @@ knownFilesRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake recorde
670668getModuleGraphRule :: Recorder (WithPriority Log ) -> Rules ()
671669getModuleGraphRule recorder = defineNoFile (cmapWithPrio LogShake recorder) $ \ GetModuleGraph -> do
672670 fs <- toKnownFiles <$> useNoFile_ GetKnownTargets
673- rawDepInfo <- rawDependencyInformation (HashSet. toList fs)
674- pure $ processDependencyInformation rawDepInfo
671+ (rawDepInfo, bm) <- rawDependencyInformation (HashSet. toList fs)
672+ let (all_fs, _all_ids) = unzip $ HM. toList $ pathToIdMap $ rawPathIdMap rawDepInfo
673+ mss <- map (fmap msrModSummary) <$> uses GetModSummaryWithoutTimestamps all_fs
674+ #if MIN_VERSION_ghc(9,3,0)
675+ let deps = map (\ i -> IM. lookup (getFilePathId i) (rawImports rawDepInfo)) _all_ids
676+ nodeKeys = IM. fromList $ catMaybes $ zipWith (\ fi mms -> (getFilePathId fi,) . NodeKey_Module . msKey <$> mms) _all_ids mss
677+ mns = catMaybes $ zipWith go mss deps
678+ go (Just ms) (Just (Right (ModuleImports xs))) = Just $ ModuleNode this_dep_keys ms
679+ where this_dep_ids = mapMaybe snd xs
680+ this_dep_keys = mapMaybe (\ fi -> IM. lookup (getFilePathId fi) nodeKeys) this_dep_ids
681+ go (Just ms) _ = Just $ ModuleNode [] ms
682+ go _ _ = Nothing
683+ mg = mkModuleGraph mns
684+ #else
685+ let mg = mkModuleGraph $
686+ #if MIN_VERSION_ghc(9,2,0)
687+ -- We don't do any instantiation for backpack at this point of time, so it is OK to use
688+ -- 'extendModSummaryNoDeps'.
689+ -- This may have to change in the future.
690+ map extendModSummaryNoDeps $
691+ #endif
692+ (catMaybes mss)
693+ #endif
694+ pure $ processDependencyInformation rawDepInfo bm mg
675695
676696-- This is factored out so it can be directly called from the GetModIface
677697-- rule. Directly calling this rule means that on the initial load we can
@@ -773,19 +793,8 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
773793 depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
774794 ifaces <- uses_ GetModIface deps
775795 let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails Nothing ) ifaces
776- #if MIN_VERSION_ghc(9,3,0)
777- -- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
778- -- also points to all the direct descendants of the current module. To get the keys for the descendants
779- -- we must get their `ModSummary`s
780- ! final_deps <- do
781- dep_mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
782- -- Don't want to retain references to the entire ModSummary when just the key will do
783- return $!! map (NodeKey_Module . msKey) dep_mss
784- let moduleNode = (ms, final_deps)
785- #else
786- let moduleNode = ms
787- #endif
788- session' <- liftIO $ mergeEnvs hsc moduleNode inLoadOrder depSessions
796+ mg <- depModuleGraph <$> useNoFile_ GetModuleGraph
797+ >>>>>>> b1f09906 (Implement sharing of module graphs)
789798
790799 Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [] )
791800
0 commit comments