Skip to content

Commit

Permalink
In 00f4e61 we attempted to share the filepaths in GHC's usage field. (#…
Browse files Browse the repository at this point in the history
…3713)

Unfortunately the `mi_usages` is evaluated by `checkOldIface` before we have a chance to do the sharing,
resulting in them not actually being shared on the first load.

Solution is to share the usages before `checkOldIface` has a chance to inspect them, breaking the sharing.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
wz1000 and mergify[bot] authored Jul 25, 2023
1 parent 7a2b9a1 commit c9519af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
25 changes: 22 additions & 3 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Development.IDE.Core.Compile
, TypecheckHelpers(..)
, sourceTypecheck
, sourceParser
, shareUsages
) where

import Control.Monad.IO.Class
Expand Down Expand Up @@ -472,6 +473,8 @@ filterUsages = id
#endif

-- | Mitigation for https://gitlab.haskell.org/ghc/ghc/-/issues/22744
-- Important to do this immediately after reading the unit before
-- anything else has a chance to read `mi_usages`
shareUsages :: ModIface -> ModIface
shareUsages iface = iface {mi_usages = usages}
where usages = map go (mi_usages iface)
Expand Down Expand Up @@ -1490,11 +1493,28 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
| source_version <= dest_version -> SourceUnmodified
| otherwise -> SourceModified

old_iface <- case mb_old_iface of
Just iface -> pure (Just iface)
Nothing -> do
let ncu = hsc_NC sessionWithMsDynFlags
read_dflags = hsc_dflags sessionWithMsDynFlags
#if MIN_VERSION_ghc(9,3,0)
read_result <- liftIO $ readIface read_dflags ncu mod iface_file
#else
read_result <- liftIO $ initIfaceCheck (text "readIface") sessionWithMsDynFlags
$ readIface mod iface_file
#endif
case read_result of
Util.Failed{} -> return Nothing
-- important to call `shareUsages` here before checkOldIface
-- consults `mi_usages`
Util.Succeeded iface -> return $ Just (shareUsages iface)

-- If mb_old_iface is nothing then checkOldIface will load it for us
-- given that the source is unmodified
(recomp_iface_reqd, mb_checked_iface)
#if MIN_VERSION_ghc(9,3,0)
<- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \case
<- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \case
UpToDateItem x -> pure (UpToDate, Just x)
OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
#else
Expand All @@ -1508,8 +1528,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
regenerate linkableNeeded

case (mb_checked_iface, recomp_iface_reqd) of
(Just iface', UpToDate) -> do
let iface = shareUsages iface'
(Just iface, UpToDate) -> do
details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
-- parse the runtime dependencies from the annotations
let runtime_deps
Expand Down
1 change: 1 addition & 0 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Development.IDE.GHC.Compat.Core (
lookupType,
needWiredInHomeIface,
loadWiredInHomeIface,
readIface,
loadSysInterface,
importDecl,
#if MIN_VERSION_ghc(8,8,0)
Expand Down

0 comments on commit c9519af

Please sign in to comment.