Skip to content

Commit 6c647d1

Browse files
authored
Preserve dirty set and add dirtiness assertion (#2279)
* do not throw away the previous dirty set * assertion
1 parent 37370f4 commit 6c647d1

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

ghcide/ghcide.cabal

+6-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ library
213213
Development.IDE.Types.Action
214214
Text.Fuzzy.Parallel
215215

216-
ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns -Wno-unticked-promoted-constructors
216+
ghc-options:
217+
-Wall
218+
-Wno-name-shadowing
219+
-Wincomplete-uni-patterns
220+
-Wno-unticked-promoted-constructors
221+
-fno-ignore-asserts
217222

218223
if flag(ghc-patched-unboxed-bytecode)
219224
cpp-options: -DGHC_PATCHED_UNBOXED_BYTECODE

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ import Development.IDE.Core.PositionMapping
109109
import Development.IDE.Core.ProgressReporting
110110
import Development.IDE.Core.RuleTypes
111111
import Development.IDE.Core.Tracing
112-
import Development.IDE.GHC.Compat (NameCacheUpdater (..),
113-
upNameCache, NameCache,
112+
import Development.IDE.GHC.Compat (NameCache,
113+
NameCacheUpdater (..),
114114
initNameCache,
115+
knownKeyNames,
115116
mkSplitUniqSupply,
116-
knownKeyNames)
117+
upNameCache)
117118
import Development.IDE.GHC.Orphans ()
118119
import Development.IDE.Graph hiding (ShakeValue)
119120
import qualified Development.IDE.Graph as Shake
@@ -914,7 +915,10 @@ defineEarlyCutoff' doDiagnostics key file old mode action = do
914915
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) $ Vector.toList diags
915916
return $ Just $ RunResult ChangedNothing old $ A v
916917
_ -> return Nothing
917-
_ -> return Nothing
918+
_ ->
919+
-- assert that a "clean" rule is never a cache miss
920+
-- as this is likely a bug in the dirty key tracking
921+
assert (mode /= RunDependenciesSame) $ return Nothing
918922
res <- case val of
919923
Just res -> return res
920924
Nothing -> do

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ incDatabase db (Just kk) = do
6666
intern <- readIORef (databaseIds db)
6767
let dirtyIds = mapMaybe (`Intern.lookup` intern) kk
6868
transitiveDirtyIds <- transitiveDirtySet db dirtyIds
69-
writeIORef (databaseDirtySet db) (Just $ Set.toList transitiveDirtyIds)
69+
modifyIORef (databaseDirtySet db) (\dd -> Just $ fromMaybe mempty dd <> transitiveDirtyIds)
7070
withLock (databaseLock db) $
7171
Ids.forMutate (databaseValues db) $ \i -> \case
7272
(k, Running _ _ x) -> (k, Dirty x)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import qualified Data.HashMap.Strict as Map
1414
import Data.IORef
1515
import Data.IntMap (IntMap)
1616
import qualified Data.IntMap as IntMap
17+
import qualified Data.IntSet as Set
1718
import Data.List (dropWhileEnd, foldl',
1819
intercalate, partition,
1920
sort, sortBy)
@@ -45,7 +46,7 @@ writeProfile :: FilePath -> Database -> IO ()
4546
writeProfile out db = do
4647
dirtyKeys <- readIORef (databaseDirtySet db)
4748
(report, mapping) <- toReport db
48-
let dirtyKeysMapped = mapMaybe (`IntMap.lookup` mapping) <$> dirtyKeys
49+
let dirtyKeysMapped = mapMaybe (`IntMap.lookup` mapping) . Set.toList <$> dirtyKeys
4950
rpt <- generateHTML (sort <$> dirtyKeysMapped) report
5051
LBS.writeFile out rpt
5152

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ data Database = Database {
8181
databaseExtra :: Dynamic,
8282
databaseRules :: TheRules,
8383
databaseStep :: !(IORef Step),
84-
databaseDirtySet :: IORef (Maybe [Id]),
84+
-- | Nothing means that everything is dirty
85+
databaseDirtySet :: IORef (Maybe IntSet),
8586
-- Hold the lock while mutating Ids/Values
8687
databaseLock :: !Lock,
8788
databaseIds :: !(IORef (Intern Key)),

0 commit comments

Comments
 (0)