@@ -143,9 +143,7 @@ import Data.Hashable
143
143
import Data.IORef
144
144
import qualified Data.Rope.UTF16 as Rope
145
145
import Data.Time (UTCTime (.. ))
146
- import FastString (FastString (uniq ))
147
146
import GHC.IO.Encoding
148
- import qualified HeaderInfo as Hdr
149
147
import Module
150
148
import TcRnMonad (tcg_dependent_files )
151
149
@@ -311,7 +309,7 @@ priorityFilesOfInterest = Priority (-2)
311
309
-- GHC wiki about: https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations
312
310
getParsedModuleRule :: Rules ()
313
311
getParsedModuleRule = defineEarlyCutoff $ \ GetParsedModule file -> do
314
- (ms, _) <- use_ GetModSummary file
312
+ ModSummaryResult {msrModSummary = ms} <- use_ GetModSummary file
315
313
sess <- use_ GhcSession file
316
314
let hsc = hscEnv sess
317
315
opt <- getIdeOptions
@@ -376,7 +374,7 @@ mergeParseErrorsHaddock normal haddock = normal ++
376
374
-- So it is suitable for use cases where you need a perfect edit.
377
375
getParsedModuleWithCommentsRule :: Rules ()
378
376
getParsedModuleWithCommentsRule = defineEarlyCutoff $ \ GetParsedModuleWithComments file -> do
379
- (ms, _) <- use_ GetModSummary file
377
+ ModSummaryResult {msrModSummary = ms} <- use_ GetModSummary file
380
378
sess <- use_ GhcSession file
381
379
opt <- getIdeOptions
382
380
@@ -397,7 +395,7 @@ getParsedModuleDefinition packageState opt file ms = do
397
395
getLocatedImportsRule :: Rules ()
398
396
getLocatedImportsRule =
399
397
define $ \ GetLocatedImports file -> do
400
- (ms,_) <- use_ GetModSummaryWithoutTimestamps file
398
+ ModSummaryResult {msrModSummary = ms} <- use_ GetModSummaryWithoutTimestamps file
401
399
targets <- useNoFile_ GetKnownTargets
402
400
let imports = [(False , imp) | imp <- ms_textual_imps ms] ++ [(True , imp) | imp <- ms_srcimps ms]
403
401
env_eq <- use_ GhcSession file
@@ -442,7 +440,7 @@ rawDependencyInformation fs = do
442
440
return (rdi { rawBootMap = bm })
443
441
where
444
442
goPlural ff = do
445
- mss <- lift $ (fmap . fmap ) fst <$> uses GetModSummaryWithoutTimestamps ff
443
+ mss <- lift $ (fmap . fmap ) msrModSummary <$> uses GetModSummaryWithoutTimestamps ff
446
444
zipWithM go ff mss
447
445
448
446
go :: NormalizedFilePath -- ^ Current module being processed
@@ -563,7 +561,7 @@ reportImportCyclesRule =
563
561
where rng = fromMaybe noRange $ srcSpanToRange (getLoc imp)
564
562
fp = toNormalizedFilePath' $ fromMaybe noFilePath $ srcSpanToFilename (getLoc imp)
565
563
getModuleName file = do
566
- ms <- fst <$> use_ GetModSummaryWithoutTimestamps file
564
+ ms <- msrModSummary <$> use_ GetModSummaryWithoutTimestamps file
567
565
pure (moduleNameString . moduleName . ms_mod $ ms)
568
566
showCycle mods = T. intercalate " , " (map T. pack mods)
569
567
@@ -769,7 +767,7 @@ ghcSessionDepsDefinition :: NormalizedFilePath -> Action (IdeResult HscEnvEq)
769
767
ghcSessionDepsDefinition file = do
770
768
env <- use_ GhcSession file
771
769
let hsc = hscEnv env
772
- (ms,_) <- use_ GetModSummaryWithoutTimestamps file
770
+ ms <- msrModSummary <$> use_ GetModSummaryWithoutTimestamps file
773
771
deps <- use_ GetDependencies file
774
772
let tdeps = transitiveModuleDeps deps
775
773
uses_th_qq =
@@ -793,7 +791,7 @@ ghcSessionDepsDefinition file = do
793
791
-- This rule also ensures that the `.hie` and `.o` (if needed) files are written out.
794
792
getModIfaceFromDiskRule :: Rules ()
795
793
getModIfaceFromDiskRule = defineEarlyCutoff $ \ GetModIfaceFromDisk f -> do
796
- (ms,_) <- use_ GetModSummary f
794
+ ms <- msrModSummary <$> use_ GetModSummary f
797
795
(diags_session, mb_session) <- ghcSessionDepsDefinition f
798
796
case mb_session of
799
797
Nothing -> return (Nothing , (diags_session, Nothing ))
@@ -850,7 +848,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ \GetModIfaceFromDiskAndInd
850
848
851
849
isHiFileStableRule :: Rules ()
852
850
isHiFileStableRule = defineEarlyCutoff $ \ IsHiFileStable f -> do
853
- (ms,_) <- use_ GetModSummaryWithoutTimestamps f
851
+ ms <- msrModSummary <$> use_ GetModSummaryWithoutTimestamps f
854
852
let hiFile = toNormalizedFilePath'
855
853
$ ml_hi_file $ ms_location ms
856
854
mbHiVersion <- use GetModificationTime_ {missingFileDiagnostics= False } hiFile
@@ -873,47 +871,30 @@ getModSummaryRule :: Rules ()
873
871
getModSummaryRule = do
874
872
defineEarlyCutoff $ \ GetModSummary f -> do
875
873
session <- hscEnv <$> use_ GhcSession f
876
- let dflags = hsc_dflags session
877
874
(modTime, mFileContent) <- getFileContents f
878
875
let fp = fromNormalizedFilePath f
879
876
modS <- liftIO $ runExceptT $
880
877
getModSummaryFromImports session fp modTime (textToStringBuffer <$> mFileContent)
881
878
case modS of
882
- Right res@ (ms,_) -> do
883
- let fingerPrint = hash (computeFingerprint f (fromJust $ ms_hspp_buf ms) dflags ms, hashUTC modTime)
884
- return ( Just (BS. pack $ show fingerPrint) , ([] , Just res))
879
+ Right res -> do
880
+ bufFingerPrint <- liftIO $
881
+ fingerprintFromStringBuffer $ fromJust $ ms_hspp_buf $ msrModSummary res
882
+ let fingerPrint = fingerprintFingerprints
883
+ [ msrFingerprint res, bufFingerPrint ]
884
+ return ( Just (fingerprintToBS fingerPrint) , ([] , Just res))
885
885
Left diags -> return (Nothing , (diags, Nothing ))
886
886
887
887
defineEarlyCutoff $ \ GetModSummaryWithoutTimestamps f -> do
888
888
ms <- use GetModSummary f
889
889
case ms of
890
- Just res@ (msWithTimestamps,_) -> do
891
- let ms = msWithTimestamps {
890
+ Just res@ ModSummaryResult { .. } -> do
891
+ let ms = msrModSummary {
892
892
ms_hs_date = error " use GetModSummary instead of GetModSummaryWithoutTimestamps" ,
893
893
ms_hspp_buf = error " use GetModSummary instead of GetModSummaryWithoutTimestamps"
894
894
}
895
- dflags <- hsc_dflags . hscEnv <$> use_ GhcSession f
896
- let fp = BS. pack $ show $ hash (computeFingerprint f (fromJust $ ms_hspp_buf msWithTimestamps) dflags ms)
897
- return (Just fp, ([] , Just res))
895
+ fp = fingerprintToBS msrFingerprint
896
+ return (Just fp, ([] , Just res{msrModSummary = ms}))
898
897
Nothing -> return (Nothing , ([] , Nothing ))
899
- where
900
- -- Compute a fingerprint from the contents of `ModSummary`,
901
- -- eliding the timestamps and other non relevant fields.
902
- computeFingerprint f sb dflags ModSummary {.. } =
903
- let fingerPrint =
904
- ( moduleNameString (moduleName ms_mod)
905
- , ms_hspp_file
906
- , map unLoc opts
907
- , ml_hs_file ms_location
908
- , fingerPrintImports ms_srcimps
909
- , fingerPrintImports ms_textual_imps
910
- )
911
- fingerPrintImports = map (fmap uniq *** (moduleNameString . unLoc))
912
- opts = Hdr. getOptions dflags sb (fromNormalizedFilePath f)
913
- in fingerPrint
914
-
915
- hashUTC UTCTime {.. } = (fromEnum utctDay, fromEnum utctDayTime)
916
-
917
898
918
899
generateCore :: RunSimplifier -> NormalizedFilePath -> Action (IdeResult ModGuts )
919
900
generateCore runSimplifier file = do
@@ -1074,9 +1055,10 @@ needsCompilationRule = defineEarlyCutoff $ \NeedsCompilation file -> do
1074
1055
-- that we just threw away, and thus have to recompile all dependencies once
1075
1056
-- again, this time keeping the object code.
1076
1057
-- A file needs to be compiled if any file that depends on it uses TemplateHaskell or needs to be compiled
1077
- (ms,_) <- fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1078
- (modsums,needsComps) <- par (map (fmap (fst . fst )) <$> usesWithStale GetModSummaryWithoutTimestamps revdeps)
1079
- (uses NeedsCompilation revdeps)
1058
+ ms <- msrModSummary . fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
1059
+ (modsums,needsComps) <-
1060
+ par (map (fmap (msrModSummary . fst )) <$> usesWithStale GetModSummaryWithoutTimestamps revdeps)
1061
+ (uses NeedsCompilation revdeps)
1080
1062
pure $ computeLinkableType ms modsums (map join needsComps)
1081
1063
1082
1064
pure (Just $ BS. pack $ show $ hash res, ([] , Just res))
0 commit comments