Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC

Commits:

27 changed files:

Changes:

  • compiler/GHC.hs
    ... ... @@ -442,13 +442,14 @@ import GHC.Types.PkgQual
    442 442
     import GHC.Unit
    
    443 443
     import GHC.Unit.Env as UnitEnv
    
    444 444
     import GHC.Unit.Finder
    
    445
    -import GHC.Unit.Module.ModIface
    
    446
    -import GHC.Unit.Module.ModGuts
    
    445
    +import GHC.Unit.Home.Graph qualified as HUG
    
    446
    +import GHC.Unit.Home.ModInfo
    
    447
    +import GHC.Unit.Home.PackageTable qualified as HPT
    
    448
    +import GHC.Unit.Module.Graph
    
    447 449
     import GHC.Unit.Module.ModDetails
    
    450
    +import GHC.Unit.Module.ModGuts
    
    451
    +import GHC.Unit.Module.ModIface
    
    448 452
     import GHC.Unit.Module.ModSummary
    
    449
    -import GHC.Unit.Module.Graph
    
    450
    -import GHC.Unit.Home.ModInfo
    
    451
    -import qualified GHC.Unit.Home.Graph as HUG
    
    452 453
     
    
    453 454
     import Control.Applicative ((<|>))
    
    454 455
     import Control.Monad
    
    ... ... @@ -693,14 +694,43 @@ setUnitDynFlagsNoCheck uid dflags1 = do
    693 694
       (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 (hscUIC hsc_env) (hsc_all_home_unit_ids hsc_env)
    
    694 695
       updated_dflags <- liftIO $ updatePlatformConstants dflags1 mconstants
    
    695 696
     
    
    696
    -  let upd hue =
    
    697
    -       hue
    
    698
    -          { homeUnitEnv_units = unit_state
    
    699
    -          , homeUnitEnv_dflags = updated_dflags
    
    700
    -          , homeUnitEnv_home_unit = Just home_unit
    
    701
    -          }
    
    697
    +  let
    
    698
    +    upd hue = do
    
    699
    +      let
    
    700
    +        warnOnNonEmptyTable =
    
    701
    +          whenM (not <$> HPT.isHptEmpty (homeUnitEnv_hpt hue)) $ do
    
    702
    +            logInfo logger
    
    703
    +              ( text "Changed the ghc mode" <+> ppr (ghcMode $ homeUnitEnv_dflags hue) <+> text "to" <+> ppr (ghcMode updated_dflags) $$
    
    704
    +                text "The home package table was not empty!" $$
    
    705
    +                text "The table was cleared any way."
    
    706
    +              )
    
    707
    +      the_hpt <-
    
    708
    +        case (HPT.isOneShotMode (homeUnitEnv_hpt hue), ghcMode updated_dflags) of
    
    709
    +          (True,  OneShot) ->
    
    710
    +            pure $ homeUnitEnv_hpt hue
    
    711
    +          (True,  CompManager) -> do
    
    712
    +            warnOnNonEmptyTable
    
    713
    +            HPT.emptyHomePackageTable
    
    714
    +          (True,  MkDepend) -> do
    
    715
    +            warnOnNonEmptyTable
    
    716
    +            HPT.emptyHomePackageTable
    
    717
    +          (False, OneShot) -> do
    
    718
    +            warnOnNonEmptyTable
    
    719
    +            HPT.emptyOnDemandHomePackageTable
    
    720
    +          (False, CompManager) ->
    
    721
    +            pure $ homeUnitEnv_hpt hue
    
    722
    +          (False, MkDepend) ->
    
    723
    +            pure $ homeUnitEnv_hpt hue
    
    724
    +      pure hue
    
    725
    +        { homeUnitEnv_units = unit_state
    
    726
    +        , homeUnitEnv_dflags = updated_dflags
    
    727
    +        , homeUnitEnv_home_unit = Just home_unit
    
    728
    +        , homeUnitEnv_hpt = the_hpt
    
    729
    +        }
    
    730
    +
    
    731
    +
    
    702 732
     
    
    703
    -  let unit_env = UnitEnv.ue_updateHomeUnitEnv upd uid (hsc_unit_env hsc_env)
    
    733
    +  unit_env <- liftIO $ UnitEnv.ue_adjustHomeUnitEnvA upd uid (hsc_unit_env hsc_env)
    
    704 734
     
    
    705 735
       let dflags = updated_dflags
    
    706 736
     
    

  • compiler/GHC/Core/Opt/Pipeline.hs
    ... ... @@ -102,7 +102,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod
    102 102
         logger         = hsc_logger hsc_env
    
    103 103
         unit_env       = hsc_unit_env hsc_env
    
    104 104
         extra_vars     = interactiveInScope (hsc_IC hsc_env)
    
    105
    -    home_pkg_rules = hugRulesBelow hsc_env (moduleUnitId mod)
    
    105
    +    home_pkg_rules = hugRulesBelow (hsc_unit_env hsc_env) (moduleUnitId mod)
    
    106 106
                           (GWIB { gwib_mod = moduleName mod, gwib_isBoot = NotBoot })
    
    107 107
         name_ppr_ctx   = mkNamePprCtx ptc unit_env rdr_env
    
    108 108
         ptc            = initPromotionTickContext dflags
    
    ... ... @@ -468,7 +468,7 @@ doCorePass pass guts = do
    468 468
       p_fam_env <- getPackageFamInstEnv
    
    469 469
       l_fam_env <- getLazyHomeFamInstEnv
    
    470 470
       let platform = targetPlatform dflags
    
    471
    -  let fam_envs = (p_fam_env `unionFamInstEnv` l_fam_env, mg_fam_inst_env guts)
    
    471
    +  let fam_envs = (p_fam_env, mg_fam_inst_env guts `unionFamInstEnv` l_fam_env)
    
    472 472
       let updateBinds  f = return $ guts { mg_binds = f (mg_binds guts) }
    
    473 473
       let updateBindsM f = f (mg_binds guts) >>= \b' -> return $ guts { mg_binds = b' }
    
    474 474
       let updateBindsAndRulesM f = f (mg_binds guts) (mg_rules guts) >>= \(b',r') -> return $ guts { mg_binds = b', mg_rules = r' }
    

  • compiler/GHC/Core/Opt/Simplify.hs
    ... ... @@ -44,7 +44,7 @@ import GHC.Types.Unique.FM
    44 44
     
    
    45 45
     import Control.Monad
    
    46 46
     import Data.Foldable ( for_ )
    
    47
    -import GHC.Unit.Home.PackageTable (hptLoadedRuleBase, HomePackageTable)
    
    47
    +import GHC.Unit.Home.PackageTable (hptLoadedRuleBase, hptLoadedFamInstEnv, HomePackageTable)
    
    48 48
     
    
    49 49
     {-
    
    50 50
     ************************************************************************
    
    ... ... @@ -74,8 +74,9 @@ simplifyExpr :: Logger
    74 74
     simplifyExpr logger euc hpt opts expr
    
    75 75
       = withTiming logger (text "Simplify [expr]") (const ()) $
    
    76 76
         do  { eps <- eucEPS euc ;
    
    77
    +        ; home_fam_inst_env <- hptLoadedFamInstEnv hpt
    
    77 78
             ; let fam_envs = ( eps_fam_inst_env eps
    
    78
    -                         , extendFamInstEnvList emptyFamInstEnv $ se_fam_inst opts
    
    79
    +                         , extendFamInstEnvList home_fam_inst_env $ se_fam_inst opts
    
    79 80
                              )
    
    80 81
                   -- See Note [Seed the in-scope set for open expressions]
    
    81 82
                   simpl_env = setInScopeSet base_env
    
    ... ... @@ -278,6 +279,7 @@ simplifyPgm logger unit_env name_ppr_ctx opts
    278 279
                     -- value (via read_rule_env) and then combine it with the existing rule base.
    
    279 280
                     -- See `GHC.Core.Opt.Simplify.Monad.getSimplRules`.
    
    280 281
               eps <- ueEPS unit_env ;
    
    282
    +          home_fam_inst_env <- hptLoadedFamInstEnv (ue_hpt unit_env) ;
    
    281 283
                let  { -- base_rule_env contains
    
    282 284
                       --    (a) home package rules, fixed across all iterations
    
    283 285
                       --    (b) local rules (substituted) from `local_rules` arg to do_iteration
    
    ... ... @@ -294,7 +296,7 @@ simplifyPgm logger unit_env name_ppr_ctx opts
    294 296
                     ; read_rule_env :: IO RuleEnv
    
    295 297
                     ; read_rule_env = (\ home_rules eps_rules -> updExternalPackageRules (updHomePackageRules base_rule_env home_rules) eps_rules) <$> read_home_rules <*> read_eps_rules
    
    296 298
     
    
    297
    -                ; fam_envs = (eps_fam_inst_env eps, fam_inst_env)
    
    299
    +                ; fam_envs = (eps_fam_inst_env eps, fam_inst_env `unionFamInstEnv` home_fam_inst_env)
    
    298 300
                     ; simpl_env = mkSimplEnv mode fam_envs } ;
    
    299 301
     
    
    300 302
                     -- Simplify the program
    

  • compiler/GHC/Core/Rules.hs
    ... ... @@ -401,7 +401,7 @@ lookupRuleBase = lookupUFM
    401 401
     
    
    402 402
     unionRuleBase :: RuleBase -> RuleBase -> RuleBase
    
    403 403
     unionRuleBase
    
    404
    -  = plusUFM
    
    404
    +  = plusUFM_C (++)
    
    405 405
     
    
    406 406
     pprRuleBase :: RuleBase -> SDoc
    
    407 407
     pprRuleBase rules = pprUFM rules $ \rss ->
    

  • compiler/GHC/Driver/Env.hs
    ... ... @@ -99,6 +99,7 @@ import Data.IORef
    99 99
     import qualified Data.Set as Set
    
    100 100
     import GHC.Types.Name.Reader (ExactRdrName(..))
    
    101 101
     import qualified GHC.Unit.Home.PackageTable as HomePackageTable
    
    102
    +import qualified GHC.Unit.Home.PackageTable as HPT
    
    102 103
     
    
    103 104
     runHsc :: HscEnv -> Hsc a -> IO a
    
    104 105
     runHsc hsc_env hsc = do
    
    ... ... @@ -259,26 +260,26 @@ hscUIC hsc_env = ue_uic (hsc_unit_env hsc_env)
    259 260
     
    
    260 261
     -- | Find all rules in modules that are in the transitive closure of the given
    
    261 262
     -- module.
    
    262
    -hugRulesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
    
    263
    -hugRulesBelow hsc_env uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
    
    264
    -  hugSomeThingsBelowUs (md_rules . hm_details) False hsc_env uid mn
    
    263
    +hugRulesBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
    
    264
    +hugRulesBelow unit_env uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
    
    265
    +  hugSomeThingsBelowUs (md_rules . hm_details) False unit_env uid mn
    
    265 266
     
    
    266 267
     -- | Get annotations from all modules "below" this one (in the dependency
    
    267 268
     -- sense) within the home units. If the module is @Nothing@, returns /all/
    
    268 269
     -- annotations in the home units.
    
    269
    -hugAnnsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
    
    270
    -hugAnnsBelow hsc_env uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
    
    271
    -  hugSomeThingsBelowUs (md_anns . hm_details) False hsc_env uid mn
    
    270
    +hugAnnsBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
    
    271
    +hugAnnsBelow unit_env uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
    
    272
    +  hugSomeThingsBelowUs (md_anns . hm_details) False unit_env uid mn
    
    272 273
     
    
    273 274
     -- | Find all COMPLETE pragmas in modules that are in the transitive closure of the
    
    274 275
     -- given module.
    
    275
    -hugCompleteSigsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
    
    276
    -hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$>
    
    277
    -  hugSomeThingsBelowUs (md_complete_matches . hm_details) False hsc uid mn
    
    276
    +hugCompleteSigsBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
    
    277
    +hugCompleteSigsBelow unit_env uid mn = foldr (++) [] <$>
    
    278
    +  hugSomeThingsBelowUs (md_complete_matches . hm_details) False unit_env uid mn
    
    278 279
     
    
    279 280
     -- | Find instances visible from the given set of imports
    
    280
    -hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
    
    281
    -hugInstancesBelow hsc_env uid mnwib = do
    
    281
    +hugInstancesBelow :: UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
    
    282
    +hugInstancesBelow unit_env uid mnwib = do
    
    282 283
      let mn = mkModule uid (gwib_mod mnwib)
    
    283 284
      (insts, famInsts) <-
    
    284 285
          unzip . concat <$>
    
    ... ... @@ -289,7 +290,7 @@ hugInstancesBelow hsc_env uid mnwib = do
    289 290
                                            then []
    
    290 291
                                            else [(md_insts details, md_fam_insts details)])
    
    291 292
                               True -- Include -hi-boot
    
    292
    -                          hsc_env
    
    293
    +                          unit_env
    
    293 294
                               uid
    
    294 295
                               mnwib
    
    295 296
      return (foldl' unionInstEnv emptyInstEnv insts, concat famInsts)
    
    ... ... @@ -297,16 +298,18 @@ hugInstancesBelow hsc_env uid mnwib = do
    297 298
     -- | Get things from modules in the transitive closure of the given module.
    
    298 299
     --
    
    299 300
     -- Note: Don't expose this function. This is a footgun if exposed!
    
    300
    -hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
    
    301
    +hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
    
    301 302
     -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk
    
    302 303
     -- These things are currently stored in the EPS for home packages. (See #25795 for
    
    303 304
     -- progress in removing these kind of checks; and making these functions of
    
    304 305
     -- `UnitEnv` rather than `HscEnv`)
    
    305 306
     -- See Note [The ModuleGraph]
    
    306
    -hugSomeThingsBelowUs _ _ hsc_env _ _ | isOneShot (ghcMode (hsc_dflags hsc_env)) = return []
    
    307
    -hugSomeThingsBelowUs extract include_hi_boot hsc_env uid mn
    
    308
    -  = let hug = hsc_HUG hsc_env
    
    309
    -        mg  = hsc_mod_graph hsc_env
    
    307
    +hugSomeThingsBelowUs extract include_hi_boot unit_env uid mn
    
    308
    +  | HPT.isOneShotMode (ue_hpt unit_env)
    
    309
    +  = pure []
    
    310
    +  | otherwise
    
    311
    +  = let hug = ue_home_unit_graph unit_env
    
    312
    +        mg  = ue_module_graph unit_env
    
    310 313
         in
    
    311 314
         sequence
    
    312 315
         [ things
    
    ... ... @@ -346,14 +349,15 @@ prepareAnnotations hsc_env mb_guts = do
    346 349
             -- otherwise load annotations from all home package table
    
    347 350
             -- entries regardless of dependency ordering.
    
    348 351
             get_mod mg = (moduleUnitId (mg_module mg), GWIB (moduleName (mg_module mg)) NotBoot)
    
    349
    -    home_pkg_anns  <- fromMaybe (hugAllAnns (hsc_unit_env hsc_env))
    
    350
    -                      $ uncurry (hugAnnsBelow hsc_env)
    
    351
    -                      . get_mod <$> mb_guts
    
    352
    -    more_home_pkg_anns <- HomePackageTable.hptLoadedAnnEnv $ hsc_HPT hsc_env
    
    352
    +    home_pkg_anns  <- case mb_guts of
    
    353
    +      Nothing   -> hugAllAnns (hsc_unit_env hsc_env)
    
    354
    +      Just guts -> plusAnnEnv
    
    355
    +        <$> uncurry (hugAnnsBelow (hsc_unit_env hsc_env)) (get_mod guts)
    
    356
    +        <*> HomePackageTable.hptLoadedAnnEnv (hsc_HPT hsc_env)
    
    353 357
         let
    
    354 358
             other_pkg_anns = eps_ann_env eps
    
    355 359
             !ann_env       = maybe id plusAnnEnv mb_this_module_anns $!
    
    356
    -            plusAnnEnv home_pkg_anns (plusAnnEnv more_home_pkg_anns other_pkg_anns)
    
    360
    +            plusAnnEnv home_pkg_anns other_pkg_anns
    
    357 361
         return ann_env
    
    358 362
     
    
    359 363
     -- | Find the 'TyThing' for the given 'Name' by using all the resources
    

  • compiler/GHC/Driver/Main/Compile.hs
    1 1
     {-# LANGUAGE NondecreasingIndentation #-}
    
    2 2
     {-# LANGUAGE MultiWayIf #-}
    
    3
    +{-# LANGUAGE OverloadedRecordDot #-}
    
    3 4
     
    
    4 5
     {-# OPTIONS_GHC -fprof-auto-top #-}
    
    5 6
     
    
    ... ... @@ -215,7 +216,7 @@ loadIfaceByteCode hsc_env iface location type_env =
    215 216
       where
    
    216 217
         compile decls = do
    
    217 218
           bco <- compileWholeCoreBindings hsc_env type_env decls
    
    218
    -      return $! Linkable (gbc_hash bco) (mi_module iface) (pure (DotGBC bco))
    
    219
    +      return $! Linkable (gbc_hash bco) (decls.wcb_module) (pure (DotGBC bco))
    
    219 220
     
    
    220 221
     loadIfaceByteCodeLazy ::
    
    221 222
       HscEnv ->
    

  • compiler/GHC/Driver/Main/Hsc.hs
    ... ... @@ -85,6 +85,7 @@ import GHC.Types.Error
    85 85
     import GHC.Types.Name.Cache ( newNameCache )
    
    86 86
     
    
    87 87
     import GHC.Utils.Panic
    
    88
    +import qualified GHC.Utils.Outputable as Outputable
    
    88 89
     import GHC.Utils.Logger
    
    89 90
     import GHC.Utils.TmpFs
    
    90 91
     
    
    ... ... @@ -107,7 +108,10 @@ import System.IO
    107 108
     
    
    108 109
     newHscEnv :: FilePath -> DynFlags -> IO HscEnv
    
    109 110
     newHscEnv top_dir dflags = do
    
    110
    -  hpt <- emptyHomePackageTable
    
    111
    +  hpt <- case ghcMode dflags of
    
    112
    +    OneShot -> emptyOnDemandHomePackageTable
    
    113
    +    CompManager -> emptyHomePackageTable
    
    114
    +    MkDepend -> emptyHomePackageTable
    
    111 115
       newHscEnvWithHUG top_dir dflags (homeUnitId_ dflags) (home_unit_graph hpt)
    
    112 116
       where
    
    113 117
         home_unit_graph hpt = HUG.unitEnv_singleton
    
    ... ... @@ -271,8 +275,10 @@ dumpIfaceStats hsc_env = do
    271 275
         logger = hsc_logger hsc_env
    
    272 276
         dump_rn_stats = logHasDumpFlag logger Opt_D_dump_rn_stats
    
    273 277
         dump_if_trace = logHasDumpFlag logger Opt_D_dump_if_trace
    
    274
    -  when (dump_if_trace || dump_rn_stats) $
    
    275
    -    logDumpMsg logger "Interface statistics" (ifaceStats eps)
    
    278
    +  when (dump_if_trace || dump_rn_stats) $ do
    
    279
    +    mb_home_stats <- hptLoadedStats (hsc_HPT hsc_env)
    
    280
    +    logDumpMsg logger "Interface statistics" $
    
    281
    +      ifaceStats eps Outputable.$$ maybe Outputable.empty pprHptStats mb_home_stats
    
    276 282
     
    
    277 283
     
    
    278 284
     
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -100,66 +100,65 @@ import GHC.Builtin.PrimOps.Ids
    100 100
     import GHC.Builtin.WiredIn.Prim
    
    101 101
     import GHC.Builtin.WiredIn.Ids( seqId )
    
    102 102
     
    
    103
    +import GHC.Core (CoreRule)
    
    104
    +import GHC.Core.FamInstEnv
    
    105
    +import GHC.Core.InstEnv
    
    103 106
     import GHC.Core.Rules
    
    104 107
     import GHC.Core.TyCon
    
    105
    -import GHC.Core.InstEnv
    
    106
    -import GHC.Core.FamInstEnv
    
    107 108
     
    
    108
    -import GHC.Parser.Annotation( noLocA, noAnn )
    
    109
    +import GHC.Parser.Annotation (noAnn, noLocA)
    
    109 110
     
    
    110 111
     import GHC.Types.Annotations
    
    112
    +import GHC.Types.Avail
    
    113
    +import GHC.Types.DefaultEnv (DefaultEnv)
    
    114
    +import GHC.Types.Fixity
    
    115
    +import GHC.Types.Fixity.Env
    
    111 116
     import GHC.Types.Id
    
    112 117
     import GHC.Types.Name
    
    113 118
     import GHC.Types.Name.Cache
    
    114 119
     import GHC.Types.Name.Env
    
    115 120
     import GHC.Types.Name.Reader
    
    116
    -import GHC.Types.Avail
    
    117
    -import GHC.Types.Fixity
    
    118
    -import GHC.Types.Fixity.Env
    
    121
    +import GHC.Types.PkgQual
    
    122
    +import GHC.Types.SafeHaskell
    
    119 123
     import GHC.Types.SourceError
    
    120 124
     import GHC.Types.SourceFile
    
    121
    -import GHC.Types.SafeHaskell
    
    122
    -import GHC.Types.TypeEnv
    
    123
    -import GHC.Types.Unique.DSet
    
    124
    -import GHC.Types.Unique.Map( listToUniqMap )
    
    125
    -import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM, elemUFM )
    
    125
    +import GHC.Types.SourceText
    
    126 126
     import GHC.Types.SrcLoc
    
    127 127
     import GHC.Types.TyThing
    
    128
    -import GHC.Types.PkgQual
    
    129
    -import GHC.Types.SourceText
    
    128
    +import GHC.Types.TypeEnv
    
    129
    +import GHC.Types.Unique.DSet
    
    130
    +import GHC.Types.Unique.FM (UniqFM, elemUFM, listToUFM, lookupUFM)
    
    131
    +import GHC.Types.Unique.Map (listToUniqMap)
    
    130 132
     
    
    133
    +import GHC.Unit.Env
    
    131 134
     import GHC.Unit.External
    
    135
    +import GHC.Unit.Finder
    
    136
    +import GHC.Unit.Home
    
    137
    +import GHC.Unit.Home.Graph qualified as HUG
    
    138
    +import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable)
    
    139
    +import GHC.Unit.Home.PackageTable
    
    140
    +import GHC.Unit.Home.PackageTable qualified as HomePackageTable
    
    132 141
     import GHC.Unit.Module
    
    142
    +import GHC.Unit.Module.Deps
    
    133 143
     import GHC.Unit.Module.Graph
    
    134
    -import GHC.Unit.Module.Warnings
    
    144
    +import GHC.Unit.Module.ModDetails (ModDetails (..))
    
    135 145
     import GHC.Unit.Module.ModIface
    
    136
    -import GHC.Unit.Module.Deps
    
    146
    +import GHC.Unit.Module.Warnings
    
    137 147
     import GHC.Unit.State
    
    138
    -import GHC.Unit.Home
    
    139
    -import qualified GHC.Unit.Home.Graph as HUG
    
    140
    -import GHC.Unit.Home.PackageTable
    
    141
    -import GHC.Unit.Finder
    
    142
    -import GHC.Unit.Env
    
    143 148
     
    
    144 149
     import GHC.Stack( callStack )
    
    145 150
     import GHC.Data.Maybe
    
    146 151
     
    
    147 152
     import Language.Haskell.Syntax.Lit (StringLiteral(..))
    
    148 153
     
    
    154
    +import Control.Applicative ((<|>))
    
    149 155
     import Control.Monad
    
    150
    -import qualified Data.Foldable as Foldable
    
    156
    +import Data.Foldable qualified as Foldable
    
    151 157
     import Data.Function ((&))
    
    152
    -import Data.Map ( toList )
    
    153
    -import qualified Data.Set as Set
    
    154
    -import System.FilePath
    
    158
    +import Data.Map (toList)
    
    159
    +import Data.Set qualified as Set
    
    155 160
     import System.Directory
    
    156
    -import GHC.Types.DefaultEnv (DefaultEnv)
    
    157
    -import GHC.Core (CoreRule)
    
    158
    -import GHC.Unit.Module.ModDetails (ModDetails(..))
    
    159
    -import GHC.Unit.Home.ModInfo (HomeModInfo(..), emptyHomeModInfoLinkable)
    
    160
    -import qualified Data.Set as Set
    
    161
    -import qualified GHC.Unit.Home.PackageTable as HomePackageTable
    
    162
    -import Control.Applicative ((<|>))
    
    161
    +import System.FilePath
    
    163 162
     
    
    164 163
     
    
    165 164
     {- *********************************************************************
    
    ... ... @@ -522,8 +521,8 @@ importDecl name
    522 521
     
    
    523 522
             -- Now look it up again; this time we should find it
    
    524 523
             { eps <- getEps -- @fendor: DONE
    
    525
    -        ; loaderTypeEnv <- queryHpt HomePackageTable.hptLoadedTypeEnv
    
    526
    -        ; case lookupTypeEnv loaderTypeEnv name <|> lookupTypeEnv (eps_PTE eps) name of
    
    524
    +        ; mb_home_thing <- queryHpt (`HomePackageTable.hptLookupLoadedType` name)
    
    525
    +        ; case mb_home_thing <|> lookupTypeEnv (eps_PTE eps) name of
    
    527 526
                 Just thing -> return $ Succeeded thing
    
    528 527
                 Nothing    -> return $ Failed $
    
    529 528
                   Can'tFindNameInInterface name
    
    ... ... @@ -799,8 +798,8 @@ loadInterface doc_str mod from
    799 798
     
    
    800 799
             -- READ THE MODULE IN
    
    801 800
             ; hpt <- getHpt
    
    802
    -        ; hls <- liftIO (hptLoaderState hpt)
    
    803
    -        ; read_result <- case wantHiBootFile mhome_unit hls mod from of
    
    801
    +        ; is_boot_map <- liftIO (hptLoadedIsBoot hpt)
    
    802
    +        ; read_result <- case wantHiBootFile mhome_unit is_boot_map mod from of
    
    804 803
                                Failed err             -> return (Failed err)
    
    805 804
                                Succeeded hi_boot_file -> do
    
    806 805
                                  hsc_env <- getTopEnv
    
    ... ... @@ -834,7 +833,7 @@ loadInterface doc_str mod from
    834 833
             ; if fromMaybe False $ fmap (`isHomeModule` mod) mhome_unit -- TODO @fendor: horrible code
    
    835 834
                 then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here
    
    836 835
                   massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
    
    837
    -                      (text "Attempting to non-home package interface into the Home Loader State" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
    
    836
    +                      (text "Attempting to load non-home package interface into the Home Loader State" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
    
    838 837
                   tcParts <- tcPartsOfTheIface mod iface
    
    839 838
                   addModIfacePartsToHpt gbl_env mod loc iface tcParts
    
    840 839
                 else dontLeakTheHUG $ do
    
    ... ... @@ -858,7 +857,7 @@ loadInterface doc_str mod from
    858 857
                         (moduleUnitId mod `Set.notMember` hsc_all_home_unit_ids hsc_env)
    
    859 858
                           (text "Attempting to load home package interface into the EPS" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
    
    860 859
                   tcParts <- tcPartsOfTheIface mod iface
    
    861
    -              addModIfacePartsToEps gbl_env mod loc iface tcParts
    
    860
    +              addModIfacePartsToEps mod iface tcParts
    
    862 861
     
    
    863 862
             ; -- invoke plugins with *full* interface, not final_iface, to ensure
    
    864 863
               -- that plugins have access to declarations, etc.
    
    ... ... @@ -868,37 +867,37 @@ loadInterface doc_str mod from
    868 867
     
    
    869 868
     tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches)
    
    870 869
     tcPartsOfTheIface mod iface = do
    
    871
    -  ignore_prags      <- goptM Opt_IgnoreInterfacePragmas
    
    872
    -  new_eps_decls     <- tcIfaceDecls ignore_prags (mi_decls iface)
    
    873
    -  new_eps_insts     <- mapM tcIfaceInst (mi_insts iface)
    
    874
    -  new_eps_defaults  <- tcIfaceDefaults mod (mi_defaults iface)
    
    875
    -  new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
    
    876
    -  new_eps_rules     <- tcIfaceRules ignore_prags (mi_rules iface)
    
    877
    -  new_eps_anns      <- tcIfaceAnnotations (mi_anns iface)
    
    878
    -  new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
    
    870
    +  ignore_prags  <- goptM Opt_IgnoreInterfacePragmas
    
    871
    +  new_decls     <- tcIfaceDecls ignore_prags (mi_decls iface)
    
    872
    +  new_insts     <- mapM tcIfaceInst (mi_insts iface)
    
    873
    +  new_defaults  <- tcIfaceDefaults mod (mi_defaults iface)
    
    874
    +  new_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
    
    875
    +  new_rules     <- tcIfaceRules ignore_prags (mi_rules iface)
    
    876
    +  new_anns      <- tcIfaceAnnotations (mi_anns iface)
    
    877
    +  new_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
    
    879 878
       pure
    
    880
    -    ( new_eps_decls
    
    881
    -    , new_eps_insts
    
    882
    -    , new_eps_defaults
    
    883
    -    , new_eps_fam_insts
    
    884
    -    , new_eps_rules
    
    885
    -    , new_eps_anns
    
    886
    -    , new_eps_complete_matches
    
    879
    +    ( new_decls
    
    880
    +    , new_insts
    
    881
    +    , new_defaults
    
    882
    +    , new_fam_insts
    
    883
    +    , new_rules
    
    884
    +    , new_anns
    
    885
    +    , new_complete_matches
    
    887 886
         )
    
    888 887
     
    
    889 888
     addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule],  [Annotation], [CompleteMatch]) -> IfL ()
    
    890
    -addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
    
    889
    +addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
    
    891 890
       hsc_env <- getTopEnv
    
    892 891
       let
    
    893 892
         details = ModDetails
    
    894
    -      { md_types            = mkNameEnv new_eps_decls
    
    893
    +      { md_types            = mkNameEnv new_decls
    
    895 894
           , md_exports          = mi_exports iface
    
    896
    -      , md_defaults         = new_eps_defaults
    
    897
    -      , md_insts            = mkInstEnv new_eps_insts
    
    898
    -      , md_fam_insts        = new_eps_fam_insts
    
    899
    -      , md_rules            = new_eps_rules
    
    900
    -      , md_anns             = new_eps_anns
    
    901
    -      , md_complete_matches = new_eps_complete_matches
    
    895
    +      , md_defaults         = new_defaults
    
    896
    +      , md_insts            = mkInstEnv new_insts
    
    897
    +      , md_fam_insts        = new_fam_insts
    
    898
    +      , md_rules            = new_rules
    
    899
    +      , md_anns             = new_anns
    
    900
    +      , md_complete_matches = new_complete_matches
    
    902 901
           }
    
    903 902
     
    
    904 903
         bad_boot = mi_boot iface == IsBoot
    
    ... ... @@ -907,87 +906,70 @@ addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e
    907 906
                         -- of one's own boot file! (one-shot only)
    
    908 907
                         -- See Note [Loading your own hi-boot file]
    
    909 908
     
    
    909
    +    mb_bytecode = loadIfaceByteCode hsc_env iface loc (md_types details)
    
    910
    +
    
    911
    +    final_iface = stripLoadedIface "home package table" iface
    
    912
    +
    
    910 913
       warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
    
    911 914
         hpt <- getHpt
    
    912
    -    -- Create an IO action that loads and compiles bytecode from Core
    
    913
    -    -- bindings.
    
    914
    -    --
    
    915
    -    -- See Note [Interface Files with Core Definitions]
    
    916
    -    let lazy_bytecode = loadIfaceByteCode hsc_env iface loc (mkNameEnv new_eps_decls)
    
    917
    -    liftIO $ addHomeModInfoToHpt (HomeModInfo iface details emptyHomeModInfoLinkable) hpt
    
    918
    -    liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) lazy_bytecode
    
    919
    -
    
    920
    -addModIfacePartsToEps :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule],  [Annotation], [CompleteMatch]) -> IfL ()
    
    921
    -addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
    
    915
    +    liftIO $ if bad_boot
    
    916
    +      then hptAddOwnBootTypes hpt new_decls
    
    917
    +      else addOnDemandHomeModule hpt (HomeModInfo final_iface details emptyHomeModInfoLinkable) mb_bytecode
    
    918
    +
    
    919
    +addModIfacePartsToEps :: Module -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule],  [Annotation], [CompleteMatch]) -> IfL ()
    
    920
    +addModIfacePartsToEps mod iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
    
    922 921
       purged_hsc_env <- getTopEnv
    
    923 922
     
    
    924 923
       let
    
    925
    -    final_iface = iface
    
    926
    -      & set_mi_decls     (panic "No mi_decls in PIT")
    
    927
    -      & set_mi_insts     (panic "No mi_insts in PIT")
    
    928
    -      & set_mi_defaults  (panic "No mi_defaults in PIT")
    
    929
    -      & set_mi_fam_insts (panic "No mi_fam_insts in PIT")
    
    930
    -      & set_mi_rules     (panic "No mi_rules in PIT")
    
    931
    -      & set_mi_anns      (panic "No mi_anns in PIT")
    
    932
    -      & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
    
    933
    -
    
    934
    -    bad_boot = mi_boot iface == IsBoot
    
    935
    -                && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
    
    936
    -                  -- Warn against an EPS-updating import
    
    937
    -                  -- of one's own boot file! (one-shot only)
    
    938
    -                  -- See Note [Loading your own hi-boot file]
    
    939
    -
    
    940
    -    -- Create an IO action that loads and compiles bytecode from Core
    
    941
    -    -- bindings.
    
    942
    -    --
    
    943
    -    -- See Note [Interface Files with Core Definitions]
    
    944
    -    add_bytecode old
    
    945
    -      | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
    
    946
    -      = extendModuleEnv old mod action
    
    947
    -      -- Don't add an entry if the iface doesn't have 'extra_decls'
    
    948
    -      -- so 'get_link_deps' knows that it should load object code.
    
    949
    -      | otherwise
    
    950
    -      = old
    
    924
    +    final_iface = stripLoadedIface "PIT" iface
    
    951 925
     
    
    952 926
         mhome_unit = ue_homeUnit (hsc_unit_env purged_hsc_env)
    
    953
    -  warnPprTrace bad_boot "loadInterface" (ppr mod) $
    
    954
    -    updateEps_  $ \ eps ->
    
    955
    -      if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
    
    956
    -          then eps
    
    957
    -      else if bad_boot
    
    958
    -          -- See Note [Loading your own hi-boot file]
    
    959
    -          then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
    
    960
    -      else
    
    961
    -          eps {
    
    962
    -            eps_PIT          = extendModuleEnv (eps_PIT eps) mod final_iface,
    
    963
    -            eps_PTE          = addDeclsToPTE   (eps_PTE eps) new_eps_decls,
    
    964
    -            eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
    
    965
    -            eps_rule_base    = extendRuleBaseList (eps_rule_base eps)
    
    966
    -                                                  new_eps_rules,
    
    967
    -            eps_complete_matches
    
    968
    -                              = eps_complete_matches eps ++ new_eps_complete_matches,
    
    969
    -            eps_inst_env     = extendInstEnvList (eps_inst_env eps)
    
    970
    -                                                  new_eps_insts,
    
    971
    -            eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
    
    972
    -                                                    new_eps_fam_insts,
    
    973
    -            eps_ann_env      = extendAnnEnvList (eps_ann_env eps)
    
    974
    -                                                new_eps_anns,
    
    975
    -            eps_mod_fam_inst_env
    
    976
    -                              = let
    
    977
    -                                  fam_inst_env =
    
    978
    -                                    extendFamInstEnvList emptyFamInstEnv
    
    979
    -                                                        new_eps_fam_insts
    
    980
    -                                in
    
    981
    -                                extendModuleEnv (eps_mod_fam_inst_env eps)
    
    982
    -                                                mod
    
    983
    -                                                fam_inst_env,
    
    984
    -            eps_stats        = addEpsInStats (eps_stats eps)
    
    985
    -                                              (length new_eps_decls)
    
    986
    -                                              (length new_eps_insts)
    
    987
    -                                              (length new_eps_rules),
    
    988
    -            eps_defaults    =  extendModuleEnv (eps_defaults eps) mod new_eps_defaults
    
    989
    -                                              }
    
    990
    -
    
    927
    +  updateEps_  $ \ eps ->
    
    928
    +    if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
    
    929
    +        then eps
    
    930
    +    else
    
    931
    +        eps {
    
    932
    +          eps_PIT          = extendModuleEnv (eps_PIT eps) mod final_iface,
    
    933
    +          eps_PTE          = addDeclsToPTE   (eps_PTE eps) new_decls,
    
    934
    +          eps_rule_base    = extendRuleBaseList (eps_rule_base eps)
    
    935
    +                                                new_rules,
    
    936
    +          eps_complete_matches
    
    937
    +                            = eps_complete_matches eps ++ new_complete_matches,
    
    938
    +          eps_inst_env     = extendInstEnvList (eps_inst_env eps)
    
    939
    +                                                new_insts,
    
    940
    +          eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
    
    941
    +                                                  new_fam_insts,
    
    942
    +          eps_ann_env      = extendAnnEnvList (eps_ann_env eps)
    
    943
    +                                              new_anns,
    
    944
    +          eps_mod_fam_inst_env
    
    945
    +                            = let
    
    946
    +                                fam_inst_env =
    
    947
    +                                  extendFamInstEnvList emptyFamInstEnv
    
    948
    +                                                      new_fam_insts
    
    949
    +                              in
    
    950
    +                              extendModuleEnv (eps_mod_fam_inst_env eps)
    
    951
    +                                              mod
    
    952
    +                                              fam_inst_env,
    
    953
    +          eps_stats        = addEpsInStats (eps_stats eps)
    
    954
    +                                            (length new_decls)
    
    955
    +                                            (length new_insts)
    
    956
    +                                            (length new_rules),
    
    957
    +          eps_defaults    =  extendModuleEnv (eps_defaults eps) mod new_defaults
    
    958
    +                                            }
    
    959
    +
    
    960
    +
    
    961
    +stripLoadedIface :: String -> ModIface -> ModIface
    
    962
    +stripLoadedIface table iface = iface
    
    963
    +  & set_mi_decls     (gone "mi_decls")
    
    964
    +  & set_mi_insts     (gone "mi_insts")
    
    965
    +  & set_mi_defaults  (gone "mi_defaults")
    
    966
    +  & set_mi_fam_insts (gone "mi_fam_insts")
    
    967
    +  & set_mi_rules     (gone "mi_rules")
    
    968
    +  & set_mi_anns      (gone "mi_anns")
    
    969
    +  & set_mi_simplified_core (gone "mi_simplified_core")
    
    970
    +  where
    
    971
    +    gone :: String -> a
    
    972
    +    gone field = panic ("No " ++ field ++ " in " ++ table)
    
    991 973
     
    
    992 974
     {- Note [Loading your own hi-boot file]
    
    993 975
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -1204,10 +1186,10 @@ moduleFreeHolesPrecise doc_str mod
    1204 1186
                     return (Succeeded (renameFreeHoles ifhs insts))
    
    1205 1187
                 Failed err -> return (Failed err)
    
    1206 1188
     
    
    1207
    -wantHiBootFile :: Maybe HomeUnit -> HomeLoaderState -> Module -> WhereFrom
    
    1189
    +wantHiBootFile :: Maybe HomeUnit -> InstalledModuleEnv ModuleNameWithIsBoot -> Module -> WhereFrom
    
    1208 1190
                    -> MaybeErr MissingInterfaceError IsBootInterface
    
    1209 1191
     -- Figure out whether we want Foo.hi or Foo.hi-boot
    
    1210
    -wantHiBootFile mhome_unit hls mod from
    
    1192
    +wantHiBootFile mhome_unit is_boot_map mod from
    
    1211 1193
       = case from of
    
    1212 1194
            ImportByUser usr_boot
    
    1213 1195
               | usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
    
    ... ... @@ -1226,9 +1208,9 @@ wantHiBootFile mhome_unit hls mod from
    1226 1208
                  -- We never import boot modules from other packages!
    
    1227 1209
     
    
    1228 1210
               | otherwise
    
    1229
    -          -> case hlsIsBoot hls (toUnitId <$> mod) of
    
    1230
    -                Just is_boot ->
    
    1231
    -                  Succeeded is_boot
    
    1211
    +          -> case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
    
    1212
    +                Just mnib ->
    
    1213
    +                  Succeeded $ gwib_isBoot mnib
    
    1232 1214
                     Nothing ->
    
    1233 1215
                       Succeeded NotBoot
    
    1234 1216
                          -- The boot-ness of the requested interface,
    

  • compiler/GHC/Iface/Recomp.hs
    ... ... @@ -427,10 +427,9 @@ checkVersions hsc_env mod_summary iface self_recomp
    427 427
            -- (in which case we are done with this module) or it'll fail (in which
    
    428 428
            -- case we'll compile the module from scratch anyhow).
    
    429 429
     
    
    430
    -       when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
    
    431
    -          ; hpt <- getHpt
    
    432
    -          ; liftIO $ hlsSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
    
    433
    -       }
    
    430
    +       ; hpt <- getHpt
    
    431
    +       ; liftIO $ hptSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
    
    432
    +
    
    434 433
            ; recomp <- checkList [checkModUsage (hsc_FC hsc_env) u
    
    435 434
                                  | u <- mi_sr_usages self_recomp]
    
    436 435
            ; case recomp of (NeedsRecompile reason) -> return $ OutOfDateItem reason (Just iface) ; _ -> do {
    

  • compiler/GHC/IfaceToCore.hs
    ... ... @@ -138,6 +138,8 @@ import Language.Haskell.Syntax.BooleanFormula qualified as BF(BooleanFormula(..)
    138 138
     import Language.Haskell.Syntax.Extension (NoExtField (NoExtField))
    
    139 139
     import GHC.Builtin.KnownKeys (ioTyConKey)
    
    140 140
     import GHC.Unit.Home.PackageTable
    
    141
    +import GHC.Unit.Home (isHomeModule)
    
    142
    +import GHC.Driver.Env (hsc_HPT, hsc_home_unit_maybe)
    
    141 143
     
    
    142 144
     {-
    
    143 145
     This module takes
    
    ... ... @@ -633,12 +635,12 @@ tcHiBootIface hsc_src mod
    633 635
             -- a SOURCE import) or that our hi-boot file has mysteriously
    
    634 636
             -- disappeared.
    
    635 637
         do  { hpt <- getHpt
    
    636
    -        ; hls <- liftIO $ hptLoaderState hpt
    
    637
    -        ; case hlsIsBoot hls (toUnitId <$> mod) of
    
    638
    +        ; is_boot_map <- liftIO $ hptLoadedIsBoot hpt
    
    639
    +        ; case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
    
    638 640
                 -- The typical case
    
    639 641
                 Nothing -> return NoSelfBoot
    
    640 642
                 -- error cases
    
    641
    -            Just is_boot -> case is_boot of
    
    643
    +            Just mnib -> case gwib_isBoot mnib of
    
    642 644
                   IsBoot ->
    
    643 645
                     let diag = Can'tFindInterface err
    
    644 646
                                  (LookingForHiBoot mod)
    
    ... ... @@ -1103,8 +1105,19 @@ tc_iface_decl_fingerprint ignore_prags (_version, decl)
    1103 1105
     bumpDeclStats :: Name -> IfL ()         -- Record that one more declaration has actually been used
    
    1104 1106
     bumpDeclStats name
    
    1105 1107
       = do  { traceIf (text "Loading decl for" <+> ppr name)
    
    1106
    -        ; updateEps_ (\eps -> let stats = eps_stats eps
    
    1107
    -                              in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
    
    1108
    +        ; hsc_env <- getTopEnv
    
    1109
    +        ; let hpt = hsc_HPT hsc_env
    
    1110
    +              is_on_demand_home_decl
    
    1111
    +                | isOneShotMode hpt
    
    1112
    +                , Just home_unit <- hsc_home_unit_maybe hsc_env
    
    1113
    +                , Just mod <- nameModule_maybe name
    
    1114
    +                = isHomeModule home_unit mod
    
    1115
    +                | otherwise
    
    1116
    +                = False
    
    1117
    +        ; if is_on_demand_home_decl
    
    1118
    +            then liftIO $ hptBumpDeclsOut hpt
    
    1119
    +            else updateEps_ (\eps -> let stats = eps_stats eps
    
    1120
    +                                     in eps { eps_stats = stats { n_decls_out = n_decls_out stats + 1 } })
    
    1108 1121
             }
    
    1109 1122
     
    
    1110 1123
     tc_fd :: FunDep IfLclName -> IfL (FunDep TyVar)
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -90,7 +90,7 @@ import GHC.Utils.TmpFs
    90 90
     
    
    91 91
     import GHC.Unit.Env
    
    92 92
     import GHC.Unit.Home.ModInfo
    
    93
    -import GHC.Unit.External (ExternalPackageState (..))
    
    93
    +import GHC.Unit.Home.PackageTable (hptLoadedByteCode)
    
    94 94
     import GHC.Unit.Module
    
    95 95
     import GHC.Unit.Module.ModNodeKey
    
    96 96
     import GHC.Unit.Module.Graph
    
    ... ... @@ -666,8 +666,8 @@ findWholeCoreBindings hsc_env mod = do
    666 666
           _ <- initIfaceLoad hsc_env $
    
    667 667
                  loadInterface (text "get_reachable_nodes" <+> parens (ppr mod))
    
    668 668
                      mod ImportBySystem
    
    669
    -      EPS {eps_iface_bytecode} <- hscEPS hsc_env
    
    670
    -      sequence (lookupModuleEnv eps_iface_bytecode mod)
    
    669
    +      mb_action <- hptLoadedByteCode (hsc_HPT hsc_env) mod
    
    670
    +      sequence mb_action
    
    671 671
     
    
    672 672
     
    
    673 673
     findBytecodeLinkableMaybe :: HscEnv -> ModLocation -> IO (Maybe Linkable)
    

  • compiler/GHC/Tc/Instance/Family.hs
    ... ... @@ -409,9 +409,9 @@ getFamInsts hpt_fam_insts mod
    409 409
       | Just env <- lookupModuleEnv hpt_fam_insts mod = return env
    
    410 410
       | otherwise = do { _ <- initIfaceTcRn (loadSysInterface doc mod)
    
    411 411
                        ; eps <- getEps
    
    412
    -                   ; hpt_extra_mod_fam_insts <- queryHpt HomePackageTable.hptLoadedModFamInstEnv
    
    412
    +                   ; mb_home_fam_insts <- queryHpt (`HomePackageTable.hptLoadedModFamInsts` mod)
    
    413 413
                        ; return (expectJust $
    
    414
    -                             lookupModuleEnv hpt_extra_mod_fam_insts mod <|> lookupModuleEnv (eps_mod_fam_inst_env eps) mod) }
    
    414
    +                             mb_home_fam_insts <|> lookupModuleEnv (eps_mod_fam_inst_env eps) mod) }
    
    415 415
       where
    
    416 416
         doc = ppr mod <+> text "is a family-instance module"
    
    417 417
     
    
    ... ... @@ -619,7 +619,7 @@ addLocalFamInst (home_fie, my_fis) fam_inst
    619 619
                -- we've ever seen. Fixing this is part of #13102.
    
    620 620
            ; eps <- getEps
    
    621 621
            ; extra <- queryHpt HomePackageTable.hptLoadedFamInstEnv
    
    622
    -       ; let inst_envs = (eps_fam_inst_env eps `unionFamInstEnv` extra, home_fie)
    
    622
    +       ; let inst_envs = (eps_fam_inst_env eps, home_fie `unionFamInstEnv` extra)
    
    623 623
                  home_fie' = extendFamInstEnv home_fie fam_inst
    
    624 624
     
    
    625 625
                -- Check for conflicting instance decls and injectivity violations
    

  • compiler/GHC/Tc/Module.hs
    ... ... @@ -191,7 +191,7 @@ import qualified Data.Map as M
    191 191
     import Data.Foldable ( for_ )
    
    192 192
     import Data.Traversable ( for )
    
    193 193
     import Data.IORef( newIORef )
    
    194
    -import GHC.Unit.Home.PackageTable (hlsSetBootInfo)
    
    194
    +import GHC.Unit.Home.PackageTable (hptSetBootInfo, isOneShotMode)
    
    195 195
     
    
    196 196
     {-
    
    197 197
     ************************************************************************
    
    ... ... @@ -501,21 +501,19 @@ tcRnImports hsc_env import_decls
    501 501
               -- modules batch (@--make@) compiled before this one, but
    
    502 502
               -- which are not below this one.
    
    503 503
             ; (home_insts, home_fam_insts) <- liftIO $
    
    504
    -              hugInstancesBelow hsc_env unitId mnwib
    
    504
    +              hugInstancesBelow (hsc_unit_env hsc_env) unitId mnwib
    
    505 505
     
    
    506 506
               -- We use 'unsafeInterleaveIO' to avoid redundant memory allocations
    
    507 507
               -- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad
    
    508 508
               -- and see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14274#note_620545
    
    509 509
             ; completeSigsBelow <- liftIO $ unsafeInterleaveIO $
    
    510
    -              hugCompleteSigsBelow hsc_env unitId mnwib
    
    510
    +              hugCompleteSigsBelow (hsc_unit_env hsc_env) unitId mnwib
    
    511 511
     
    
    512
    -          -- Record boot-file info in the EPS, so that it's
    
    512
    +          -- Record boot-file info in the HPT, so that it's
    
    513 513
               -- visible to loadHiBootInterface in tcRnSrcDecls,
    
    514 514
               -- and any other incrementally-performed imports
    
    515
    -        ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
    
    516
    -            ; hpt <- getHpt
    
    517
    -            ; liftIO $ hlsSetBootInfo hpt (imp_boot_mods imports)
    
    518
    -         }
    
    515
    +        ; hpt <- getHpt
    
    516
    +        ; liftIO $ hptSetBootInfo hpt (imp_boot_mods imports)
    
    519 517
     
    
    520 518
                     -- Update the gbl env
    
    521 519
             ; updGblEnv ( \ gbl ->
    
    ... ... @@ -2177,7 +2175,10 @@ runTcInteractive tcm_plugin_handling hsc_env thing_inside
    2177 2175
                                              (renameRawPkgQual (hsc_unit_env hsc_env) (hsModuleName $ unLoc $ ideclName i) (ideclPkgQual i))
    
    2178 2176
     
    
    2179 2177
     
    
    2180
    -       ; (home_insts, home_fam_insts) <- liftIO $ UnitEnv.hugAllInstances (hsc_unit_env hsc_env)
    
    2178
    +       ; (home_insts, home_fam_insts) <-
    
    2179
    +           if isOneShotMode (hsc_HPT hsc_env)
    
    2180
    +             then pure (emptyInstEnv, [])
    
    2181
    +             else liftIO $ UnitEnv.hugAllInstances (hsc_unit_env hsc_env)
    
    2181 2182
     
    
    2182 2183
            ; let imports = emptyImportAvails { imp_orphs = orphs }
    
    2183 2184
     
    

  • compiler/GHC/Tc/Utils/Env.hs
    ... ... @@ -386,8 +386,7 @@ tcGetClsDefaults :: [Module] -> TcM [DefaultEnv]
    386 386
     tcGetClsDefaults mods = do
    
    387 387
       hug <- hsc_HUG <$> getTopEnv
    
    388 388
       module_env_defaults <- eps_defaults <$> getEps
    
    389
    -  more_env_defaults <- queryHpt HomePackageTable.hptLoadedDefaults
    
    390
    -  liftIO $ mapMaybeM (lookupClsDefault hug (module_env_defaults `plusModuleEnv` more_env_defaults)) mods
    
    389
    +  liftIO $ mapMaybeM (lookupClsDefault hug module_env_defaults) mods
    
    391 390
     
    
    392 391
     lookupClsDefault :: HomeUnitGraph -> ModuleEnv DefaultEnv -> Module -> IO (Maybe DefaultEnv)
    
    393 392
     lookupClsDefault hug module_env_defaults mod =
    

  • compiler/GHC/Tc/Utils/Instantiate.hs
    ... ... @@ -947,13 +947,6 @@ addLocalInst (home_ie, my_insts) ispec
    947 947
              ; let (_tvs, cls, tys) = instanceHead ispec
    
    948 948
                    (matches, _, _)  = lookupInstEnv False inst_envs cls tys
    
    949 949
                    dups             = filter (identicalClsInstHead ispec) (map fst matches)
    
    950
    -         ; traceRn "addLocalInst 0" (ppr ispec)
    
    951
    -         ; traceRn "addLocalInst 1" (ppr home_ie)
    
    952
    -         ; traceRn "addLocalInst 2" (ppr my_insts)
    
    953
    -         ; traceRn "addLocalInst 3" (ppr matches)
    
    954
    -         ; traceRn "addLocalInst 4" (ppr dups)
    
    955
    -         ; traceRn "addLocalInst 5" (ppr global_ie)
    
    956
    -         ; traceRn "addLocalInst 6" (ppr extra_inst_env)
    
    957 950
              ; unless (null dups) $
    
    958 951
                dupInstErr ispec (head dups)
    
    959 952
     
    

  • compiler/GHC/Unit/Env.hs
    ... ... @@ -52,6 +52,7 @@ module GHC.Unit.Env
    52 52
         , ue_unitHomeUnit
    
    53 53
         , ue_unitHomeUnit_maybe
    
    54 54
         , ue_updateHomeUnitEnv
    
    55
    +    , ue_adjustHomeUnitEnvA
    
    55 56
         , ue_all_home_unit_ids
    
    56 57
         , ue_unsafeHomeUnit
    
    57 58
     
    
    ... ... @@ -360,6 +361,13 @@ ue_updateHomeUnitEnv f uid e = e
    360 361
       { ue_home_unit_graph = HUG.unitEnv_adjust f uid $ ue_home_unit_graph e
    
    361 362
       }
    
    362 363
     
    
    364
    +ue_adjustHomeUnitEnvA :: Applicative f => (HomeUnitEnv -> f HomeUnitEnv) -> UnitId -> UnitEnv -> f UnitEnv
    
    365
    +ue_adjustHomeUnitEnvA f uid e =
    
    366
    +  let
    
    367
    +    hugA = HUG.unitEnv_adjustA f uid $ ue_home_unit_graph e
    
    368
    +  in
    
    369
    +    (\ hug -> e { ue_home_unit_graph = hug }) <$> hugA
    
    370
    +
    
    363 371
     ue_all_home_unit_ids :: UnitEnv -> Set.Set UnitId
    
    364 372
     ue_all_home_unit_ids = HUG.allUnits . ue_home_unit_graph
    
    365 373
     
    

  • compiler/GHC/Unit/External.hs
    ... ... @@ -36,8 +36,6 @@ import GHC.Types.Unique.DSet
    36 36
     
    
    37 37
     import GHC.Utils.Fingerprint ( Fingerprint )
    
    38 38
     
    
    39
    -import GHC.Linker.Types (Linkable)
    
    40
    -
    
    41 39
     import Data.IORef
    
    42 40
     
    
    43 41
     
    
    ... ... @@ -74,7 +72,6 @@ initExternalPackageState = EPS
    74 72
       { eps_PIT              = emptyPackageIfaceTable
    
    75 73
       , eps_free_holes       = emptyInstalledModuleEnv
    
    76 74
       , eps_PTE              = emptyTypeEnv
    
    77
    -  , eps_iface_bytecode   = emptyModuleEnv
    
    78 75
       , eps_inst_env         = emptyInstEnv
    
    79 76
       , eps_fam_inst_env     = emptyFamInstEnv
    
    80 77
       , eps_rule_base        = mkRuleBase builtinRules
    
    ... ... @@ -135,12 +132,6 @@ data ExternalPackageState
    135 132
                     -- interface files we have sucked in. The domain of
    
    136 133
                     -- the mapping is external-package modules
    
    137 134
     
    
    138
    -        -- | If an interface was written with @-fwrite-if-simplified-core@, this
    
    139
    -        -- will contain an IO action that compiles bytecode from core bindings.
    
    140
    -        --
    
    141
    -        -- See Note [Interface Files with Core Definitions]
    
    142
    -        eps_iface_bytecode :: !(ModuleEnv (IO Linkable)),
    
    143
    -
    
    144 135
             eps_known_keys   :: ModuleEnv (Fingerprint, KnownKeyNameMaps),
    
    145 136
               -- ^ Cache of the known-entity maps of all loaded 'GHC.Essentials'
    
    146 137
               -- modules, keyed by module and the corresponding interface ABI hash.
    

  • compiler/GHC/Unit/Home/Graph.hs
    ... ... @@ -61,6 +61,8 @@ module GHC.Unit.Home.Graph
    61 61
       , unitEnv_foldWithKey
    
    62 62
       , unitEnv_singleton
    
    63 63
       , unitEnv_adjust
    
    64
    +  , unitEnv_adjustA
    
    65
    +  , unitEnv_alterF
    
    64 66
       , unitEnv_keys
    
    65 67
       , unitEnv_insert
    
    66 68
       , unitEnv_new
    
    ... ... @@ -320,6 +322,17 @@ unitEnv_adjust f uid unitEnv = unitEnv
    320 322
       { unitEnv_graph = Map.adjust f uid (unitEnv_graph unitEnv)
    
    321 323
       }
    
    322 324
     
    
    325
    +unitEnv_adjustA :: Applicative f => (v -> f v) -> UnitEnvGraphKey -> UnitEnvGraph v -> f (UnitEnvGraph v)
    
    326
    +unitEnv_adjustA f uid unitEnv =
    
    327
    +  unitEnv_alterF go uid unitEnv
    
    328
    +  where
    
    329
    +    go Nothing = pure Nothing
    
    330
    +    go (Just v) = Just <$> f v
    
    331
    +
    
    332
    +unitEnv_alterF :: Functor f => (Maybe v -> f (Maybe v)) -> UnitEnvGraphKey -> UnitEnvGraph v -> f (UnitEnvGraph v)
    
    333
    +unitEnv_alterF f uid unitEnv =
    
    334
    +  UnitEnvGraph <$> Map.alterF f uid (unitEnv_graph unitEnv)
    
    335
    +
    
    323 336
     unitEnv_singleton :: UnitEnvGraphKey -> v -> UnitEnvGraph v
    
    324 337
     unitEnv_singleton active m = UnitEnvGraph
    
    325 338
       { unitEnv_graph = Map.singleton active m
    

  • compiler/GHC/Unit/Home/PackageTable.hs
    ... ... @@ -21,13 +21,18 @@
    21 21
     -- Or, do you really need a function to traverse all modules in the HPT? It is
    
    22 22
     -- often better to keep the computation internal to this module, such as in
    
    23 23
     -- 'hptCollectObjects'...
    
    24
    +{-# OPTIONS_GHC -Wall -Wincomplete-record-selectors #-}
    
    24 25
     module GHC.Unit.Home.PackageTable
    
    25 26
       (
    
    26
    -    HomePackageTable(..)
    
    27
    +    HomePackageTable
    
    27 28
       , emptyHomePackageTable
    
    29
    +  , emptyOnDemandHomePackageTable
    
    28 30
     
    
    29
    -  , HomeLoaderState -- TODO: should this be opaque? Probably
    
    30
    -  , emptyHomeLoaderState
    
    31
    +  , isOneShotMode
    
    32
    +  , isHptEmpty
    
    33
    +
    
    34
    +  -- , HomeLoaderState -- TODO: should this be opaque? Probably
    
    35
    +  -- , emptyHomeLoaderState
    
    31 36
     
    
    32 37
         -- * Lookups in the HPT
    
    33 38
       , lookupHpt
    
    ... ... @@ -37,27 +42,31 @@ module GHC.Unit.Home.PackageTable
    37 42
       , addHomeModInfoToHpt
    
    38 43
       , addHomeModInfosToHpt
    
    39 44
       , addOnDemandHomeModule
    
    45
    +  , hptAddOwnBootTypes
    
    40 46
     
    
    41 47
         -- * Restrict the HPT
    
    42 48
       , restrictHpt
    
    43 49
     
    
    44 50
         -- * Queries about home modules
    
    51
    +  , listHptIfaces
    
    45 52
       , hptCompleteSigs
    
    46 53
       , hptAllInstances
    
    47 54
       , hptAllFamInstances
    
    48 55
       , hptAllAnnotations
    
    49
    -  , hlsIsModuleNameWithBoot
    
    50
    -  , hlsIsBoot
    
    51
    -  , hlsSetBootInfo
    
    56
    +  , hptSetBootInfo
    
    52 57
       , hptLoadedIsBoot
    
    53
    -  , hptLoadedTypeEnv
    
    58
    +  , hptLookupLoadedType
    
    54 59
       , hptLoadedInstEnv
    
    55 60
       , hptLoadedFamInstEnv
    
    56
    -  , hptLoadedModFamInstEnv
    
    61
    +  , hptLoadedModFamInsts
    
    57 62
       , hptLoadedRuleBase
    
    58 63
       , hptLoadedAnnEnv
    
    59 64
       , hptLoadedCompleteMatches
    
    60
    -  , hptLoadedDefaults
    
    65
    +  , hptLoadedByteCode
    
    66
    +  , HptStats(..)
    
    67
    +  , hptLoadedStats
    
    68
    +  , hptBumpDeclsOut
    
    69
    +  , pprHptStats
    
    61 70
     
    
    62 71
         -- ** More Traversal-based queries
    
    63 72
       , hptCollectDependencies
    
    ... ... @@ -78,9 +87,8 @@ module GHC.Unit.Home.PackageTable
    78 87
         --
    
    79 88
         -- In GHC itself these should be avoided, and other uses should justify why
    
    80 89
         -- it is not sufficient to go through the intended insert-only API.
    
    81
    -  , hptInternalTableRef
    
    90
    +  -- , hptInternalTableRef
    
    82 91
       , hptInternalTableFromRef
    
    83
    -  , hptLoaderState
    
    84 92
         -- * Legacy API
    
    85 93
         --
    
    86 94
         -- | This API is deprecated and meant to be removed.
    
    ... ... @@ -113,28 +121,21 @@ import GHC.Unit.Module.ModIface
    113 121
     import GHC.Utils.Outputable
    
    114 122
     import GHC.Types.Name
    
    115 123
     import GHC.Types.Name.Env (extendNameEnvList)
    
    116
    -import GHC.Types.DefaultEnv (DefaultEnv)
    
    117
    -import GHC.Core
    
    118 124
     
    
    119 125
     -- | Helps us find information about modules in the home package
    
    120
    -data HomePackageTable = HPT {
    
    126
    +data HomePackageTable
    
    127
    +  = HPT_Make { table :: {-# UNPACK #-} !(IORef (DModuleNameEnv HomeModInfo)) }
    
    128
    +  | HPT_OneShot { loader :: {-# UNPACK #-} !(IORef HomeLoaderState) }
    
    121 129
     
    
    122
    -    table :: IORef (DModuleNameEnv HomeModInfo),
    
    123
    -    -- ^ Domain = modules in this home unit
    
    124
    -    --
    
    125
    -    -- This is an IORef because we want to avoid leaking HPTs (see the particularly bad #25511).
    
    126
    -    -- Moreover, the HPT invariant allows mutability in this table without compromising thread safety or soundness.
    
    127
    -    -- To recall:
    
    128
    -    --   A query to the HPT should depend only on data relevant to that query, such that
    
    129
    -    --   there being more or less unrelated entries in the HPT does not influence the result in any way.
    
    130
    -    --
    
    131
    -    -- Note that the HPT increases monotonically, except at certain barrier
    
    132
    -    -- points like when 'restrictHpt' is called. At these barriers, it is safe
    
    133
    -    -- to temporarily violate the HPT monotonicity.
    
    134
    -    --
    
    135
    -    -- The elements of this table may be updated (e.g. on rehydration).
    
    136
    -    loader :: IORef HomeLoaderState
    
    137
    -  }
    
    130
    +isOneShotMode :: HomePackageTable -> Bool
    
    131
    +isOneShotMode = \ case
    
    132
    +  HPT_OneShot{} -> True
    
    133
    +  HPT_Make{} -> False
    
    134
    +
    
    135
    +isHptEmpty :: HomePackageTable -> IO Bool
    
    136
    +isHptEmpty = \ case
    
    137
    +  HPT_OneShot{loader} -> null . hls_table <$> readIORef loader
    
    138
    +  HPT_Make{table} -> isNullUDFM <$> readIORef table
    
    138 139
     
    
    139 140
     -- | Create a new 'HomePackageTable'.
    
    140 141
     --
    
    ... ... @@ -145,85 +146,195 @@ emptyHomePackageTable :: IO HomePackageTable
    145 146
     -- romes:todo: use a MutableArray directly?
    
    146 147
     emptyHomePackageTable = do
    
    147 148
       table <- newIORef emptyUDFM
    
    149
    +  return HPT_Make{table}
    
    150
    +
    
    151
    +emptyOnDemandHomePackageTable :: IO HomePackageTable
    
    152
    +emptyOnDemandHomePackageTable = do
    
    148 153
       loader <- newIORef emptyHomeLoaderState
    
    149
    -  return HPT{table, loader}
    
    154
    +  return HPT_OneShot{loader}
    
    150 155
     
    
    151 156
     data HomeLoaderState = HomeLoaderState
    
    152
    -  { hls_modules          :: ModuleEnv ()
    
    157
    +  { hls_table            :: DModuleNameEnv HomeModInfo
    
    158
    +  , hls_indices          :: !LoaderIndices
    
    153 159
       , hls_is_boot          :: InstalledModuleEnv ModuleNameWithIsBoot
    
    154
    -  , hls_type_env         :: !TypeEnv
    
    160
    +  , hls_boot_type_env    :: !TypeEnv
    
    155 161
       , hls_iface_bytecode   :: !(ModuleEnv (IO Linkable))
    
    156
    -  , hls_inst_env         :: !InstEnv
    
    157
    -  , hls_fam_inst_env     :: !FamInstEnv
    
    158
    -  , hls_mod_fam_inst_env :: !(ModuleEnv FamInstEnv)
    
    159
    -  , hls_rule_base        :: !RuleBase
    
    160
    -  , hls_ann_env          :: !AnnEnv
    
    161
    -  , hls_complete_matches :: !CompleteMatches
    
    162
    -  , hls_defaults         :: ModuleEnv DefaultEnv
    
    162
    +  , hls_stats            :: !HptStats
    
    163
    +  }
    
    164
    +
    
    165
    +data LoaderIndices = LoaderIndices
    
    166
    +  { li_inst_env         :: !InstEnv
    
    167
    +  , li_fam_inst_env     :: !FamInstEnv
    
    168
    +  , li_rule_base        :: !RuleBase
    
    169
    +  , li_ann_env          :: !AnnEnv
    
    170
    +  , li_complete_matches :: !CompleteMatches
    
    163 171
       }
    
    164 172
     
    
    173
    +emptyLoaderIndices :: LoaderIndices
    
    174
    +emptyLoaderIndices = LoaderIndices
    
    175
    +  { li_inst_env         = emptyInstEnv
    
    176
    +  , li_fam_inst_env     = emptyFamInstEnv
    
    177
    +  , li_rule_base        = emptyRuleBase
    
    178
    +  , li_ann_env          = emptyAnnEnv
    
    179
    +  , li_complete_matches = []
    
    180
    +  }
    
    181
    +
    
    182
    +extendLoaderIndices :: LoaderIndices -> HomeModInfo -> LoaderIndices
    
    183
    +extendLoaderIndices li hmi = LoaderIndices
    
    184
    +  { li_inst_env         = extendInstEnvList (li_inst_env li) (instEnvElts (md_insts details))
    
    185
    +  , li_fam_inst_env     = extendFamInstEnvList (li_fam_inst_env li) (md_fam_insts details)
    
    186
    +  , li_rule_base        = extendRuleBaseList (li_rule_base li) (md_rules details)
    
    187
    +  , li_ann_env          = extendAnnEnvList (li_ann_env li) (md_anns details)
    
    188
    +  , li_complete_matches = li_complete_matches li ++ md_complete_matches details
    
    189
    +  }
    
    190
    +  where
    
    191
    +    details = hm_details hmi
    
    192
    +
    
    165 193
     emptyHomeLoaderState :: HomeLoaderState
    
    166 194
     emptyHomeLoaderState =
    
    167 195
       HomeLoaderState
    
    168
    -    { hls_modules = emptyModuleEnv
    
    196
    +    { hls_table = emptyUDFM
    
    197
    +    , hls_indices = emptyLoaderIndices
    
    169 198
         , hls_is_boot = emptyInstalledModuleEnv
    
    170
    -    , hls_type_env = emptyTypeEnv
    
    199
    +    , hls_boot_type_env = emptyTypeEnv
    
    171 200
         , hls_iface_bytecode = emptyModuleEnv
    
    172
    -    , hls_inst_env = emptyInstEnv
    
    173
    -    , hls_fam_inst_env = emptyFamInstEnv
    
    174
    -    , hls_mod_fam_inst_env = emptyModuleEnv
    
    175
    -    , hls_rule_base = emptyRuleBase
    
    176
    -    , hls_ann_env = emptyAnnEnv
    
    177
    -    , hls_complete_matches = []
    
    178
    -    , hls_defaults = emptyModuleEnv
    
    201
    +    , hls_stats = emptyHptStats
    
    179 202
         }
    
    180 203
     
    
    204
    +insertLoadedHomeModInfo :: ModuleName -> HomeModInfo -> HomeLoaderState -> HomeLoaderState
    
    205
    +insertLoadedHomeModInfo mn hmi hls
    
    206
    +  | mn `elemUDFM` hls_table hls
    
    207
    +  = hls { hls_table   = table'
    
    208
    +        , hls_indices = foldl' extendLoaderIndices emptyLoaderIndices (eltsUDFM table')
    
    209
    +        , hls_stats   = stats'
    
    210
    +        }
    
    211
    +  | otherwise
    
    212
    +  = hls { hls_table   = table'
    
    213
    +        , hls_indices = extendLoaderIndices (hls_indices hls) hmi
    
    214
    +        , hls_stats   = stats'
    
    215
    +        }
    
    216
    +  where
    
    217
    +    table' = addToUDFM (hls_table hls) mn hmi
    
    218
    +    details = hm_details hmi
    
    219
    +    stats' = addHptInStats (hls_stats hls)
    
    220
    +                           (length (typeEnvElts (md_types details)))
    
    221
    +                           (length (instEnvElts (md_insts details)))
    
    222
    +                           (length (md_rules details))
    
    223
    +
    
    181 224
     --------------------------------------------------------------------------------
    
    182 225
     -- * Lookups in the HPT
    
    183 226
     --------------------------------------------------------------------------------
    
    184 227
     
    
    185 228
     -- | Lookup the 'HomeModInfo' of a module in the HPT, given its name.
    
    186 229
     lookupHpt :: HomePackageTable -> ModuleName -> IO (Maybe HomeModInfo)
    
    187
    -lookupHpt HPT{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
    
    230
    +lookupHpt HPT_Make{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
    
    231
    +lookupHpt HPT_OneShot{loader=hpt} mn = (`lookupUDFM` mn) . hls_table <$!> readIORef hpt
    
    188 232
     
    
    189 233
     -- | Lookup the 'HomeModInfo' of a 'Module' in the HPT.
    
    190 234
     lookupHptByModule :: HomePackageTable -> Module -> IO (Maybe HomeModInfo)
    
    191
    -lookupHptByModule hpt mod
    
    235
    +lookupHptByModule hpt modl
    
    192 236
       = -- The HPT is indexed by ModuleName, not Module,
    
    193 237
         -- we must check for a hit on the right Module
    
    194
    -    lookupHpt hpt (moduleName mod) >>= pure . \case
    
    195
    -      Just hm | mi_module (hm_iface hm) == mod -> Just hm
    
    238
    +    lookupHpt hpt (moduleName modl) >>= pure . \case
    
    239
    +      Just hm | mi_module (hm_iface hm) == modl -> Just hm
    
    196 240
           _otherwise                               -> Nothing
    
    197 241
     
    
    198
    -hptLoaderState :: HomePackageTable -> IO HomeLoaderState
    
    199
    -hptLoaderState = readIORef . loader
    
    242
    +queryOnDemandHpt :: a -> (HomeLoaderState -> a) -> HomePackageTable -> IO a
    
    243
    +queryOnDemandHpt a f hpt =
    
    244
    +  case hpt of
    
    245
    +    HPT_Make{} ->
    
    246
    +      pure a
    
    247
    +    HPT_OneShot{loader} ->
    
    248
    +      f <$> readIORef loader
    
    200 249
     
    
    201 250
     hptLoadedIsBoot :: HomePackageTable -> IO (InstalledModuleEnv ModuleNameWithIsBoot)
    
    202
    -hptLoadedIsBoot hpt = hls_is_boot <$> readIORef (loader hpt)
    
    203
    -
    
    204
    -hptLoadedTypeEnv :: HomePackageTable -> IO TypeEnv
    
    205
    -hptLoadedTypeEnv hpt = hls_type_env <$> readIORef (loader hpt)
    
    251
    +hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot
    
    252
    +
    
    253
    +hptLookupLoadedType :: HomePackageTable -> Name -> IO (Maybe TyThing)
    
    254
    +hptLookupLoadedType HPT_Make{} _ = pure Nothing
    
    255
    +hptLookupLoadedType hpt@HPT_OneShot{loader} name = do
    
    256
    +  mb_hmi <- case nameModule_maybe name of
    
    257
    +    Just modl -> lookupHptByModule hpt modl
    
    258
    +    Nothing  -> pure Nothing
    
    259
    +  case mb_hmi of
    
    260
    +    Just hmi -> pure $! lookupTypeEnv (md_types (hm_details hmi)) name
    
    261
    +    Nothing  -> (`lookupTypeEnv` name) . hls_boot_type_env <$> readIORef loader
    
    262
    +
    
    263
    +hptLoadedModFamInsts :: HomePackageTable -> Module -> IO (Maybe FamInstEnv)
    
    264
    +hptLoadedModFamInsts HPT_Make{} _ = pure Nothing
    
    265
    +hptLoadedModFamInsts hpt@HPT_OneShot{} modl =
    
    266
    +  fmap (extendFamInstEnvList emptyFamInstEnv . md_fam_insts . hm_details)
    
    267
    +    <$> lookupHptByModule hpt modl
    
    206 268
     
    
    207 269
     hptLoadedInstEnv :: HomePackageTable -> IO InstEnv
    
    208
    -hptLoadedInstEnv hpt = hls_inst_env <$> readIORef (loader hpt)
    
    270
    +hptLoadedInstEnv = queryOnDemandHpt emptyInstEnv (li_inst_env . hls_indices)
    
    209 271
     
    
    210 272
     hptLoadedFamInstEnv :: HomePackageTable -> IO FamInstEnv
    
    211
    -hptLoadedFamInstEnv hpt = hls_fam_inst_env <$> readIORef (loader hpt)
    
    212
    -
    
    213
    -hptLoadedModFamInstEnv :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
    
    214
    -hptLoadedModFamInstEnv hpt = hls_mod_fam_inst_env <$> readIORef (loader hpt)
    
    273
    +hptLoadedFamInstEnv = queryOnDemandHpt emptyFamInstEnv (li_fam_inst_env . hls_indices)
    
    215 274
     
    
    216 275
     hptLoadedRuleBase :: HomePackageTable -> IO RuleBase
    
    217
    -hptLoadedRuleBase hpt = hls_rule_base <$> readIORef (loader hpt)
    
    276
    +hptLoadedRuleBase = queryOnDemandHpt emptyRuleBase (li_rule_base . hls_indices)
    
    218 277
     
    
    219 278
     hptLoadedAnnEnv :: HomePackageTable -> IO AnnEnv
    
    220
    -hptLoadedAnnEnv hpt = hls_ann_env <$> readIORef (loader hpt)
    
    279
    +hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv (li_ann_env . hls_indices)
    
    221 280
     
    
    222 281
     hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
    
    223
    -hptLoadedCompleteMatches hpt = hls_complete_matches <$> readIORef (loader hpt)
    
    282
    +hptLoadedCompleteMatches = queryOnDemandHpt [] (li_complete_matches . hls_indices)
    
    283
    +
    
    284
    +hptLoadedByteCode :: HomePackageTable -> Module -> IO (Maybe (IO Linkable))
    
    285
    +hptLoadedByteCode hpt modl =
    
    286
    +  queryOnDemandHpt Nothing (\ hls -> lookupModuleEnv (hls_iface_bytecode hls) modl) hpt
    
    287
    +
    
    288
    +hptLoadedStats :: HomePackageTable -> IO (Maybe HptStats)
    
    289
    +hptLoadedStats = queryOnDemandHpt Nothing (Just . hls_stats)
    
    290
    +
    
    291
    +hptBumpDeclsOut :: HomePackageTable -> IO ()
    
    292
    +hptBumpDeclsOut HPT_Make{} = pure ()
    
    293
    +hptBumpDeclsOut HPT_OneShot{loader} =
    
    294
    +  atomicModifyIORef' loader $ \ hls ->
    
    295
    +    let stats = hls_stats hls
    
    296
    +    in (hls { hls_stats = stats { hpt_n_decls_out = hpt_n_decls_out stats + 1 } }, ())
    
    297
    +
    
    298
    +data HptStats = HptStats
    
    299
    +  { hpt_n_ifaces_in :: !Int
    
    300
    +  , hpt_n_decls_in  :: !Int
    
    301
    +  , hpt_n_decls_out :: !Int
    
    302
    +  , hpt_n_insts_in  :: !Int
    
    303
    +  , hpt_n_rules_in  :: !Int
    
    304
    +  }
    
    305
    +
    
    306
    +emptyHptStats :: HptStats
    
    307
    +emptyHptStats = HptStats
    
    308
    +  { hpt_n_ifaces_in = 0
    
    309
    +  , hpt_n_decls_in  = 0
    
    310
    +  , hpt_n_decls_out = 0
    
    311
    +  , hpt_n_insts_in  = 0
    
    312
    +  , hpt_n_rules_in  = 0
    
    313
    +  }
    
    224 314
     
    
    225
    -hptLoadedDefaults :: HomePackageTable -> IO (ModuleEnv DefaultEnv)
    
    226
    -hptLoadedDefaults hpt = hls_defaults <$> readIORef (loader hpt)
    
    315
    +addHptInStats :: HptStats -> Int -> Int -> Int -> HptStats
    
    316
    +addHptInStats stats n_decls n_insts n_rules
    
    317
    +  = stats { hpt_n_ifaces_in = hpt_n_ifaces_in stats + 1
    
    318
    +          , hpt_n_decls_in  = hpt_n_decls_in stats + n_decls
    
    319
    +          , hpt_n_insts_in  = hpt_n_insts_in stats + n_insts
    
    320
    +          , hpt_n_rules_in  = hpt_n_rules_in stats + n_rules }
    
    321
    +
    
    322
    +pprHptStats :: HptStats -> SDoc
    
    323
    +pprHptStats stats
    
    324
    +  = hcat [text "Home interface stats: ", msg]
    
    325
    +  where
    
    326
    +    msg = vcat
    
    327
    +        [int (hpt_n_ifaces_in stats) <+> text "interfaces read",
    
    328
    +         hsep [ int (hpt_n_decls_out stats), text "type/class/variable imported, out of",
    
    329
    +                int (hpt_n_decls_in stats), text "read"],
    
    330
    +         hsep [ int (hpt_n_insts_in stats), text "instance decls read"],
    
    331
    +         hsep [ int (hpt_n_rules_in stats), text "rule decls read"]
    
    332
    +        ]
    
    333
    +
    
    334
    +listHptIfaces :: HomePackageTable -> IO (DModuleNameEnv HomeModInfo)
    
    335
    +listHptIfaces = \ case
    
    336
    +  HPT_Make{table} -> readIORef table
    
    337
    +  HPT_OneShot{loader} -> hls_table <$> readIORef loader
    
    227 338
     
    
    228 339
     --------------------------------------------------------------------------------
    
    229 340
     -- * Extending the HPT
    
    ... ... @@ -244,10 +355,12 @@ addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi)
    244 355
     {-# DEPRECATED addToHpt "Deprecated in favour of 'addHomeModInfoToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
    
    245 356
     -- After deprecation cycle, move `addToHpt` to a `where` clause inside `addHomeModInfoToHpt`.
    
    246 357
     addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO ()
    
    247
    -addToHpt HPT{table=hptr} mn hmi = do
    
    358
    +addToHpt HPT_Make{table=hptr} mn hmi = do
    
    248 359
       atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
    
    249 360
       -- If the key already existed in the map, this insertion is overwriting
    
    250 361
       -- the HMI of a previously loaded module (likely in rehydration).
    
    362
    +addToHpt HPT_OneShot{loader} mn hmi =
    
    363
    +  atomicModifyIORef' loader (\hls -> (insertLoadedHomeModInfo mn hmi hls, ()))
    
    251 364
     
    
    252 365
     -- | 'addHomeModInfoToHpt' for multiple module infos.
    
    253 366
     addHomeModInfosToHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
    
    ... ... @@ -262,64 +375,39 @@ addHomeModInfosToHpt hpt = mapM_ (flip addHomeModInfoToHpt hpt)
    262 375
     -- called at barrier points, such as the end of upsweep, when all threads are
    
    263 376
     -- done and we want to clean up failed entries.
    
    264 377
     restrictHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
    
    265
    -restrictHpt HPT{table=hptr} hmis =
    
    378
    +restrictHpt HPT_Make{table=hptr} hmis =
    
    266 379
       let key_set = map (getKey . getUnique . hmi_mod) hmis
    
    267 380
           hmi_mod hmi = moduleName (mi_module (hm_iface hmi))
    
    268 381
       in atomicModifyIORef' hptr (\hpt -> (udfmRestrictKeysSet hpt (W64.fromList key_set), ()))
    
    382
    +restrictHpt HPT_OneShot{} _ = pure ()
    
    269 383
     
    
    270 384
     {-# DEPRECATED addListToHpt "Deprecated in favour of 'addHomeModInfosToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
    
    271 385
     -- After deprecation cycle, remove.
    
    272 386
     addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
    
    273 387
     addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
    
    274 388
     
    
    275
    -addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> Maybe (IO Linkable) -> IO ()
    
    276
    -addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_defaults, new_hls_fam_insts, new_hls_rules, new_hls_anns, new_hls_complete_matches) bytecode = do
    
    277
    -  atomicModifyIORef (loader hpt) $ \hls ->
    
    278
    -    ( if mn `elemModuleEnv` hls_modules hls
    
    279
    -        then hls -- If already loaded, don't add twice
    
    280
    -        else
    
    281
    -          if bad_boot
    
    282
    -            then addHomeModTypeEnv hls
    
    283
    -            else addHomeModData hls
    
    284
    -    , ()
    
    285
    -    )
    
    389
    +addOnDemandHomeModule :: HomePackageTable -> HomeModInfo -> Maybe (IO Linkable) -> IO ()
    
    390
    +addOnDemandHomeModule hpt@HPT_Make{} hmi _ = addHomeModInfoToHpt hmi hpt
    
    391
    +addOnDemandHomeModule HPT_OneShot{loader} hmi mb_bytecode =
    
    392
    +  atomicModifyIORef' loader $ \hls ->
    
    393
    +    let hls' = insertLoadedHomeModInfo (moduleName modl) hmi hls
    
    394
    +    in ( case mb_bytecode of
    
    395
    +           Nothing     -> hls'
    
    396
    +           Just action -> hls' { hls_iface_bytecode = extendModuleEnv (hls_iface_bytecode hls') modl action }
    
    397
    +       , () )
    
    286 398
       where
    
    287
    -    addHomeModTypeEnv hls = hls
    
    288
    -      { hls_type_env = extendNameEnvList   (hls_type_env hls) new_hls_decls
    
    289
    -      }
    
    290
    -
    
    291
    -    addHomeModData hls = hls {
    
    292
    -      hls_modules        =  extendModuleEnv (hls_modules hls) mn (),
    
    293
    -      hls_type_env       = extendNameEnvList (hls_type_env hls) new_hls_decls,
    
    294
    -      hls_iface_bytecode = case bytecode of
    
    295
    -        Nothing -> hls_iface_bytecode hls
    
    296
    -        Just bc -> extendModuleEnv (hls_iface_bytecode hls) mn bc,
    
    297
    -      hls_rule_base      = extendRuleBaseList (hls_rule_base hls)
    
    298
    -                                            new_hls_rules,
    
    299
    -      hls_complete_matches
    
    300
    -                         = hls_complete_matches hls ++ new_hls_complete_matches,
    
    301
    -      hls_inst_env       = extendInstEnvList (hls_inst_env hls)
    
    302
    -                                            new_hls_insts,
    
    303
    -      hls_fam_inst_env   = extendFamInstEnvList (hls_fam_inst_env hls)
    
    304
    -                                              new_hls_fam_insts,
    
    305
    -      hls_ann_env        = extendAnnEnvList (hls_ann_env hls)
    
    306
    -                                          new_hls_anns,
    
    307
    -      hls_mod_fam_inst_env
    
    308
    -                         =
    
    309
    -                          let
    
    310
    -                            fam_inst_env =
    
    311
    -                              extendFamInstEnvList emptyFamInstEnv
    
    312
    -                                                  new_hls_fam_insts
    
    313
    -                          in
    
    314
    -                          extendModuleEnv (hls_mod_fam_inst_env hls)
    
    315
    -                                          mn
    
    316
    -                                          fam_inst_env,
    
    317
    -      hls_defaults       =  extendModuleEnv (hls_defaults hls) mn new_hls_defaults
    
    318
    -  }
    
    319
    -
    
    320
    -hlsSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
    
    321
    -hlsSetBootInfo hpt is_boot_env =
    
    322
    -  atomicModifyIORef' (loader hpt) $ \ hls ->
    
    399
    +    modl = mi_module (hm_iface hmi)
    
    400
    +
    
    401
    +hptAddOwnBootTypes :: HomePackageTable -> [(Name, TyThing)] -> IO ()
    
    402
    +hptAddOwnBootTypes HPT_Make{} _ = pure ()
    
    403
    +hptAddOwnBootTypes HPT_OneShot{loader} decls =
    
    404
    +  atomicModifyIORef' loader $ \hls ->
    
    405
    +    (hls { hls_boot_type_env = extendNameEnvList (hls_boot_type_env hls) decls }, ())
    
    406
    +
    
    407
    +hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
    
    408
    +hptSetBootInfo HPT_Make{} _ = pure ()
    
    409
    +hptSetBootInfo HPT_OneShot{loader} is_boot_env =
    
    410
    +  atomicModifyIORef' loader $ \ hls ->
    
    323 411
         (hls { hls_is_boot = is_boot_env }, ())
    
    324 412
     
    
    325 413
     ----------------------------------------------------------------------------------
    
    ... ... @@ -329,11 +417,15 @@ hlsSetBootInfo hpt is_boot_env =
    329 417
     -- | Get all 'CompleteMatches' (arising from COMPLETE pragmas) present in all
    
    330 418
     -- modules from this unit's HPT.
    
    331 419
     hptCompleteSigs :: HomePackageTable -> IO CompleteMatches
    
    332
    -hptCompleteSigs = concatHpt (md_complete_matches . hm_details)
    
    420
    +hptCompleteSigs HPT_OneShot{loader} = li_complete_matches . hls_indices <$> readIORef loader
    
    421
    +hptCompleteSigs hpt@HPT_Make{} = concatHpt (md_complete_matches . hm_details) hpt
    
    333 422
     
    
    334 423
     -- | Find all the instance declarations (of classes and families) from this Home Package Table
    
    335 424
     hptAllInstances :: HomePackageTable -> IO (InstEnv, [FamInst])
    
    336
    -hptAllInstances hpt = do
    
    425
    +hptAllInstances HPT_OneShot{loader} = do
    
    426
    +  li <- hls_indices <$> readIORef loader
    
    427
    +  return (li_inst_env li, famInstEnvElts (li_fam_inst_env li))
    
    428
    +hptAllInstances hpt@HPT_Make{} = do
    
    337 429
       hits <- flip concatHpt hpt $ \mod_info -> do
    
    338 430
          let details = hm_details mod_info
    
    339 431
          return (md_insts details, md_fam_insts details)
    
    ... ... @@ -350,13 +442,8 @@ hptAllFamInstances = fmap mkModuleEnv . concatHpt (\hmi -> [(hmiModule hmi, hmiF
    350 442
     
    
    351 443
     -- | All annotations from the HPT
    
    352 444
     hptAllAnnotations :: HomePackageTable -> IO AnnEnv
    
    353
    -hptAllAnnotations = fmap mkAnnEnv . concatHpt (md_anns . hm_details)
    
    354
    -
    
    355
    -hlsIsBoot :: HomeLoaderState -> InstalledModule -> Maybe IsBootInterface
    
    356
    -hlsIsBoot hls mn = gwib_isBoot <$> hlsIsModuleNameWithBoot hls mn
    
    357
    -
    
    358
    -hlsIsModuleNameWithBoot :: HomeLoaderState -> InstalledModule -> Maybe ModuleNameWithIsBoot
    
    359
    -hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn
    
    445
    +hptAllAnnotations HPT_OneShot{loader} = li_ann_env . hls_indices <$> readIORef loader
    
    446
    +hptAllAnnotations hpt@HPT_Make{} = mkAnnEnv <$> concatHpt (md_anns . hm_details) hpt
    
    360 447
     
    
    361 448
     --------------------------------------------------------------------------------
    
    362 449
     -- * Traversal-based queries
    
    ... ... @@ -370,7 +457,11 @@ hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn
    370 457
     -- currently takes all dependencies only to then filter them with an ad-hoc transitive closure check.
    
    371 458
     -- See #25639
    
    372 459
     hptCollectDependencies :: HomePackageTable -> IO (Set.Set (IfaceImportLevel, UnitId))
    
    373
    -hptCollectDependencies HPT{table} = do
    
    460
    +hptCollectDependencies HPT_OneShot{loader} = do
    
    461
    +  hpt <- readIORef loader
    
    462
    +  return $
    
    463
    +    foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty (hls_table hpt)
    
    464
    +hptCollectDependencies HPT_Make{table} = do
    
    374 465
       hpt <- readIORef table
    
    375 466
       return $
    
    376 467
         foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty hpt
    
    ... ... @@ -380,7 +471,11 @@ hptCollectDependencies HPT{table} = do
    380 471
     --
    
    381 472
     -- $O(n)$ in the number of modules in the HPT.
    
    382 473
     hptCollectHomeModInfo :: HomePackageTable -> IO [HomeModInfo]
    
    383
    -hptCollectHomeModInfo HPT{table} = do
    
    474
    +hptCollectHomeModInfo HPT_OneShot{loader} = do
    
    475
    +  hpt <- readIORef loader
    
    476
    +  return $
    
    477
    +    foldr (:) [] (hls_table hpt)
    
    478
    +hptCollectHomeModInfo HPT_Make{table} = do
    
    384 479
       hpt <- readIORef table
    
    385 480
       return $
    
    386 481
         foldr (:) [] hpt
    
    ... ... @@ -398,7 +493,13 @@ hptCollectHomeModInfo HPT{table} = do
    398 493
     -- unit map in failed lookups.
    
    399 494
     pprHPT :: HomePackageTable -> IO SDoc
    
    400 495
     -- A bit arbitrary for now
    
    401
    -pprHPT HPT{table=hptr} = do
    
    496
    +pprHPT HPT_OneShot{loader=hptr} = do
    
    497
    +  hpt <- readIORef hptr
    
    498
    +  return $!
    
    499
    +    pprUDFM (hls_table hpt) $ \hms ->
    
    500
    +      vcat [ ppr (mi_module (hm_iface hm))
    
    501
    +           | hm <- hms ]
    
    502
    +pprHPT HPT_Make{table=hptr} = do
    
    402 503
       hpt <- readIORef hptr
    
    403 504
       return $!
    
    404 505
         pprUDFM hpt $ \hms ->
    
    ... ... @@ -437,7 +538,12 @@ pprHPT HPT{table=hptr} = do
    437 538
     -- If this function is ever exposed from the HPT module, make sure the
    
    438 539
     -- argument function doesn't introduce leaks.
    
    439 540
     concatHpt :: (HomeModInfo -> [a]) -> HomePackageTable -> IO [a]
    
    440
    -concatHpt f HPT{table} = do
    
    541
    +concatHpt f HPT_OneShot{loader} = do
    
    542
    +  hpt <- readIORef loader
    
    543
    +  return $ concat . eltsUDFM . mapMaybeUDFM g $ hls_table hpt
    
    544
    +  where
    
    545
    +    g hmi = case f hmi of { [] -> Nothing; as -> Just as }
    
    546
    +concatHpt f HPT_Make{table} = do
    
    441 547
       hpt <- readIORef table
    
    442 548
       return $ concat . eltsUDFM . mapMaybeUDFM g $ hpt
    
    443 549
       where
    
    ... ... @@ -449,15 +555,15 @@ concatHpt f HPT{table} = do
    449 555
     
    
    450 556
     -- | Gets the internal 'IORef' which holds the 'HomeModInfo's of this HPT.
    
    451 557
     -- Use with care.
    
    452
    -hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
    
    453
    -hptInternalTableRef = table
    
    558
    +-- hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
    
    559
    +-- hptInternalTableRef = \ case
    
    560
    +--   HPT_Make{table} -> table
    
    561
    +--   HPT_OneShot{} ->  -- TODO: @fendor how does this make sense?
    
    454 562
     
    
    455 563
     -- | Construct a HomePackageTable from the IORef.
    
    456 564
     -- Use with care, only if you can really justify going around the intended insert-only API.
    
    457 565
     hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
    
    458 566
     hptInternalTableFromRef ref = do
    
    459
    -  loader <- newIORef emptyHomeLoaderState
    
    460
    -  return HPT {
    
    461
    -    table = ref,
    
    462
    -    loader
    
    567
    +  return HPT_Make {
    
    568
    +    table = ref
    
    463 569
       }

  • compiler/GHC/Unit/Module/Env.hs
    ... ... @@ -249,7 +249,7 @@ lookupModuleNameEnv :: ModuleNameEnv elt -> ModuleName -> Maybe elt
    249 249
     lookupModuleNameEnv = lookupUFM
    
    250 250
     
    
    251 251
     unionModuleNameEnv :: ModuleNameEnv elt -> ModuleNameEnv elt -> ModuleNameEnv elt
    
    252
    -unionModuleNameEnv = unionModuleNameEnv
    
    252
    +unionModuleNameEnv = plusUFM
    
    253 253
     
    
    254 254
     -- | A map keyed off of 'ModuleName's (actually, their 'Unique's)
    
    255 255
     -- Has deterministic folds and can be deterministically converted to a list
    

  • ghc/GHCi/Leak.hs
    ... ... @@ -7,7 +7,6 @@ module GHCi.Leak
    7 7
     
    
    8 8
     import Control.Monad
    
    9 9
     import Data.Bits
    
    10
    -import Data.IORef
    
    11 10
     import Foreign.Ptr (ptrToIntPtr, intPtrToPtr)
    
    12 11
     import GHC
    
    13 12
     import GHC.Ptr (Ptr (..))
    
    ... ... @@ -43,7 +42,7 @@ data LeakModIndicators = LeakModIndicators
    43 42
     getLeakIndicators :: HscEnv -> IO LeakIndicators
    
    44 43
     getLeakIndicators hsc_env =
    
    45 44
       fmap LeakIndicators $ do
    
    46
    -    hpt <- readIORef $ hptInternalTableRef $ hsc_HPT hsc_env
    
    45
    +    hpt <- listHptIfaces $ hsc_HPT hsc_env
    
    47 46
         forM (eltsUDFM hpt) $ \hmi@HomeModInfo{..} -> do
    
    48 47
           leakMod <- mkWeakPtr hmi Nothing
    
    49 48
           leakIface <- mkWeakPtr hm_iface Nothing
    

  • testsuite/tests/bytecode/T25090/Makefile
    ... ... @@ -16,9 +16,11 @@ T25090a:
    16 16
     	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A.o -o exe
    
    17 17
     	./exe
    
    18 18
     
    
    19
    -# Like T25090a, but without .gbc files: the bytecode for the splice has to be
    
    20
    -# compiled from the Core stored in the interface files
    
    21
    -# (-fwrite-if-simplified-core). See Note [Interface Files with Core Definitions].
    
    19
    +T25090b:
    
    20
    +	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0
    
    21
    +	./exe
    
    22
    +
    
    23
    +# Like T25090a, but get bytecode for splicing from simplified core in the interface files.
    
    22 24
     T25090c:
    
    23 25
     	'$(TEST_HC)' -c -fwrite-if-simplified-core C.hs-boot
    
    24 26
     	'$(TEST_HC)' -c -fwrite-if-simplified-core B.hs
    
    ... ... @@ -31,7 +33,3 @@ T25090c:
    31 33
     	'$(TEST_HC)' -c -fwrite-if-simplified-core -fprefer-byte-code A.hs
    
    32 34
     	'$(TEST_HC)' A.o -o exe
    
    33 35
     	./exe
    34
    -
    
    35
    -T25090b:
    
    36
    -	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0
    
    37
    -	./exe

  • testsuite/tests/driver/one-shot-boot/A.hs
    ... ... @@ -4,5 +4,4 @@ module A where
    4 4
     import Fam
    
    5 5
     import {-# SOURCE #-} M (T)
    
    6 6
     
    
    7
    --- This instance mentions 'T' from M's boot file.
    
    8 7
     type instance F T = Int

  • testsuite/tests/driver/one-shot-boot/B.hs
    ... ... @@ -3,8 +3,4 @@ module B where
    3 3
     
    
    4 4
     import Fam
    
    5 5
     
    
    6
    --- A second family-instance module for 'F', so that compiling M has to check
    
    7
    --- the consistency of A's and B's instances. That check forces 'T', which
    
    8
    --- makes GHC load M.hi-boot while compiling M itself.
    
    9
    --- See Note [Loading your own hi-boot file] in GHC.Iface.Load.
    
    10 6
     type instance F Bool = Char

  • testsuite/tests/driver/one-shot-boot/M.hs
    ... ... @@ -7,11 +7,8 @@ import B ()
    7 7
     
    
    8 8
     data T = MkT Int
    
    9 9
     
    
    10
    --- Also declared in M.hs-boot: loading M.hi-boot while compiling M must not
    
    11
    --- cause a duplicate instance error.
    
    12 10
     instance Show T where
    
    13 11
       show (MkT n) = "MkT " ++ show n
    
    14 12
     
    
    15
    --- Not part of M.hs-boot. Needs A's instance of 'F' to typecheck.
    
    16 13
     onlyInM :: F T
    
    17 14
     onlyInM = 42

  • testsuite/tests/driver/one-shot-boot/Makefile
    ... ... @@ -2,9 +2,6 @@ TOP=../../..
    2 2
     include $(TOP)/mk/boilerplate.mk
    
    3 3
     include $(TOP)/mk/test.mk
    
    4 4
     
    
    5
    -# One-shot compilation of a SOURCE-import cycle where type family instances
    
    6
    -# mention the type from the boot file. Every module is compiled by its own
    
    7
    -# invocation of GHC.
    
    8 5
     OneShotBootFamInst:
    
    9 6
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
    
    10 7
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
    
    ... ... @@ -15,9 +12,6 @@ OneShotBootFamInst:
    15 12
     	'$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main
    
    16 13
     	./main
    
    17 14
     
    
    18
    -# Like OneShotBootFamInst, but M and Main are compiled by the same invocation.
    
    19
    -# Compiling M loads M.hi-boot (see Note [Loading your own hi-boot file]); that
    
    20
    -# must not make Main see the boot interface of M instead of the real one.
    
    21 15
     OneShotBootSameInvocation:
    
    22 16
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
    
    23 17
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
    

  • testsuite/tests/driver/one-shot-boot/all.T
    1
    -# Compiling M loads M.hi-boot, which triggers a warnPprTrace in debug builds.
    
    2
    -# See Note [Loading your own hi-boot file] in GHC.Iface.Load.
    
    3 1
     def test_one_shot_boot(name):
    
    4 2
         return test(name,
    
    5 3
                     [extra_files(['Fam.hs', 'M.hs-boot', 'A.hs', 'B.hs', 'M.hs', 'Main.hs']),