Wolfgang Jeltsch pushed to branch wip/jeltsch/more-efficient-home-unit-imports-finding at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -252,25 +252,37 @@ findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit
    252 252
         hpt_deps :: Set.Set UnitId
    
    253 253
         hpt_deps = homeUnitDepends units
    
    254 254
     
    
    255
    -    sorted_deps = sortHomeUnitsByLikelihoodFor home_module_name_providers_map mod_name hpt_deps
    
    255
    +    sorted_deps = rankedHomeUnits home_module_name_providers_map mod_name hpt_deps
    
    256 256
     
    
    257 257
         other_fopts =
    
    258 258
           [ (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))
    
    259 259
           | uid <- sorted_deps
    
    260 260
           ]
    
    261 261
     
    
    262
    -sortHomeUnitsByLikelihoodFor :: HomeModuleNameProvidersMap -> ModuleName -> Set.Set UnitId -> [UnitId]
    
    263
    -sortHomeUnitsByLikelihoodFor _ _ hpt_deps | Set.null hpt_deps = []
    
    262
    +rankedHomeUnits :: HomeModuleNameProvidersMap
    
    263
    +                -> ModuleName
    
    264
    +                -> Set.Set UnitId
    
    265
    +                -> [UnitId]
    
    266
    +rankedHomeUnits _ _ hpt_deps | Set.null hpt_deps
    
    267
    +    = []
    
    268
    +rankedHomeUnits home_module_name_providers_map mod_name hpt_deps
    
    269
    +    = Set.toList cached_deps ++ Set.toList uncached_deps
    
    270
    +    where
    
    271
    +
    
    272
    +    cached_providers :: Set.Set UnitId
    
    273
    +    cached_providers = lookupWithDefaultUniqMap home_module_name_providers_map
    
    274
    +                                                Set.empty
    
    275
    +                                                mod_name
    
    276
    +
    
    277
    +    cached_deps :: Set.Set UnitId
    
    278
    +    cached_deps = Set.intersection hpt_deps cached_providers
    
    279
    +
    
    280
    +    uncached_deps :: Set.Set UnitId
    
    281
    +    uncached_deps = Set.difference hpt_deps cached_providers
    
    264 282
     {-
    
    265
    -    With the above shortcut, evaluation of the module graph will not be
    
    266
    -    triggered.
    
    283
    +    The special handling of the case that the dependency set is empty does not
    
    284
    +    change the result, but it avoids triggering evaluation of the module graph.
    
    267 285
     -}
    
    268
    -sortHomeUnitsByLikelihoodFor home_module_name_providers_map mod_name hpt_deps =
    
    269
    -  let
    
    270
    -    cached_module_providers = lookupWithDefaultUniqMap home_module_name_providers_map Set.empty mod_name
    
    271
    -    cached_providing_deps = Set.toList (Set.intersection hpt_deps cached_module_providers)
    
    272
    -    uncached_providing_deps = Set.toList (Set.difference hpt_deps cached_module_providers)
    
    273
    -  in cached_providing_deps ++ uncached_providing_deps
    
    274 286
     
    
    275 287
     -- | Locate a plugin module requested by the user, for a compiler
    
    276 288
     -- plugin.  This consults the same set of exposed packages as
    

  • compiler/GHC/Unit/Module/Graph.hs
    ... ... @@ -206,7 +206,7 @@ data ModuleGraph = ModuleGraph
    206 206
       -- Cached computation, whether any of the ModuleGraphNode are isHoleModule,
    
    207 207
       -- This is only used for a hack in GHC.Iface.Load to do with backpack, please
    
    208 208
       -- remove this at the earliest opportunity.
    
    209
    -  , mg_home_module_name_providers_map :: !HomeModuleNameProvidersMap
    
    209
    +  , mg_home_module_name_providers_map :: HomeModuleNameProvidersMap
    
    210 210
         -- ^ For each module name, which home units provide it.
    
    211 211
       }
    
    212 212