@@ -12,6 +12,7 @@ module Development.IDE.Core.Rules(
12
12
-- * Types
13
13
IdeState , GetParsedModule (.. ), TransitiveDependencies (.. ),
14
14
GhcSessionIO (.. ), GetClientSettings (.. ),
15
+ useTransDepModuleGraph ,
15
16
-- * Functions
16
17
runAction ,
17
18
toIdeResult ,
@@ -472,7 +473,7 @@ rawDependencyInformation fs = do
472
473
reportImportCyclesRule :: Recorder (WithPriority Log ) -> Rules ()
473
474
reportImportCyclesRule recorder =
474
475
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
476
477
case pathToId depPathIdMap file of
477
478
-- The header of the file does not parse, so it can't be part of any import cycles.
478
479
Nothing -> pure []
@@ -633,17 +634,17 @@ dependencyInfoForFiles fs = do
633
634
(rawDepInfo, bm) <- rawDependencyInformation fs
634
635
let (all_fs, _all_ids) = unzip $ HM. toList $ pathToIdMap $ rawPathIdMap rawDepInfo
635
636
msrs <- uses GetModSummaryWithoutTimestamps all_fs
636
- let mss = map (fmap msrModSummary) msrs
637
+ let mss = zip _all_ids $ map (fmap msrModSummary) msrs
637
638
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
639
640
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)
641
642
where this_dep_ids = mapMaybe snd xs
642
643
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)
644
645
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
647
648
Just x -> (getFilePathId i,msrFingerprint x): acc
648
649
Nothing -> acc) [] $ zip _all_ids msrs
649
650
pure (fingerprintToBS $ Util. fingerprintFingerprints $ map (maybe fingerprint0 msrFingerprint) msrs, processDependencyInformation rawDepInfo bm mg shallowFingers)
@@ -663,7 +664,7 @@ typeCheckRuleDefinition hsc pm fp = do
663
664
unlift <- askUnliftIO
664
665
let dets = TypecheckHelpers
665
666
{ getLinkables = unliftIO unlift . uses_ GetLinkable
666
- , getModuleGraph = unliftIO unlift $ useWithSeparateFingerprintRule_ GetModuleGraphTransDepsFingerprints GetModuleGraph fp
667
+ , getModuleGraph = unliftIO unlift $ useTransDepModuleGraph fp
667
668
}
668
669
addUsageDependencies $ liftIO $
669
670
typecheckModule defer hsc dets pm
@@ -735,6 +736,11 @@ instance Default GhcSessionDepsConfig where
735
736
{ fullModuleGraph = True
736
737
}
737
738
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
+
738
744
-- | Note [GhcSessionDeps]
739
745
-- ~~~~~~~~~~~~~~~~~~~~~
740
746
-- For a file 'Foo', GhcSessionDeps "Foo.hs" results in an HscEnv which includes
@@ -760,10 +766,10 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
760
766
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
761
767
ifaces <- uses_ GetModIface deps
762
768
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
765
771
if fullModuleGraph
766
- then return $ depModuleGraph de
772
+ then return $ IntMap. elems $ depModuleGraph de
767
773
else do
768
774
let mgs = map hsc_mod_graph depSessions
769
775
-- 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
775
781
let module_graph_nodes =
776
782
nubOrdOn mkNodeKey (ModuleNode final_deps ms : concatMap mgModSummaries' mgs)
777
783
liftIO $ evaluate $ liftRnf rwhnf module_graph_nodes
778
- return $ mkModuleGraph module_graph_nodes
784
+ return module_graph_nodes
779
785
session' <- liftIO $ mergeEnvs hsc mg de ms inLoadOrder depSessions
780
786
781
787
-- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new
@@ -805,7 +811,7 @@ getModIfaceFromDiskRule recorder = defineEarlyCutoff (cmapWithPrio LogShake reco
805
811
, old_value = m_old
806
812
, get_file_version = use GetModificationTime_ {missingFileDiagnostics = False }
807
813
, 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
809
815
, regenerate = regenerateHiFile session f ms
810
816
}
811
817
hsc_env' <- setFileCacheHook (hscEnv session)
@@ -1139,7 +1145,7 @@ needsCompilationRule file
1139
1145
| " boot" `isSuffixOf` fromNormalizedFilePath file =
1140
1146
pure (Just $ encodeLinkableType Nothing , Just Nothing )
1141
1147
needsCompilationRule file = do
1142
- graph <- useWithSeparateFingerprintRule GetModuleGraphImmediateReverseDepsFingerprints GetModuleGraph file
1148
+ graph <- useImmediateDepsModuleGraph file
1143
1149
res <- case graph of
1144
1150
-- Treat as False if some reverse dependency header fails to parse
1145
1151
Nothing -> pure Nothing
0 commit comments