Skip to content

Commit a5444d9

Browse files
committed
In 00f4e61 we attempted to share the filepaths in GHC's usage field.
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.
1 parent 27f46d7 commit a5444d9

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module Development.IDE.Core.Compile
3636
, TypecheckHelpers(..)
3737
, sourceTypecheck
3838
, sourceParser
39+
, shareUsages
3940
) where
4041

4142
import Control.Monad.IO.Class
@@ -468,6 +469,8 @@ filterUsages = id
468469
#endif
469470

470471
-- | Mitigation for https://gitlab.haskell.org/ghc/ghc/-/issues/22744
472+
-- Important to do this immediately after reading the unit before
473+
-- anything else has a chance to read `mi_usages`
471474
shareUsages :: ModIface -> ModIface
472475
shareUsages iface = iface {mi_usages = usages}
473476
where usages = map go (mi_usages iface)
@@ -1479,11 +1482,23 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
14791482
| source_version <= dest_version -> SourceUnmodified
14801483
| otherwise -> SourceModified
14811484

1485+
old_iface <- case mb_old_iface of
1486+
Just iface -> pure (Just iface)
1487+
Nothing -> do
1488+
let ncu = hsc_NC sessionWithMsDynFlags
1489+
read_dflags = hsc_dflags sessionWithMsDynFlags
1490+
read_result <- liftIO $ readIface read_dflags ncu mod iface_file
1491+
case read_result of
1492+
Util.Failed{} -> return Nothing
1493+
-- important to call `shareUsages` here before checkOldIface
1494+
-- consults `mi_usages`
1495+
Util.Succeeded iface -> return $ Just (shareUsages iface)
1496+
14821497
-- If mb_old_iface is nothing then checkOldIface will load it for us
14831498
-- given that the source is unmodified
14841499
(recomp_iface_reqd, mb_checked_iface)
14851500
#if MIN_VERSION_ghc(9,3,0)
1486-
<- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \case
1501+
<- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \case
14871502
UpToDateItem x -> pure (UpToDate, Just x)
14881503
OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
14891504
#else
@@ -1497,8 +1512,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
14971512
regenerate linkableNeeded
14981513

14991514
case (mb_checked_iface, recomp_iface_reqd) of
1500-
(Just iface', UpToDate) -> do
1501-
let iface = shareUsages iface'
1515+
(Just iface, UpToDate) -> do
15021516
details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
15031517
-- parse the runtime dependencies from the annotations
15041518
let runtime_deps

ghcide/src/Development/IDE/GHC/Compat/Core.hs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module Development.IDE.GHC.Compat.Core (
3939
lookupType,
4040
needWiredInHomeIface,
4141
loadWiredInHomeIface,
42+
readIface,
4243
loadSysInterface,
4344
importDecl,
4445
#if MIN_VERSION_ghc(8,8,0)

0 commit comments

Comments
 (0)