Skip to content

Commit ef19f2c

Browse files
committed
Prevent GetModificationTime in dependency file
1 parent 3c5aaf2 commit ef19f2c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
11581158
-- No changes in the dependencies and we have
11591159
-- an existing successful result.
11601160
Just (v@(Succeeded _ x), diags) -> do
1161-
ver <- estimateFileVersionUnsafely key (Just x) file
1161+
ver <- estimateFileVersionUnsafely key FromProject (Just x) file
11621162
doDiagnostics (vfsVersion =<< ver) $ Vector.toList diags
11631163
return $ Just $ RunResult ChangedNothing old $ A v
11641164
_ -> return Nothing
@@ -1174,20 +1174,20 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
11741174
Just (Succeeded ver v, _) -> Stale Nothing ver v
11751175
Just (Stale d ver v, _) -> Stale d ver v
11761176
Just (Failed b, _) -> Failed b
1177-
(bs, (diags, res)) <- do
1177+
(fileOrigin, (bs, (diags, res))) <- do
11781178
let doAction = actionCatch
11791179
(do v <- action staleV; liftIO $ evaluate $ force v) $
11801180
\(e :: SomeException) -> do
11811181
pure (Nothing, ([ideErrorText file $ T.pack $ show e | not $ isBadDependency e],Nothing))
11821182
case getSourceFileOrigin file of
1183-
FromProject -> doAction
1183+
FromProject -> (\r -> (FromProject, r)) <$> doAction
11841184
FromDependency -> if isSafeDependencyRule key
1185-
then doAction
1185+
then (\r -> (FromDependency, r)) <$> doAction
11861186
else error $
11871187
"defineEarlyCutoff': Undefined action for dependency source files\n"
11881188
++ show file ++ "\n"
11891189
++ show key
1190-
ver <- estimateFileVersionUnsafely key res file
1190+
ver <- estimateFileVersionUnsafely key fileOrigin res file
11911191
(bs, res) <- case res of
11921192
Nothing -> do
11931193
pure (toShakeValue ShakeStale bs, staleV)
@@ -1214,10 +1214,11 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
12141214
:: forall k v
12151215
. IdeRule k v
12161216
=> k
1217+
-> SourceFileOrigin
12171218
-> Maybe v
12181219
-> NormalizedFilePath
12191220
-> Action (Maybe FileVersion)
1220-
estimateFileVersionUnsafely _k v fp
1221+
estimateFileVersionUnsafely _k fileOrigin v fp
12211222
| fp == emptyFilePath = pure Nothing
12221223
| Just Refl <- eqT @k @GetModificationTime = pure v
12231224
-- GetModificationTime depends on these rules, so avoid creating a cycle
@@ -1228,7 +1229,10 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
12281229
-- For all other rules - compute the version properly without:
12291230
-- * creating a dependency: If everything depends on GetModificationTime, we lose early cutoff
12301231
-- * creating bogus "file does not exists" diagnostics
1231-
| otherwise = useWithoutDependency (GetModificationTime_ False) fp
1232+
| otherwise =
1233+
case fileOrigin of
1234+
FromDependency -> pure Nothing
1235+
FromProject -> useWithoutDependency (GetModificationTime_ False) fp
12321236
isSafeDependencyRule
12331237
:: forall k v
12341238
. IdeRule k v

0 commit comments

Comments
 (0)