Skip to content

Commit e758781

Browse files
committed
remove running wait
1 parent e12a7d3 commit e758781

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ computeToPreserve db dirtySet = do
100100
updateDirty :: Monad m => Focus.Focus KeyDetails m ()
101101
updateDirty = Focus.adjust $ \(KeyDetails status rdeps) ->
102102
let status'
103-
| Running _ x _ <- status = Dirty x
103+
| Running _ x <- status = Dirty x
104104
| Clean x <- status = Dirty (Just x)
105105
| otherwise = status
106106
in KeyDetails status' rdeps
@@ -156,7 +156,6 @@ data FirstTime = FirstTime | NotFirstTime
156156
builderOne' :: FirstTime -> Key -> Database -> Stack -> Key -> IO BuildContinue
157157
builderOne' firstTime parentKey db@Database {..} stack kid = do
158158
traceEvent ("builderOne: " ++ show kid) return ()
159-
barrier <- newEmptyMVar
160159
-- join is used to register the async
161160
join $ atomicallyNamed "builder" $ do
162161
-- Spawn the id if needed
@@ -167,23 +166,28 @@ builderOne' firstTime parentKey db@Database {..} stack kid = do
167166
NotFirstTime -> return ()
168167
status <- SMap.lookup kid databaseValues
169168
current <- readTVar databaseStep
169+
let revisit =
170+
case firstTime of
171+
FirstTime -> pure . pure $ BCContinue $ do
172+
br <- builderOne' NotFirstTime parentKey db stack kid
173+
case br of
174+
BCContinue ioR -> ioR
175+
BCStop k r -> pure $ Right (k, r)
176+
NotFirstTime -> retry
170177
case (viewToRun current . keyStatus) =<< status of
171178
Nothing -> do
172-
SMap.focus (updateStatus $ Running current Nothing barrier) kid databaseValues
173-
let register = spawnRefresh1 db stack kid barrier Nothing refresh
174-
$ atomicallyNamed "builderOne rollback" $ SMap.delete kid databaseValues
175-
return $ register >> return (BCContinue $ readMVar barrier)
176-
Just (Dirty _) -> case firstTime of
177-
FirstTime -> pure . pure $ BCContinue $ do
178-
br <- builderOne' NotFirstTime parentKey db stack kid
179-
case br of
180-
BCContinue ioR -> ioR
181-
BCStop k r -> pure $ Right (k, r)
182-
NotFirstTime -> retry
183-
Just (Clean r) -> pure . pure $ BCStop kid r
184-
Just (Running _step _s wait)
179+
SMap.focus (updateStatus $ Running current Nothing) kid databaseValues
180+
let register barrier = do
181+
spawnRefresh1 db stack kid barrier Nothing refresh
182+
$ atomicallyNamed "builderOne rollback" $ SMap.delete kid databaseValues
183+
return $ do
184+
barrier <- newEmptyMVar
185+
register barrier >> return (BCContinue $ readMVar barrier)
186+
Just (Dirty _) -> revisit
187+
Just (Running _step _s)
185188
| memberStack kid stack -> throw $ StackException stack
186-
| otherwise -> pure . pure $ BCContinue $ readMVar wait
189+
| otherwise -> revisit
190+
Just (Clean r) -> pure . pure $ BCStop kid r
187191

188192
-- Original spawnRefresh1 implementation moved below to use the abstraction
189193

@@ -248,7 +252,7 @@ upSweep db@Database {..} stack key childtKey = mask $ \restore -> do
248252
case viewDirty current $ maybe (Dirty Nothing) keyStatus status of
249253
-- if it is still dirty, we update it and propogate further
250254
(Dirty s) -> do
251-
SMap.focus (updateStatus $ Running current s barrier) key databaseValues
255+
SMap.focus (updateStatus $ Running current s) key databaseValues
252256
-- if it is clean, other event update it, so it is fine.
253257
return $ spawnRefresh1 db stack key barrier s (\db stack key s -> restore $ do
254258
result <- refresh db stack key s

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ data Status
477477
| Running {
478478
runningStep :: !Step,
479479
-- runningResult :: Result, -- LAZY
480-
runningPrev :: !(Maybe Result),
481-
runningWait :: !(MVar (Either SomeException (Key, Result)))
480+
runningPrev :: !(Maybe Result)
482481
}
483482

484483
viewDirty :: Step -> Status -> Status
@@ -492,9 +491,9 @@ viewToRun :: Step -> Status -> Maybe Status
492491
viewToRun _ other = Just other
493492

494493
getResult :: Status -> Maybe Result
495-
getResult (Clean re) = Just re
496-
getResult (Dirty m_re) = m_re
497-
getResult (Running _ m_re _) = m_re -- watch out: this returns the previous result
494+
getResult (Clean re) = Just re
495+
getResult (Dirty m_re) = m_re
496+
getResult (Running _ m_re) = m_re -- watch out: this returns the previous result
498497

499498

500499
data Result = Result {

0 commit comments

Comments
 (0)