@@ -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
@@ -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`
471474shareUsages :: ModIface -> ModIface
472475shareUsages iface = iface {mi_usages = usages}
473476 where usages = map go (mi_usages iface)
@@ -1479,11 +1482,28 @@ 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+ #if MIN_VERSION_ghc(9,3,0)
1491+ read_result <- liftIO $ readIface read_dflags ncu mod iface_file
1492+ #else
1493+ read_result <- liftIO $ initIfaceCheck (text " readIface" ) sessionWithMsDynFlags
1494+ $ readIface mod iface_file
1495+ #endif
1496+ case read_result of
1497+ Util. Failed {} -> return Nothing
1498+ -- important to call `shareUsages` here before checkOldIface
1499+ -- consults `mi_usages`
1500+ Util. Succeeded iface -> return $ Just (shareUsages iface)
1501+
14821502 -- If mb_old_iface is nothing then checkOldIface will load it for us
14831503 -- given that the source is unmodified
14841504 (recomp_iface_reqd, mb_checked_iface)
14851505#if MIN_VERSION_ghc(9,3,0)
1486- <- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \ case
1506+ <- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \ case
14871507 UpToDateItem x -> pure (UpToDate , Just x)
14881508 OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
14891509#else
@@ -1497,8 +1517,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
14971517 regenerate linkableNeeded
14981518
14991519 case (mb_checked_iface, recomp_iface_reqd) of
1500- (Just iface', UpToDate ) -> do
1501- let iface = shareUsages iface'
1520+ (Just iface, UpToDate ) -> do
15021521 details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
15031522 -- parse the runtime dependencies from the annotations
15041523 let runtime_deps
0 commit comments