Skip to content

Commit 2c81b4f

Browse files
committed
Actually force usages
In 00f4e61 we attempted to share the filepaths in GHC's usage field. Unfortunately the `mi_usages` field is lazy and so these turned out to not actually be shared because the thunk responsible for sharing was never evaluated. Add the right strictness annotations to ensure these are actually shared
1 parent 27f46d7 commit 2c81b4f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
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+
dflags = hsc_dflags sessionWithMsDynFlags
1490+
read_result <- readIface read_dflags ncu mod iface_file
1491+
case read_result of
1492+
Failed _err -> return Nothing
1493+
-- important to call `shareUsages` here before checkOldIface
1494+
-- consults `mi_usages`
1495+
Just 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
@@ -1498,7 +1513,6 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
14981513

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

0 commit comments

Comments
 (0)