@@ -12,6 +12,7 @@ module Development.IDE.Core.Rules(
1212 -- * Types
1313 IdeState , GetParsedModule (.. ), TransitiveDependencies (.. ),
1414 GhcSessionIO (.. ), GetClientSettings (.. ),
15+ useTransDepModuleGraph ,
1516 -- * Functions
1617 runAction ,
1718 toIdeResult ,
@@ -472,7 +473,7 @@ rawDependencyInformation fs = do
472473reportImportCyclesRule :: Recorder (WithPriority Log ) -> Rules ()
473474reportImportCyclesRule recorder =
474475 defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \ ReportImportCycles file -> fmap (\ errs -> if null errs then (Just " 1" ,([] , Just () )) else (Nothing , (errs, Nothing ))) $ do
475- DependencyInformation { .. } <- useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph file
476+ DependencyInformation {depErrorNodes, depPathIdMap } <- useTransDepModuleGraph file
476477 case pathToId depPathIdMap file of
477478 -- The header of the file does not parse, so it can't be part of any import cycles.
478479 Nothing -> pure []
@@ -633,17 +634,17 @@ dependencyInfoForFiles fs = do
633634 (rawDepInfo, bm) <- rawDependencyInformation fs
634635 let (all_fs, _all_ids) = unzip $ HM. toList $ pathToIdMap $ rawPathIdMap rawDepInfo
635636 msrs <- uses GetModSummaryWithoutTimestamps all_fs
636- let mss = map (fmap msrModSummary) msrs
637+ let mss = zip _all_ids $ map (fmap msrModSummary) msrs
637638 let deps = map (\ i -> IM. lookup (getFilePathId i) (rawImports rawDepInfo)) _all_ids
638- nodeKeys = IM. fromList $ catMaybes $ zipWith (\ fi mms -> (getFilePathId fi,) . NodeKey_Module . msKey <$> mms) _all_ids mss
639+ nodeKeys = IM. fromList $ catMaybes $ zipWith (\ fi (_, mms) -> (getFilePathId fi,) . NodeKey_Module . msKey <$> mms) _all_ids mss
639640 mns = catMaybes $ zipWith go mss deps
640- go (Just ms) (Just (Right (ModuleImports xs))) = Just $ ModuleNode this_dep_keys ms
641+ go (pid, Just ms) (Just (Right (ModuleImports xs))) = Just $ (pid, ModuleNode this_dep_keys ms)
641642 where this_dep_ids = mapMaybe snd xs
642643 this_dep_keys = mapMaybe (\ fi -> IM. lookup (getFilePathId fi) nodeKeys) this_dep_ids
643- go (Just ms) _ = Just $ ModuleNode [] ms
644+ go (pid, Just ms) _ = Just $ (pid, ModuleNode [] ms)
644645 go _ _ = Nothing
645- mg = mkModuleGraph mns
646- let shallowFingers = IntMap. fromList $ foldr' (\ (i, m) acc -> case m of
646+ mg = IntMap. fromList $ map (first getFilePathId) mns
647+ let shallowFingers = IntMap. fromList $! foldr' (\ (i, m) acc -> case m of
647648 Just x -> (getFilePathId i,msrFingerprint x): acc
648649 Nothing -> acc) [] $ zip _all_ids msrs
649650 pure (fingerprintToBS $ Util. fingerprintFingerprints $ map (maybe fingerprint0 msrFingerprint) msrs, processDependencyInformation rawDepInfo bm mg shallowFingers)
@@ -663,7 +664,7 @@ typeCheckRuleDefinition hsc pm fp = do
663664 unlift <- askUnliftIO
664665 let dets = TypecheckHelpers
665666 { getLinkables = unliftIO unlift . uses_ GetLinkable
666- , getModuleGraph = unliftIO unlift $ useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph fp
667+ , getModuleGraph = unliftIO unlift $ useTransDepModuleGraph fp
667668 }
668669 addUsageDependencies $ liftIO $
669670 typecheckModule defer hsc dets pm
@@ -735,6 +736,11 @@ instance Default GhcSessionDepsConfig where
735736 { fullModuleGraph = True
736737 }
737738
739+ useTransDepModuleGraph :: NormalizedFilePath -> Action DependencyInformation
740+ useTransDepModuleGraph file = filterDependencyInformationReachable file <$> useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph file
741+ useImmediateDepsModuleGraph :: NormalizedFilePath -> Action (Maybe DependencyInformation )
742+ useImmediateDepsModuleGraph file = useWithSeparateFingerprintRule GetModuleGraphTransDepsFingerprints GetModuleGraph file
743+
738744-- | Note [GhcSessionDeps]
739745-- ~~~~~~~~~~~~~~~~~~~~~
740746-- For a file 'Foo', GhcSessionDeps "Foo.hs" results in an HscEnv which includes
@@ -760,10 +766,10 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
760766 depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
761767 ifaces <- uses_ GetModIface deps
762768 let inLoadOrder = map (\ HiFileResult {.. } -> HomeModInfo hirModIface hirModDetails emptyHomeModInfoLinkable) ifaces
763- de <- useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph file
764- mg <- do
769+ de <- useTransDepModuleGraph file
770+ mg <- mkModuleGraph <$> do
765771 if fullModuleGraph
766- then return $ depModuleGraph de
772+ then return $ IntMap. elems $ depModuleGraph de
767773 else do
768774 let mgs = map hsc_mod_graph depSessions
769775 -- On GHC 9.4+, the module graph contains not only ModSummary's but each `ModuleNode` in the graph
@@ -775,7 +781,7 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
775781 let module_graph_nodes =
776782 nubOrdOn mkNodeKey (ModuleNode final_deps ms : concatMap mgModSummaries' mgs)
777783 liftIO $ evaluate $ liftRnf rwhnf module_graph_nodes
778- return $ mkModuleGraph module_graph_nodes
784+ return module_graph_nodes
779785 session' <- liftIO $ mergeEnvs hsc mg de ms inLoadOrder depSessions
780786
781787 -- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new
@@ -805,7 +811,7 @@ getModIfaceFromDiskRule recorder = defineEarlyCutoff (cmapWithPrio LogShake reco
805811 , old_value = m_old
806812 , get_file_version = use GetModificationTime_ {missingFileDiagnostics = False }
807813 , get_linkable_hashes = \ fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs
808- , get_module_graph = useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph f
814+ , get_module_graph = useTransDepModuleGraph f
809815 , regenerate = regenerateHiFile session f ms
810816 }
811817 hsc_env' <- setFileCacheHook (hscEnv session)
@@ -1139,7 +1145,7 @@ needsCompilationRule file
11391145 | " boot" `isSuffixOf` fromNormalizedFilePath file =
11401146 pure (Just $ encodeLinkableType Nothing , Just Nothing )
11411147needsCompilationRule file = do
1142- graph <- useWithSeparateFingerprintRule GetModuleGraphImmediateReverseDepsFingerprints GetModuleGraph file
1148+ graph <- useImmediateDepsModuleGraph file
11431149 res <- case graph of
11441150 -- Treat as False if some reverse dependency header fails to parse
11451151 Nothing -> pure Nothing
0 commit comments