Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect reverse dependencies #802

Closed
wants to merge 33 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4bf8dbb
Collect reverse dependencies
pepeiborra Mar 14, 2021
7cd0112
don't use return
pepeiborra Mar 16, 2021
c150aea
backwards compat.
pepeiborra Mar 16, 2021
7b39567
redundant pragma
pepeiborra Mar 16, 2021
e864c62
export
pepeiborra Mar 16, 2021
7e56674
alwaysRerun
pepeiborra Mar 16, 2021
9a85eaa
Add SCC pragmas, needed because not exported
pepeiborra Mar 17, 2021
7f2d282
clarify error call
pepeiborra Mar 17, 2021
d5693f8
Unbreak early cutoff
pepeiborra Mar 17, 2021
1867be0
Add some more comments
pepeiborra Mar 18, 2021
d4b49f6
compatibility with older base
pepeiborra Mar 19, 2021
5c8c2a8
Masking async exceptions
pepeiborra Mar 19, 2021
6649576
redundant import
pepeiborra Mar 19, 2021
c3983fa
add more diagnostics
pepeiborra Mar 19, 2021
3d47a41
fix another bug
pepeiborra Mar 19, 2021
ba0fbe1
avoid copying Result records
pepeiborra Mar 19, 2021
32a4f6c
do not mark AlwaysRerun as dirty by default
pepeiborra Mar 19, 2021
d01c40c
Existential wrapper for ShakeValue
pepeiborra Mar 19, 2021
0dfbd0a
fix typo
pepeiborra Mar 19, 2021
834a764
microopt: store the RDeps in an IORef
pepeiborra Mar 19, 2021
d357f9f
use getResult
pepeiborra Mar 21, 2021
ee46bc2
Add stateful dirty set to keep track across runs
pepeiborra Mar 21, 2021
67d2501
Increase diagnostic output
pepeiborra Mar 21, 2021
0f29380
mask until the dirty set is updated
pepeiborra Mar 21, 2021
52ed87e
redundant import
pepeiborra Mar 21, 2021
e0ee243
comments
pepeiborra Mar 21, 2021
4270b2e
Store the reverse dependencies in an Ids array
pepeiborra Mar 21, 2021
0313892
imports
pepeiborra Mar 21, 2021
e6c0199
Compat. with GHC 8.0
pepeiborra Mar 22, 2021
6669768
shakeReverseDependencies
pepeiborra Apr 2, 2021
0a7ce83
Special handling of alwaysRerun
pepeiborra May 13, 2021
ec620ac
Visit only the dirty dependencies
pepeiborra May 15, 2021
35cdf3a
fix imports
pepeiborra May 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Visit only the dirty dependencies
pepeiborra committed Jul 4, 2021
commit ec620ac40de77d58f22103a8cff9b2747a83f8ba
3 changes: 2 additions & 1 deletion src/Development/Shake/Database.hs
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ import Development.Shake.Internal.Core.Run
import Development.Shake.Internal.Core.Types
import Development.Shake.Internal.Rules.Default
import Development.Shake.Internal.Value (SomeShakeValue(..), newKey)
import Development.Shake.Internal.Core.Database (markDirty, getIdFromKey)
import Development.Shake.Internal.Core.Database (flushDirty, markDirty, getIdFromKey, runLocked)


data UseState
@@ -169,6 +169,7 @@ shakeRunDatabaseForKeys keysChanged (ShakeDatabase use s) as = uninterruptibleMa
when openOneShot $
throwM $ errorStructured "Error when calling shakeRunDatabase twice, after calling shakeOneShotDatabase" [] ""
reset s
runLocked (database s) $ flushDirty (database s)

-- record the keys changed and continue
whenJust keysChanged $ \kk -> do
15 changes: 13 additions & 2 deletions src/Development/Shake/Internal/Core/Build.hs
Original file line number Diff line number Diff line change
@@ -172,11 +172,22 @@ buildRunMode global stack database i r = do
Just id -> any (\(Depends x) -> id `elem` x) (depends me)
pure $ if changed then RunDependenciesChanged else RunDependenciesSame

isDirtyOrAlwaysRerun :: MonadIO m => DatabasePoly Key v -> m (Id -> Bool)
isDirtyOrAlwaysRerun database = do
lookup <- liftIO $ getIdFromKey database
dirtySet <- liftIO $ getDirtySet database
let alwaysRerunId = lookup $ newKey $ AlwaysRerunQ ()
pure $ \id -> Just id == alwaysRerunId || id `HashSet.member` dirtySet

-- | Have the dependencies changed
buildRunDependenciesChanged :: Global -> Stack -> Database -> Id -> Result a -> Wait Locked Bool
buildRunDependenciesChanged global stack database i r = isJust <$> firstJustM id
[firstJustWaitUnordered (fmap test . lookupOne global stack database) x | Depends x <- depends r]
buildRunDependenciesChanged global stack database i r = do
isDirty <- isDirtyOrAlwaysRerun database
isJust <$> firstJustM id
[firstJustWaitUnordered (fmap test . lookupOne global stack database) x'
| Depends x <- depends r
, let x' = if globalUseDirtySet global then filter isDirty x else x
]
where
test (Right dep) | changed dep <= built r = Nothing
test _ = Just ()
13 changes: 10 additions & 3 deletions src/Development/Shake/Internal/Core/Database.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving, RecordWildCards #-}

{-# LANGUAGE TupleSections #-}
module Development.Shake.Internal.Core.Database(
Locked, runLocked,
maskLocked,
DatabasePoly, createDatabase,
mkId,
getValueFromKey, getIdFromKey, getKeyValues, getKeyValueFromId, getKeyValuesFromId,
setMem, setDisk, modifyAllMem,
isDirty, getDirtySet, markDirty, unmarkDirty,
isDirty, getDirtySet, markDirty, unmarkDirty, flushDirty,
getReverseDependencies, setReverseDependencies
) where

@@ -48,7 +49,7 @@ data DatabasePoly k v = Database
,rdeps :: Ids.Ids (HashSet Id) -- ^ Id |-> reverse dependencies
,journal :: Id -> k -> v -> IO () -- ^ Record all changes to status
,vDefault :: v
,dirty :: IORef (HashSet Id)
,clean,dirty :: IORef (HashSet Id)
-- ^ An approximation of the dirty set across runs of 'shakeRunDatabaseForKeys'
}

@@ -65,6 +66,7 @@ createDatabase status rdeps journal vDefault = do
intern <- newIORef $ Intern.fromList [(k, i) | (i, (k,_)) <- xs]
lock <- newLock
dirty <- newIORef mempty
clean <- newIORef mempty
pure Database{..}


@@ -138,4 +140,9 @@ markDirty Database{..} ids = atomicModifyIORef'_ dirty $ HSet.union ids

unmarkDirty :: DatabasePoly k v -> Id -> IO ()
unmarkDirty Database{..} i = do
atomicModifyIORef'_ dirty (HSet.delete i)
atomicModifyIORef'_ clean (HSet.insert i)

flushDirty :: DatabasePoly k v -> Locked ()
flushDirty Database{..} = liftIO $ do
cleanIds <- atomicModifyIORef' clean (mempty,)
atomicModifyIORef'_ dirty (`HSet.difference` cleanIds)