@@ -36,6 +36,7 @@ module Development.IDE.Core.Compile
3636 , TypecheckHelpers (.. )
3737 , sourceTypecheck
3838 , sourceParser
39+ , shareUsages
3940 ) where
4041
4142import Control.Monad.IO.Class
@@ -472,6 +473,8 @@ filterUsages = id
472473#endif
473474
474475-- | Mitigation for https://gitlab.haskell.org/ghc/ghc/-/issues/22744
476+ -- Important to do this immediately after reading the unit before
477+ -- anything else has a chance to read `mi_usages`
475478shareUsages :: ModIface -> ModIface
476479shareUsages iface = iface {mi_usages = usages}
477480 where usages = map go (mi_usages iface)
@@ -1490,11 +1493,28 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
14901493 | source_version <= dest_version -> SourceUnmodified
14911494 | otherwise -> SourceModified
14921495
1496+ old_iface <- case mb_old_iface of
1497+ Just iface -> pure (Just iface)
1498+ Nothing -> do
1499+ let ncu = hsc_NC sessionWithMsDynFlags
1500+ read_dflags = hsc_dflags sessionWithMsDynFlags
1501+ #if MIN_VERSION_ghc(9,3,0)
1502+ read_result <- liftIO $ readIface read_dflags ncu mod iface_file
1503+ #else
1504+ read_result <- liftIO $ initIfaceCheck (text " readIface" ) sessionWithMsDynFlags
1505+ $ readIface mod iface_file
1506+ #endif
1507+ case read_result of
1508+ Util. Failed {} -> return Nothing
1509+ -- important to call `shareUsages` here before checkOldIface
1510+ -- consults `mi_usages`
1511+ Util. Succeeded iface -> return $ Just (shareUsages iface)
1512+
14931513 -- If mb_old_iface is nothing then checkOldIface will load it for us
14941514 -- given that the source is unmodified
14951515 (recomp_iface_reqd, mb_checked_iface)
14961516#if MIN_VERSION_ghc(9,3,0)
1497- <- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \ case
1517+ <- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \ case
14981518 UpToDateItem x -> pure (UpToDate , Just x)
14991519 OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
15001520#else
@@ -1508,8 +1528,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
15081528 regenerate linkableNeeded
15091529
15101530 case (mb_checked_iface, recomp_iface_reqd) of
1511- (Just iface', UpToDate ) -> do
1512- let iface = shareUsages iface'
1531+ (Just iface, UpToDate ) -> do
15131532 details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
15141533 -- parse the runtime dependencies from the annotations
15151534 let runtime_deps
0 commit comments