@@ -36,7 +36,7 @@ import GHC.Utils.Outputable (renderWithContext)
3636
3737-- | Given a file and some contents, apply any necessary preprocessors,
3838-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
39- preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], HscEnv )
39+ preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], HscEnv , Util. Fingerprint )
4040preprocessor env filename mbContents = do
4141 -- Perform unlit
4242 (isOnDisk, contents) <-
@@ -48,6 +48,10 @@ preprocessor env filename mbContents = do
4848 let isOnDisk = isNothing mbContents
4949 return (isOnDisk, contents)
5050
51+ -- Compute the source hash before the preprocessor because this is
52+ -- how GHC does it.
53+ ! src_hash <- liftIO $ Util. fingerprintFromStringBuffer contents
54+
5155 -- Perform cpp
5256 (opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
5357 let dflags = hsc_dflags env
@@ -73,11 +77,11 @@ preprocessor env filename mbContents = do
7377
7478 -- Perform preprocessor
7579 if not $ gopt Opt_Pp dflags then
76- return (contents, opts, env)
80+ return (contents, opts, env, src_hash )
7781 else do
7882 contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
7983 (opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80- return (contents, opts, env)
84+ return (contents, opts, env, src_hash )
8185 where
8286 logAction :: IORef [CPPLog ] -> LogActionCompat
8387 logAction cppLogs dflags _reason severity srcSpan _style msg = do
0 commit comments