Skip to content

Commit 3d6d44a

Browse files
committed
lock-free hls-graph
1 parent 4e2a99e commit 3d6d44a

File tree

8 files changed

+187
-379
lines changed

8 files changed

+187
-379
lines changed

hls-graph/hls-graph.cabal

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ library
4242
Development.IDE.Graph.Internal.Options
4343
Development.IDE.Graph.Internal.Rules
4444
Development.IDE.Graph.Internal.Database
45-
Development.IDE.Graph.Internal.Ids
46-
Development.IDE.Graph.Internal.Intern
4745
Development.IDE.Graph.Internal.Paths
4846
Development.IDE.Graph.Internal.Profile
4947
Development.IDE.Graph.Internal.Types
@@ -63,11 +61,15 @@ library
6361
, exceptions
6462
, extra
6563
, filepath
64+
, focus
6665
, hashable
6766
, js-dgtable
6867
, js-flot
6968
, js-jquery
69+
, list-t
7070
, primitive
71+
, stm
72+
, stm-containers
7173
, time
7274
, transformers
7375
, unordered-containers

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ module Development.IDE.Graph.Database(
1212
shakeGetDirtySet,
1313
shakeGetCleanKeys
1414
,shakeGetBuildEdges) where
15+
import Control.Concurrent.STM (atomically,
16+
readTVarIO)
1517
import Data.Dynamic
16-
import Data.IORef (readIORef)
1718
import Data.Maybe
1819
import Development.IDE.Graph.Classes ()
1920
import Development.IDE.Graph.Internal.Action
2021
import Development.IDE.Graph.Internal.Database
21-
import qualified Development.IDE.Graph.Internal.Ids as Ids
2222
import Development.IDE.Graph.Internal.Options
2323
import Development.IDE.Graph.Internal.Profile (writeProfile)
2424
import Development.IDE.Graph.Internal.Rules
@@ -45,12 +45,12 @@ shakeRunDatabase = shakeRunDatabaseForKeys Nothing
4545
-- | Returns the set of dirty keys annotated with their age (in # of builds)
4646
shakeGetDirtySet :: ShakeDatabase -> IO [(Key, Int)]
4747
shakeGetDirtySet (ShakeDatabase _ _ db) =
48-
fmap snd <$> Development.IDE.Graph.Internal.Database.getDirtySet db
48+
Development.IDE.Graph.Internal.Database.getDirtySet db
4949

5050
-- | Returns the build number
5151
shakeGetBuildStep :: ShakeDatabase -> IO Int
5252
shakeGetBuildStep (ShakeDatabase _ _ db) = do
53-
Step s <- readIORef $ databaseStep db
53+
Step s <- readTVarIO $ databaseStep db
5454
return s
5555

5656
-- Only valid if we never pull on the results, which we don't
@@ -64,7 +64,7 @@ shakeRunDatabaseForKeys
6464
-> [Action a]
6565
-> IO ([a], [IO ()])
6666
shakeRunDatabaseForKeys keysChanged (ShakeDatabase lenAs1 as1 db) as2 = do
67-
incDatabase db keysChanged
67+
atomically $ incDatabase db keysChanged
6868
as <- fmap (drop lenAs1) $ runActions db $ map unvoid as1 ++ as2
6969
return (as, [])
7070

@@ -75,12 +75,12 @@ shakeProfileDatabase (ShakeDatabase _ _ s) file = writeProfile file s
7575
-- | Returns the clean keys in the database
7676
shakeGetCleanKeys :: ShakeDatabase -> IO [(Key, Result )]
7777
shakeGetCleanKeys (ShakeDatabase _ _ db) = do
78-
keys <- Ids.elems $ databaseValues db
78+
keys <- getDatabaseValues db
7979
return [ (k,res) | (k, Clean res) <- keys]
8080

8181
-- | Returns the total count of edges in the build graph
8282
shakeGetBuildEdges :: ShakeDatabase -> IO Int
8383
shakeGetBuildEdges (ShakeDatabase _ _ db) = do
84-
keys <- Ids.elems $ databaseValues db
84+
keys <- getDatabaseValues db
8585
let ress = mapMaybe (getResult . snd) keys
8686
return $ sum $ map (length . getResultDepsDefault [] . resultDeps) ress

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ runActions db xs = do
130130
getDirtySet :: Action [(Key, Int)]
131131
getDirtySet = do
132132
db <- getDatabase
133-
liftIO $ fmap snd <$> Development.IDE.Graph.Internal.Database.getDirtySet db
133+
liftIO $ Development.IDE.Graph.Internal.Database.getDirtySet db
134134

135135
getKeysAndVisitedAge :: Action [(Key, Int)]
136136
getKeysAndVisitedAge = do

0 commit comments

Comments
 (0)