Skip to content

Commit ceff4d0

Browse files
committed
write reverse deps directly
1 parent a1c4768 commit ceff4d0

File tree

10 files changed

+307
-231
lines changed

10 files changed

+307
-231
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ getModIfaceFromDiskAndIndexRule recorder =
838838
se@ShakeExtras{withHieDb} <- getShakeExtras
839839

840840
-- GetModIfaceFromDisk should have written a `.hie` file, must check if it matches version in db
841+
842+
-- this might not happens if the changes to cache dir does not actually inroduce a change to GetModIfaceFromDisk
843+
841844
let ms = hirModSummary x
842845
hie_loc = Compat.ml_hie_file $ ms_location ms
843846
fileHash <- liftIO $ Util.getFileHash hie_loc

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ import Development.IDE.Graph.Database (ShakeDatabase,
154154
shakePeekAsyncsDelivers,
155155
shakeProfileDatabase,
156156
shakeRunDatabaseForKeysSep,
157-
shakeShutDatabase,
158-
shakedatabaseRuntimeDep)
159-
import Development.IDE.Graph.Internal.Action (runActionInDbCb)
157+
shakeShutDatabase)
158+
import Development.IDE.Graph.Internal.Action (isAsyncException,
159+
runActionInDbCb)
160160
import Development.IDE.Graph.Internal.Database (AsyncParentKill (AsyncParentKill))
161161
import Development.IDE.Graph.Internal.Types (DBQue, Step (..),
162162
getShakeQueue,
@@ -261,7 +261,7 @@ instance Pretty Log where
261261
, "Current step:" <+> pretty (show step)
262262
, "Aborting previous build session took" <+> pretty (showDuration abortDuration) <+> pretty shakeProfilePath ]
263263
LogBuildSessionRestartTakingTooLong seconds ->
264-
"Build restart is taking too long (" <> pretty seconds <> " seconds)"
264+
"Build restart is taking too long (" <> pretty (showDuration seconds) <> ")"
265265
LogDelayedAction delayedAct seconds ->
266266
hsep
267267
[ "Finished:" <+> pretty (actionName delayedAct)
@@ -949,10 +949,11 @@ runRestartTask recorder ideStateVar shakeRestartArgs = do
949949
shakeSession
950950
( \runner -> do
951951
newDirtyKeys <- sraBetweenSessions shakeRestartArgs
952-
reverseMap <- shakedatabaseRuntimeDep shakeDb
953-
(preservekvs, allRunning2) <- shakeComputeToPreserve shakeDb $ fromListKeySet newDirtyKeys
954-
logWith recorder Debug $ LogPreserveKeys (map fst preservekvs) newDirtyKeys [] reverseMap
955-
(stopTime, ()) <- duration $ logErrorAfter 10 $ cancelShakeSession runner $ S.fromList $ map snd preservekvs
952+
-- reverseMap <- shakedatabaseRuntimeDep shakeDb
953+
-- logWith recorder Debug $ LogPreserveKeys (map fst preservekvs) newDirtyKeys [] reverseMap
954+
(stopTime, ()) <- duration $ do
955+
(preservekvs, _allRunning2) <- shakeComputeToPreserve shakeDb $ fromListKeySet newDirtyKeys
956+
logErrorAfter 10 $ cancelShakeSession runner $ S.fromList $ map snd preservekvs
956957
survivedDelivers <- shakePeekAsyncsDelivers shakeDb
957958
-- it is every important to update the dirty keys after we enter the critical section
958959
-- see Note [Housekeeping rule cache and dirty key outside of hls-graph]
@@ -1041,7 +1042,7 @@ newSession recorder extras@ShakeExtras{..} vfsMod shakeDb acts reason newDirtyKe
10411042
-- Runs actions from the work queue sequentially
10421043
logResult :: Show a => String -> [Either SomeException a] -> IO ()
10431044
logResult label results = for_ results $ \case
1044-
Left e | Just (AsyncParentKill _ _) <- fromException e -> logWith recorder Debug $ LogShakeText (T.pack $ label ++ " failed: " ++ show e)
1045+
Left e | isAsyncException e -> logWith recorder Debug $ LogShakeText (T.pack $ label ++ " failed: " ++ show e)
10451046
Left e -> logWith recorder Error $ LogShakeText (T.pack $ label ++ " failed: " ++ show e)
10461047
Right r -> logWith recorder Debug $ LogShakeText (T.pack $ label ++ " finished: " ++ show r)
10471048
pumpActionThread = do

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

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ module Development.IDE.Graph.Database(
1414
shakeShutDatabase,
1515
shakeGetActionQueueLength,
1616
shakeComputeToPreserve,
17-
shakedatabaseRuntimeDep,
17+
-- shakedatabaseRuntimeDep,
1818
shakePeekAsyncsDelivers,
19-
upSweepAction) where
19+
upSweepAction,
20+
shakeGetTransitiveDirtyListBottomUp) where
2021
import Control.Concurrent.Async (Async)
2122
import Control.Concurrent.STM.Stats (atomically,
2223
readTVarIO)
2324
import Control.Exception (SomeException)
24-
import Control.Monad (forM, join)
25+
import Control.Monad (join)
2526
import Data.Dynamic
26-
import Data.HashMap.Strict (toList)
2727
import Data.Maybe
2828
import Data.Set (Set)
2929
import Debug.Trace (traceEvent)
@@ -79,7 +79,7 @@ shakeRunDatabaseForKeysSep
7979
-> [Action a]
8080
-> IO (IO [Either SomeException a])
8181
shakeRunDatabaseForKeysSep keysChanged (ShakeDatabase lenAs1 as1 db) as2 = do
82-
traceEvent ("upsweep dirties " ++ show keysChanged) $ incDatabase db keysChanged
82+
bottomUp <- traceEvent ("upsweep dirties " ++ show keysChanged) $ incDatabase db keysChanged
8383
-- Prepare upsweep actions for changed keys if provided
8484
ups <- case keysChanged of
8585
Nothing -> pure []
@@ -91,39 +91,16 @@ shakeRunDatabaseForKeysSep keysChanged (ShakeDatabase lenAs1 as1 db) as2 = do
9191
-- as2Delayed <- mapM (mkDelayedActionI "user" 1) as2
9292
return $ drop lenAs1 <$> runActions (newKey "root") db (map unvoid (as1 ++ ups) ++ as2)
9393

94-
-- shakeRunDatabaseForDelayedActionsSep
95-
-- :: Maybe [Key]
96-
-- -- ^ Set of keys changed since last run. 'Nothing' means everything has changed
97-
-- -> ShakeDatabase
98-
-- -> [Action a]
99-
-- -> [(Key, Async ())]
100-
-- -> Maybe KeySet
101-
-- -> KeySet
102-
-- -> IO (IO [Either SomeException a])
103-
-- shakeRunDatabaseForDelayedActionsSep keysChanged (ShakeDatabase _lenAs1 as1 db) as2 preservedKeys affected newDirtyKeys = do
104-
-- incDatabase db keysChanged
105-
-- -- todo run as2 too
106-
-- let preservedKeyset = fromListKeySet $ map fst preservedKeys
107-
-- das1 = filter (\da -> shouldRun $ actionName da) as1
108-
-- lenAs1 = length das1
109-
-- shouldRun k = case (keysChanged, affected) of
110-
-- (Nothing, _) -> k `notMemberKeySet` preservedKeyset
111-
-- (Just _, Just afs) -> k `memberKeySet` afs
112-
-- (Just _, Nothing) -> True
113-
-- Step s <- readTVarIO (databaseStep db)
114-
-- -- we don't know the child that triggered; use a self-child to kick the chain
115-
-- ups <- mapM (\k -> mkDelayedActionFixed ("upsweep-" ++ show k) 1 (upSweepAction (Step s) k k)) (toListKeySet newDirtyKeys)
116-
-- return $ drop lenAs1 <$> runActions db (map unvoid (das1 ++ ups) ++ filter (\da -> actionName da `notMemberKeySet` preservedKeyset) as2 )
117-
118-
shakedatabaseRuntimeDep :: ShakeDatabase -> IO [(Key, KeySet)]
119-
shakedatabaseRuntimeDep (ShakeDatabase _ _ db) =
120-
atomically $ toList <$> computeReverseRuntimeMap db
121-
12294

12395
shakeComputeToPreserve :: ShakeDatabase -> KeySet -> IO ([(Key, Async ())], KeySet)
12496
shakeComputeToPreserve (ShakeDatabase _ _ db) ks = atomically (computeToPreserve db ks)
12597

126-
--a dsfds
98+
-- | Compute the transitive closure of the given keys over reverse dependencies
99+
-- and return them in bottom-up order (children before parents).
100+
shakeGetTransitiveDirtyListBottomUp :: ShakeDatabase -> [Key] -> IO [Key]
101+
shakeGetTransitiveDirtyListBottomUp (ShakeDatabase _ _ db) seeds =
102+
transitiveDirtyListBottomUp db seeds
103+
127104
-- fds make it possible to do al ot of jobs
128105
shakeRunDatabaseForKeys
129106
:: Maybe [Key]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Development.IDE.Graph.Internal.Action
1414
, Development.IDE.Graph.Internal.Action.getDirtySet
1515
, getKeysAndVisitedAge
1616
, runActionInDbCb
17+
, isAsyncException
1718
) where
1819

1920
import Control.Concurrent.Async

0 commit comments

Comments
 (0)