Skip to content

Commit 773bfee

Browse files
committed
new hls-graph runtime
1 parent 08350aa commit 773bfee

File tree

19 files changed

+367
-281
lines changed

19 files changed

+367
-281
lines changed

ghcide/ghcide.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ library
142142
Development.IDE.Core.Shake
143143
Development.IDE.Core.Tracing
144144
Development.IDE.Core.UseStale
145-
Development.IDE.Core.WorkerThread
146145
Development.IDE.GHC.Compat
147146
Development.IDE.GHC.Compat.Core
148147
Development.IDE.GHC.Compat.CmdLine

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

Lines changed: 10 additions & 2 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
109108
import qualified Development.IDE.GHC.Compat.Util as Compat
110109
import Development.IDE.Session.Diagnostics (renderCradleError)
111110
import Development.IDE.Types.Shake (WithHieDb,
112111
WithHieDbShield (..),
113112
toNoFileKey)
113+
import Development.IDE.WorkerThread
114114
import GHC.Data.Graph.Directed
115115
import HieDb.Create
116116
import HieDb.Types
@@ -153,6 +153,14 @@ 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+
156164
instance Pretty Log where
157165
pretty = \case
158166
LogSessionWorkerThread msg -> pretty msg
@@ -384,7 +392,7 @@ runWithDb recorder fp = ContT $ \k -> do
384392
_ <- withWriteDbRetryable deleteMissingRealFiles
385393
_ <- withWriteDbRetryable garbageCollectTypeNames
386394

387-
runContT (withWorkerQueue (cmapWithPrio LogSessionWorkerThread recorder) "hiedb thread" (writer withWriteDbRetryable))
395+
runContT (withWorkerQueue (logWith (cmapWithPrio LogSessionWorkerThread recorder) Debug) "hiedb thread" (writer withWriteDbRetryable))
388396
$ \chan -> withHieDb fp (\readDb -> k (WithHieDbShield $ makeWithHieDbRetryable recorder rng readDb, chan))
389397
where
390398
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.Core.WorkerThread (writeTaskQueue)
78+
import Development.IDE.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
4948
import Development.IDE.GHC.Orphans ()
5049
import Development.IDE.Graph
5150
import Development.IDE.Import.DependencyInformation
5251
import Development.IDE.Types.Diagnostics
5352
import Development.IDE.Types.Location
5453
import Development.IDE.Types.Options
5554
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: 121 additions & 87 deletions
Large diffs are not rendered by default.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ 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
5049
import qualified Development.IDE.Session as Session
5150
import Development.IDE.Types.Shake (WithHieDb,
5251
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)
5758
import System.Timeout (timeout)
5859
data Log
5960
= LogRegisteringIdeConfig !IdeConfiguration
@@ -67,10 +68,13 @@ data Log
6768
| LogShutDownTimeout Int
6869
| LogServerExitWith (Either () Int)
6970
| LogReactorShutdownConfirmed !T.Text
71+
| LogInitializeIdeStateTookTooLong Seconds
7072
deriving Show
7173

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

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

hls-graph/hls-graph.cabal

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

7071
autogen-modules: Paths_hls_graph
7172
hs-source-dirs: src
7273
build-depends:
74+
, mtl ^>=2.3.1
75+
, safe-exceptions ^>=0.1.7.4
7376
, aeson
7477
, async >=2.0
7578
, base >=4.12 && <5
@@ -129,6 +132,7 @@ test-suite tests
129132
-threaded -rtsopts -with-rtsopts=-N -fno-ignore-asserts
130133

131134
build-depends:
135+
, transformers ^>=0.6.1.2
132136
, base
133137
, extra
134138
, hls-graph
@@ -138,5 +142,6 @@ test-suite tests
138142
, tasty
139143
, tasty-hspec >= 1.2
140144
, tasty-rerun
145+
, transformers
141146

142147
build-tool-depends: hspec-discover:hspec-discover

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

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

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

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

2527

2628
-- Placeholder to be the 'extra' if the user doesn't set it
2729
data NonExportedType = NonExportedType
2830

29-
shakeNewDatabase :: ShakeOptions -> Rules () -> IO ShakeDatabase
30-
shakeNewDatabase opts rules = do
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
3136
let extra = fromMaybe (toDyn NonExportedType) $ shakeExtra opts
3237
(theRules, actions) <- runRules extra rules
33-
db <- newDatabase extra theRules
38+
db <- newDatabase que extra theRules
3439
pure $ ShakeDatabase (length actions) actions db
3540

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

0 commit comments

Comments
 (0)