@@ -426,9 +426,9 @@ setValues :: IdeRule k v
426
426
-> NormalizedFilePath
427
427
-> Value v
428
428
-> Vector FileDiagnostic
429
- -> IO ()
429
+ -> STM ()
430
430
setValues state key file val diags =
431
- atomically $ STM. insert (ValueWithDiagnostics (fmap toDyn val) diags) (toKey key file) state
431
+ STM. insert (ValueWithDiagnostics (fmap toDyn val) diags) (toKey key file) state
432
432
433
433
434
434
-- | Delete the value stored for a given ide build key
@@ -460,16 +460,17 @@ getValues ::
460
460
Values ->
461
461
k ->
462
462
NormalizedFilePath ->
463
- IO (Maybe (Value v , Vector FileDiagnostic ))
463
+ STM (Maybe (Value v , Vector FileDiagnostic ))
464
464
getValues state key file = do
465
- atomically ( STM. lookup (toKey key file) state) >>= \ case
465
+ STM. lookup (toKey key file) state >>= \ case
466
466
Nothing -> pure Nothing
467
467
Just (ValueWithDiagnostics v diagsV) -> do
468
- let r = fmap (fromJust . fromDynamic @ v ) v
468
+ let ! r = seqValue $ fmap (fromJust . fromDynamic @ v ) v
469
+ ! res = (r,diagsV)
469
470
-- Force to make sure we do not retain a reference to the HashMap
470
471
-- and we blow up immediately if the fromJust should fail
471
472
-- (which would be an internal error).
472
- evaluate (r `seqValue` Just (r, diagsV))
473
+ return $ Just res
473
474
474
475
-- | Get all the files in the project
475
476
knownTargets :: Action (Hashed KnownTargets )
@@ -480,11 +481,11 @@ knownTargets = do
480
481
-- | Seq the result stored in the Shake value. This only
481
482
-- evaluates the value to WHNF not NF. We take care of the latter
482
483
-- elsewhere and doing it twice is expensive.
483
- seqValue :: Value v -> b -> b
484
- seqValue v b = case v of
485
- Succeeded ver v -> rnf ver `seq` v `seq` b
486
- Stale d ver v -> rnf d `seq` rnf ver `seq` v `seq` b
487
- Failed _ -> b
484
+ seqValue :: Value v -> Value v
485
+ seqValue val = case val of
486
+ Succeeded ver v -> rnf ver `seq` v `seq` val
487
+ Stale d ver v -> rnf d `seq` rnf ver `seq` v `seq` val
488
+ Failed _ -> val
488
489
489
490
-- | Open a 'IdeState', should be shut using 'shakeShut'.
490
491
shakeOpen :: Maybe (LSP. LanguageContextEnv Config )
@@ -906,7 +907,7 @@ useWithStaleFast' key file = do
906
907
wait <- delayedAction $ mkDelayedAction (" C:" ++ show key ++ " :" ++ fromNormalizedFilePath file) Debug $ use key file
907
908
908
909
s@ ShakeExtras {state} <- askShake
909
- r <- liftIO $ getValues state key file
910
+ r <- liftIO $ atomically $ getValues state key file
910
911
liftIO $ case r of
911
912
-- block for the result if we haven't computed before
912
913
Nothing -> do
@@ -1015,7 +1016,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1015
1016
(if optSkipProgress options key then id else inProgress progress file) $ do
1016
1017
val <- case old of
1017
1018
Just old | mode == RunDependenciesSame -> do
1018
- v <- liftIO $ getValues state key file
1019
+ v <- liftIO $ atomically $ getValues state key file
1019
1020
case v of
1020
1021
-- No changes in the dependencies and we have
1021
1022
-- an existing successful result.
@@ -1034,10 +1035,10 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1034
1035
(do v <- action; liftIO $ evaluate $ force v) $
1035
1036
\ (e :: SomeException ) -> do
1036
1037
pure (Nothing , ([ideErrorText file $ T. pack $ show e | not $ isBadDependency e],Nothing ))
1037
- modTime <- liftIO $ (currentValue . fst =<< ) <$> getValues state GetModificationTime file
1038
+ modTime <- liftIO $ (currentValue . fst =<< ) <$> atomically ( getValues state GetModificationTime file)
1038
1039
(bs, res) <- case res of
1039
1040
Nothing -> do
1040
- staleV <- liftIO $ getValues state key file
1041
+ staleV <- liftIO $ atomically $ getValues state key file
1041
1042
pure $ case staleV of
1042
1043
Nothing -> (toShakeValue ShakeResult bs, Failed False )
1043
1044
Just v -> case v of
@@ -1048,7 +1049,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1048
1049
(Failed b, _) ->
1049
1050
(toShakeValue ShakeResult bs, Failed b)
1050
1051
Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
1051
- liftIO $ setValues state key file res (Vector. fromList diags)
1052
+ liftIO $ atomically $ setValues state key file res (Vector. fromList diags)
1052
1053
doDiagnostics diags
1053
1054
let eq = case (bs, fmap decodeShakeValue old) of
1054
1055
(ShakeResult a, Just (ShakeResult b)) -> cmp a b
@@ -1148,7 +1149,7 @@ updateFileDiagnostics :: MonadIO m
1148
1149
-> [(ShowDiagnostic ,Diagnostic )] -- ^ current results
1149
1150
-> m ()
1150
1151
updateFileDiagnostics fp k ShakeExtras {logger, diagnostics, hiddenDiagnostics, publishedDiagnostics, state, debouncer, lspEnv} current = liftIO $ do
1151
- modTime <- (currentValue . fst =<< ) <$> getValues state GetModificationTime fp
1152
+ modTime <- (currentValue . fst =<< ) <$> atomically ( getValues state GetModificationTime fp)
1152
1153
let (currentShown, currentHidden) = partition ((== ShowDiag ) . fst ) current
1153
1154
uri = filePathToUri' fp
1154
1155
ver = vfsVersion =<< modTime
0 commit comments