@@ -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
@@ -468,6 +469,8 @@ filterUsages = id
468
469
#endif
469
470
470
471
-- | 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`
471
474
shareUsages :: ModIface -> ModIface
472
475
shareUsages iface = iface {mi_usages = usages}
473
476
where usages = map go (mi_usages iface)
@@ -1479,11 +1482,28 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
1479
1482
| source_version <= dest_version -> SourceUnmodified
1480
1483
| otherwise -> SourceModified
1481
1484
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
+
1482
1502
-- If mb_old_iface is nothing then checkOldIface will load it for us
1483
1503
-- given that the source is unmodified
1484
1504
(recomp_iface_reqd, mb_checked_iface)
1485
1505
#if MIN_VERSION_ghc(9,3,0)
1486
- <- liftIO $ checkOldIface sessionWithMsDynFlags ms mb_old_iface >>= \ case
1506
+ <- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \ case
1487
1507
UpToDateItem x -> pure (UpToDate , Just x)
1488
1508
OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
1489
1509
#else
@@ -1497,8 +1517,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
1497
1517
regenerate linkableNeeded
1498
1518
1499
1519
case (mb_checked_iface, recomp_iface_reqd) of
1500
- (Just iface', UpToDate ) -> do
1501
- let iface = shareUsages iface'
1520
+ (Just iface, UpToDate ) -> do
1502
1521
details <- liftIO $ mkDetailsFromIface sessionWithMsDynFlags iface
1503
1522
-- parse the runtime dependencies from the annotations
1504
1523
let runtime_deps
0 commit comments