Patrick pushed to branch wip/T26118-remove-hptallfaminstances-usage-during-upsweep at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/Driver/Env.hs
    ... ... @@ -34,7 +34,6 @@ module GHC.Driver.Env
    34 34
        , hugInstancesBelow
    
    35 35
        , hugAnnsBelow
    
    36 36
        , hugCompleteSigsBelow
    
    37
    -   , hugFamInstancesBelow
    
    38 37
     
    
    39 38
         -- * Legacy API
    
    40 39
        , hscUpdateHPT
    
    ... ... @@ -231,17 +230,6 @@ hugAnnsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
    231 230
     hugAnnsBelow hsc uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
    
    232 231
       hugSomeThingsBelowUs (md_anns . hm_details) False hsc uid mn
    
    233 232
     
    
    234
    -hugFamInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (ModuleEnv FamInstEnv)
    
    235
    -hugFamInstancesBelow = hugSomeThingsBelowUs' combine emptyModuleEnv True
    
    236
    -  where
    
    237
    -    hmiFamInstEnv = extendFamInstEnvList emptyFamInstEnv . (md_fam_insts . hm_details)
    
    238
    -    hmiModule     = mi_module . hm_iface
    
    239
    -    combine :: HomeModInfo -> ModuleEnv FamInstEnv -> ModuleEnv FamInstEnv
    
    240
    -    combine md acc = do
    
    241
    -      let famInstEnv = hmiFamInstEnv md
    
    242
    -          mod = hmiModule md
    
    243
    -       in extendModuleEnvWith unionFamInstEnv acc mod famInstEnv
    
    244
    -
    
    245 233
     -- | Find all COMPLETE pragmas in modules that are in the transitive closure of the
    
    246 234
     -- given module.
    
    247 235
     hugCompleteSigsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
    
    ... ... @@ -249,7 +237,7 @@ hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$>
    249 237
       hugSomeThingsBelowUs (md_complete_matches . hm_details) False hsc uid mn
    
    250 238
     
    
    251 239
     -- | Find instances visible from the given set of imports
    
    252
    -hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
    
    240
    +hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [(Module, FamInstEnv)])
    
    253 241
     hugInstancesBelow hsc_env uid mnwib = do
    
    254 242
      let mn = gwib_mod mnwib
    
    255 243
      (insts, famInsts) <-
    
    ... ... @@ -259,7 +247,7 @@ hugInstancesBelow hsc_env uid mnwib = do
    259 247
                                       -- Don't include instances for the current module
    
    260 248
                                       in if moduleName (mi_module (hm_iface mod_info)) == mn
    
    261 249
                                            then []
    
    262
    -                                       else [(md_insts details, md_fam_insts details)])
    
    250
    +                                       else [(md_insts details, [(mi_module $ hm_iface mod_info, extendFamInstEnvList emptyFamInstEnv $ md_fam_insts details)])])
    
    263 251
                               True -- Include -hi-boot
    
    264 252
                               hsc_env
    
    265 253
                               uid
    
    ... ... @@ -269,19 +257,16 @@ hugInstancesBelow hsc_env uid mnwib = do
    269 257
     -- | Get things from modules in the transitive closure of the given module.
    
    270 258
     --
    
    271 259
     -- Note: Don't expose this function. This is a footgun if exposed!
    
    272
    -hugSomeThingsBelowUs' :: (HomeModInfo -> a -> a) -> a -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO a
    
    273
    -hugSomeThingsBelowUs' _ acc _ hsc_env _ _ | isOneShot (ghcMode (hsc_dflags hsc_env)) = return acc
    
    260
    +hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
    
    274 261
     -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk
    
    275 262
     -- These things are currently stored in the EPS for home packages. (See #25795 for
    
    276 263
     -- progress in removing these kind of checks)
    
    277 264
     -- See Note [Downsweep and the ModuleGraph]
    
    278
    -hugSomeThingsBelowUs' combine acc include_hi_boot hsc_env uid mn
    
    265
    +hugSomeThingsBelowUs _ _ hsc_env _ _ | isOneShot (ghcMode (hsc_dflags hsc_env)) = return []
    
    266
    +hugSomeThingsBelowUs extract include_hi_boot hsc_env uid mn
    
    279 267
       = let hug = hsc_HUG hsc_env
    
    280 268
             mg  = hsc_mod_graph hsc_env
    
    281
    -        combine' Nothing acc = acc
    
    282
    -        combine' (Just hmi) acc = combine hmi acc
    
    283 269
         in
    
    284
    -    foldr combine' acc <$>
    
    285 270
         sequence
    
    286 271
         [ things
    
    287 272
           -- "Finding each non-hi-boot module below me" maybe could be cached (well,
    
    ... ... @@ -300,8 +285,8 @@ hugSomeThingsBelowUs' combine acc include_hi_boot hsc_env uid mn
    300 285
     
    
    301 286
             -- Look it up in the HUG
    
    302 287
         , let things = lookupHug hug mod_uid mod >>= \case
    
    303
    -                    Just info -> return $ Just info
    
    304
    -                    Nothing -> pprTrace "WARNING in hugSomeThingsBelowUs" msg (pure Nothing)
    
    288
    +                    Just info -> return $ extract info
    
    289
    +                    Nothing -> pprTrace "WARNING in hugSomeThingsBelowUs" msg mempty
    
    305 290
               msg = vcat [text "missing module" <+> ppr mod,
    
    306 291
                          text "When starting from"  <+> ppr mn,
    
    307 292
                          text "below:" <+> ppr (moduleGraphModulesBelow mg uid mn),
    
    ... ... @@ -309,14 +294,6 @@ hugSomeThingsBelowUs' combine acc include_hi_boot hsc_env uid mn
    309 294
                             -- This really shouldn't happen, but see #962
    
    310 295
         ]
    
    311 296
     
    
    312
    --- | Get things from modules in the transitive closure of the given module.
    
    313
    ---
    
    314
    --- Note: Don't expose this function. This is a footgun if exposed!
    
    315
    -hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
    
    316
    -hugSomeThingsBelowUs f = hugSomeThingsBelowUs' combine []
    
    317
    -  where
    
    318
    -    combine hmi acc = f hmi : acc
    
    319
    -
    
    320 297
     -- | Deal with gathering annotations in from all possible places
    
    321 298
     --   and combining them into a single 'AnnEnv'
    
    322 299
     prepareAnnotations :: HscEnv -> Maybe ModGuts -> IO AnnEnv
    

  • compiler/GHC/Tc/Instance/Family.hs
    ... ... @@ -25,7 +25,6 @@ import GHC.Core.TyCo.Rep
    25 25
     import GHC.Core.TyCo.FVs
    
    26 26
     
    
    27 27
     import GHC.Iface.Load
    
    28
    -import GHC.IO (unsafeInterleaveIO)
    
    29 28
     
    
    30 29
     import GHC.Tc.Errors.Types
    
    31 30
     import GHC.Tc.Types.Evidence
    
    ... ... @@ -287,8 +286,8 @@ why we still do redundant checks.
    287 286
     -- We don't need to check the current module, this is done in
    
    288 287
     -- tcExtendLocalFamInstEnv.
    
    289 288
     -- See Note [The type family instance consistency story].
    
    290
    -checkFamInstConsistency :: [Module] -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> TcM ()
    
    291
    -checkFamInstConsistency directlyImpMods hsc_env unitId mnwib
    
    289
    +checkFamInstConsistency :: ModuleEnv FamInstEnv -> [Module] -> TcM ()
    
    290
    +checkFamInstConsistency hpt_fam_insts directlyImpMods
    
    292 291
       = do { (eps, hug) <- getEpsAndHug
    
    293 292
            ; traceTc "checkFamInstConsistency" (ppr directlyImpMods)
    
    294 293
            ; let { -- Fetch the iface of a given module.  Must succeed as
    
    ... ... @@ -318,7 +317,6 @@ checkFamInstConsistency directlyImpMods hsc_env unitId mnwib
    318 317
                  -- See Note [Order of type family consistency checks]
    
    319 318
                  }
    
    320 319
     
    
    321
    -       ; hpt_fam_insts <- liftIO $ unsafeInterleaveIO $ hugFamInstancesBelow hsc_env unitId mnwib
    
    322 320
            ; debug_consistent_set <- mapM (\x -> (\y -> (x, length y)) <$> modConsistent x) directlyImpMods
    
    323 321
            ; traceTc "init_consistent_set" (ppr debug_consistent_set)
    
    324 322
            ; let init_consistent_set = map fst (reverse (sortOn snd debug_consistent_set))
    

  • compiler/GHC/Tc/Module.hs
    ... ... @@ -120,7 +120,7 @@ import GHC.Core.TyCo.Ppr( debugPprType )
    120 120
     import GHC.Core.TyCo.Tidy( tidyTopType )
    
    121 121
     import GHC.Core.FamInstEnv
    
    122 122
        ( FamInst, pprFamInst, famInstsRepTyCons, orphNamesOfFamInst
    
    123
    -   , famInstEnvElts, extendFamInstEnvList, normaliseType )
    
    123
    +   , famInstEnvElts, extendFamInstEnvList, normaliseType, emptyFamInstEnv, unionFamInstEnv )
    
    124 124
     
    
    125 125
     import GHC.Parser.Header       ( mkPrelImports )
    
    126 126
     
    
    ... ... @@ -467,8 +467,8 @@ tcRnImports hsc_env import_decls
    467 467
       = do  { (rn_imports, imp_user_spec, rdr_env, imports) <- rnImports import_decls
    
    468 468
             -- Get the default declarations for the classes imported by this module
    
    469 469
             -- and group them by class.
    
    470
    -        ; tc_defaults <-(NE.groupBy ((==) `on` cd_class) . (concatMap defaultList))
    
    471
    -                        <$> tcGetClsDefaults (M.keys $ imp_mods imports)
    
    470
    +        ; tc_defaults <- NE.groupBy ((==) `on` cd_class) . (concatMap defaultList)
    
    471
    +                         <$> tcGetClsDefaults (M.keys $ imp_mods imports)
    
    472 472
             ; this_mod <- getModule
    
    473 473
             ; gbl_env <- getGblEnv
    
    474 474
             ; let unitId = homeUnitId $ hsc_home_unit hsc_env
    
    ... ... @@ -480,8 +480,10 @@ tcRnImports hsc_env import_decls
    480 480
                     -- filtering also ensures that we don't see instances from
    
    481 481
                     -- modules batch (@--make@) compiled before this one, but
    
    482 482
                     -- which are not below this one.
    
    483
    -              ; (home_insts, home_fam_insts) <- liftIO $
    
    483
    +              ; (home_insts, home_mod_fam_inst_env) <- liftIO $
    
    484 484
                         hugInstancesBelow hsc_env unitId mnwib
    
    485
    +              ; let home_fam_inst_env = foldl' unionFamInstEnv emptyFamInstEnv $ snd <$> home_mod_fam_inst_env
    
    486
    +              ; let hpt_fam_insts = mkModuleEnv home_mod_fam_inst_env
    
    485 487
     
    
    486 488
                     -- We use 'unsafeInterleaveIO' to avoid redundant memory allocations
    
    487 489
                     -- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad
    
    ... ... @@ -507,8 +509,7 @@ tcRnImports hsc_env import_decls
    507 509
                   tcg_rn_imports   = rn_imports,
    
    508 510
                   tcg_default      = foldMap subsume tc_defaults,
    
    509 511
                   tcg_inst_env     = tcg_inst_env gbl `unionInstEnv` home_insts,
    
    510
    -              tcg_fam_inst_env = extendFamInstEnvList (tcg_fam_inst_env gbl)
    
    511
    -                                                      home_fam_insts
    
    512
    +              tcg_fam_inst_env = unionFamInstEnv (tcg_fam_inst_env gbl) home_fam_inst_env
    
    512 513
                 }) $ do {
    
    513 514
     
    
    514 515
             ; traceRn "rn1" (ppr (imp_direct_dep_mods imports))
    
    ... ... @@ -538,7 +539,7 @@ tcRnImports hsc_env import_decls
    538 539
                                  $ imports }
    
    539 540
             ; logger <- getLogger
    
    540 541
             ; withTiming logger (text "ConsistencyCheck"<+>brackets (ppr this_mod)) (const ())
    
    541
    -            $ checkFamInstConsistency dir_imp_mods hsc_env unitId mnwib
    
    542
    +            $ checkFamInstConsistency hpt_fam_insts dir_imp_mods
    
    542 543
             ; traceRn "rn1: } checking family instance consistency" empty
    
    543 544
     
    
    544 545
             ; gbl_env <- getGblEnv