Skip to content

Commit 08e7a8a

Browse files
committed
Revert "new hls-graph runtime"
This reverts commit 773bfee.
1 parent f0ae0ee commit 08e7a8a

File tree

19 files changed

+281
-367
lines changed

19 files changed

+281
-367
lines changed

ghcide/ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ library
142142
Development.IDE.Core.Shake
143143
Development.IDE.Core.Tracing
144144
Development.IDE.Core.UseStale
145+
Development.IDE.Core.WorkerThread
145146
Development.IDE.GHC.Compat
146147
Development.IDE.GHC.Compat.Core
147148
Development.IDE.GHC.Compat.CmdLine

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ import qualified Data.HashSet as Set
105105
import qualified Data.Set as OS
106106
import Database.SQLite.Simple
107107
import Development.IDE.Core.Tracing (withTrace)
108+
import Development.IDE.Core.WorkerThread
108109
import qualified Development.IDE.GHC.Compat.Util as Compat
109110
import Development.IDE.Session.Diagnostics (renderCradleError)
110111
import Development.IDE.Types.Shake (WithHieDb,
111112
WithHieDbShield (..),
112113
toNoFileKey)
113-
import Development.IDE.WorkerThread
114114
import GHC.Data.Graph.Directed
115115
import HieDb.Create
116116
import HieDb.Types
@@ -153,14 +153,6 @@ data Log
153153
| LogSessionWorkerThread LogWorkerThread
154154
deriving instance Show Log
155155

156-
instance Pretty LogWorkerThread where
157-
pretty = \case
158-
LogThreadEnding t -> "Worker thread ending:" <+> pretty t
159-
LogThreadEnded t -> "Worker thread ended:" <+> pretty t
160-
LogSingleWorkStarting t -> "Worker starting a unit of work: " <+> pretty t
161-
LogSingleWorkEnded t -> "Worker ended a unit of work: " <+> pretty t
162-
LogMainThreadId t tid -> "Main thread for" <+> pretty t <+> "is" <+> pretty (show tid)
163-
164156
instance Pretty Log where
165157
pretty = \case
166158
LogSessionWorkerThread msg -> pretty msg
@@ -392,7 +384,7 @@ runWithDb recorder fp = ContT $ \k -> do
392384
_ <- withWriteDbRetryable deleteMissingRealFiles
393385
_ <- withWriteDbRetryable garbageCollectTypeNames
394386

395-
runContT (withWorkerQueue (logWith (cmapWithPrio LogSessionWorkerThread recorder) Debug) "hiedb thread" (writer withWriteDbRetryable))
387+
runContT (withWorkerQueue (cmapWithPrio LogSessionWorkerThread recorder) "hiedb thread" (writer withWriteDbRetryable))
396388
$ \chan -> withHieDb fp (\readDb -> k (WithHieDbShield $ makeWithHieDbRetryable recorder rng readDb, chan))
397389
where
398390
writer withHieDbRetryable l = do

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import Development.IDE.Core.Preprocessor
7575
import Development.IDE.Core.ProgressReporting (progressUpdate)
7676
import Development.IDE.Core.RuleTypes
7777
import Development.IDE.Core.Shake
78-
import Development.IDE.WorkerThread (writeTaskQueue)
78+
import Development.IDE.Core.WorkerThread (writeTaskQueue)
7979
import Development.IDE.Core.Tracing (withTrace)
8080
import qualified Development.IDE.GHC.Compat as Compat
8181
import qualified Development.IDE.GHC.Compat as GHC

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ import Development.IDE.Core.IdeConfiguration (isWorkspaceFile)
4545
import Development.IDE.Core.RuleTypes
4646
import Development.IDE.Core.Shake hiding (Log)
4747
import qualified Development.IDE.Core.Shake as Shake
48+
import Development.IDE.Core.WorkerThread
4849
import Development.IDE.GHC.Orphans ()
4950
import Development.IDE.Graph
5051
import Development.IDE.Import.DependencyInformation
5152
import Development.IDE.Types.Diagnostics
5253
import Development.IDE.Types.Location
5354
import Development.IDE.Types.Options
5455
import Development.IDE.Types.Shake (toKey)
55-
import Development.IDE.WorkerThread
5656
import HieDb.Create (deleteMissingRealFiles)
5757
import Ide.Logger (Pretty (pretty),
5858
Priority (Info),

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 87 additions & 121 deletions
Large diffs are not rendered by default.

hls-graph/src/Development/IDE/WorkerThread.hs renamed to ghcide/src/Development/IDE/Core/WorkerThread.hs

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
11
{-
2-
Module : Development.IDE.WorkerThread
2+
Module : Development.IDE.Core.WorkerThread
33
Author : @soulomoon
44
SPDX-License-Identifier: Apache-2.0
55
66
Description : This module provides an API for managing worker threads in the IDE.
77
see Note [Serializing runs in separate thread]
88
-}
9-
{-# LANGUAGE LambdaCase #-}
10-
{-# LANGUAGE OverloadedStrings #-}
11-
12-
module Development.IDE.WorkerThread
9+
module Development.IDE.Core.WorkerThread
1310
( LogWorkerThread (..),
1411
withWorkerQueue,
1512
awaitRunInThread,
1613
TaskQueue,
1714
writeTaskQueue,
18-
withWorkerQueueSimple,
19-
awaitRunInThreadStm,
20-
awaitRunInThreadStmInNewThread
21-
) where
15+
withWorkerQueueSimple
16+
)
17+
where
2218

23-
import Control.Concurrent.Async (Async, async, withAsync)
19+
import Control.Concurrent.Async (withAsync)
2420
import Control.Concurrent.STM
25-
import Control.Exception.Safe (MonadMask (..),
26-
SomeException (SomeException),
27-
finally, throw, try)
28-
import Control.Monad.Cont (ContT (ContT))
29-
import qualified Data.Text as T
30-
31-
import Control.Concurrent
32-
import Control.Exception (catch)
33-
import Control.Monad (void, when)
21+
import Control.Concurrent.Strict (newBarrier, signalBarrier,
22+
waitBarrier)
23+
import Control.Exception.Safe (SomeException, finally, throwIO,
24+
try)
25+
import Control.Monad.Cont (ContT (ContT))
26+
import qualified Data.Text as T
27+
import Ide.Logger
3428

3529
data LogWorkerThread
3630
= LogThreadEnding !T.Text
3731
| LogThreadEnded !T.Text
3832
| LogSingleWorkStarting !T.Text
3933
| LogSingleWorkEnded !T.Text
40-
| LogMainThreadId !T.Text !ThreadId
4134
deriving (Show)
4235

43-
-- instance Pretty LogWorkerThread where
44-
-- pretty = \case
45-
-- LogThreadEnding t -> "Worker thread ending:" <+> pretty t
46-
-- LogThreadEnded t -> "Worker thread ended:" <+> pretty t
47-
-- LogSingleWorkStarting t -> "Worker starting a unit of work: " <+> pretty t
48-
-- LogSingleWorkEnded t -> "Worker ended a unit of work: " <+> pretty t
49-
-- LogMainThreadId t tid -> "Main thread for" <+> pretty t <+> "is" <+> pretty (show tid)
36+
instance Pretty LogWorkerThread where
37+
pretty = \case
38+
LogThreadEnding t -> "Worker thread ending:" <+> pretty t
39+
LogThreadEnded t -> "Worker thread ended:" <+> pretty t
40+
LogSingleWorkStarting t -> "Worker starting a unit of work: " <+> pretty t
41+
LogSingleWorkEnded t -> "Worker ended a unit of work: " <+> pretty t
5042

5143
{-
5244
Note [Serializing runs in separate thread]
@@ -62,17 +54,14 @@ data TaskQueue a = TaskQueue (TQueue a)
6254
newTaskQueueIO :: IO (TaskQueue a)
6355
newTaskQueueIO = TaskQueue <$> newTQueueIO
6456
data ExitOrTask t = Exit | Task t
65-
type Logger = LogWorkerThread -> IO ()
6657

6758
-- | 'withWorkerQueue' creates a new 'TQueue', and launches a worker
6859
-- thread which polls the queue for requests and runs the given worker
6960
-- function on them.
70-
withWorkerQueueSimple :: Logger -> T.Text -> ContT () IO (TaskQueue (IO ()))
61+
withWorkerQueueSimple :: Recorder (WithPriority LogWorkerThread) -> T.Text -> ContT () IO (TaskQueue (IO ()))
7162
withWorkerQueueSimple log title = withWorkerQueue log title id
72-
withWorkerQueue :: Logger -> T.Text -> (t -> IO ()) -> ContT () IO (TaskQueue t)
63+
withWorkerQueue :: Recorder (WithPriority LogWorkerThread) -> T.Text -> (t -> IO ()) -> ContT () IO (TaskQueue t)
7364
withWorkerQueue log title workerAction = ContT $ \mainAction -> do
74-
tid <- myThreadId
75-
log (LogMainThreadId title tid)
7665
q <- newTaskQueueIO
7766
-- Use a TMVar as a stop flag to coordinate graceful shutdown.
7867
-- The worker thread checks this flag before dequeuing each job; if set, it exits immediately,
@@ -87,8 +76,8 @@ withWorkerQueue log title workerAction = ContT $ \mainAction -> do
8776
-- if we want to debug the exact location the worker swallows an async exception, we can
8877
-- temporarily comment out the `finally` clause.
8978
`finally` atomically (putTMVar b ())
90-
log (LogThreadEnding title)
91-
log (LogThreadEnded title)
79+
logWith log Debug (LogThreadEnding title)
80+
logWith log Debug (LogThreadEnded title)
9281
where
9382
-- writerThread :: TaskQueue t -> TMVar () -> (forall a. IO a -> IO a) -> IO ()
9483
writerThread q b =
@@ -104,46 +93,24 @@ withWorkerQueue log title workerAction = ContT $ \mainAction -> do
10493
case task of
10594
Exit -> return ()
10695
Task t -> do
107-
log $ LogSingleWorkStarting title
96+
logWith log Debug $ LogSingleWorkStarting title
10897
workerAction t
109-
log $ LogSingleWorkEnded title
98+
logWith log Debug $ LogSingleWorkEnded title
11099
writerThread q b
111100

112101

113102
-- | 'awaitRunInThread' queues up an 'IO' action to be run by a worker thread,
114103
-- and then blocks until the result is computed. If the action throws an
115104
-- non-async exception, it is rethrown in the calling thread.
116-
awaitRunInThreadStm :: TaskQueue (IO ()) -> IO result -> STM result
117-
awaitRunInThreadStm (TaskQueue q) act = do
118-
barrier <- newEmptyTMVar
119-
-- Take an action from TQueue, run it and
120-
-- use barrier to wait for the result
121-
writeTQueue q (try act >>= atomically . putTMVar barrier)
122-
resultOrException <- takeTMVar barrier
123-
case resultOrException of
124-
Left e -> throw (e :: SomeException)
125-
Right r -> return r
126-
127-
awaitRunInThreadStmInNewThread :: STM Int -> Int -> TaskQueue (IO ()) -> TVar [Async ()] -> IO result -> (SomeException -> IO ()) -> STM ()
128-
awaitRunInThreadStmInNewThread getStep deliverStep (TaskQueue q) tthreads act handler = do
129-
-- Take an action from TQueue, run it and
130-
-- use barrier to wait for the result
131-
writeTQueue q (uninterruptibleMask $ \restore -> do
132-
curStep <- atomically getStep
133-
when (curStep == deliverStep) $ do
134-
sync <- async (restore (void act `catch` \(SomeException e) -> handler (SomeException e)))
135-
atomically $ modifyTVar' tthreads (sync:)
136-
)
137-
138105
awaitRunInThread :: TaskQueue (IO ()) -> IO result -> IO result
139106
awaitRunInThread (TaskQueue q) act = do
140-
barrier <- newEmptyTMVarIO
141107
-- Take an action from TQueue, run it and
142108
-- use barrier to wait for the result
143-
atomically $ writeTQueue q (try act >>= atomically . putTMVar barrier)
144-
resultOrException <- atomically $ takeTMVar barrier
109+
barrier <- newBarrier
110+
atomically $ writeTQueue q (try act >>= signalBarrier barrier)
111+
resultOrException <- waitBarrier barrier
145112
case resultOrException of
146-
Left e -> throw (e :: SomeException)
113+
Left e -> throwIO (e :: SomeException)
147114
Right r -> return r
148115

149116
writeTaskQueue :: TaskQueue a -> a -> STM ()

ghcide/src/Development/IDE/LSP/LanguageServer.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ import Development.IDE.Core.IdeConfiguration
4646
import Development.IDE.Core.Service (shutdown)
4747
import Development.IDE.Core.Shake hiding (Log)
4848
import Development.IDE.Core.Tracing
49+
import Development.IDE.Core.WorkerThread
4950
import qualified Development.IDE.Session as Session
5051
import Development.IDE.Types.Shake (WithHieDb,
5152
WithHieDbShield (..))
52-
import Development.IDE.WorkerThread
5353
import Ide.Logger
5454
import Language.LSP.Server (LanguageContextEnv,
5555
LspServerLog,
5656
type (<~>))
57-
import System.Time.Extra (Seconds, sleep)
5857
import System.Timeout (timeout)
5958
data Log
6059
= LogRegisteringIdeConfig !IdeConfiguration
@@ -68,13 +67,10 @@ data Log
6867
| LogShutDownTimeout Int
6968
| LogServerExitWith (Either () Int)
7069
| LogReactorShutdownConfirmed !T.Text
71-
| LogInitializeIdeStateTookTooLong Seconds
7270
deriving Show
7371

7472
instance Pretty Log where
7573
pretty = \case
76-
LogInitializeIdeStateTookTooLong seconds ->
77-
"Building the initial session took more than" <+> pretty seconds <+> "seconds"
7874
LogReactorShutdownRequested b ->
7975
"Requested reactor shutdown; stop signal posted: " <+> pretty b
8076
LogReactorShutdownConfirmed msg ->
@@ -354,8 +350,8 @@ handleInit initParams env (TRequestMessage _ _ m params) = otTracedHandler "Init
354350
runWithWorkerThreads :: Recorder (WithPriority Session.Log) -> FilePath -> (WithHieDb -> ThreadQueue -> IO ()) -> IO ()
355351
runWithWorkerThreads recorder dbLoc f = evalContT $ do
356352
(WithHieDbShield hiedb, threadQueue) <- runWithDb recorder dbLoc
357-
sessionRestartTQueue <- withWorkerQueueSimple (logWith (cmapWithPrio Session.LogSessionWorkerThread recorder) Debug) "RestartTQueue"
358-
sessionLoaderTQueue <- withWorkerQueueSimple (logWith (cmapWithPrio Session.LogSessionWorkerThread recorder) Debug) "SessionLoaderTQueue"
353+
sessionRestartTQueue <- withWorkerQueueSimple (cmapWithPrio Session.LogSessionWorkerThread recorder) "RestartTQueue"
354+
sessionLoaderTQueue <- withWorkerQueueSimple (cmapWithPrio Session.LogSessionWorkerThread recorder) "SessionLoaderTQueue"
359355
liftIO $ f hiedb (ThreadQueue threadQueue sessionRestartTQueue sessionLoaderTQueue)
360356

361357
-- | Runs the action until it ends or until the given MVar is put.

hls-graph/hls-graph.cabal

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,11 @@ library
6565
Development.IDE.Graph.KeyMap
6666
Development.IDE.Graph.KeySet
6767
Development.IDE.Graph.Rule
68-
Development.IDE.WorkerThread
6968
Paths_hls_graph
7069

7170
autogen-modules: Paths_hls_graph
7271
hs-source-dirs: src
7372
build-depends:
74-
, mtl ^>=2.3.1
75-
, safe-exceptions ^>=0.1.7.4
7673
, aeson
7774
, async >=2.0
7875
, base >=4.12 && <5
@@ -132,7 +129,6 @@ test-suite tests
132129
-threaded -rtsopts -with-rtsopts=-N -fno-ignore-asserts
133130

134131
build-depends:
135-
, transformers ^>=0.6.1.2
136132
, base
137133
, extra
138134
, hls-graph
@@ -142,6 +138,5 @@ test-suite tests
142138
, tasty
143139
, tasty-hspec >= 1.2
144140
, tasty-rerun
145-
, transformers
146141

147142
build-tool-depends: hspec-discover:hspec-discover

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module Development.IDE.Graph(
1818
-- * Actions for inspecting the keys in the database
1919
getDirtySet,
2020
getKeysAndVisitedAge,
21-
2221
module Development.IDE.Graph.KeyMap,
2322
module Development.IDE.Graph.KeySet,
2423
) where

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ module Development.IDE.Graph.Database(
99
shakeGetDatabaseKeys,
1010
shakeGetDirtySet,
1111
shakeGetCleanKeys
12-
,shakeGetBuildEdges,
13-
shakeShutDatabase) where
12+
,shakeGetBuildEdges) where
1413
import Control.Concurrent.STM.Stats (readTVarIO)
1514
import Data.Dynamic
1615
import Data.Maybe
@@ -22,20 +21,16 @@ import Development.IDE.Graph.Internal.Options
2221
import Development.IDE.Graph.Internal.Profile (writeProfile)
2322
import Development.IDE.Graph.Internal.Rules
2423
import Development.IDE.Graph.Internal.Types
25-
import Development.IDE.WorkerThread (TaskQueue)
2624

2725

2826
-- Placeholder to be the 'extra' if the user doesn't set it
2927
data NonExportedType = NonExportedType
3028

31-
shakeShutDatabase :: ShakeDatabase -> IO ()
32-
shakeShutDatabase (ShakeDatabase _ _ db) = shutDatabase db
33-
34-
shakeNewDatabase :: TaskQueue (IO ()) -> ShakeOptions -> Rules () -> IO ShakeDatabase
35-
shakeNewDatabase que opts rules = do
29+
shakeNewDatabase :: ShakeOptions -> Rules () -> IO ShakeDatabase
30+
shakeNewDatabase opts rules = do
3631
let extra = fromMaybe (toDyn NonExportedType) $ shakeExtra opts
3732
(theRules, actions) <- runRules extra rules
38-
db <- newDatabase que extra theRules
33+
db <- newDatabase extra theRules
3934
pure $ ShakeDatabase (length actions) actions db
4035

4136
shakeRunDatabase :: ShakeDatabase -> [Action a] -> IO [a]

0 commit comments

Comments
 (0)