@@ -143,9 +143,7 @@ import           Data.Hashable
143143import            Data.IORef 
144144import  qualified  Data.Rope.UTF16                               as  Rope 
145145import            Data.Time                                     (UTCTime  (.. ))
146- import            FastString                                    (FastString  (uniq ))
147146import            GHC.IO.Encoding 
148- import  qualified  HeaderInfo                                    as  Hdr 
149147import            Module 
150148import            TcRnMonad                                     (tcg_dependent_files )
151149
@@ -311,7 +309,7 @@ priorityFilesOfInterest = Priority (-2)
311309--  GHC wiki about: https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations 
312310getParsedModuleRule  ::  Rules  () 
313311getParsedModuleRule =  defineEarlyCutoff $  \ GetParsedModule  file ->  do 
314-     (ms, _)  <-  use_ GetModSummary  file
312+     ModSummaryResult {msrModSummary  =  ms}  <-  use_ GetModSummary  file
315313    sess <-  use_ GhcSession  file
316314    let  hsc =  hscEnv sess
317315    opt <-  getIdeOptions
@@ -376,7 +374,7 @@ mergeParseErrorsHaddock normal haddock = normal ++
376374--  So it is suitable for use cases where you need a perfect edit. 
377375getParsedModuleWithCommentsRule  ::  Rules  () 
378376getParsedModuleWithCommentsRule =  defineEarlyCutoff $  \ GetParsedModuleWithComments  file ->  do 
379-     (ms, _)  <-  use_ GetModSummary  file
377+     ModSummaryResult {msrModSummary  =  ms}  <-  use_ GetModSummary  file
380378    sess <-  use_ GhcSession  file
381379    opt <-  getIdeOptions
382380
@@ -397,7 +395,7 @@ getParsedModuleDefinition packageState opt file ms = do
397395getLocatedImportsRule  ::  Rules  () 
398396getLocatedImportsRule = 
399397    define $  \ GetLocatedImports  file ->  do 
400-         (ms,_)  <-  use_ GetModSummaryWithoutTimestamps  file
398+         ModSummaryResult {msrModSummary  =  ms}  <-  use_ GetModSummaryWithoutTimestamps  file
401399        targets <-  useNoFile_ GetKnownTargets 
402400        let  imports =  [(False |  imp <-  ms_textual_imps ms] ++  [(True |  imp <-  ms_srcimps ms]
403401        env_eq <-  use_ GhcSession  file
@@ -442,7 +440,7 @@ rawDependencyInformation fs = do
442440    return  (rdi { rawBootMap =  bm })
443441  where 
444442    goPlural ff =  do 
445-         mss <-  lift $  (fmap . fmap ) fst  <$>  uses GetModSummaryWithoutTimestamps  ff
443+         mss <-  lift $  (fmap . fmap ) msrModSummary  <$>  uses GetModSummaryWithoutTimestamps  ff
446444        zipWithM go ff mss
447445
448446    go  ::  NormalizedFilePath  --  ^  Current module being processed 
@@ -563,7 +561,7 @@ reportImportCyclesRule =
563561            where  rng =  fromMaybe noRange $  srcSpanToRange (getLoc imp)
564562                  fp =  toNormalizedFilePath' $  fromMaybe noFilePath $  srcSpanToFilename (getLoc imp)
565563          getModuleName file =  do 
566-            ms <-  fst  <$>  use_ GetModSummaryWithoutTimestamps  file
564+            ms <-  msrModSummary  <$>  use_ GetModSummaryWithoutTimestamps  file
567565           pure  (moduleNameString .  moduleName .  ms_mod $  ms)
568566          showCycle mods  =  T. intercalate " , " map  T. pack mods)
569567
@@ -769,7 +767,7 @@ ghcSessionDepsDefinition :: NormalizedFilePath -> Action (IdeResult HscEnvEq)
769767ghcSessionDepsDefinition file =  do 
770768        env <-  use_ GhcSession  file
771769        let  hsc =  hscEnv env
772-         (ms,_)  <-  use_ GetModSummaryWithoutTimestamps  file
770+         ms  <-  msrModSummary  <$>  use_ GetModSummaryWithoutTimestamps  file
773771        deps <-  use_ GetDependencies  file
774772        let  tdeps =  transitiveModuleDeps deps
775773            uses_th_qq = 
@@ -793,7 +791,7 @@ ghcSessionDepsDefinition file = do
793791--  This rule also ensures that the `.hie` and `.o` (if needed) files are written out. 
794792getModIfaceFromDiskRule  ::  Rules  () 
795793getModIfaceFromDiskRule =  defineEarlyCutoff $  \ GetModIfaceFromDisk  f ->  do 
796-   (ms,_)  <-  use_ GetModSummary  f
794+   ms  <-  msrModSummary  <$>  use_ GetModSummary  f
797795  (diags_session, mb_session) <-  ghcSessionDepsDefinition f
798796  case  mb_session of 
799797    Nothing  ->  return  (Nothing , (diags_session, Nothing ))
@@ -850,7 +848,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ \GetModIfaceFromDiskAndInd
850848
851849isHiFileStableRule  ::  Rules  () 
852850isHiFileStableRule =  defineEarlyCutoff $  \ IsHiFileStable  f ->  do 
853-     (ms,_)  <-  use_ GetModSummaryWithoutTimestamps  f
851+     ms  <-  msrModSummary  <$>  use_ GetModSummaryWithoutTimestamps  f
854852    let  hiFile =  toNormalizedFilePath'
855853                $  ml_hi_file $  ms_location ms
856854    mbHiVersion <-  use  GetModificationTime_ {missingFileDiagnostics= False 
@@ -873,47 +871,30 @@ getModSummaryRule :: Rules ()
873871getModSummaryRule =  do 
874872    defineEarlyCutoff $  \ GetModSummary  f ->  do 
875873        session <-  hscEnv <$>  use_ GhcSession  f
876-         let  dflags =  hsc_dflags session
877874        (modTime, mFileContent) <-  getFileContents f
878875        let  fp =  fromNormalizedFilePath f
879876        modS <-  liftIO $  runExceptT $ 
880877                getModSummaryFromImports session fp modTime (textToStringBuffer <$>  mFileContent)
881878        case  modS of 
882-             Right @ (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 ->  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))
885885            Left ->  return  (Nothing , (diags, Nothing ))
886886
887887    defineEarlyCutoff $  \ GetModSummaryWithoutTimestamps  f ->  do 
888888        ms <-  use GetModSummary  f
889889        case  ms of 
890-             Just  res@ (msWithTimestamps,_)  ->  do 
891-                 let  ms =  msWithTimestamps  {
890+             Just  res@ ModSummaryResult { .. }  ->  do 
891+                 let  ms =  msrModSummary  {
892892                    ms_hs_date =  error  " use GetModSummary instead of GetModSummaryWithoutTimestamps" 
893893                    ms_hspp_buf =  error  " use GetModSummary instead of GetModSummaryWithoutTimestamps" 
894894                    }
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}))
898897            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- 
917898
918899generateCore  ::  RunSimplifier  ->  NormalizedFilePath  ->  Action  (IdeResult  ModGuts )
919900generateCore runSimplifier file =  do 
@@ -1074,9 +1055,10 @@ needsCompilationRule = defineEarlyCutoff $ \NeedsCompilation file -> do
10741055        --  that we just threw away, and thus have to recompile all dependencies once
10751056        --  again, this time keeping the object code.
10761057        --  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)
10801062        pure  $  computeLinkableType ms modsums (map  join needsComps)
10811063
10821064  pure  (Just  $  BS. pack $  show  $  hash res, ([] , Just  res))
0 commit comments