Skip to content

Commit 38e7bf2

Browse files
committed
cleanup
1 parent f64fc67 commit 38e7bf2

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ isAsyncException e
8484
| Just (_ :: SomeAsyncException) <- fromException e = True
8585
| Just (_ :: AsyncCancelled) <- fromException e = True
8686
| Just (_ :: AsyncException) <- fromException e = True
87-
| Just (_ :: AsyncParentKill) <- fromException e = True
8887
| Just (_ :: ExitCode) <- fromException e = True
8988
| otherwise = False
9089

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{-# LANGUAGE RecordWildCards #-}
99
{-# LANGUAGE TypeFamilies #-}
1010

11-
module Development.IDE.Graph.Internal.Database (compute, newDatabase, incDatabase, build, getDirtySet, getKeysAndVisitAge, AsyncParentKill(..)) where
11+
module Development.IDE.Graph.Internal.Database (compute, newDatabase, incDatabase, build, getDirtySet, getKeysAndVisitAge) where
1212

1313
import Prelude hiding (unzip)
1414

@@ -88,8 +88,7 @@ build
8888
=> Database -> Stack -> f key -> IO (f Key, f value)
8989
-- build _ st k | traceShow ("build", st, k) False = undefined
9090
build db stack keys = do
91-
step <- readTVarIO $ databaseStep db
92-
!built <- runAIO step $ builder db stack (fmap newKey keys)
91+
!built <- runAIO $ builder db stack (fmap newKey keys)
9392
let (ids, vs) = unzip built
9493
pure (ids, fmap (asV . resultValue) vs)
9594
where
@@ -118,13 +117,13 @@ builderOne ba db@Database {..} stack id = UE.mask $ \restore -> do
118117
status <- SMap.lookup id databaseValues
119118
val <-
120119
let refreshRsult s = do
121-
let act =
122-
case ba of
123-
BuildNary -> restore $ asyncWithCleanUp $
124-
refresh db stack id s
125-
`UE.onException` (UE.uninterruptibleMask_ $ liftIO (atomicallyNamed "builder - onException" (SMap.focus updateDirty id databaseValues)))
126-
BuildUnary -> fmap return $ refresh db stack id s
127-
-- Mark the key as running
120+
let act = restore $ case ba of
121+
BuildNary ->
122+
asyncWithCleanUp $
123+
refresh db stack id s
124+
`UE.onException` (UE.uninterruptibleMask_ $ liftIO (atomicallyNamed "builder - onException" (SMap.focus updateDirty id databaseValues)))
125+
BuildUnary -> fmap return $ refresh db stack id s
126+
-- Mark the key as running
128127
SMap.focus (updateStatus $ Running current s) id databaseValues
129128
return act
130129
in case viewDirty current $ maybe (Dirty Nothing) keyStatus status of
@@ -286,23 +285,15 @@ transitiveDirtySet database = flip State.execStateT mempty . traverse_ loop
286285
newtype AIO a = AIO { unAIO :: ReaderT (IORef [Async ()]) IO a }
287286
deriving newtype (Applicative, Functor, Monad, MonadIO)
288287

289-
data AsyncParentKill = AsyncParentKill ThreadId Step
290-
deriving (Show, Eq)
291-
292-
instance Exception AsyncParentKill where
293-
toException = asyncExceptionToException
294-
fromException = asyncExceptionFromException
295-
296288
-- | Run the monadic computation, cancelling all the spawned asyncs if an exception arises
297-
runAIO :: Step -> AIO a -> IO a
298-
runAIO s (AIO act) = do
289+
runAIO :: AIO a -> IO a
290+
runAIO (AIO act) = do
299291
asyncsRef <- newIORef []
300292
-- Log the exact exception (including async exceptions) before cleanup,
301293
-- then rethrow to preserve previous semantics.
302294
runReaderT act asyncsRef `onException` do
303295
asyncs <- atomicModifyIORef' asyncsRef ([],)
304-
tid <- myThreadId
305-
cleanupAsync asyncs tid s
296+
cleanupAsync asyncs
306297

307298
-- | Like 'async' but with built-in cancellation.
308299
-- Returns an IO action to wait on the result.
@@ -326,12 +317,11 @@ instance MonadUnliftIO AIO where
326317
st <- AIO ask
327318
liftIO $ k (\aio -> runReaderT (unAIO aio) st)
328319

329-
cleanupAsync :: [Async a] -> ThreadId -> Step -> IO ()
320+
cleanupAsync :: [Async a] -> IO ()
330321
-- mask to make sure we interrupt all the asyncs
331-
cleanupAsync asyncs tid step = uninterruptibleMask $ \unmask -> do
322+
cleanupAsync asyncs = uninterruptibleMask $ \unmask -> do
332323
-- interrupt all the asyncs without waiting
333-
-- mapM_ (\a -> throwTo (asyncThreadId a) AsyncCancelled) asyncs
334-
mapM_ (\a -> throwTo (asyncThreadId a) $ AsyncParentKill tid step) asyncs
324+
mapM_ (\a -> throwTo (asyncThreadId a) AsyncCancelled) asyncs
335325
-- Wait until all the asyncs are done
336326
-- But if it takes more than 10 seconds, log to stderr
337327
unless (null asyncs) $ do

0 commit comments

Comments
 (0)