Skip to content

Commit

Permalink
Preserve dirty set and add dirtiness assertion (#2279)
Browse files Browse the repository at this point in the history
* do not throw away the previous dirty set

* assertion
  • Loading branch information
pepeiborra committed Oct 17, 2021
1 parent 37370f4 commit 6c647d1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
7 changes: 6 additions & 1 deletion ghcide/ghcide.cabal
Expand Up @@ -213,7 +213,12 @@ library
Development.IDE.Types.Action
Text.Fuzzy.Parallel

ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns -Wno-unticked-promoted-constructors
ghc-options:
-Wall
-Wno-name-shadowing
-Wincomplete-uni-patterns
-Wno-unticked-promoted-constructors
-fno-ignore-asserts

if flag(ghc-patched-unboxed-bytecode)
cpp-options: -DGHC_PATCHED_UNBOXED_BYTECODE
Expand Down
12 changes: 8 additions & 4 deletions ghcide/src/Development/IDE/Core/Shake.hs
Expand Up @@ -109,11 +109,12 @@ import Development.IDE.Core.PositionMapping
import Development.IDE.Core.ProgressReporting
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Tracing
import Development.IDE.GHC.Compat (NameCacheUpdater (..),
upNameCache, NameCache,
import Development.IDE.GHC.Compat (NameCache,
NameCacheUpdater (..),
initNameCache,
knownKeyNames,
mkSplitUniqSupply,
knownKeyNames)
upNameCache)
import Development.IDE.GHC.Orphans ()
import Development.IDE.Graph hiding (ShakeValue)
import qualified Development.IDE.Graph as Shake
Expand Down Expand Up @@ -914,7 +915,10 @@ defineEarlyCutoff' doDiagnostics key file old mode action = do
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) $ Vector.toList diags
return $ Just $ RunResult ChangedNothing old $ A v
_ -> return Nothing
_ -> return Nothing
_ ->
-- assert that a "clean" rule is never a cache miss
-- as this is likely a bug in the dirty key tracking
assert (mode /= RunDependenciesSame) $ return Nothing
res <- case val of
Just res -> return res
Nothing -> do
Expand Down
2 changes: 1 addition & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Database.hs
Expand Up @@ -66,7 +66,7 @@ incDatabase db (Just kk) = do
intern <- readIORef (databaseIds db)
let dirtyIds = mapMaybe (`Intern.lookup` intern) kk
transitiveDirtyIds <- transitiveDirtySet db dirtyIds
writeIORef (databaseDirtySet db) (Just $ Set.toList transitiveDirtyIds)
modifyIORef (databaseDirtySet db) (\dd -> Just $ fromMaybe mempty dd <> transitiveDirtyIds)
withLock (databaseLock db) $
Ids.forMutate (databaseValues db) $ \i -> \case
(k, Running _ _ x) -> (k, Dirty x)
Expand Down
3 changes: 2 additions & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Profile.hs
Expand Up @@ -14,6 +14,7 @@ import qualified Data.HashMap.Strict as Map
import Data.IORef
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as Set
import Data.List (dropWhileEnd, foldl',
intercalate, partition,
sort, sortBy)
Expand Down Expand Up @@ -45,7 +46,7 @@ writeProfile :: FilePath -> Database -> IO ()
writeProfile out db = do
dirtyKeys <- readIORef (databaseDirtySet db)
(report, mapping) <- toReport db
let dirtyKeysMapped = mapMaybe (`IntMap.lookup` mapping) <$> dirtyKeys
let dirtyKeysMapped = mapMaybe (`IntMap.lookup` mapping) . Set.toList <$> dirtyKeys
rpt <- generateHTML (sort <$> dirtyKeysMapped) report
LBS.writeFile out rpt

Expand Down
3 changes: 2 additions & 1 deletion hls-graph/src/Development/IDE/Graph/Internal/Types.hs
Expand Up @@ -81,7 +81,8 @@ data Database = Database {
databaseExtra :: Dynamic,
databaseRules :: TheRules,
databaseStep :: !(IORef Step),
databaseDirtySet :: IORef (Maybe [Id]),
-- | Nothing means that everything is dirty
databaseDirtySet :: IORef (Maybe IntSet),
-- Hold the lock while mutating Ids/Values
databaseLock :: !Lock,
databaseIds :: !(IORef (Intern Key)),
Expand Down

0 comments on commit 6c647d1

Please sign in to comment.