Skip to content

Commit e967dde

Browse files
committed
fix the race between cache value updated but not updated hls-database
1 parent 48d5644 commit e967dde

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
12001200
Just (v@(Succeeded _ x), diags) -> do
12011201
ver <- estimateFileVersionUnsafely key (Just x) file
12021202
doDiagnostics (vfsVersion =<< ver) $ Vector.toList diags
1203-
return $ Just $ RunResult ChangedNothing old $ A v
1203+
return $ Just $ RunResult ChangedNothing old (A v) mempty
12041204
_ -> return Nothing
12051205
_ ->
12061206
-- assert that a "clean" rule is never a cache miss
@@ -1224,7 +1224,6 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
12241224
Nothing -> do
12251225
pure (toShakeValue ShakeStale mbBs, staleV)
12261226
Just v -> pure (maybe ShakeNoCutoff ShakeResult mbBs, Succeeded ver v)
1227-
liftIO $ atomicallyNamed "define - write" $ setValues state key file res (Vector.fromList diags)
12281227
doDiagnostics (vfsVersion =<< ver) diags
12291228
let eq = case (bs, fmap decodeShakeValue mbOld) of
12301229
(ShakeResult a, Just (ShakeResult b)) -> cmp a b
@@ -1234,9 +1233,9 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
12341233
_ -> False
12351234
return $ RunResult
12361235
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff)
1237-
(encodeShakeValue bs) $
1238-
A res
1239-
liftIO $ atomicallyNamed "define - dirtyKeys" $ modifyTVar' dirtyKeys (deleteKeySet $ toKey key file)
1236+
(encodeShakeValue bs)
1237+
(A res)
1238+
(setValues state key file res (Vector.fromList diags) >> modifyTVar' dirtyKeys (deleteKeySet $ toKey key file))
12401239
return res
12411240
where
12421241
-- Highly unsafe helper to compute the version of a file

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ otTracedAction key file mode result act
112112
ExitCaseSuccess res -> do
113113
setTag sp "result" (pack $ result $ runValue res)
114114
setTag sp "changed" $ case res of
115-
RunResult x _ _ -> fromString $ show x
115+
RunResult x _ _ _ -> fromString $ show x
116116
endSpan sp)
117117
(\sp -> act (liftIO . setTag sp "diagnostics" . encodeUtf8 . showDiagnostics ))
118118
| otherwise = act (\_ -> return ())

hls-graph/src/Development/IDE/Graph/Internal/Database.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ compute db@Database{..} stack key mode result = do
200200
(getResultDepsDefault mempty previousDeps)
201201
deps
202202
_ -> pure ()
203-
atomicallyNamed "compute" $ SMap.focus (updateStatus $ Clean res) key databaseValues
203+
atomicallyNamed "compute and run hook" $ do
204+
runHook
205+
SMap.focus (updateStatus $ Clean res) key databaseValues
204206
pure res
205207

206208
updateStatus :: Monad m => Status -> Focus.Focus KeyDetails m ()

hls-graph/src/Development/IDE/Graph/Internal/Types.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import qualified StmContainers.Map as SMap
2727
import StmContainers.Map (Map)
2828
import System.Time.Extra (Seconds)
2929
import UnliftIO (MonadUnliftIO)
30+
import Control.Concurrent.STM (STM)
3031

3132
#if !MIN_VERSION_base(4,18,0)
3233
import Control.Applicative (liftA2)
@@ -202,11 +203,10 @@ data RunResult value = RunResult
202203
-- ^ The value to store in the Shake database.
203204
,runValue :: value
204205
-- ^ The value to return from 'Development.Shake.Rule.apply'.
206+
,runHook :: STM ()
207+
-- ^ The value to return from 'Development.Shake.Rule.apply'.
205208
} deriving Functor
206209

207-
instance NFData value => NFData (RunResult value) where
208-
rnf (RunResult x1 x2 x3) = rnf x1 `seq` x2 `seq` rnf x3
209-
210210
---------------------------------------------------------------------
211211
-- EXCEPTIONS
212212

0 commit comments

Comments
 (0)