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
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.
  • Loading branch information
wz1000 committed Jul 18, 2023
1 parent 27f46d7 commit 9ade701
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 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 @@ -468,6 +469,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 @@ -1479,11 +1482,23 @@ 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
dflags = hsc_dflags sessionWithMsDynFlags
read_result <- readIface read_dflags ncu mod iface_file
case read_result of
Failed _err -> return Nothing
-- important to call `shareUsages` here before checkOldIface
-- consults `mi_usages`
Just 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 @@ -1498,7 +1513,6 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do

case (mb_checked_iface, recomp_iface_reqd) of
(Just iface', UpToDate) -> do
let iface = shareUsages iface'
details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
-- parse the runtime dependencies from the annotations
let runtime_deps
Expand Down

0 comments on commit 9ade701

Please sign in to comment.