Skip to content

Commit fa48fda

Browse files
authored
Fix core file location in GetLinkable (#4347)
Fix #4145 The error case is demonstrated in #4145 (comment) Include ModLocation in the ModSummaryResult fingerprint. Instead of getting the core file location from GetModSummary, get it from the result of GetModIface directly since that is the actual location the core file written to.
1 parent f0ba40b commit fa48fda

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import Development.IDE.Types.Location
9494
import Development.IDE.Types.Options
9595
import GHC (ForeignHValue,
9696
GetDocsFailure (..),
97-
parsedSource)
97+
parsedSource, ModLocation (..))
9898
import qualified GHC.LanguageExtensions as LangExt
9999
import GHC.Serialized
100100
import HieDb hiding (withHieDb)
@@ -1021,8 +1021,17 @@ getModSummaryFromImports env fp _modTime mContents = do
10211021
return $! Util.fingerprintFingerprints $
10221022
[ Util.fingerprintString fp
10231023
, fingerPrintImports
1024+
, modLocationFingerprint ms_location
10241025
] ++ map Util.fingerprintString opts
10251026

1027+
modLocationFingerprint :: ModLocation -> Util.Fingerprint
1028+
modLocationFingerprint ModLocation{..} = Util.fingerprintFingerprints $
1029+
Util.fingerprintString <$> [ fromMaybe "" ml_hs_file
1030+
, ml_hi_file
1031+
, ml_dyn_hi_file
1032+
, ml_obj_file
1033+
, ml_dyn_obj_file
1034+
, ml_hie_file]
10261035

10271036
-- | Parse only the module header
10281037
parseHeader

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,10 +1039,9 @@ usePropertyByPathAction path plId p = do
10391039
getLinkableRule :: Recorder (WithPriority Log) -> Rules ()
10401040
getLinkableRule recorder =
10411041
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GetLinkable f -> do
1042-
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary f
1043-
HiFileResult{hirModIface, hirModDetails, hirCoreFp} <- use_ GetModIface f
1044-
let obj_file = ml_obj_file (ms_location ms)
1045-
core_file = ml_core_file (ms_location ms)
1042+
HiFileResult{hirModSummary, hirModIface, hirModDetails, hirCoreFp} <- use_ GetModIface f
1043+
let obj_file = ml_obj_file (ms_location hirModSummary)
1044+
core_file = ml_core_file (ms_location hirModSummary)
10461045
case hirCoreFp of
10471046
Nothing -> error $ "called GetLinkable for a file without a linkable: " ++ show f
10481047
Just (bin_core, fileHash) -> do
@@ -1055,7 +1054,7 @@ getLinkableRule recorder =
10551054
core_t <- liftIO $ getModTime core_file
10561055
(warns, hmi) <- case linkableType of
10571056
-- Bytecode needs to be regenerated from the core file
1058-
BCOLinkable -> liftIO $ coreFileToLinkable linkableType (hscEnv session) ms hirModIface hirModDetails bin_core (posixSecondsToUTCTime core_t)
1057+
BCOLinkable -> liftIO $ coreFileToLinkable linkableType (hscEnv session) hirModSummary hirModIface hirModDetails bin_core (posixSecondsToUTCTime core_t)
10591058
-- Object code can be read from the disk
10601059
ObjectLinkable -> do
10611060
-- object file is up to date if it is newer than the core file
@@ -1068,8 +1067,8 @@ getLinkableRule recorder =
10681067
else pure Nothing
10691068
case mobj_time of
10701069
Just obj_t
1071-
| obj_t >= core_t -> pure ([], Just $ HomeModInfo hirModIface hirModDetails (justObjects $ LM (posixSecondsToUTCTime obj_t) (ms_mod ms) [DotO obj_file]))
1072-
_ -> liftIO $ coreFileToLinkable linkableType (hscEnv session) ms hirModIface hirModDetails bin_core (error "object doesn't have time")
1070+
| obj_t >= core_t -> pure ([], Just $ HomeModInfo hirModIface hirModDetails (justObjects $ LM (posixSecondsToUTCTime obj_t) (ms_mod hirModSummary) [DotO obj_file]))
1071+
_ -> liftIO $ coreFileToLinkable linkableType (hscEnv session) hirModSummary hirModIface hirModDetails bin_core (error "object doesn't have time")
10731072
-- Record the linkable so we know not to unload it, and unload old versions
10741073
whenJust ((homeModInfoByteCode =<< hmi) <|> (homeModInfoObject =<< hmi)) $ \(LM time mod _) -> do
10751074
compiledLinkables <- getCompiledLinkables <$> getIdeGlobalAction

0 commit comments

Comments
 (0)