@@ -36,6 +36,7 @@ module Development.IDE.Core.Compile
36
36
, TypecheckHelpers (.. )
37
37
, sourceTypecheck
38
38
, sourceParser
39
+ , shareUsages
39
40
) where
40
41
41
42
import Control.Monad.IO.Class
@@ -472,6 +473,8 @@ filterUsages = id
472
473
#endif
473
474
474
475
-- | 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`
475
478
shareUsages :: ModIface -> ModIface
476
479
shareUsages iface = iface {mi_usages = usages}
477
480
where usages = map go (mi_usages iface)
@@ -1490,11 +1493,28 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
1490
1493
| source_version <= dest_version -> SourceUnmodified
1491
1494
| otherwise -> SourceModified
1492
1495
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
+
1493
1513
-- If mb_old_iface is nothing then checkOldIface will load it for us
1494
1514
-- given that the source is unmodified
1495
1515
(recomp_iface_reqd, mb_checked_iface)
1496
1516
#if MIN_VERSION_ghc(9,3,0)
1497
- <- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \ case
1517
+ <- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \ case
1498
1518
UpToDateItem x -> pure (UpToDate , Just x)
1499
1519
OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
1500
1520
#else
@@ -1508,8 +1528,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
1508
1528
regenerate linkableNeeded
1509
1529
1510
1530
case (mb_checked_iface, recomp_iface_reqd) of
1511
- (Just iface', UpToDate ) -> do
1512
- let iface = shareUsages iface'
1531
+ (Just iface, UpToDate ) -> do
1513
1532
details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
1514
1533
-- parse the runtime dependencies from the annotations
1515
1534
let runtime_deps
0 commit comments