Skip to content

Commit 01a03ff

Browse files
committed
Refactor builder functions to support BuildArity for unary and n-ary cases
1 parent b11b939 commit 01a03ff

File tree

1 file changed

+11
-7
lines changed
  • hls-graph/src/Development/IDE/Graph/Internal

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,35 @@ build db stack keys = do
9696
asV :: Value -> value
9797
asV (Value x) = unwrapDynamic x
9898

99+
data BuildArity = BuildUnary | BuildNary
99100
-- | Build a list of keys and return their results.
100101
-- If none of the keys are dirty, we can return the results immediately.
101102
-- Otherwise, a blocking computation is returned *which must be evaluated asynchronously* to avoid deadlock.
102103
builder :: (Traversable f) => Database -> Stack -> f Key -> AIO (f (Key, Result))
103104
-- builder _ st kk | traceShow ("builder", st,kk) False = undefined
104105
builder db stack keys = do
105-
keyWaits <- for keys $ \k -> builderOne db stack k
106+
let ba = if length keys == 1 then BuildUnary else BuildNary
107+
keyWaits <- for keys $ \k -> builderOne ba db stack k
106108
!res <- for keyWaits $ \(k, waitR) -> do
107109
!v<- liftIO waitR
108110
return (k, v)
109111
return res
110112

111-
builderOne :: Database -> Stack -> Key -> AIO (Key, IO Result)
112-
builderOne db@Database {..} stack id = UE.mask $ \restore -> do
113+
builderOne :: BuildArity -> Database -> Stack -> Key -> AIO (Key, IO Result)
114+
builderOne ba db@Database {..} stack id = UE.mask $ \restore -> do
113115
current <- liftIO $ readTVarIO databaseStep
114116
(k, registerWaitResult) <- liftIO $ atomicallyNamed "builder" $ do
115117
-- Spawn the id if needed
116118
status <- SMap.lookup id databaseValues
117119
val <-
118120
let refreshRsult s = do
119121
let act =
120-
restore $ asyncWithCleanUp $
121-
refresh db stack id s
122-
`UE.onException` (UE.uninterruptibleMask_ $ liftIO (atomicallyNamed "builder - onException" (SMap.focus updateDirty id databaseValues)))
123-
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
124128
SMap.focus (updateStatus $ Running current s) id databaseValues
125129
return act
126130
in case viewDirty current $ maybe (Dirty Nothing) keyStatus status of

0 commit comments

Comments
 (0)