Skip to content

Commit e426e76

Browse files
committed
Characterize eval plugin race leading to GetLinkable errors
1 parent 9593d04 commit e426e76

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
529529
core_file = codeGutsToCoreFile iface_hash guts
530530
iface_hash = getModuleHash final_iface
531531
core_hash1 <- atomicFileWrite se core_fp $ \fp ->
532-
writeBinCoreFile fp core_file
532+
533+
trace ("TRACE: writeBinCoreFile: core_fp=" <> core_fp) $ writeBinCoreFile fp core_file
533534
-- We want to drop references to guts and read in a serialized, compact version
534535
-- of the core file from disk (as it is deserialised lazily)
535536
-- This is because we don't want to keep the guts in memory for every file in
@@ -1448,6 +1449,9 @@ instance NFData IdeLinkable where
14481449
ml_core_file :: ModLocation -> FilePath
14491450
ml_core_file ml = ml_hi_file ml <.> "core"
14501451

1452+
ts :: Show a => String -> a -> a
1453+
ts label x = trace ("TRACE: " <> label <> "=" <> show x) x
1454+
14511455
-- | Returns an up-to-date module interface, regenerating if needed.
14521456
-- Assumes file exists.
14531457
-- Requires the 'HscEnv' to be set up with dependencies

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ import GHC (mgModSummaries)
181181
import qualified Data.IntMap as IM
182182
#endif
183183

184-
184+
import Debug.Trace
185185

186186
data Log
187187
= LogShake Shake.Log
@@ -940,7 +940,7 @@ getModIfaceRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $
940940
hsc <- hscEnv <$> use_ GhcSessionDeps f
941941
let compile = fmap ([],) $ use GenerateCore f
942942
se <- getShakeExtras
943-
(diags, !mbHiFile) <- writeCoreFileIfNeeded se hsc linkableType compile tmr
943+
(diags, !mbHiFile) <- writeCoreFileIfNeeded se hsc (ts2 "linkableType" f linkableType) compile tmr
944944
let fp = hiFileFingerPrint <$> mbHiFile
945945
hiDiags <- case mbHiFile of
946946
Just hiFile
@@ -969,6 +969,12 @@ incrementRebuildCount = do
969969
count <- getRebuildCountVar <$> getIdeGlobalAction
970970
liftIO $ atomically $ modifyTVar' count (+1)
971971

972+
ts :: Show a => String -> a -> a
973+
ts label x = trace ("TRACE: " <> label <> "=" <> show x) x
974+
975+
ts2 :: Show a => String -> NormalizedFilePath -> a -> a
976+
ts2 label nfp x = trace ("TRACE: " <> label <> "=" <> show x <> " (" <> show nfp <> ")") x
977+
972978
-- | Also generates and indexes the `.hie` file, along with the `.o` file if needed
973979
-- Invariant maintained is that if the `.hi` file was successfully written, then the
974980
-- `.hie` and `.o` file (if needed) were also successfully written
@@ -994,7 +1000,7 @@ regenerateHiFile sess f ms compNeeded = do
9941000
se <- getShakeExtras
9951001

9961002
-- Bang pattern is important to avoid leaking 'tmr'
997-
(diags'', !res) <- writeCoreFileIfNeeded se hsc compNeeded compile tmr
1003+
(diags'', !res) <- writeCoreFileIfNeeded se hsc (ts2 "compNeeded" f compNeeded) compile tmr
9981004

9991005
-- Write hi file
10001006
hiDiags <- case res of

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Rules.hs

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import GHC.Parser.Annotation
4141
import Ide.Logger (Recorder, WithPriority,
4242
cmapWithPrio)
4343
import Ide.Plugin.Eval.Types
44-
44+
import Debug.Trace
4545

4646
rules :: Recorder (WithPriority Log) -> Rules ()
4747
rules recorder = do
@@ -56,13 +56,13 @@ instance IsIdeGlobal EvaluatingVar
5656
queueForEvaluation :: IdeState -> NormalizedFilePath -> IO ()
5757
queueForEvaluation ide nfp = do
5858
EvaluatingVar var <- getIdeGlobalState ide
59-
atomicModifyIORef' var (\fs -> (Set.insert nfp fs, ()))
59+
atomicModifyIORef' var (\fs -> (trace ("TRACE: queueForEvaluation: " <> show nfp ) $ Set.insert nfp fs, ()))
6060

6161
unqueueForEvaluation :: IdeState -> NormalizedFilePath -> IO ()
6262
unqueueForEvaluation ide nfp = do
6363
EvaluatingVar var <- getIdeGlobalState ide
6464
-- remove the module from the Evaluating state, so that next time it won't evaluate to True
65-
atomicModifyIORef' var $ \fs -> (Set.delete nfp fs, ())
65+
atomicModifyIORef' var $ \fs -> (trace ("TRACE: unqueueForEvaluation: " <> show nfp ) $ Set.delete nfp fs, ())
6666

6767
apiAnnComments' :: ParsedModule -> [SrcLoc.RealLocated EpaCommentTok]
6868
apiAnnComments' pm = do
@@ -110,7 +110,7 @@ isEvaluatingRule :: Recorder (WithPriority Log) -> Rules ()
110110
isEvaluatingRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $ RuleNoDiagnostics $ \IsEvaluating f -> do
111111
alwaysRerun
112112
EvaluatingVar var <- getIdeGlobalAction
113-
b <- liftIO $ (f `Set.member`) <$> readIORef var
113+
b <- fmap (ts2 "isMemberEvaluatingVar" f) . liftIO $ (f `Set.member`) <$> readIORef var
114114
return (Just (if b then BS.singleton 1 else BS.empty), Just b)
115115

116116
-- Redefine the NeedsCompilation rule to set the linkable type to Just _
@@ -120,12 +120,15 @@ isEvaluatingRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $
120120
-- leading to much better performance of the evaluate code lens
121121
redefinedNeedsCompilation :: Recorder (WithPriority Log) -> Rules ()
122122
redefinedNeedsCompilation recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $ RuleWithCustomNewnessCheck (<=) $ \NeedsCompilation f -> do
123-
isEvaluating <- use_ IsEvaluating f
123+
isEvaluating <- ts2 "isEvaluating" f <$> use_ IsEvaluating f
124124

125125
if not isEvaluating then needsCompilationRule f else do
126126
ms <- msrModSummary . fst <$> useWithStale_ GetModSummaryWithoutTimestamps f
127127
let df' = ms_hspp_opts ms
128128
linkableType = computeLinkableTypeForDynFlags df'
129129
fp = encodeLinkableType $ Just linkableType
130130

131-
pure (Just fp, Just (Just linkableType))
131+
pure (Just fp, ts2 "redefinedNeedsCompilation" f $ Just (Just linkableType))
132+
133+
ts2 :: Show a => String -> NormalizedFilePath -> a -> a
134+
ts2 label nfp x = trace ("TRACE: " <> label <> "=" <> show x <> "(" <> show nfp <> ")") x

0 commit comments

Comments
 (0)