From 40603e83e2493d7fba2b6df5f5bcd862f5e841a2 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 6 Oct 2021 17:03:40 +0100 Subject: [PATCH 1/2] do not throw away the previous dirty set --- hls-graph/src/Development/IDE/Graph/Internal/Database.hs | 2 +- hls-graph/src/Development/IDE/Graph/Internal/Profile.hs | 3 ++- hls-graph/src/Development/IDE/Graph/Internal/Types.hs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs index bfd08a8df8..19a932980f 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs @@ -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) diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs b/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs index 18837386a6..62a3cc714d 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs @@ -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) @@ -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 diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Types.hs b/hls-graph/src/Development/IDE/Graph/Internal/Types.hs index db0b34ef5d..a8845cc0cc 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Types.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Types.hs @@ -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)), From 3308a8ec12285ced58496ab995aea290f0759b0c Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sun, 17 Oct 2021 09:15:30 +0100 Subject: [PATCH 2/2] assertion --- ghcide/ghcide.cabal | 7 ++++++- ghcide/src/Development/IDE/Core/Shake.hs | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ghcide/ghcide.cabal b/ghcide/ghcide.cabal index 72e304ddec..0ff9eb5adc 100644 --- a/ghcide/ghcide.cabal +++ b/ghcide/ghcide.cabal @@ -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 diff --git a/ghcide/src/Development/IDE/Core/Shake.hs b/ghcide/src/Development/IDE/Core/Shake.hs index 99c0cfb71a..57a0f237e9 100644 --- a/ghcide/src/Development/IDE/Core/Shake.hs +++ b/ghcide/src/Development/IDE/Core/Shake.hs @@ -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 @@ -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