Wolfgang Jeltsch pushed to branch wip/jeltsch/smaller-pit at Glasgow Haskell Compiler / GHC

Commits:

25 changed files:

Changes:

  • compiler/GHC/Driver/Downsweep.hs
    ... ... @@ -688,7 +688,8 @@ expandFixedModuleNode key loc = do
    688 688
           -- part of the compiler.
    
    689 689
           lookupIfaceByModuleHsc hsc_env (mnkToModule key) >>= \case
    
    690 690
             Just iface -> return (M.Succeeded iface)
    
    691
    -        Nothing -> readIface (hsc_hooks hsc_env) (hsc_logger hsc_env) (hsc_dflags hsc_env) (hsc_NC hsc_env) (mnkToModule key) (ml_hi_file loc)
    
    691
    +        Nothing    -> fmap shrinkModIface <$>
    
    692
    +                      readIface (hsc_hooks hsc_env) (hsc_logger hsc_env) (hsc_dflags hsc_env) (hsc_NC hsc_env) (mnkToModule key) (ml_hi_file loc)
    
    692 693
         case read_result of
    
    693 694
           M.Succeeded iface -> do
    
    694 695
             -- Computer information about this node
    

  • compiler/GHC/Driver/Env.hs
    ... ... @@ -372,10 +372,10 @@ lookupIfaceByModule
    372 372
             :: HomeUnitGraph
    
    373 373
             -> PackageIfaceTable
    
    374 374
             -> Module
    
    375
    -        -> IO (Maybe ModIface)
    
    375
    +        -> IO (Maybe RetainedModIface)
    
    376 376
     lookupIfaceByModule hug pit mod
    
    377 377
       = HUG.lookupHugByModule mod hug >>= pure . \case
    
    378
    -       Just hm -> Just (hm_iface hm)
    
    378
    +       Just hm -> Just (shrinkModIface (hm_iface hm))
    
    379 379
            Nothing -> lookupModuleEnv pit mod
    
    380 380
        -- If the module does come from the home package, why do we look in the PIT as well?
    
    381 381
        -- (a) In OneShot mode, even home-package modules accumulate in the PIT
    
    ... ... @@ -384,7 +384,7 @@ lookupIfaceByModule hug pit mod
    384 384
        -- We could eliminate (b) if we wanted, by making GHC.Prim belong to a package
    
    385 385
        -- of its own, but it doesn't seem worth the bother.
    
    386 386
     
    
    387
    -lookupIfaceByModuleHsc :: HscEnv -> Module -> IO (Maybe ModIface)
    
    387
    +lookupIfaceByModuleHsc :: HscEnv -> Module -> IO (Maybe RetainedModIface)
    
    388 388
     lookupIfaceByModuleHsc hsc_env mod = do
    
    389 389
       eps <- hscEPS hsc_env
    
    390 390
       lookupIfaceByModule (hsc_HUG hsc_env) (eps_PIT eps) mod
    

  • compiler/GHC/Driver/Main/Interactive.hs
    ... ... @@ -148,7 +148,7 @@ hscIsGHCiMonad :: HscEnv -> String -> IO Name
    148 148
     hscIsGHCiMonad hsc_env name
    
    149 149
       = runHsc hsc_env $ ioMsgMaybe $ hoistTcRnMessage $ isGHCiMonad hsc_env name
    
    150 150
     
    
    151
    -hscGetModuleInterface :: HscEnv -> Module -> IO ModIface
    
    151
    +hscGetModuleInterface :: HscEnv -> Module -> IO RetainedModIface
    
    152 152
     hscGetModuleInterface hsc_env0 mod = runInteractiveHsc hsc_env0 $ do
    
    153 153
       hsc_env <- getHscEnv
    
    154 154
       ioMsgMaybe $ hoistTcRnMessage $ getModuleInterface hsc_env mod
    
    ... ... @@ -270,7 +270,7 @@ hscCheckSafe' m l = do
    270 270
                 _ | isHomeModule home_unit mod      -> True
    
    271 271
                 _ -> isUnitTrusted unit_state (moduleUnit m)
    
    272 272
     
    
    273
    -    lookup' :: Module -> Hsc (Maybe ModIface)
    
    273
    +    lookup' :: Module -> Hsc (Maybe RetainedModIface)
    
    274 274
         lookup' m = do
    
    275 275
             hsc_env <- getHscEnv
    
    276 276
             iface <- liftIO $ lookupIfaceByModuleHsc hsc_env m
    

  • compiler/GHC/Driver/Main/Passes.hs
    ... ... @@ -1335,7 +1335,7 @@ hscCheckSafe' m l = do
    1335 1335
                 _ | isHomeModule home_unit mod      -> True
    
    1336 1336
                 _ -> isUnitTrusted unit_state (moduleUnit m)
    
    1337 1337
     
    
    1338
    -    lookup' :: Module -> Hsc (Maybe ModIface)
    
    1338
    +    lookup' :: Module -> Hsc (Maybe RetainedModIface)
    
    1339 1339
         lookup' m = do
    
    1340 1340
             hsc_env <- getHscEnv
    
    1341 1341
             iface <- liftIO $ lookupIfaceByModuleHsc hsc_env m
    

  • compiler/GHC/Driver/Plugins.hs
    ... ... @@ -224,7 +224,7 @@ data PluginWithArgs = PluginWithArgs
    224 224
     data LoadedPlugin = LoadedPlugin
    
    225 225
       { lpPlugin :: PluginWithArgs
    
    226 226
       -- ^ the actual plugin together with its commandline arguments
    
    227
    -  , lpModule :: ModIface
    
    227
    +  , lpModule :: RetainedModIface
    
    228 228
       -- ^ the module containing the plugin
    
    229 229
       }
    
    230 230
     
    

  • compiler/GHC/Driver/Session/Inspect.hs
    ... ... @@ -87,7 +87,7 @@ data ModuleInfo = ModuleInfo {
    87 87
             minf_type_env  :: TypeEnv,
    
    88 88
             minf_exports   :: [AvailInfo],
    
    89 89
             minf_instances :: [ClsInst],
    
    90
    -        minf_iface     :: Maybe ModIface,
    
    90
    +        minf_iface     :: Maybe RetainedModIface,
    
    91 91
             minf_safe      :: SafeHaskellMode,
    
    92 92
             minf_modBreaks :: Maybe InternalModBreaks
    
    93 93
       }
    
    ... ... @@ -140,7 +140,7 @@ getHomeModuleInfo hsc_env mdl =
    140 140
         Nothing  -> return Nothing
    
    141 141
         Just hmi -> do
    
    142 142
           let details  = hm_details hmi
    
    143
    -          iface    = hm_iface hmi
    
    143
    +          iface    = shrinkModIface (hm_iface hmi)
    
    144 144
           return (Just (ModuleInfo {
    
    145 145
                             minf_type_env  = md_types details,
    
    146 146
                             minf_exports   = md_exports details,
    
    ... ... @@ -187,7 +187,7 @@ modInfoLookupName minf name = withSession $ \hsc_env -> do
    187 187
          Just tyThing -> return (Just tyThing)
    
    188 188
          Nothing      -> liftIO (lookupType hsc_env name)
    
    189 189
     
    
    190
    -modInfoIface :: ModuleInfo -> Maybe ModIface
    
    190
    +modInfoIface :: ModuleInfo -> Maybe RetainedModIface
    
    191 191
     modInfoIface = minf_iface
    
    192 192
     
    
    193 193
     -- | Retrieve module safe haskell mode
    

  • compiler/GHC/HsToCore/Usage.hs
    ... ... @@ -276,7 +276,7 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
    276 276
         --  a) we used something from it; has something in used_names
    
    277 277
         --  b) we imported it, even if we used nothing from it
    
    278 278
         --     (need to recompile if its export list changes: export_fprint)
    
    279
    -    mkUsage :: Module -> ModIface -> Maybe Usage
    
    279
    +    mkUsage :: Module -> RetainedModIface -> Maybe Usage
    
    280 280
         mkUsage mod iface
    
    281 281
           | toUnitId (moduleUnit mod) `Set.notMember` home_unit_ids
    
    282 282
           = Just $ UsagePackageModule{ usg_mod      = mod,
    
    ... ... @@ -302,9 +302,9 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
    302 302
                           usg_entities = Map.toList ent_hashs,
    
    303 303
                           usg_safe     = imp_safe }
    
    304 304
           where
    
    305
    -        finsts_mod = mi_finsts iface
    
    305
    +        finsts_mod = mi_abi_finsts (mi_abi_hashes iface)
    
    306 306
             hash_env   = mi_hash_fn iface
    
    307
    -        mod_hash   = mi_mod_hash iface
    
    307
    +        mod_hash   = mi_abi_mod_hash (mi_abi_hashes iface)
    
    308 308
             imported_exports
    
    309 309
               = if not depend_on_exports
    
    310 310
                 then Nothing
    
    ... ... @@ -312,9 +312,9 @@ mk_mod_usage_info uc home_unit home_unit_ids this_mod direct_imports imp_decls u
    312 312
                   Just $
    
    313 313
                     HomeModImport
    
    314 314
                      { hmiu_orphanLikeHash
    
    315
    -                     = mi_orphan_like_hash iface
    
    315
    +                     = mi_abi_orphan_like_hash (mi_abi_hashes iface)
    
    316 316
                      , hmiu_importedAvails
    
    317
    -                     = moduleImportedAvails mod (mi_export_avails_hash iface) imp_decls
    
    317
    +                     = moduleImportedAvails mod (mi_abi_export_avails_hash (mi_abi_hashes iface)) imp_decls
    
    318 318
                      }
    
    319 319
     
    
    320 320
             by_is_safe (ImportedByUser imv) = imv_is_safe imv
    

  • compiler/GHC/Iface/Binary.hs
    ... ... @@ -197,7 +197,7 @@ getIfaceWithExtFields name_cache bh = do
    197 197
       modIfaceBinData <- freezeBinHandle bh start
    
    198 198
       pure $ mod_iface
    
    199 199
         & set_mi_ext_fields extFields
    
    200
    -    & set_mi_hi_bytes (FullIfaceBinHandle $ Strict.Just modIfaceBinData)
    
    200
    +    & set_mi_hi_bytes (Strict.Just modIfaceBinData)
    
    201 201
     
    
    202 202
     -- | This performs a get action after reading the dictionary and symbol
    
    203 203
     -- table. It is necessary to run this before trying to deserialise any
    
    ... ... @@ -276,10 +276,10 @@ writeBinIface profile traceBinIface compressionLevel hi_path mod_iface = do
    276 276
     putIfaceWithExtFields :: TraceBinIFace -> CompressionIFace -> WriteBinHandle -> ModIface -> IO ()
    
    277 277
     putIfaceWithExtFields traceBinIface compressionLevel bh mod_iface =
    
    278 278
       case mi_hi_bytes mod_iface of
    
    279
    -    FullIfaceBinHandle Strict.Nothing -> do
    
    279
    +    Strict.Nothing -> do
    
    280 280
           forwardPutRel_ bh (\_ -> put_ bh (mi_ext_fields mod_iface)) $ do
    
    281 281
             putWithUserData traceBinIface compressionLevel bh mod_iface
    
    282
    -    FullIfaceBinHandle (Strict.Just binData) -> putFullBinData bh binData
    
    282
    +    Strict.Just binData -> putFullBinData bh binData
    
    283 283
     
    
    284 284
     -- | Put a piece of data with an initialised `UserData` field. This
    
    285 285
     -- is necessary if you want to serialise Names or FastStrings.
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -308,7 +308,7 @@ loadKnownKeyOccMaps
    308 308
         known_key_maps :: Module -> IfM lcl KnownKeyNameMaps
    
    309 309
         known_key_maps mod
    
    310 310
           = do { iface <- loadInterfaceWithException doc mod ImportBySystem
    
    311
    -           ; let !abi_hash = mi_mod_hash iface
    
    311
    +           ; let !abi_hash = mi_abi_mod_hash (mi_abi_hashes iface)
    
    312 312
                ; eps <- getEps
    
    313 313
                ; case lookupModuleEnv (eps_known_keys eps) mod of
    
    314 314
                    Just (cached_hash, kk_maps)
    
    ... ... @@ -321,7 +321,7 @@ loadKnownKeyOccMaps
    321 321
                                          (abi_hash, kk_maps) }
    
    322 322
                            ; return kk_maps } }
    
    323 323
     
    
    324
    -    build_maps :: ModIface -> KnownKeyNameMaps
    
    324
    +    build_maps :: RetainedModIface -> KnownKeyNameMaps
    
    325 325
         build_maps iface = (kk_map, occ_map)
    
    326 326
           where
    
    327 327
             kk_map :: UniqFM KnownKey Name
    
    ... ... @@ -628,7 +628,7 @@ loadSrcInterface :: SDoc
    628 628
                      -> ModuleName
    
    629 629
                      -> IsBootInterface     -- {-# SOURCE #-} ?
    
    630 630
                      -> PkgQual             -- "package", if any
    
    631
    -                 -> RnM ModIface
    
    631
    +                 -> RnM RetainedModIface
    
    632 632
     
    
    633 633
     loadSrcInterface doc scope mod want_boot maybe_pkg
    
    634 634
       = do { res <- loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
    
    ... ... @@ -648,7 +648,7 @@ loadSrcInterface_maybe :: SDoc
    648 648
                            -> ModuleName
    
    649 649
                            -> IsBootInterface     -- {-# SOURCE #-} ?
    
    650 650
                            -> PkgQual             -- "package", if any
    
    651
    -                       -> RnM (MaybeErr MissingInterfaceError ModIface)
    
    651
    +                       -> RnM (MaybeErr MissingInterfaceError RetainedModIface)
    
    652 652
     
    
    653 653
     loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
    
    654 654
       -- We must first find which Module this import refers to.  This involves
    
    ... ... @@ -667,7 +667,7 @@ loadSrcInterface_maybe doc scope mod want_boot maybe_pkg
    667 667
     -- rare operation, but in particular it is used to load orphan modules
    
    668 668
     -- in order to pull their instances into the global package table and to
    
    669 669
     -- handle some operations in GHCi).
    
    670
    -loadModuleInterface :: SDoc -> Module -> TcM ModIface
    
    670
    +loadModuleInterface :: SDoc -> Module -> TcM RetainedModIface
    
    671 671
     loadModuleInterface doc mod = initIfaceTcRn (loadSysInterface doc mod)
    
    672 672
     
    
    673 673
     -- | Load interfaces for a collection of modules.
    
    ... ... @@ -681,7 +681,7 @@ loadModuleInterfaces doc mods
    681 681
     -- | Loads the interface for a given Name.
    
    682 682
     -- Should only be called for an imported name;
    
    683 683
     -- otherwise loadSysInterface may not find the interface
    
    684
    -loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
    
    684
    +loadInterfaceForName :: SDoc -> Name -> TcRn RetainedModIface
    
    685 685
     loadInterfaceForName doc name
    
    686 686
       = do { when debugIsOn $  -- Check pre-condition
    
    687 687
              do { this_mod <- getModule
    
    ... ... @@ -690,7 +690,7 @@ loadInterfaceForName doc name
    690 690
             initIfaceTcRn $ loadSysInterface doc (nameModule name) }
    
    691 691
     
    
    692 692
     -- | Loads the interface for a given Module.
    
    693
    -loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface
    
    693
    +loadInterfaceForModule :: SDoc -> Module -> TcRn RetainedModIface
    
    694 694
     loadInterfaceForModule doc m
    
    695 695
       = do
    
    696 696
         -- Should not be called with this module
    
    ... ... @@ -724,23 +724,23 @@ loadWiredInHomeIface name
    724 724
     
    
    725 725
     ------------------
    
    726 726
     -- | Loads a system interface and throws an exception if it fails
    
    727
    -loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
    
    727
    +loadSysInterface :: SDoc -> Module -> IfM lcl RetainedModIface
    
    728 728
     loadSysInterface doc mod_name = loadInterfaceWithException doc mod_name ImportBySystem
    
    729 729
     
    
    730 730
     ------------------
    
    731 731
     -- | Loads a user interface and throws an exception if it fails. The first parameter indicates
    
    732 732
     -- whether we should import the boot variant of the module
    
    733
    -loadUserInterface :: IsBootInterface -> SDoc -> Module -> IfM lcl ModIface
    
    733
    +loadUserInterface :: IsBootInterface -> SDoc -> Module -> IfM lcl RetainedModIface
    
    734 734
     loadUserInterface is_boot doc mod_name
    
    735 735
       = loadInterfaceWithException doc mod_name (ImportByUser is_boot)
    
    736 736
     
    
    737
    -loadPluginInterface :: SDoc -> Module -> IfM lcl ModIface
    
    737
    +loadPluginInterface :: SDoc -> Module -> IfM lcl RetainedModIface
    
    738 738
     loadPluginInterface doc mod_name
    
    739 739
       = loadInterfaceWithException doc mod_name ImportByPlugin
    
    740 740
     
    
    741 741
     ------------------
    
    742 742
     -- | A wrapper for 'loadInterface' that throws an exception if it fails
    
    743
    -loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl ModIface
    
    743
    +loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl RetainedModIface
    
    744 744
     loadInterfaceWithException doc mod_name where_from
    
    745 745
       = do
    
    746 746
         dflags <- getDynFlags
    
    ... ... @@ -749,7 +749,7 @@ loadInterfaceWithException doc mod_name where_from
    749 749
     
    
    750 750
     ------------------
    
    751 751
     loadInterface :: SDoc -> Module -> WhereFrom
    
    752
    -              -> IfM lcl (MaybeErr MissingInterfaceError ModIface)
    
    752
    +              -> IfM lcl (MaybeErr MissingInterfaceError RetainedModIface)
    
    753 753
     
    
    754 754
     -- loadInterface looks in both the HPT and PIT for the required interface
    
    755 755
     -- If not found, it loads it, and puts it in the PIT (always).
    
    ... ... @@ -796,7 +796,7 @@ loadInterface doc_str mod from
    796 796
                                  liftIO $ computeInterface hsc_env doc_str hi_boot_file mod
    
    797 797
             ; case read_result of {
    
    798 798
                 Failed err -> do
    
    799
    -                { let fake_iface = emptyFullModIface mod
    
    799
    +                { let fake_iface = shrinkModIface (emptyFullModIface mod)
    
    800 800
     
    
    801 801
                     ; updateEps_ $ \eps ->
    
    802 802
                             eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
    
    ... ... @@ -856,16 +856,7 @@ loadInterface doc_str mod from
    856 856
             ; new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
    
    857 857
             ; purged_hsc_env <- getTopEnv
    
    858 858
     
    
    859
    -        ; let final_iface = iface
    
    860
    -                               & set_mi_decls     (panic "No mi_decls in PIT")
    
    861
    -                               & set_mi_insts     (panic "No mi_insts in PIT")
    
    862
    -                               & set_mi_defaults  (panic "No mi_defaults in PIT")
    
    863
    -                               & set_mi_fam_insts (panic "No mi_fam_insts in PIT")
    
    864
    -                               & set_mi_rules     (panic "No mi_rules in PIT")
    
    865
    -                               & set_mi_anns      (panic "No mi_anns in PIT")
    
    866
    -                               & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
    
    867
    -
    
    868
    -              bad_boot = mi_boot iface == IsBoot
    
    859
    +        ; let bad_boot = mi_boot iface == IsBoot
    
    869 860
                               && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
    
    870 861
                                 -- Warn against an EPS-updating import
    
    871 862
                                 -- of one's own boot file! (one-shot only)
    
    ... ... @@ -892,7 +883,7 @@ loadInterface doc_str mod from
    892 883
                     then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
    
    893 884
                else
    
    894 885
                     eps {
    
    895
    -                  eps_PIT          = extendModuleEnv (eps_PIT eps) mod final_iface,
    
    886
    +                  eps_PIT          = extendModuleEnv (eps_PIT eps) mod (shrinkModIface iface),
    
    896 887
                       eps_PTE          = addDeclsToPTE   (eps_PTE eps) new_eps_decls,
    
    897 888
                       eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
    
    898 889
                       eps_rule_base    = extendRuleBaseList (eps_rule_base eps)
    
    ... ... @@ -921,10 +912,8 @@ loadInterface doc_str mod from
    921 912
                       eps_defaults    =  extendModuleEnv (eps_defaults eps) mod new_eps_defaults
    
    922 913
                                                        }
    
    923 914
     
    
    924
    -        ; -- invoke plugins with *full* interface, not final_iface, to ensure
    
    925
    -          -- that plugins have access to declarations, etc.
    
    926
    -          res <- withPlugins (hsc_plugins hsc_env) (\p -> interfaceLoadAction p) iface
    
    927
    -        ; return (Succeeded res)
    
    915
    +        ; res <- withPlugins (hsc_plugins hsc_env) (\p -> interfaceLoadAction p) iface
    
    916
    +        ; return (Succeeded (shrinkModIface res))
    
    928 917
         }}}}
    
    929 918
     
    
    930 919
     {- Note [Loading your own hi-boot file]
    

  • compiler/GHC/Iface/Load.hs-boot
    ... ... @@ -2,7 +2,7 @@ module GHC.Iface.Load where
    2 2
     
    
    3 3
     import GHC.Unit.Module (Module)
    
    4 4
     import GHC.Tc.Utils.Monad (IfM)
    
    5
    -import GHC.Unit.Module.ModIface (ModIface)
    
    5
    +import GHC.Unit.Module.ModIface (RetainedModIface)
    
    6 6
     import GHC.Utils.Outputable (SDoc)
    
    7 7
     
    
    8
    -loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
    8
    +loadSysInterface :: SDoc -> Module -> IfM lcl RetainedModIface

  • compiler/GHC/Iface/Make.hs
    ... ... @@ -77,6 +77,7 @@ import GHC.Iface.Binary
    77 77
     
    
    78 78
     import GHC.Data.FastString
    
    79 79
     import GHC.Data.Maybe
    
    80
    +import qualified GHC.Data.Strict as Strict
    
    80 81
     
    
    81 82
     import GHC.HsToCore.Docs
    
    82 83
     import GHC.HsToCore.Usage
    
    ... ... @@ -394,7 +395,7 @@ mkIface_ hsc_env
    394 395
               & set_mi_docs             docs
    
    395 396
               & set_mi_abi_hashes       ()
    
    396 397
               & set_mi_ext_fields       emptyExtensibleFields
    
    397
    -          & set_mi_hi_bytes         PartialIfaceBinHandle
    
    398
    +          & set_mi_hi_bytes         Strict.Nothing
    
    398 399
     
    
    399 400
       where
    
    400 401
          cmp_rule     = lexicalCompareFS `on` ifRuleName
    

  • compiler/GHC/Iface/Recomp.hs
    ... ... @@ -707,7 +707,7 @@ checkDependencies hsc_env summary iface
    707 707
             return $ needsRecompileBecause $ ModulePackageChanged new_name
    
    708 708
     
    
    709 709
     
    
    710
    -needInterface :: Module -> (ModIface -> IO RecompileRequired)
    
    710
    +needInterface :: Module -> (RetainedModIface -> IO RecompileRequired)
    
    711 711
                  -> IfG RecompileRequired
    
    712 712
     needInterface mod continue
    
    713 713
       = do
    
    ... ... @@ -727,7 +727,7 @@ needBytecode mod continue
    727 727
             Nothing -> return $ NeedsRecompile MustCompile
    
    728 728
             Just mbc -> liftIO $ continue mbc
    
    729 729
     
    
    730
    -tryGetModIface :: String -> Module -> IfG (Maybe ModIface)
    
    730
    +tryGetModIface :: String -> Module -> IfG (Maybe RetainedModIface)
    
    731 731
     tryGetModIface doc_msg mod
    
    732 732
       = do  -- Load the imported interface if possible
    
    733 733
         logger <- getLogger
    
    ... ... @@ -779,7 +779,7 @@ checkModUsage _ UsagePackageModule{
    779 779
       logger <- getLogger
    
    780 780
       needInterface mod $ \iface -> do
    
    781 781
         let reason = ModuleChanged (moduleName mod)
    
    782
    -    checkModuleFingerprint logger reason old_mod_hash (mi_mod_hash iface)
    
    782
    +    checkModuleFingerprint logger reason old_mod_hash (mi_abi_mod_hash (mi_abi_hashes iface))
    
    783 783
             -- We only track the ABI hash of package modules, rather than
    
    784 784
             -- individual entity usages, so if the ABI hash changes we must
    
    785 785
             -- recompile.  This is safe but may entail more recompilation when
    
    ... ... @@ -789,7 +789,7 @@ checkModUsage _ UsageMergedRequirement{ usg_mod = mod, usg_mod_hash = old_mod_ha
    789 789
       logger <- getLogger
    
    790 790
       needInterface mod $ \iface -> do
    
    791 791
         let reason = ModuleChangedRaw (moduleName mod)
    
    792
    -    checkModuleFingerprint logger reason old_mod_hash (mi_mod_hash iface)
    
    792
    +    checkModuleFingerprint logger reason old_mod_hash (mi_abi_mod_hash (mi_abi_hashes iface))
    
    793 793
     checkModUsage _  UsageHomeModuleBytecode{ usg_mod_name = mod_name
    
    794 794
                                                      , usg_unit_id = uid
    
    795 795
                                                      , usg_bytecode_hash = old_bytecode_hash } = do
    
    ... ... @@ -810,7 +810,7 @@ checkModUsage _ UsageHomeModule{
    810 810
         logger <- getLogger
    
    811 811
         needInterface mod $ \iface -> do
    
    812 812
          let
    
    813
    -         new_mod_hash    = mi_mod_hash iface
    
    813
    +         new_mod_hash    = mi_abi_mod_hash (mi_abi_hashes iface)
    
    814 814
              new_decl_hash   = mi_hash_fn  iface
    
    815 815
              reason = ModuleChanged (moduleName mod)
    
    816 816
     
    
    ... ... @@ -864,7 +864,7 @@ checkModUsage fc UsageDirectory{ usg_dir_path = dir,
    864 864
     -- Does this require recompilation?
    
    865 865
     --
    
    866 866
     -- See Note [When to recompile when export lists change?]
    
    867
    -checkHomeModImport :: Logger -> RecompReason -> Maybe HomeModImport -> ModIface -> IO RecompileRequired
    
    867
    +checkHomeModImport :: Logger -> RecompReason -> Maybe HomeModImport -> RetainedModIface -> IO RecompileRequired
    
    868 868
     checkHomeModImport _ _ Nothing _ = return UpToDate
    
    869 869
     checkHomeModImport logger reason
    
    870 870
       (Just (HomeModImport old_orphan_like_hash old_avails))
    
    ... ... @@ -901,8 +901,8 @@ checkHomeModImport logger reason
    901 901
                           2 (ppr changes)
    
    902 902
                      return $ needsRecompileBecause reason
    
    903 903
       where
    
    904
    -    new_orphan_like_hash = mi_orphan_like_hash iface
    
    905
    -    new_avails_hash      = mi_export_avails_hash iface
    
    904
    +    new_orphan_like_hash = mi_abi_orphan_like_hash (mi_abi_hashes iface)
    
    905
    +    new_avails_hash      = mi_abi_export_avails_hash (mi_abi_hashes iface)
    
    906 906
         new_exports          = mi_exports iface
    
    907 907
     
    
    908 908
     -- | The exported avails of a module have changed. Should this cause recompilation
    
    ... ... @@ -1617,7 +1617,7 @@ getOrphanHashes hsc_env mods = do
    1617 1617
         get_orph_hash mod = do
    
    1618 1618
               iface <- initIfaceLoad hsc_env . withIfaceErr ctx
    
    1619 1619
                                 $ loadInterface (text "getOrphanHashes") mod ImportBySystem
    
    1620
    -          return (mi_orphan_hash iface)
    
    1620
    +          return (mi_abi_orphan_hash (mi_abi_hashes iface))
    
    1621 1621
     
    
    1622 1622
       mapM get_orph_hash mods
    
    1623 1623
     
    

  • compiler/GHC/Rename/Names.hs
    ... ... @@ -517,7 +517,7 @@ renamePkgQual unit_env mn mb_pkg = case mb_pkg of
    517 517
     -- interface, but without 'imp_mods'.
    
    518 518
     calculateAvails :: HomeUnit
    
    519 519
                     -> S.Set UnitId
    
    520
    -                -> ModIface
    
    520
    +                -> RetainedModIface
    
    521 521
                     -> IsSafeImport
    
    522 522
                     -> IsBootInterface
    
    523 523
                     -> ImportedBy
    
    ... ... @@ -525,8 +525,8 @@ calculateAvails :: HomeUnit
    525 525
     calculateAvails home_unit other_home_units iface mod_safe' want_boot imported_by =
    
    526 526
       let imp_mod    = mi_module iface
    
    527 527
           imp_sem_mod= mi_semantic_module iface
    
    528
    -      orph_iface = mi_orphan iface
    
    529
    -      has_finsts = mi_finsts iface
    
    528
    +      orph_iface = mi_abi_orphan (mi_abi_hashes iface)
    
    529
    +      has_finsts = mi_abi_finsts (mi_abi_hashes iface)
    
    530 530
           deps       = mi_deps iface
    
    531 531
           trust      = getSafeMode $ mi_trust iface
    
    532 532
           trust_pkg  = mi_trust_pkg iface
    
    ... ... @@ -1209,7 +1209,7 @@ gresFromAvail hsc_env prov avail =
    1209 1209
     gresFromAvails :: HscEnv -> Maybe ImportSpec -> [AvailInfo] -> [GlobalRdrElt]
    
    1210 1210
     gresFromAvails hsc_env prov = concatMap (gresFromAvail hsc_env prov)
    
    1211 1211
     
    
    1212
    -importsFromIface :: HscEnv -> ModIface -> ImpDeclSpec -> Maybe NameSet -> GlobalRdrEnv
    
    1212
    +importsFromIface :: HscEnv -> RetainedModIface -> ImpDeclSpec -> Maybe NameSet -> GlobalRdrEnv
    
    1213 1213
     importsFromIface hsc_env iface decl_spec hidden = mkGlobalRdrEnv $ case hidden of
    
    1214 1214
         Nothing -> all_gres
    
    1215 1215
         Just hidden_names -> filter (not . (`elemNameSet` hidden_names) . greName) all_gres
    
    ... ... @@ -1225,7 +1225,7 @@ rnNamespaceSpecifier (DataNamespaceSpecifier x) = DataNamespaceSpecifier x
    1225 1225
     filterImports
    
    1226 1226
         :: HasDebugCallStack
    
    1227 1227
         => HscEnv
    
    1228
    -    -> ModIface
    
    1228
    +    -> RetainedModIface
    
    1229 1229
         -> ImpDeclSpec
    
    1230 1230
              -- ^ Import spec
    
    1231 1231
         -> Maybe (ImportListInterpretation, [LIE GhcPs])
    
    ... ... @@ -2327,7 +2327,7 @@ getMinimalImports ie_decls
    2327 2327
           where
    
    2328 2328
             doc = text "Compute minimal imports for" <+> ppr decl
    
    2329 2329
     
    
    2330
    -    to_ie :: GlobalRdrEnv -> ModIface -> AvailInfo -> RnM [IE GhcRn]
    
    2330
    +    to_ie :: GlobalRdrEnv -> RetainedModIface -> AvailInfo -> RnM [IE GhcRn]
    
    2331 2331
         -- The main trick here is that if we're importing all the constructors
    
    2332 2332
         -- we want to say "T(..)", but if we're importing only a subset we want
    
    2333 2333
         -- to say "T(A,B,C)".  So we have to find out what the module exports.
    
    ... ... @@ -2529,7 +2529,7 @@ DRFPatSynExport for a test of this.
    2529 2529
     -}
    
    2530 2530
     
    
    2531 2531
     badImportItemErr
    
    2532
    -  :: ModIface -> ImpDeclSpec -> IE GhcPs
    
    2532
    +  :: RetainedModIface -> ImpDeclSpec -> IE GhcPs
    
    2533 2533
       -> IsSubordinateError
    
    2534 2534
       -> [AvailInfo]
    
    2535 2535
       -> TcRn (NonEmpty ImportLookupReason)
    

  • compiler/GHC/Rename/Utils.hs
    ... ... @@ -534,7 +534,7 @@ warnIfDeclDeprecated gre@(GRE { gre_imp = iss })
    534 534
         definedMod = moduleName $ assertPpr (isExternalName name) (ppr name) (nameModule name)
    
    535 535
         doc = text "The name" <+> quotes (ppr occ) <+> text "is mentioned explicitly"
    
    536 536
     
    
    537
    -lookupImpDeclDeprec :: ModIface -> GlobalRdrElt -> Maybe (WarningTxt GhcRn)
    
    537
    +lookupImpDeclDeprec :: RetainedModIface -> GlobalRdrElt -> Maybe (WarningTxt GhcRn)
    
    538 538
     lookupImpDeclDeprec iface gre
    
    539 539
       -- Bleat if the thing, or its parent, is warn'd
    
    540 540
       = mi_decl_warn_fn iface (greOccName gre) `mplus`
    

  • compiler/GHC/Runtime/Loader.hs
    ... ... @@ -190,7 +190,7 @@ checkExternalInterpreter hsc_env = case interpInstance <$> hsc_interp hsc_env of
    190 190
         -> throwIO (InstallationError "Plugins require -fno-external-interpreter")
    
    191 191
       _ -> pure ()
    
    192 192
     
    
    193
    -loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, ModIface, [LinkableUsage], PkgsLoaded)
    
    193
    +loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, RetainedModIface, [LinkableUsage], PkgsLoaded)
    
    194 194
     loadPlugin' occ_name plugin_name hsc_env mod_name
    
    195 195
       = do { let plugin_rdr_name = mkRdrQual mod_name occ_name
    
    196 196
                  dflags = hsc_dflags hsc_env
    
    ... ... @@ -341,7 +341,7 @@ lessUnsafeCoerce logger context what = do
    341 341
     -- Need the module as well to record information in the interface file
    
    342 342
     lookupRdrNameInModuleForPlugins :: HasDebugCallStack
    
    343 343
                                     => HscEnv -> ModuleName -> RdrName
    
    344
    -                                -> IO (Maybe (Name, ModIface))
    
    344
    +                                -> IO (Maybe (Name, RetainedModIface))
    
    345 345
     lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do
    
    346 346
         let dflags     = hsc_dflags hsc_env
    
    347 347
         -- First find the unit the module resides in by searching exposed units and home modules
    

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -6386,7 +6386,7 @@ pprImportLookup :: ImportLookupReason -> SDoc
    6386 6386
     pprImportLookup = \case
    
    6387 6387
       ImportLookupBad k iface decl_spec ie _exts ->
    
    6388 6388
         let
    
    6389
    -      pprImpDeclSpec :: ModIface -> ImpDeclSpec -> SDoc
    
    6389
    +      pprImpDeclSpec :: RetainedModIface -> ImpDeclSpec -> SDoc
    
    6390 6390
           pprImpDeclSpec iface decl_spec =
    
    6391 6391
             quotes (ppr (moduleName $ is_mod decl_spec)) <+> case mi_boot iface of
    
    6392 6392
                 IsBoot  -> text "(hi-boot interface)"
    

  • compiler/GHC/Tc/Errors/Types.hs
    ... ... @@ -215,7 +215,7 @@ import GHC.Types.DefaultEnv (ClassDefaults)
    215 215
     
    
    216 216
     import GHC.Unit.Types (Module, ModuleName)
    
    217 217
     import GHC.Unit.State (UnitState)
    
    218
    -import GHC.Unit.Module.ModIface (ModIface)
    
    218
    +import GHC.Unit.Module.ModIface (RetainedModIface)
    
    219 219
     
    
    220 220
     import GHC.Utils.Outputable
    
    221 221
     
    
    ... ... @@ -6634,7 +6634,7 @@ data ImportLookupReason where
    6634 6634
           T9006, T11071, T9905fail2, T5385, T10668
    
    6635 6635
       -}
    
    6636 6636
       ImportLookupBad :: BadImportKind
    
    6637
    -                  -> ModIface
    
    6637
    +                  -> RetainedModIface
    
    6638 6638
                       -> ImpDeclSpec
    
    6639 6639
                       -> IE GhcPs
    
    6640 6640
                       -> ImportLookupExtensions
    

  • compiler/GHC/Tc/Gen/Splice.hs
    ... ... @@ -1693,7 +1693,7 @@ lookupArgDoc i nm = do
    1693 1693
             _ -> pure Nothing
    
    1694 1694
     
    
    1695 1695
     -- | Returns the module a Name belongs to, if it is isn't local.
    
    1696
    -getExternalModIface :: Name -> TcM (Maybe ModIface)
    
    1696
    +getExternalModIface :: Name -> TcM (Maybe RetainedModIface)
    
    1697 1697
     getExternalModIface nm = do
    
    1698 1698
       isLocal <- nameIsLocalOrFrom <$> getModule <*> pure nm
    
    1699 1699
       if isLocal
    

  • compiler/GHC/Tc/Instance/Family.hs
    ... ... @@ -308,7 +308,7 @@ checkFamInstConsistency directlyImpMods
    308 308
                      ifc <- modIface mod
    
    309 309
                      deps <- dep_finsts . mi_deps <$> modIface mod
    
    310 310
                      pure $
    
    311
    -                   if mi_finsts ifc
    
    311
    +                   if mi_abi_finsts (mi_abi_hashes ifc)
    
    312 312
                           then mod:deps
    
    313 313
                           else deps
    
    314 314
     
    

  • compiler/GHC/Tc/Module.hs
    ... ... @@ -2966,7 +2966,7 @@ externaliseAndTidyId this_mod id
    2966 2966
     -- a package module with an interface on disk.  If neither of these is
    
    2967 2967
     -- true, then the result will be an error indicating the interface
    
    2968 2968
     -- could not be found.
    
    2969
    -getModuleInterface :: HscEnv -> Module -> IO (Messages TcRnMessage, Maybe ModIface)
    
    2969
    +getModuleInterface :: HscEnv -> Module -> IO (Messages TcRnMessage, Maybe RetainedModIface)
    
    2970 2970
     getModuleInterface hsc_env mod
    
    2971 2971
       = runTcInteractive NoTcMPlugins hsc_env $
    
    2972 2972
         loadModuleInterface (text "getModuleInterface") mod
    

  • compiler/GHC/Unit/External.hs
    ... ... @@ -49,7 +49,7 @@ type PackageAnnEnv = AnnEnv
    49 49
     type PackageCompleteMatches  = CompleteMatches
    
    50 50
     
    
    51 51
     -- | Helps us find information about modules in the imported packages
    
    52
    -type PackageIfaceTable = ModuleEnv ModIface
    
    52
    +type PackageIfaceTable = ModuleEnv RetainedModIface
    
    53 53
             -- Domain = modules in the imported packages
    
    54 54
     
    
    55 55
     -- | Constructs an empty PackageIfaceTable
    

  • compiler/GHC/Unit/Module/ModIface.hs
    ... ... @@ -2,6 +2,7 @@
    2 2
     {-# LANGUAGE UndecidableInstances #-}
    
    3 3
     {-# LANGUAGE PatternSynonyms #-}
    
    4 4
     {-# LANGUAGE DeriveAnyClass #-}
    
    5
    +{-# LANGUAGE RecordWildCards #-}
    
    5 6
     
    
    6 7
     module GHC.Unit.Module.ModIface
    
    7 8
        ( ModIface
    
    ... ... @@ -68,19 +69,31 @@ module GHC.Unit.Module.ModIface
    68 69
        , set_mi_fix_fn
    
    69 70
        , set_mi_hash_fn
    
    70 71
        , completePartialModIface
    
    71
    -   , IfaceBinHandle(..)
    
    72
    +   , shrinkModIface
    
    73
    +   , IfaceBinHandle
    
    72 74
        , PartialModIface
    
    75
    +   , RetainedModIface
    
    73 76
        , IfaceAbiHashes (..)
    
    74 77
        , IfaceSelfRecomp (..)
    
    75 78
        , IfaceCache (..)
    
    76 79
        , IfaceSimplifiedCore (..)
    
    77 80
        , withSelfRecomp
    
    78
    -   , IfaceDeclExts
    
    79
    -   , IfaceAbiHashesExts
    
    81
    +   , IfaceSelfRecompData
    
    82
    +   , IfaceSimplifiedCoreData
    
    83
    +   , ExtensibleFieldsData
    
    84
    +   , IfaceAnnotationsData
    
    85
    +   , IfaceDeclsData
    
    86
    +   , IfaceDefaultsData
    
    87
    +   , IfaceClsInstsData
    
    88
    +   , IfaceFamInstsData
    
    89
    +   , IfaceRulesData
    
    90
    +   , IfaceCompleteMatchesData
    
    91
    +   , IfaceAbiHashesData
    
    80 92
        , IfaceExport
    
    81 93
        , IfacePublic_(..)
    
    82 94
        , IfacePublic
    
    83 95
        , PartialIfacePublic
    
    96
    +   , RetainedIfacePublic
    
    84 97
        , IfaceModInfo(..)
    
    85 98
        , WhetherHasOrphans
    
    86 99
        , WhetherHasFamInst
    
    ... ... @@ -147,6 +160,7 @@ import GHC.Utils.Binary
    147 160
     
    
    148 161
     import Control.DeepSeq
    
    149 162
     import Control.Exception
    
    163
    +import Data.Void (Void)
    
    150 164
     
    
    151 165
     
    
    152 166
     {- Note [Interface file stages]
    
    ... ... @@ -167,9 +181,11 @@ We can build a full interface file two ways:
    167 181
     
    
    168 182
     type PartialModIface = ModIface_ 'ModIfaceCore
    
    169 183
     type ModIface = ModIface_ 'ModIfaceFinal
    
    184
    +type RetainedModIface = ModIface_ 'ModIfaceRetained
    
    170 185
     
    
    171 186
     type PartialIfacePublic = IfacePublic_ 'ModIfaceCore
    
    172 187
     type IfacePublic = IfacePublic_ 'ModIfaceFinal
    
    188
    +type RetainedIfacePublic = IfacePublic_ 'ModIfaceRetained
    
    173 189
     
    
    174 190
     -- | Extends a PartialModIface with hashes of the ABI.
    
    175 191
     --
    
    ... ... @@ -212,34 +228,78 @@ data IfaceCache = IfaceCache
    212 228
     
    
    213 229
     data ModIfacePhase
    
    214 230
       = ModIfaceCore
    
    215
    -  -- ^ Partial interface built based on output of core pipeline.
    
    231
    +    -- ^ Partial interface built from the output of the core pipeline
    
    216 232
       | ModIfaceFinal
    
    217
    -
    
    218
    --- | Selects a IfaceDecl representation.
    
    219
    --- For fully instantiated interfaces we also maintain
    
    220
    --- a fingerprint, which is used for recompilation checks.
    
    221
    -type family IfaceDeclExts (phase :: ModIfacePhase) = decl | decl -> phase where
    
    222
    -  IfaceDeclExts 'ModIfaceCore = IfaceDecl
    
    223
    -  IfaceDeclExts 'ModIfaceFinal = (Fingerprint, IfaceDecl)
    
    224
    -
    
    225
    -type family IfaceAbiHashesExts (phase :: ModIfacePhase) = bk | bk -> phase where
    
    226
    -  IfaceAbiHashesExts 'ModIfaceCore = ()
    
    227
    -  IfaceAbiHashesExts 'ModIfaceFinal = IfaceAbiHashes
    
    233
    +    -- ^ Complete interface
    
    234
    +  | ModIfaceRetained
    
    235
    +    -- ^ Interface shrunk to the parts that may be retained
    
    228 236
     
    
    229 237
     -- | In-memory byte array representation of a 'ModIface'.
    
    230 238
     --
    
    231 239
     -- See Note [Sharing of ModIface] for why we need this.
    
    232
    -data IfaceBinHandle (phase :: ModIfacePhase) where
    
    233
    -  -- | A partial 'ModIface' cannot be serialised to disk.
    
    234
    -  PartialIfaceBinHandle :: IfaceBinHandle 'ModIfaceCore
    
    235
    -  -- | Optional 'FullBinData' that can be serialised to disk directly.
    
    236
    -  --
    
    237
    -  -- See Note [Private fields in ModIface] for when this fields needs to be cleared
    
    238
    -  -- (e.g., set to 'Nothing').
    
    239
    -  FullIfaceBinHandle :: !(Strict.Maybe FullBinData) -> IfaceBinHandle 'ModIfaceFinal
    
    240
    -
    
    241
    -
    
    242
    -withSelfRecomp :: ModIface_ phase -> r -> (IfaceSelfRecomp -> r) -> r
    
    240
    +type family IfaceBinHandle (phase :: ModIfacePhase) where
    
    241
    +  IfaceBinHandle 'ModIfaceCore     = Void
    
    242
    +  IfaceBinHandle 'ModIfaceFinal    = FullBinData
    
    243
    +  IfaceBinHandle 'ModIfaceRetained = Void
    
    244
    +
    
    245
    +type family IfaceSelfRecompData (phase :: ModIfacePhase) where
    
    246
    +  IfaceSelfRecompData 'ModIfaceCore     = Maybe IfaceSelfRecomp
    
    247
    +  IfaceSelfRecompData 'ModIfaceFinal    = Maybe IfaceSelfRecomp
    
    248
    +  IfaceSelfRecompData 'ModIfaceRetained = ()
    
    249
    +
    
    250
    +type family IfaceSimplifiedCoreData (phase :: ModIfacePhase) where
    
    251
    +  IfaceSimplifiedCoreData 'ModIfaceCore     = Maybe IfaceSimplifiedCore
    
    252
    +  IfaceSimplifiedCoreData 'ModIfaceFinal    = Maybe IfaceSimplifiedCore
    
    253
    +  IfaceSimplifiedCoreData 'ModIfaceRetained = ()
    
    254
    +
    
    255
    +type family ExtensibleFieldsData (phase :: ModIfacePhase) where
    
    256
    +  ExtensibleFieldsData 'ModIfaceCore     = ExtensibleFields
    
    257
    +  ExtensibleFieldsData 'ModIfaceFinal    = ExtensibleFields
    
    258
    +  ExtensibleFieldsData 'ModIfaceRetained = ()
    
    259
    +
    
    260
    +type family IfaceAnnotationsData (phase :: ModIfacePhase) where
    
    261
    +  IfaceAnnotationsData 'ModIfaceCore     = [IfaceAnnotation]
    
    262
    +  IfaceAnnotationsData 'ModIfaceFinal    = [IfaceAnnotation]
    
    263
    +  IfaceAnnotationsData 'ModIfaceRetained = ()
    
    264
    +
    
    265
    +-- | The fingerprint in the 'ModIfaceFinal' case is used for recompilation
    
    266
    +--   checks.
    
    267
    +type family IfaceDeclsData (phase :: ModIfacePhase) where
    
    268
    +  IfaceDeclsData 'ModIfaceCore     = [IfaceDecl]
    
    269
    +  IfaceDeclsData 'ModIfaceFinal    = [(Fingerprint, IfaceDecl)]
    
    270
    +  IfaceDeclsData 'ModIfaceRetained = ()
    
    271
    +
    
    272
    +type family IfaceDefaultsData (phase :: ModIfacePhase) where
    
    273
    +  IfaceDefaultsData 'ModIfaceCore     = [IfaceDefault]
    
    274
    +  IfaceDefaultsData 'ModIfaceFinal    = [IfaceDefault]
    
    275
    +  IfaceDefaultsData 'ModIfaceRetained = ()
    
    276
    +
    
    277
    +type family IfaceClsInstsData (phase :: ModIfacePhase) where
    
    278
    +  IfaceClsInstsData 'ModIfaceCore     = [IfaceClsInst]
    
    279
    +  IfaceClsInstsData 'ModIfaceFinal    = [IfaceClsInst]
    
    280
    +  IfaceClsInstsData 'ModIfaceRetained = ()
    
    281
    +
    
    282
    +type family IfaceFamInstsData (phase :: ModIfacePhase) where
    
    283
    +  IfaceFamInstsData 'ModIfaceCore     = [IfaceFamInst]
    
    284
    +  IfaceFamInstsData 'ModIfaceFinal    = [IfaceFamInst]
    
    285
    +  IfaceFamInstsData 'ModIfaceRetained = ()
    
    286
    +
    
    287
    +type family IfaceRulesData (phase :: ModIfacePhase) where
    
    288
    +  IfaceRulesData 'ModIfaceCore     = [IfaceRule]
    
    289
    +  IfaceRulesData 'ModIfaceFinal    = [IfaceRule]
    
    290
    +  IfaceRulesData 'ModIfaceRetained = ()
    
    291
    +
    
    292
    +type family IfaceCompleteMatchesData (phase :: ModIfacePhase) where
    
    293
    +  IfaceCompleteMatchesData 'ModIfaceCore     = [IfaceCompleteMatch]
    
    294
    +  IfaceCompleteMatchesData 'ModIfaceFinal    = [IfaceCompleteMatch]
    
    295
    +  IfaceCompleteMatchesData 'ModIfaceRetained = ()
    
    296
    +
    
    297
    +type family IfaceAbiHashesData (phase :: ModIfacePhase) where
    
    298
    +  IfaceAbiHashesData 'ModIfaceCore     = ()
    
    299
    +  IfaceAbiHashesData 'ModIfaceFinal    = IfaceAbiHashes
    
    300
    +  IfaceAbiHashesData 'ModIfaceRetained = IfaceAbiHashes
    
    301
    +
    
    302
    +withSelfRecomp :: ModIface -> r -> (IfaceSelfRecomp -> r) -> r
    
    243 303
     withSelfRecomp iface nk jk =
    
    244 304
       case mi_self_recomp_info iface of
    
    245 305
         Nothing -> nk
    
    ... ... @@ -258,11 +318,22 @@ withSelfRecomp iface nk jk =
    258 318
     -- fields.
    
    259 319
     data ModIface_ (phase :: ModIfacePhase)
    
    260 320
       = PrivateModIface {
    
    261
    -        mi_hi_bytes_ :: !(IfaceBinHandle phase),
    
    262
    -                -- ^ A serialised in-memory buffer of this 'ModIface'.
    
    263
    -                -- If this handle is given, we can avoid serialising the 'ModIface'
    
    264
    -                -- when writing this 'ModIface' to disk, and write this buffer to disk instead.
    
    265
    -                -- See Note [Sharing of ModIface].
    
    321
    +        mi_hi_bytes_ :: !(Strict.Maybe (IfaceBinHandle phase)),
    
    322
    +                -- ^ Optionally an in-memory buffer that contains the
    
    323
    +                --   serialization of this 'ModIface'. If such a buffer is
    
    324
    +                --   present, we can avoid serialising the 'ModIface' when
    
    325
    +                --   writing it to disk and write this buffer instead. See
    
    326
    +                --   Note [Sharing of ModIface] and
    
    327
    +                --   Note [Private fields in ModIface].
    
    328
    +                --
    
    329
    +                --   Only in the 'ModIfaceFinal' phase, there can be a buffer
    
    330
    +                --   with the serialization. Both @IfaceBinHandle 'ModIfaceCore@
    
    331
    +                --   and @IfaceBinHandle 'ModIfaceRetained@ are defined to be
    
    332
    +                --   'Void', so that the 'mi_hi_bytes' field gets the type
    
    333
    +                --   @Strict.Maybe Void@. This type is isomorphic to '()', even
    
    334
    +                --   when taking partially defined values into account, because
    
    335
    +                --   @Strict.Just undefined@ is @undefined@ and so @Nothing@ and
    
    336
    +                --   @undefined@ are the only inhabitants of that type.
    
    266 337
             mi_iface_hash_  :: Fingerprint, -- A hash of the whole interface
    
    267 338
     
    
    268 339
             mi_mod_info_     :: IfaceModInfo,
    
    ... ... @@ -279,11 +350,11 @@ data ModIface_ (phase :: ModIfacePhase)
    279 350
                     -- importing this module. The main, original part of an interface.
    
    280 351
     
    
    281 352
     
    
    282
    -        mi_self_recomp_ :: Maybe IfaceSelfRecomp,
    
    353
    +        mi_self_recomp_ :: IfaceSelfRecompData phase,
    
    283 354
                     -- ^ Information needed for checking self-recompilation.
    
    284 355
                     -- See Note [Self recompilation information in interface files]
    
    285 356
     
    
    286
    -        mi_simplified_core_ :: Maybe IfaceSimplifiedCore,
    
    357
    +        mi_simplified_core_ :: IfaceSimplifiedCoreData phase,
    
    287 358
                     -- ^ The part of the interface written when `-fwrite-if-simplified-core` is enabled.
    
    288 359
                     -- These parts are used to restart bytecode generation.
    
    289 360
     
    
    ... ... @@ -301,7 +372,7 @@ data ModIface_ (phase :: ModIfacePhase)
    301 372
                     -- defined by the user).  Used for GHCi and for inspecting
    
    302 373
                     -- the contents of modules via the GHC API only.
    
    303 374
     
    
    304
    -        mi_ext_fields_ :: ExtensibleFields
    
    375
    +        mi_ext_fields_ :: ExtensibleFieldsData phase
    
    305 376
                     -- ^ Additional optional fields, where the Map key represents
    
    306 377
                     -- the field name, resulting in a (size, serialized data) pair.
    
    307 378
                     -- Because the data is intended to be serialized through the
    
    ... ... @@ -334,12 +405,12 @@ data IfacePublic_ phase = IfacePublic {
    334 405
                     -- ^ Warnings
    
    335 406
                     -- NOT STRICT!  we read this field lazily from the interface file
    
    336 407
     
    
    337
    -        mi_anns_     :: [IfaceAnnotation],
    
    408
    +        mi_anns_     :: IfaceAnnotationsData phase,
    
    338 409
                     -- ^ Annotations
    
    339 410
                     -- NOT STRICT!  we read this field lazily from the interface file
    
    340 411
     
    
    341 412
     
    
    342
    -        mi_decls_    :: [IfaceDeclExts phase],
    
    413
    +        mi_decls_    :: IfaceDeclsData phase,
    
    343 414
                     -- ^ Type, class and variable declarations
    
    344 415
                     -- The hash of an Id changes if its fixity or deprecations change
    
    345 416
                     --      (as well as its type of course)
    
    ... ... @@ -347,14 +418,14 @@ data IfacePublic_ phase = IfacePublic {
    347 418
                     -- the hash of the parent class/tycon changes
    
    348 419
     
    
    349 420
     
    
    350
    -        mi_defaults_ :: [IfaceDefault],
    
    421
    +        mi_defaults_ :: IfaceDefaultsData phase,
    
    351 422
                     -- ^ default declarations exported by the module
    
    352 423
     
    
    353 424
     
    
    354 425
                     -- Instance declarations and rules
    
    355
    -        mi_insts_       :: [IfaceClsInst],     -- ^ Sorted class instance
    
    356
    -        mi_fam_insts_   :: [IfaceFamInst],  -- ^ Sorted family instances
    
    357
    -        mi_rules_       :: [IfaceRule],     -- ^ Sorted rules
    
    426
    +        mi_insts_       :: IfaceClsInstsData phase, -- ^ Sorted class instance
    
    427
    +        mi_fam_insts_   :: IfaceFamInstsData phase, -- ^ Sorted family instances
    
    428
    +        mi_rules_       :: IfaceRulesData phase,    -- ^ Sorted rules
    
    358 429
     
    
    359 430
     
    
    360 431
             mi_trust_     :: IfaceTrustInfo,
    
    ... ... @@ -367,20 +438,20 @@ data IfacePublic_ phase = IfacePublic {
    367 438
                     -- itself) but imports some trustworthy modules from its own
    
    368 439
                     -- package (which does require its own package be trusted).
    
    369 440
                     -- See Note [Trust Own Package] in GHC.Rename.Names
    
    370
    -        mi_complete_matches_ :: [IfaceCompleteMatch],
    
    441
    +        mi_complete_matches_ :: IfaceCompleteMatchesData phase,
    
    371 442
                     -- ^ {-# COMPLETE #-} declarations
    
    372 443
     
    
    373 444
             mi_caches_ :: IfaceCache,
    
    374 445
                     -- ^ Cached lookups of some parts of mi_public
    
    375 446
     
    
    376
    -        mi_abi_hashes_ :: (IfaceAbiHashesExts phase)
    
    447
    +        mi_abi_hashes_ :: IfaceAbiHashesData phase
    
    377 448
                     -- ^ Either `()` or `IfaceAbiHashes` for
    
    378 449
                     -- a fully instantiated interface.
    
    379 450
                     -- These fields are hashes of different parts of the public interface.
    
    380 451
     }
    
    381 452
     
    
    382 453
     mkIfacePublic :: [IfaceExport]
    
    383
    -                  -> [IfaceDeclExts 'ModIfaceFinal]
    
    454
    +                  -> [(Fingerprint, IfaceDecl)]
    
    384 455
                       -> [(OccName, Fixity)]
    
    385 456
                       -> IfaceWarnings
    
    386 457
                       -> [IfaceAnnotation]
    
    ... ... @@ -501,22 +572,22 @@ That's why in GHC.Driver.Main.hscMaybeWriteIface there is the call to
    501 572
     forceModIface.
    
    502 573
     -}
    
    503 574
     
    
    504
    -mi_flag_hash :: ModIface_ phase -> Maybe (FingerprintWithValue IfaceDynFlags)
    
    575
    +mi_flag_hash :: ModIface -> Maybe (FingerprintWithValue IfaceDynFlags)
    
    505 576
     mi_flag_hash = fmap mi_sr_flag_hash . mi_self_recomp_
    
    506 577
     
    
    507
    -mi_opt_hash :: ModIface_ phase -> Maybe Fingerprint
    
    578
    +mi_opt_hash :: ModIface -> Maybe Fingerprint
    
    508 579
     mi_opt_hash = fmap mi_sr_opt_hash . mi_self_recomp_
    
    509 580
     
    
    510
    -mi_hpc_hash :: ModIface_ phase -> Maybe Fingerprint
    
    581
    +mi_hpc_hash :: ModIface -> Maybe Fingerprint
    
    511 582
     mi_hpc_hash = fmap mi_sr_hpc_hash . mi_self_recomp_
    
    512 583
     
    
    513
    -mi_src_hash :: ModIface_ phase -> Maybe Fingerprint
    
    584
    +mi_src_hash :: ModIface -> Maybe Fingerprint
    
    514 585
     mi_src_hash = fmap mi_sr_src_hash . mi_self_recomp_
    
    515 586
     
    
    516
    -mi_usages :: ModIface_ phase -> Maybe [Usage]
    
    587
    +mi_usages :: ModIface -> Maybe [Usage]
    
    517 588
     mi_usages = fmap mi_sr_usages . mi_self_recomp_
    
    518 589
     
    
    519
    -mi_plugin_hash :: ModIface_ phase -> Maybe Fingerprint
    
    590
    +mi_plugin_hash :: ModIface -> Maybe Fingerprint
    
    520 591
     mi_plugin_hash = fmap mi_sr_plugin_hash . mi_self_recomp_
    
    521 592
     
    
    522 593
     -- | Accessor for the module hash of the ABI from a ModIface.
    
    ... ... @@ -547,7 +618,7 @@ mi_orphan_hash iface = mi_abi_orphan_hash (mi_abi_hashes iface)
    547 618
     
    
    548 619
     -- | Old-style accessor for whether or not the ModIface came from an hs-boot
    
    549 620
     -- file.
    
    550
    -mi_boot :: ModIface -> IsBootInterface
    
    621
    +mi_boot :: ModIface_ phase -> IsBootInterface
    
    551 622
     mi_boot iface = if mi_hsc_src iface == HsBootFile
    
    552 623
         then IsBoot
    
    553 624
         else NotBoot
    
    ... ... @@ -557,7 +628,7 @@ mi_mnwib iface = GWIB (moduleName $ mi_module iface) (mi_boot iface)
    557 628
     
    
    558 629
     -- | Lookups up a (possibly cached) fixity from a 'ModIface'. If one cannot be
    
    559 630
     -- found, 'defaultFixity' is returned instead.
    
    560
    -mi_fix :: ModIface -> OccName -> Fixity
    
    631
    +mi_fix :: ModIface_ phase -> OccName -> Fixity
    
    561 632
     mi_fix iface name = mi_fix_fn iface name `orElse` defaultFixity
    
    562 633
     
    
    563 634
     -- | The semantic module for this interface; e.g., if it's a interface
    
    ... ... @@ -573,7 +644,7 @@ mi_semantic_module iface = mi_mod_info_semantic_module (mi_mod_info iface)
    573 644
     
    
    574 645
     -- | The "precise" free holes, e.g., the signatures that this
    
    575 646
     -- 'ModIface' depends on.
    
    576
    -mi_free_holes :: ModIface -> UniqDSet ModuleName
    
    647
    +mi_free_holes :: ModIface_ phase -> UniqDSet ModuleName
    
    577 648
     mi_free_holes iface =
    
    578 649
       case getModuleInstantiation (mi_module iface) of
    
    579 650
         (_, Just indef)
    
    ... ... @@ -654,7 +725,7 @@ instance Binary ModIface where
    654 725
                      -- We can't populate this field here, as we are
    
    655 726
                      -- missing the 'mi_ext_fields_' field, which is
    
    656 727
                      -- handled in 'getIfaceWithExtFields'.
    
    657
    -                 mi_hi_bytes_    = FullIfaceBinHandle Strict.Nothing
    
    728
    +                 mi_hi_bytes_    = Strict.Nothing
    
    658 729
                      })
    
    659 730
     
    
    660 731
     instance Binary IfaceModInfo where
    
    ... ... @@ -769,9 +840,9 @@ emptyPartialModIface mod
    769 840
       = PrivateModIface
    
    770 841
           { mi_mod_info_    = emptyIfaceModInfo mod,
    
    771 842
             mi_iface_hash_  = fingerprint0,
    
    772
    -        mi_hi_bytes_    = PartialIfaceBinHandle,
    
    843
    +        mi_hi_bytes_    = Strict.Nothing,
    
    773 844
             mi_deps_        = noDependencies,
    
    774
    -        mi_public_      = emptyPublicModIface (),
    
    845
    +        mi_public_      = emptyPublicModIface [] [] [] [] [] [] [] (),
    
    775 846
             mi_simplified_core_ = Nothing,
    
    776 847
             mi_top_env_     = IfaceTopEnv emptyDetOrdAvails [] ,
    
    777 848
             mi_docs_        = Nothing,
    
    ... ... @@ -787,24 +858,39 @@ emptyIfaceModInfo mod = IfaceModInfo
    787 858
       , mi_mod_info_hsc_src = HsSrcFile
    
    788 859
       }
    
    789 860
     
    
    790
    -
    
    791
    -emptyPublicModIface :: IfaceAbiHashesExts phase -> IfacePublic_ phase
    
    792
    -emptyPublicModIface abi_hashes = IfacePublic
    
    793
    -  { mi_exports_ = []
    
    794
    -  , mi_decls_ = []
    
    795
    -  , mi_fixities_ = []
    
    796
    -  , mi_warns_ = IfWarnSome [] []
    
    797
    -  , mi_anns_ = []
    
    798
    -  , mi_defaults_ = []
    
    799
    -  , mi_insts_ = []
    
    800
    -  , mi_fam_insts_ = []
    
    801
    -  , mi_rules_ = []
    
    802
    -  , mi_abi_hashes_ = abi_hashes
    
    803
    -  , mi_trust_ = noIfaceTrustInfo
    
    804
    -  , mi_trust_pkg_ = False
    
    805
    -  , mi_caches_ = emptyModIfaceCache
    
    806
    -  , mi_complete_matches_ = []
    
    807
    -  }
    
    861
    +emptyPublicModIface :: IfaceAnnotationsData phase
    
    862
    +                    -> IfaceDeclsData phase
    
    863
    +                    -> IfaceDefaultsData phase
    
    864
    +                    -> IfaceClsInstsData phase
    
    865
    +                    -> IfaceFamInstsData phase
    
    866
    +                    -> IfaceRulesData phase
    
    867
    +                    -> IfaceCompleteMatchesData phase
    
    868
    +                    -> IfaceAbiHashesData phase
    
    869
    +                    -> IfacePublic_ phase
    
    870
    +emptyPublicModIface anns
    
    871
    +                    decls
    
    872
    +                    defaults
    
    873
    +                    insts
    
    874
    +                    fam_insts
    
    875
    +                    rules
    
    876
    +                    complete_matches
    
    877
    +                    abi_hashes
    
    878
    +  = IfacePublic
    
    879
    +    { mi_exports_ = []
    
    880
    +    , mi_fixities_ = []
    
    881
    +    , mi_warns_ = IfWarnSome [] []
    
    882
    +    , mi_anns_ = anns
    
    883
    +    , mi_decls_ = decls
    
    884
    +    , mi_defaults_ = defaults
    
    885
    +    , mi_insts_ = insts
    
    886
    +    , mi_fam_insts_ = fam_insts
    
    887
    +    , mi_rules_ = rules
    
    888
    +    , mi_trust_ = noIfaceTrustInfo
    
    889
    +    , mi_trust_pkg_ = False
    
    890
    +    , mi_complete_matches_ = complete_matches
    
    891
    +    , mi_caches_ = emptyModIfaceCache
    
    892
    +    , mi_abi_hashes_ = abi_hashes
    
    893
    +    }
    
    808 894
     
    
    809 895
     emptyModIfaceCache :: IfaceCache
    
    810 896
     emptyModIfaceCache = IfaceCache {
    
    ... ... @@ -827,8 +913,8 @@ emptyIfaceBackend = IfaceAbiHashes
    827 913
     emptyFullModIface :: Module -> ModIface
    
    828 914
     emptyFullModIface mod =
    
    829 915
         (emptyPartialModIface mod)
    
    830
    -      { mi_public_ = emptyPublicModIface emptyIfaceBackend
    
    831
    -      , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
    
    916
    +      { mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] emptyIfaceBackend
    
    917
    +      , mi_hi_bytes_ = Strict.Nothing
    
    832 918
           }
    
    833 919
     
    
    834 920
     
    
    ... ... @@ -848,11 +934,20 @@ emptyIfaceHashCache _occ = Nothing
    848 934
     
    
    849 935
     -- ModIface is completely forced since it will live in memory for a long time.
    
    850 936
     -- If forcing it uses a lot of memory, then store less things in ModIface.
    
    851
    -instance ( NFData (IfaceAbiHashesExts (phase :: ModIfacePhase))
    
    852
    -         , NFData (IfaceDeclExts (phase :: ModIfacePhase))
    
    937
    +instance ( NFData (IfaceSelfRecompData phase)
    
    938
    +         , NFData (IfaceSimplifiedCoreData phase)
    
    939
    +         , NFData (ExtensibleFieldsData phase)
    
    940
    +         , NFData (IfaceAnnotationsData phase)
    
    941
    +         , NFData (IfaceDeclsData phase)
    
    942
    +         , NFData (IfaceDefaultsData phase)
    
    943
    +         , NFData (IfaceClsInstsData phase)
    
    944
    +         , NFData (IfaceFamInstsData phase)
    
    945
    +         , NFData (IfaceRulesData phase)
    
    946
    +         , NFData (IfaceCompleteMatchesData phase)
    
    947
    +         , NFData (IfaceAbiHashesData phase)
    
    853 948
              ) => NFData (ModIface_ phase) where
    
    854 949
       rnf (PrivateModIface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
    
    855
    -    = (a1 :: IfaceBinHandle phase)
    
    950
    +    = a1
    
    856 951
         `seq` rnf a2
    
    857 952
         `seq` rnf a3
    
    858 953
         `seq` rnf a4
    
    ... ... @@ -882,7 +977,15 @@ instance NFData IfaceAbiHashes where
    882 977
         `seq` rnf a5
    
    883 978
         `seq` rnf a6
    
    884 979
     
    
    885
    -instance (NFData (IfaceAbiHashesExts phase), NFData (IfaceDeclExts phase)) => NFData (IfacePublic_ phase) where
    
    980
    +instance ( NFData (IfaceAnnotationsData phase)
    
    981
    +         , NFData (IfaceDeclsData phase)
    
    982
    +         , NFData (IfaceDefaultsData phase)
    
    983
    +         , NFData (IfaceClsInstsData phase)
    
    984
    +         , NFData (IfaceFamInstsData phase)
    
    985
    +         , NFData (IfaceRulesData phase)
    
    986
    +         , NFData (IfaceCompleteMatchesData phase)
    
    987
    +         , NFData (IfaceAbiHashesData phase)
    
    988
    +         ) => NFData (IfacePublic_ phase) where
    
    886 989
       rnf (IfacePublic a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14)
    
    887 990
         =  rnf a1
    
    888 991
         `seq` rnf a2
    
    ... ... @@ -955,10 +1058,9 @@ completePartialModIface :: PartialModIface
    955 1058
     completePartialModIface partial iface_hash decls extra_decls final_exts cache = partial
    
    956 1059
       { mi_public_ = completePublicModIface decls final_exts cache (mi_public_ partial)
    
    957 1060
       , mi_simplified_core_ = extra_decls
    
    958
    -  , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
    
    1061
    +  , mi_hi_bytes_ = Strict.Nothing
    
    959 1062
       , mi_iface_hash_ = iface_hash
    
    960 1063
       }
    
    961
    -  where
    
    962 1064
     
    
    963 1065
     -- | Given a 'PartialIfacePublic', turn it into an 'IfacePublic' by completing
    
    964 1066
     -- missing fields.
    
    ... ... @@ -973,13 +1075,39 @@ completePublicModIface decls abi_hashes cache partial = partial
    973 1075
       , mi_caches_ = cache
    
    974 1076
       }
    
    975 1077
     
    
    1078
    +shrinkModIface :: ModIface -> RetainedModIface
    
    1079
    +shrinkModIface PrivateModIface {..}
    
    1080
    +  = PrivateModIface
    
    1081
    +    {
    
    1082
    +      mi_hi_bytes_        = Strict.Nothing,
    
    1083
    +      mi_public_          = shrinkIfacePublic mi_public_,
    
    1084
    +      mi_self_recomp_     = (),
    
    1085
    +      mi_simplified_core_ = (),
    
    1086
    +      mi_ext_fields_      = (),
    
    1087
    +      ..
    
    1088
    +    }
    
    1089
    +
    
    1090
    +shrinkIfacePublic :: IfacePublic -> RetainedIfacePublic
    
    1091
    +shrinkIfacePublic IfacePublic {..}
    
    1092
    +  = IfacePublic
    
    1093
    +    {
    
    1094
    +      mi_anns_             = (),
    
    1095
    +      mi_decls_            = (),
    
    1096
    +      mi_defaults_         = (),
    
    1097
    +      mi_insts_            = (),
    
    1098
    +      mi_fam_insts_        = (),
    
    1099
    +      mi_rules_            = (),
    
    1100
    +      mi_complete_matches_ = (),
    
    1101
    +      ..
    
    1102
    +    }
    
    1103
    +
    
    976 1104
     set_mi_mod_info :: IfaceModInfo -> ModIface_ phase -> ModIface_ phase
    
    977 1105
     set_mi_mod_info val iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = val }
    
    978 1106
     
    
    979
    -set_mi_self_recomp :: Maybe IfaceSelfRecomp-> ModIface_ phase -> ModIface_ phase
    
    1107
    +set_mi_self_recomp :: IfaceSelfRecompData phase -> ModIface_ phase -> ModIface_ phase
    
    980 1108
     set_mi_self_recomp val iface = clear_mi_hi_bytes $ iface { mi_self_recomp_ = val }
    
    981 1109
     
    
    982
    -set_mi_hi_bytes :: IfaceBinHandle phase -> ModIface_ phase -> ModIface_ phase
    
    1110
    +set_mi_hi_bytes :: Strict.Maybe (IfaceBinHandle phase) -> ModIface_ phase -> ModIface_ phase
    
    983 1111
     set_mi_hi_bytes val iface = iface { mi_hi_bytes_ = val }
    
    984 1112
     
    
    985 1113
     set_mi_deps :: Dependencies -> ModIface_ phase -> ModIface_ phase
    
    ... ... @@ -988,7 +1116,7 @@ set_mi_deps val iface = clear_mi_hi_bytes $ iface { mi_deps_ = val }
    988 1116
     set_mi_public :: (IfacePublic_ phase -> IfacePublic_ phase) -> ModIface_ phase -> ModIface_ phase
    
    989 1117
     set_mi_public f iface = clear_mi_hi_bytes $ iface { mi_public_ = f (mi_public_ iface) }
    
    990 1118
     
    
    991
    -set_mi_simplified_core :: Maybe IfaceSimplifiedCore -> ModIface_ phase -> ModIface_ phase
    
    1119
    +set_mi_simplified_core :: IfaceSimplifiedCoreData phase -> ModIface_ phase -> ModIface_ phase
    
    992 1120
     set_mi_simplified_core val iface = clear_mi_hi_bytes $ iface { mi_simplified_core_ = val }
    
    993 1121
     
    
    994 1122
     set_mi_top_env :: IfaceTopEnv -> ModIface_ phase -> ModIface_ phase
    
    ... ... @@ -997,7 +1125,7 @@ set_mi_top_env val iface = clear_mi_hi_bytes $ iface { mi_top_env_ = val }
    997 1125
     set_mi_docs :: Maybe Docs -> ModIface_ phase -> ModIface_ phase
    
    998 1126
     set_mi_docs val iface = clear_mi_hi_bytes $  iface { mi_docs_ = val }
    
    999 1127
     
    
    1000
    -set_mi_ext_fields :: ExtensibleFields -> ModIface_ phase -> ModIface_ phase
    
    1128
    +set_mi_ext_fields :: ExtensibleFieldsData phase -> ModIface_ phase -> ModIface_ phase
    
    1001 1129
     set_mi_ext_fields val iface = clear_mi_hi_bytes $ iface { mi_ext_fields_ = val }
    
    1002 1130
     
    
    1003 1131
     {- Settings for mi_public interface fields -}
    
    ... ... @@ -1011,22 +1139,22 @@ set_mi_fixities val = set_mi_public (\iface -> iface { mi_fixities_ = val })
    1011 1139
     set_mi_warns :: IfaceWarnings -> ModIface_ phase -> ModIface_ phase
    
    1012 1140
     set_mi_warns val = set_mi_public (\iface -> iface { mi_warns_ = val })
    
    1013 1141
     
    
    1014
    -set_mi_anns :: [IfaceAnnotation] -> ModIface_ phase -> ModIface_ phase
    
    1142
    +set_mi_anns :: IfaceAnnotationsData phase -> ModIface_ phase -> ModIface_ phase
    
    1015 1143
     set_mi_anns val = set_mi_public (\iface -> iface { mi_anns_ = val })
    
    1016 1144
     
    
    1017
    -set_mi_insts :: [IfaceClsInst] -> ModIface_ phase -> ModIface_ phase
    
    1145
    +set_mi_insts :: IfaceClsInstsData phase -> ModIface_ phase -> ModIface_ phase
    
    1018 1146
     set_mi_insts val = set_mi_public (\iface -> iface { mi_insts_ = val })
    
    1019 1147
     
    
    1020
    -set_mi_fam_insts :: [IfaceFamInst] -> ModIface_ phase -> ModIface_ phase
    
    1148
    +set_mi_fam_insts :: IfaceFamInstsData phase -> ModIface_ phase -> ModIface_ phase
    
    1021 1149
     set_mi_fam_insts val = set_mi_public (\iface -> iface { mi_fam_insts_ = val })
    
    1022 1150
     
    
    1023
    -set_mi_rules :: [IfaceRule] -> ModIface_ phase -> ModIface_ phase
    
    1151
    +set_mi_rules :: IfaceRulesData phase -> ModIface_ phase -> ModIface_ phase
    
    1024 1152
     set_mi_rules val = set_mi_public (\iface -> iface { mi_rules_ = val })
    
    1025 1153
     
    
    1026
    -set_mi_decls :: [IfaceDeclExts phase] -> ModIface_ phase -> ModIface_ phase
    
    1154
    +set_mi_decls :: IfaceDeclsData phase -> ModIface_ phase -> ModIface_ phase
    
    1027 1155
     set_mi_decls val = set_mi_public (\iface -> iface { mi_decls_ = val })
    
    1028 1156
     
    
    1029
    -set_mi_defaults :: [IfaceDefault] -> ModIface_ phase -> ModIface_ phase
    
    1157
    +set_mi_defaults :: IfaceDefaultsData phase -> ModIface_ phase -> ModIface_ phase
    
    1030 1158
     set_mi_defaults val = set_mi_public (\iface -> iface { mi_defaults_ = val })
    
    1031 1159
     
    
    1032 1160
     set_mi_trust :: IfaceTrustInfo -> ModIface_ phase -> ModIface_ phase
    
    ... ... @@ -1035,10 +1163,10 @@ set_mi_trust val = set_mi_public (\iface -> iface { mi_trust_ = val })
    1035 1163
     set_mi_trust_pkg :: Bool -> ModIface_ phase -> ModIface_ phase
    
    1036 1164
     set_mi_trust_pkg val = set_mi_public (\iface -> iface { mi_trust_pkg_ = val })
    
    1037 1165
     
    
    1038
    -set_mi_complete_matches :: [IfaceCompleteMatch] -> ModIface_ phase -> ModIface_ phase
    
    1166
    +set_mi_complete_matches :: IfaceCompleteMatchesData phase -> ModIface_ phase -> ModIface_ phase
    
    1039 1167
     set_mi_complete_matches val = set_mi_public (\iface -> iface { mi_complete_matches_ = val })
    
    1040 1168
     
    
    1041
    -set_mi_abi_hashes :: IfaceAbiHashesExts phase -> ModIface_ phase -> ModIface_ phase
    
    1169
    +set_mi_abi_hashes :: IfaceAbiHashesData phase -> ModIface_ phase -> ModIface_ phase
    
    1042 1170
     set_mi_abi_hashes val = set_mi_public (\iface -> iface { mi_abi_hashes_ = val })
    
    1043 1171
     
    
    1044 1172
     {- Setters for mi_caches interface fields -}
    
    ... ... @@ -1082,11 +1210,7 @@ set_mi_mod_info_field f iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = f (mi
    1082 1210
     
    
    1083 1211
     -- | Invalidate any byte array buffer we might have.
    
    1084 1212
     clear_mi_hi_bytes :: ModIface_ phase -> ModIface_ phase
    
    1085
    -clear_mi_hi_bytes iface = iface
    
    1086
    -  { mi_hi_bytes_ = case mi_hi_bytes iface of
    
    1087
    -      PartialIfaceBinHandle -> PartialIfaceBinHandle
    
    1088
    -      FullIfaceBinHandle _ -> FullIfaceBinHandle Strict.Nothing
    
    1089
    -  }
    
    1213
    +clear_mi_hi_bytes iface = iface { mi_hi_bytes_ = Strict.Nothing }
    
    1090 1214
     
    
    1091 1215
     -- ----------------------------------------------------------------------------
    
    1092 1216
     -- 'ModIface' pattern synonyms to keep breakage low.
    
    ... ... @@ -1183,22 +1307,22 @@ pattern ModIface ::
    1183 1307
       -> [IfaceExport]
    
    1184 1308
       -> [(OccName, Fixity)]
    
    1185 1309
       -> IfaceWarnings
    
    1186
    -  -> [IfaceAnnotation]
    
    1187
    -  -> [IfaceDeclExts phase]
    
    1188
    -  -> Maybe IfaceSimplifiedCore
    
    1189
    -  -> [IfaceDefault]
    
    1310
    +  -> IfaceAnnotationsData phase
    
    1311
    +  -> IfaceDeclsData phase
    
    1312
    +  -> IfaceSimplifiedCoreData phase
    
    1313
    +  -> IfaceDefaultsData phase
    
    1190 1314
       -> IfaceTopEnv
    
    1191
    -  -> [IfaceClsInst]
    
    1192
    -  -> [IfaceFamInst]
    
    1193
    -  -> [IfaceRule]
    
    1315
    +  -> IfaceClsInstsData phase
    
    1316
    +  -> IfaceFamInstsData phase
    
    1317
    +  -> IfaceRulesData phase
    
    1194 1318
       -> IfaceTrustInfo
    
    1195 1319
       -> Bool
    
    1196
    -  -> [IfaceCompleteMatch]
    
    1320
    +  -> IfaceCompleteMatchesData phase
    
    1197 1321
       -> Maybe Docs
    
    1198
    -  -> IfaceAbiHashesExts phase
    
    1199
    -  -> ExtensibleFields
    
    1200
    -  -> IfaceBinHandle phase
    
    1201
    -  -> Maybe IfaceSelfRecomp
    
    1322
    +  -> IfaceAbiHashesData phase
    
    1323
    +  -> ExtensibleFieldsData phase
    
    1324
    +  -> Strict.Maybe (IfaceBinHandle phase)
    
    1325
    +  -> IfaceSelfRecompData phase
    
    1202 1326
       -> (OccName -> Maybe Fixity)
    
    1203 1327
       -> (OccName -> Maybe (OccName, Fingerprint))
    
    1204 1328
       -> (OccName -> Maybe (WarningTxt GhcRn))
    

  • ghc/Main.hs
    ... ... @@ -515,7 +515,7 @@ abiHash strs = do
    515 515
       put_ bh hiVersion
    
    516 516
         -- package hashes change when the compiler version changes (for now)
    
    517 517
         -- see #5328
    
    518
    -  mapM_ (put_ bh . mi_mod_hash) ifaces
    
    518
    +  mapM_ (put_ bh . mi_abi_mod_hash . mi_abi_hashes) ifaces
    
    519 519
       f <- fingerprintBinMem bh
    
    520 520
     
    
    521 521
       putStrLn (showPpr dflags f)
    

  • utils/count-deps/Main.hs
    ... ... @@ -79,5 +79,5 @@ calcDeps modName libdir =
    79 79
         mkModule :: String -> ModuleName -> Module
    
    80 80
         mkModule ghcUnitId = Module (stringToUnit ghcUnitId)
    
    81 81
     
    
    82
    -    modDeps :: ModIface -> [ModuleName]
    
    82
    +    modDeps :: ModIface_ phase -> [ModuleName]
    
    83 83
         modDeps mi = map (gwib_mod . (\(_, _, mn) -> mn)) $ Set.toList $ dep_direct_mods (mi_deps mi)

  • utils/haddock/haddock-api/src/Haddock/Interface.hs
    ... ... @@ -57,21 +57,25 @@ import GHC.Driver.Monad
    57 57
     import GHC.Driver.Make
    
    58 58
     import GHC.Driver.Main
    
    59 59
     import GHC.Core.InstEnv
    
    60
    +import GHC.Core.FamInstEnv
    
    60 61
     import qualified GHC.Driver.DynFlags as DynFlags
    
    61 62
     import qualified GHC.Utils.Outputable as Outputable
    
    62 63
     import GHC.Driver.Session hiding (verbosity)
    
    63 64
     import GHC.Driver.Phases
    
    64 65
     import GHC.Driver.Pipeline (compileFile)
    
    65 66
     import GHC.HsToCore.Docs (getMainDeclBinder)
    
    66
    -import GHC.Iface.Load (loadSysInterface)
    
    67
    -import GHC.IfaceToCore (tcIfaceInst, tcIfaceFamInst)
    
    68
    -import GHC.Tc.Utils.Monad (initIfaceLoad, initIfaceLcl)
    
    67
    +import GHC.Iface.Load (findAndReadIface)
    
    68
    +import GHC.IfaceToCore (tcIfaceDecls, tcIfaceInst, tcIfaceFamInst)
    
    69
    +import GHC.Tc.Utils.Monad (goptM, updateEps_, initIfaceLoad, initIfaceLcl)
    
    69 70
     import GHC.Tc.Utils.Env (lookupGlobal_maybe)
    
    70 71
     import GHC.Types.Error (mkUnknownDiagnostic)
    
    71 72
     import GHC.Types.Name.Occurrence (emptyOccEnv)
    
    73
    +import GHC.Types.Name.Env (extendNameEnvList)
    
    72 74
     import GHC.Unit.Finder (findImportedModule, ModuleLookupScope(..), FindResult(Found))
    
    73 75
     import GHC.Unit.Home.ModInfo
    
    74 76
     import GHC.Unit.Home.PackageTable
    
    77
    +import GHC.Unit.External (eps_PTE, eps_inst_env, eps_fam_inst_env)
    
    78
    +import GHC.Unit.Module (getModuleInstantiation)
    
    75 79
     import GHC.Unit.Module.Graph (ModuleGraphNode (..), ModuleNodeInfo(..))
    
    76 80
     import GHC.Unit.Module.ModDetails
    
    77 81
     import GHC.Unit.Module.ModIface (mi_semantic_module, mi_boot)
    
    ... ... @@ -254,19 +258,29 @@ dropErr :: MaybeErr e a -> Maybe a
    254 258
     dropErr (Succeeded a) = Just a
    
    255 259
     dropErr (Failed _) = Nothing
    
    256 260
     
    
    257
    -loadHiFile :: HscEnv -> Outputable.SDoc -> Module -> IO (ModIface, ([ClsInst], [FamInst]))
    
    258
    -loadHiFile hsc_env doc theModule = initIfaceLoad hsc_env $ do
    
    259
    -
    
    260
    -  mod_iface <- loadSysInterface doc theModule
    
    261
    -
    
    262
    -  insts <- initIfaceLcl (mi_semantic_module mod_iface) doc (mi_boot mod_iface) $ do
    
    263
    -
    
    264
    -    new_eps_insts     <- mapM tcIfaceInst (mi_insts mod_iface)
    
    265
    -    new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts mod_iface)
    
    266
    -
    
    267
    -    pure (new_eps_insts, new_eps_fam_insts)
    
    268
    -
    
    269
    -  pure (mod_iface, insts)
    
    261
    +loadHiFile :: Verbosity -> HscEnv -> Outputable.SDoc -> Module -> IO (ModIface, ([ClsInst], [FamInst]))
    
    262
    +loadHiFile verbosity hsc_env doc requested = initIfaceLoad hsc_env $ do
    
    263
    +  let installed = fst (getModuleInstantiation requested)
    
    264
    +  iface_fetch_result <- liftIO $ findAndReadIface hsc_env doc installed requested NotBoot
    
    265
    +  case iface_fetch_result of
    
    266
    +    Failed _ -> do
    
    267
    +      out verbosity normal $ "Loading interface for "                ++
    
    268
    +                             moduleNameString (moduleName requested) ++
    
    269
    +                             " failed"
    
    270
    +      liftIO exitFailure
    
    271
    +    Succeeded (mod_iface, _) -> do
    
    272
    +      all_insts <- initIfaceLcl (mi_semantic_module mod_iface) doc (mi_boot mod_iface) $ do
    
    273
    +        ignore_iface_pragmas <- goptM Opt_IgnoreInterfacePragmas
    
    274
    +        decls                <- tcIfaceDecls ignore_iface_pragmas (mi_decls mod_iface)
    
    275
    +        insts                <- mapM tcIfaceInst (mi_insts mod_iface)
    
    276
    +        fam_insts            <- mapM tcIfaceFamInst (mi_fam_insts mod_iface)
    
    277
    +        updateEps_ $ \ eps -> eps {
    
    278
    +          eps_PTE              = extendNameEnvList (eps_PTE eps) decls,
    
    279
    +          eps_inst_env         = extendInstEnvList (eps_inst_env eps) insts,
    
    280
    +          eps_fam_inst_env     = extendFamInstEnvList (eps_fam_inst_env eps) fam_insts
    
    281
    +        }
    
    282
    +        pure (insts, fam_insts)
    
    283
    +      pure (mod_iface, all_insts)
    
    270 284
     
    
    271 285
     processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -> WarningMap -> Ghc (Maybe Interface)
    
    272 286
     processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap = do
    
    ... ... @@ -279,7 +293,7 @@ processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap = do
    279 293
           unit_state = hsc_units hsc_env
    
    280 294
     
    
    281 295
       (mod_iface, insts) <- if Flag_NoCompilation `elem` flags
    
    282
    -    then liftIO $ loadHiFile hsc_env doc $ ms_mod modSummary
    
    296
    +    then liftIO $ loadHiFile verbosity hsc_env doc $ ms_mod modSummary
    
    283 297
         else do
    
    284 298
           hmi <- liftIO $ lookupHpt (hsc_HPT hsc_env) (moduleName $ ms_mod modSummary) >>= \case
    
    285 299
               Nothing -> error "processModule: All modules should be loaded into the HPT by this point"
    
    ... ... @@ -374,7 +388,7 @@ createOneShotIface verbosity flags instIfaceMap moduleNameStr = do
    374 388
       modifySession $ hscSetFlags dflags
    
    375 389
       hsc_env <- getSession
    
    376 390
     
    
    377
    -  (iface, insts) <- liftIO $ loadHiFile hsc_env doc $ mkMainModule_ moduleNm
    
    391
    +  (iface, insts) <- liftIO $ loadHiFile verbosity hsc_env doc $ mkMainModule_ moduleNm
    
    378 392
     
    
    379 393
       -- Update the DynFlags with the extensions from the source file (as stored in the interface file)
    
    380 394
       -- This is instead of ms_hspp_opts from ModSummary, which is not available in one-shot mode.