@@ -148,6 +148,7 @@ import GHC.Fingerprint
148
148
import Language.LSP.Types.Capabilities
149
149
import OpenTelemetry.Eventlog
150
150
151
+ import Control.Concurrent.STM.Timed (atomicallyNamed )
151
152
import Control.Exception.Extra hiding (bracket_ )
152
153
import Data.Aeson (toJSON )
153
154
import qualified Data.ByteString.Char8 as BS8
@@ -336,11 +337,11 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
336
337
MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
337
338
case mv of
338
339
Nothing -> do
339
- void $ atomically $ STM. focus (Focus. alter (alterValue $ Failed True )) (toKey k file) state
340
+ void $ atomicallyNamed " lastValueIO 1 " $ STM. focus (Focus. alter (alterValue $ Failed True )) (toKey k file) state
340
341
return Nothing
341
342
Just (v,del,ver) -> do
342
- void $ atomically $ STM. focus (Focus. alter (alterValue $ Stale (Just del) ver (toDyn v))) (toKey k file) state
343
- atomically $ Just . (v,) . addDelta del <$> mappingForVersion positionMapping file ver
343
+ void $ atomicallyNamed " lastValueIO 2 " $ STM. focus (Focus. alter (alterValue $ Stale (Just del) ver (toDyn v))) (toKey k file) state
344
+ atomicallyNamed " lastValueIO 3 " $ Just . (v,) . addDelta del <$> mappingForVersion positionMapping file ver
344
345
345
346
-- We got a new stale value from the persistent rule, insert it in the map without affecting diagnostics
346
347
alterValue new Nothing = Just (ValueWithDiagnostics new mempty ) -- If it wasn't in the map, give it empty diagnostics
@@ -350,13 +351,13 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
350
351
-- Something already succeeded before, leave it alone
351
352
_ -> old
352
353
353
- atomically (STM. lookup (toKey k file) state) >>= \ case
354
+ atomicallyNamed " lastValueIO 4 " (STM. lookup (toKey k file) state) >>= \ case
354
355
Nothing -> readPersistent
355
356
Just (ValueWithDiagnostics v _) -> case v of
356
357
Succeeded ver (fromDynamic -> Just v) ->
357
- atomically $ Just . (v,) <$> mappingForVersion positionMapping file ver
358
+ atomicallyNamed " lastValueIO 5 " $ Just . (v,) <$> mappingForVersion positionMapping file ver
358
359
Stale del ver (fromDynamic -> Just v) ->
359
- atomically $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
360
+ atomicallyNamed " lastValueIO 6 " $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
360
361
Failed p | not p -> readPersistent
361
362
_ -> pure Nothing
362
363
@@ -423,7 +424,7 @@ setValues :: IdeRule k v
423
424
-> Vector FileDiagnostic
424
425
-> IO ()
425
426
setValues state key file val diags =
426
- atomically $ STM. insert (ValueWithDiagnostics (fmap toDyn val) diags) (toKey key file) state
427
+ atomicallyNamed " setValues " $ STM. insert (ValueWithDiagnostics (fmap toDyn val) diags) (toKey key file) state
427
428
428
429
429
430
-- | Delete the value stored for a given ide build key
@@ -434,7 +435,7 @@ deleteValue
434
435
-> NormalizedFilePath
435
436
-> IO ()
436
437
deleteValue ShakeExtras {dirtyKeys, state} key file = do
437
- atomically $ STM. delete (toKey key file) state
438
+ atomicallyNamed " deleteValue " $ STM. delete (toKey key file) state
438
439
atomicModifyIORef_ dirtyKeys $ HSet. insert (toKey key file)
439
440
440
441
recordDirtyKeys
@@ -457,7 +458,7 @@ getValues ::
457
458
NormalizedFilePath ->
458
459
IO (Maybe (Value v , Vector FileDiagnostic ))
459
460
getValues state key file = do
460
- atomically (STM. lookup (toKey key file) state) >>= \ case
461
+ atomicallyNamed " getValues " (STM. lookup (toKey key file) state) >>= \ case
461
462
Nothing -> pure Nothing
462
463
Just (ValueWithDiagnostics v diagsV) -> do
463
464
let r = fmap (fromJust . fromDynamic @ v ) v
@@ -620,7 +621,7 @@ shakeRestart IdeState{..} reason acts =
620
621
(stopTime,() ) <- duration (cancelShakeSession runner)
621
622
res <- shakeDatabaseProfile shakeDb
622
623
backlog <- readIORef $ dirtyKeys shakeExtras
623
- queue <- atomically $ peekInProgress $ actionQueue shakeExtras
624
+ queue <- atomicallyNamed " actionQueue - peek " $ peekInProgress $ actionQueue shakeExtras
624
625
let profile = case res of
625
626
Just fp -> " , profile saved at " <> fp
626
627
_ -> " "
@@ -653,7 +654,7 @@ notifyTestingLogMessage extras msg = do
653
654
shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a )
654
655
shakeEnqueue ShakeExtras {actionQueue, logger} act = do
655
656
(b, dai) <- instantiateDelayedAction act
656
- atomically $ pushQueue dai actionQueue
657
+ atomicallyNamed " actionQueue - push " $ pushQueue dai actionQueue
657
658
let wait' b =
658
659
waitBarrier b `catches`
659
660
[ Handler (\ BlockedIndefinitelyOnMVar ->
@@ -662,7 +663,7 @@ shakeEnqueue ShakeExtras{actionQueue, logger} act = do
662
663
, Handler (\ e@ AsyncCancelled -> do
663
664
logPriority logger Debug $ T. pack $ actionName act <> " was cancelled"
664
665
665
- atomically $ abortQueue dai actionQueue
666
+ atomicallyNamed " actionQueue - abort " $ abortQueue dai actionQueue
666
667
throw e)
667
668
]
668
669
return (wait' b >>= either throwIO return )
@@ -677,7 +678,7 @@ newSession
677
678
-> IO ShakeSession
678
679
newSession extras@ ShakeExtras {.. } shakeDb acts reason = do
679
680
IdeOptions {optRunSubset} <- getIdeOptionsIO extras
680
- reenqueued <- atomically $ peekInProgress actionQueue
681
+ reenqueued <- atomicallyNamed " actionQueue - peek " $ peekInProgress actionQueue
681
682
allPendingKeys <-
682
683
if optRunSubset
683
684
then Just <$> readIORef dirtyKeys
@@ -686,14 +687,14 @@ newSession extras@ShakeExtras{..} shakeDb acts reason = do
686
687
-- A daemon-like action used to inject additional work
687
688
-- Runs actions from the work queue sequentially
688
689
pumpActionThread otSpan = do
689
- d <- liftIO $ atomically $ popQueue actionQueue
690
+ d <- liftIO $ atomicallyNamed " action queue - pop " $ popQueue actionQueue
690
691
actionFork (run otSpan d) $ \ _ -> pumpActionThread otSpan
691
692
692
693
-- TODO figure out how to thread the otSpan into defineEarlyCutoff
693
694
run _otSpan d = do
694
695
start <- liftIO offsetTime
695
696
getAction d
696
- liftIO $ atomically $ doneQueue d actionQueue
697
+ liftIO $ atomicallyNamed " actionQueue - done " $ doneQueue d actionQueue
697
698
runTime <- liftIO start
698
699
let msg = T. pack $ " finish: " ++ actionName d
699
700
++ " (took " ++ showDuration runTime ++ " )"
@@ -752,11 +753,11 @@ instantiateDelayedAction (DelayedAction _ s p a) = do
752
753
753
754
getDiagnostics :: IdeState -> IO [FileDiagnostic ]
754
755
getDiagnostics IdeState {shakeExtras = ShakeExtras {diagnostics}} = do
755
- atomically $ getAllDiagnostics diagnostics
756
+ atomicallyNamed " getAllDiagnostics " $ getAllDiagnostics diagnostics
756
757
757
758
getHiddenDiagnostics :: IdeState -> IO [FileDiagnostic ]
758
759
getHiddenDiagnostics IdeState {shakeExtras = ShakeExtras {hiddenDiagnostics}} = do
759
- atomically $ getAllDiagnostics hiddenDiagnostics
760
+ atomicallyNamed " getAllDiagnostics - hidden " $ getAllDiagnostics hiddenDiagnostics
760
761
761
762
-- | Find and release old keys from the state Hashmap
762
763
-- For the record, there are other state sources that this process does not release:
@@ -780,7 +781,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
780
781
start <- liftIO offsetTime
781
782
extras <- getShakeExtras
782
783
let values = state extras
783
- (n:: Int , garbage ) <- liftIO $ atomically $
784
+ (n:: Int , garbage ) <- liftIO $ atomicallyNamed " garbage collect " $
784
785
foldM (removeDirtyKey values) (0 ,[] ) agedKeys
785
786
liftIO $ atomicModifyIORef_ (dirtyKeys extras) $ \ x ->
786
787
foldl' (flip HSet. insert) x garbage
@@ -1152,13 +1153,13 @@ updateFileDiagnostics fp k ShakeExtras{logger, diagnostics, hiddenDiagnostics, p
1152
1153
-- published. Otherwise, we might never publish certain diagnostics if
1153
1154
-- an exception strikes between modifyVar but before
1154
1155
-- publishDiagnosticsNotification.
1155
- newDiags <- liftIO $ atomically $ update (map snd currentShown) diagnostics
1156
- _ <- liftIO $ atomically $ update (map snd currentHidden) hiddenDiagnostics
1156
+ newDiags <- liftIO $ atomicallyNamed " diagnostics - update " $ update (map snd currentShown) diagnostics
1157
+ _ <- liftIO $ atomicallyNamed " diagnostics - hidden " $ update (map snd currentHidden) hiddenDiagnostics
1157
1158
let uri = filePathToUri' fp
1158
1159
let delay = if null newDiags then 0.1 else 0
1159
1160
registerEvent debouncer delay uri $ do
1160
1161
join $ mask_ $ do
1161
- lastPublish <- atomically $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri publishedDiagnostics
1162
+ lastPublish <- atomicallyNamed " diagnostics - publish " $ STM. focus (Focus. lookupWithDefault [] <* Focus. insert newDiags) uri publishedDiagnostics
1162
1163
let action = when (lastPublish /= newDiags) $ case lspEnv of
1163
1164
Nothing -> -- Print an LSP event.
1164
1165
logInfo logger $ showDiagnosticsColored $ map (fp,ShowDiag ,) newDiags
@@ -1217,7 +1218,7 @@ getAllDiagnostics =
1217
1218
1218
1219
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> List TextDocumentContentChangeEvent -> IO ()
1219
1220
updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } (List changes) =
1220
- atomically $ STM. focus (Focus. alter f) uri positionMapping
1221
+ atomicallyNamed " updatePositionMapping " $ STM. focus (Focus. alter f) uri positionMapping
1221
1222
where
1222
1223
uri = toNormalizedUri _uri
1223
1224
f = Just . f' . fromMaybe mempty
0 commit comments