Skip to content

Commit f9b492c

Browse files
committed
add comments and format imports
1 parent aa8c320 commit f9b492c

File tree

1 file changed

+33
-27
lines changed
  • hls-graph/src/Development/IDE/Graph/Internal

1 file changed

+33
-27
lines changed

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

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
-- We deliberately want to ensure the function we add to the rule database
22
-- has the constraints we need on it when we get it out.
33
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
4-
{-# LANGUAGE LambdaCase #-}
4+
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE NamedFieldPuns #-}
6+
{-# LANGUAGE RecordWildCards #-}
57
{-# LANGUAGE ScopedTypeVariables #-}
6-
{-# LANGUAGE RecordWildCards #-}
7-
{-# LANGUAGE TypeFamilies #-}
8-
{-# LANGUAGE TupleSections #-}
9-
{-# LANGUAGE NamedFieldPuns #-}
8+
{-# LANGUAGE TupleSections #-}
9+
{-# LANGUAGE TypeFamilies #-}
1010

1111
module Development.IDE.Graph.Internal.Database where
1212

13-
import Development.IDE.Graph.Internal.Intern
14-
import Development.IDE.Graph.Internal.Types
15-
import Data.Dynamic
13+
import Control.Concurrent.Async
14+
import Control.Concurrent.Extra
15+
import Control.Exception
16+
import Control.Monad
17+
import Control.Monad.Trans.Reader
18+
import Data.Dynamic
19+
import Data.Either
20+
import Data.IORef.Extra
21+
import Data.Maybe
22+
import Data.Tuple.Extra
23+
import qualified Development.IDE.Graph.Internal.Ids as Ids
24+
import Development.IDE.Graph.Internal.Intern
1625
import qualified Development.IDE.Graph.Internal.Intern as Intern
17-
import qualified Development.IDE.Graph.Internal.Ids as Ids
18-
import Control.Concurrent.Extra
19-
import Data.IORef.Extra
20-
import Control.Monad
21-
import Development.Shake.Classes
22-
import qualified Development.Shake as Shake
23-
import Data.Maybe
24-
import Control.Concurrent.Async
25-
import System.IO.Unsafe
26-
import Development.IDE.Graph.Internal.Rules
27-
import qualified Development.Shake.Rule as Shake
28-
import Control.Exception
29-
import Control.Monad.Trans.Reader
30-
import Data.Tuple.Extra
31-
import Data.Either
26+
import Development.IDE.Graph.Internal.Rules
27+
import Development.IDE.Graph.Internal.Types
28+
import qualified Development.Shake as Shake
29+
import Development.Shake.Classes
30+
import qualified Development.Shake.Rule as Shake
31+
import System.IO.Unsafe
3232

3333
newDatabase :: Dynamic -> TheRules -> IO Database
3434
newDatabase databaseExtra databaseRules = do
@@ -38,15 +38,17 @@ newDatabase databaseExtra databaseRules = do
3838
databaseValues <- Ids.empty
3939
pure Database{..}
4040

41+
-- | Increment the step and mark all ids dirty
4142
incDatabase :: Database -> IO ()
4243
incDatabase db = do
4344
modifyIORef' (databaseStep db) $ \(Step i) -> Step $ i + 1
4445
Ids.forMutate (databaseValues db) $ second $ \case
45-
Clean x -> Dirty (Just x)
46-
Dirty x -> Dirty x
46+
Clean x -> Dirty (Just x)
47+
Dirty x -> Dirty x
4748
Running _ x -> Dirty x
4849

4950

51+
-- | Unwrap and build a list of keys in parallel
5052
build
5153
:: forall key value . (Shake.RuleResult key ~ value, Typeable key, Show key, Hashable key, Eq key, Typeable value)
5254
=> Database -> [key] -> IO ([Id], [value])
@@ -57,6 +59,7 @@ build db keys = do
5759
asV :: Value -> value
5860
asV (Value x) = unwrapDynamic x
5961

62+
-- | Build a list of keys in parallel
6063
builder
6164
:: Database -> [Either Id Key] -> IO [(Id, Result)]
6265
builder db@Database{..} keys = do
@@ -69,6 +72,7 @@ builder db@Database{..} keys = do
6972

7073
results <- withLock databaseLock $ do
7174
forM keys $ \idKey -> do
75+
-- Resolve the id
7276
id <- case idKey of
7377
Left id -> pure id
7478
Right key -> do
@@ -80,6 +84,7 @@ builder db@Database{..} keys = do
8084
writeIORef' databaseIds ids
8185
return id
8286

87+
-- Spawn the id if needed
8388
status <- Ids.lookup databaseValues id
8489
val <- case fromMaybe (fromRight undefined idKey, Dirty Nothing) status of
8590
(_, Clean r) -> pure r
@@ -111,7 +116,7 @@ cleanupAsync :: IORef [Async a] -> IO ()
111116
cleanupAsync ref = mapConcurrently_ uninterruptibleCancel =<< readIORef ref
112117

113118

114-
-- Check if we need to run the database.
119+
-- | Check if we need to run the database.
115120
check :: Database -> Key -> Id -> Maybe Result -> IO Result
116121
check db key id result@(Just me@Result{resultDeps=Just deps}) = do
117122
res <- builder db $ map Left deps
@@ -121,7 +126,7 @@ check db key id result@(Just me@Result{resultDeps=Just deps}) = do
121126
check db key id result = spawn db key id Shake.RunDependenciesChanged result
122127

123128

124-
-- Spawn a new computation to run the action.
129+
-- | Spawn a new computation to run the action.
125130
spawn :: Database -> Key -> Id -> Shake.RunMode -> Maybe Result -> IO Result
126131
spawn db@Database{..} key id mode result = do
127132
let act = runRule databaseRules key (fmap resultData result) mode
@@ -137,6 +142,7 @@ spawn db@Database{..} key id mode result = do
137142

138143
data Box a = Box {fromBox :: a}
139144

145+
-- | Split an IO computation into an unsafe lazy value and a forcing computation
140146
splitIO :: IO a -> (IO (), a)
141147
splitIO act = do
142148
let act2 = Box <$> act

0 commit comments

Comments
 (0)