@@ -36,7 +36,7 @@ import GHC.Utils.Outputable (renderWithContext)
36
36
37
37
-- | Given a file and some contents, apply any necessary preprocessors,
38
38
-- 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 )
40
40
preprocessor env filename mbContents = do
41
41
-- Perform unlit
42
42
(isOnDisk, contents) <-
@@ -48,6 +48,10 @@ preprocessor env filename mbContents = do
48
48
let isOnDisk = isNothing mbContents
49
49
return (isOnDisk, contents)
50
50
51
+ -- Compute the source hash before the preprocessor because this is
52
+ -- how GHC does it.
53
+ ! src_hash <- liftIO $ Util. fingerprintFromStringBuffer contents
54
+
51
55
-- Perform cpp
52
56
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
53
57
let dflags = hsc_dflags env
@@ -73,11 +77,11 @@ preprocessor env filename mbContents = do
73
77
74
78
-- Perform preprocessor
75
79
if not $ gopt Opt_Pp dflags then
76
- return (contents, opts, env)
80
+ return (contents, opts, env, src_hash )
77
81
else do
78
82
contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
79
83
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80
- return (contents, opts, env)
84
+ return (contents, opts, env, src_hash )
81
85
where
82
86
logAction :: IORef [CPPLog ] -> LogActionCompat
83
87
logAction cppLogs dflags _reason severity srcSpan _style msg = do
0 commit comments