Skip to content

Commit c266ee8

Browse files
committed
Characterize eval plugin race leading to GetLinkable errors
1 parent a6f0008 commit c266ee8

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
@@ -951,7 +951,7 @@ getModIfaceRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $
951951
hsc <- hscEnv <$> use_ GhcSessionDeps f
952952
let compile = fmap ([],) $ use GenerateCore f
953953
se <- getShakeExtras
954-
(diags, !mbHiFile) <- writeCoreFileIfNeeded se hsc linkableType compile tmr
954+
(diags, !mbHiFile) <- writeCoreFileIfNeeded se hsc (ts2 "linkableType" f linkableType) compile tmr
955955
let fp = hiFileFingerPrint <$> mbHiFile
956956
hiDiags <- case mbHiFile of
957957
Just hiFile
@@ -980,6 +980,12 @@ incrementRebuildCount = do
980980
count <- getRebuildCountVar <$> getIdeGlobalAction
981981
liftIO $ atomically $ modifyTVar' count (+1)
982982

983+
ts :: Show a => String -> a -> a
984+
ts label x = trace ("TRACE: " <> label <> "=" <> show x) x
985+
986+
ts2 :: Show a => String -> NormalizedFilePath -> a -> a
987+
ts2 label nfp x = trace ("TRACE: " <> label <> "=" <> show x <> " (" <> show nfp <> ")") x
988+
983989
-- | Also generates and indexes the `.hie` file, along with the `.o` file if needed
984990
-- Invariant maintained is that if the `.hi` file was successfully written, then the
985991
-- `.hie` and `.o` file (if needed) were also successfully written
@@ -1005,7 +1011,7 @@ regenerateHiFile sess f ms compNeeded = do
10051011
se <- getShakeExtras
10061012

10071013
-- Bang pattern is important to avoid leaking 'tmr'
1008-
(diags'', !res) <- writeCoreFileIfNeeded se hsc compNeeded compile tmr
1014+
(diags'', !res) <- writeCoreFileIfNeeded se hsc (ts2 "compNeeded" f compNeeded) compile tmr
10091015

10101016
-- Write hi file
10111017
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)