Skip to content

Commit

Permalink
Fix core file location in GetLinkable (haskell#4347)
Browse files Browse the repository at this point in the history
Fix haskell#4145
The error case is demonstrated in haskell#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.
  • Loading branch information
soulomoon authored Jul 4, 2024
1 parent f0ba40b commit fa48fda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 10 additions & 1 deletion ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import Development.IDE.Types.Location
import Development.IDE.Types.Options
import GHC (ForeignHValue,
GetDocsFailure (..),
parsedSource)
parsedSource, ModLocation (..))
import qualified GHC.LanguageExtensions as LangExt
import GHC.Serialized
import HieDb hiding (withHieDb)
Expand Down Expand Up @@ -1021,8 +1021,17 @@ getModSummaryFromImports env fp _modTime mContents = do
return $! Util.fingerprintFingerprints $
[ Util.fingerprintString fp
, fingerPrintImports
, modLocationFingerprint ms_location
] ++ map Util.fingerprintString opts

modLocationFingerprint :: ModLocation -> Util.Fingerprint
modLocationFingerprint ModLocation{..} = Util.fingerprintFingerprints $
Util.fingerprintString <$> [ fromMaybe "" ml_hs_file
, ml_hi_file
, ml_dyn_hi_file
, ml_obj_file
, ml_dyn_obj_file
, ml_hie_file]

-- | Parse only the module header
parseHeader
Expand Down
13 changes: 6 additions & 7 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,9 @@ usePropertyByPathAction path plId p = do
getLinkableRule :: Recorder (WithPriority Log) -> Rules ()
getLinkableRule recorder =
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GetLinkable f -> do
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary f
HiFileResult{hirModIface, hirModDetails, hirCoreFp} <- use_ GetModIface f
let obj_file = ml_obj_file (ms_location ms)
core_file = ml_core_file (ms_location ms)
HiFileResult{hirModSummary, hirModIface, hirModDetails, hirCoreFp} <- use_ GetModIface f
let obj_file = ml_obj_file (ms_location hirModSummary)
core_file = ml_core_file (ms_location hirModSummary)
case hirCoreFp of
Nothing -> error $ "called GetLinkable for a file without a linkable: " ++ show f
Just (bin_core, fileHash) -> do
Expand All @@ -1055,7 +1054,7 @@ getLinkableRule recorder =
core_t <- liftIO $ getModTime core_file
(warns, hmi) <- case linkableType of
-- Bytecode needs to be regenerated from the core file
BCOLinkable -> liftIO $ coreFileToLinkable linkableType (hscEnv session) ms hirModIface hirModDetails bin_core (posixSecondsToUTCTime core_t)
BCOLinkable -> liftIO $ coreFileToLinkable linkableType (hscEnv session) hirModSummary hirModIface hirModDetails bin_core (posixSecondsToUTCTime core_t)
-- Object code can be read from the disk
ObjectLinkable -> do
-- object file is up to date if it is newer than the core file
Expand All @@ -1068,8 +1067,8 @@ getLinkableRule recorder =
else pure Nothing
case mobj_time of
Just obj_t
| obj_t >= core_t -> pure ([], Just $ HomeModInfo hirModIface hirModDetails (justObjects $ LM (posixSecondsToUTCTime obj_t) (ms_mod ms) [DotO obj_file]))
_ -> liftIO $ coreFileToLinkable linkableType (hscEnv session) ms hirModIface hirModDetails bin_core (error "object doesn't have time")
| obj_t >= core_t -> pure ([], Just $ HomeModInfo hirModIface hirModDetails (justObjects $ LM (posixSecondsToUTCTime obj_t) (ms_mod hirModSummary) [DotO obj_file]))
_ -> liftIO $ coreFileToLinkable linkableType (hscEnv session) hirModSummary hirModIface hirModDetails bin_core (error "object doesn't have time")
-- Record the linkable so we know not to unload it, and unload old versions
whenJust ((homeModInfoByteCode =<< hmi) <|> (homeModInfoObject =<< hmi)) $ \(LM time mod _) -> do
compiledLinkables <- getCompiledLinkables <$> getIdeGlobalAction
Expand Down

0 comments on commit fa48fda

Please sign in to comment.