[Git][ghc/ghc][wip/jeltsch/more-efficient-home-unit-imports-finding] 2 commits: Polish the code for home module ranking
Wolfgang Jeltsch pushed to branch wip/jeltsch/more-efficient-home-unit-imports-finding at Glasgow Haskell Compiler / GHC Commits: 6ab43ba8 by Wolfgang Jeltsch at 2026-04-29T14:52:41+03:00 Polish the code for home module ranking - - - - - 46de7d57 by Wolfgang Jeltsch at 2026-04-29T14:52:52+03:00 Make the `mg_home_module_name_providers_map` field lazy - - - - - 2 changed files: - compiler/GHC/Unit/Finder.hs - compiler/GHC/Unit/Module/Graph.hs Changes: ===================================== compiler/GHC/Unit/Finder.hs ===================================== @@ -252,25 +252,37 @@ findImportedModuleNoHsc fc fopts ue home_module_name_providers_map mb_home_unit hpt_deps :: Set.Set UnitId hpt_deps = homeUnitDepends units - sorted_deps = sortHomeUnitsByLikelihoodFor home_module_name_providers_map mod_name hpt_deps + sorted_deps = rankedHomeUnits home_module_name_providers_map mod_name hpt_deps other_fopts = [ (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue))) | uid <- sorted_deps ] -sortHomeUnitsByLikelihoodFor :: HomeModuleNameProvidersMap -> ModuleName -> Set.Set UnitId -> [UnitId] -sortHomeUnitsByLikelihoodFor _ _ hpt_deps | Set.null hpt_deps = [] +rankedHomeUnits :: HomeModuleNameProvidersMap + -> ModuleName + -> Set.Set UnitId + -> [UnitId] +rankedHomeUnits _ _ hpt_deps | Set.null hpt_deps + = [] +rankedHomeUnits home_module_name_providers_map mod_name hpt_deps + = Set.toList cached_deps ++ Set.toList uncached_deps + where + + cached_providers :: Set.Set UnitId + cached_providers = lookupWithDefaultUniqMap home_module_name_providers_map + Set.empty + mod_name + + cached_deps :: Set.Set UnitId + cached_deps = Set.intersection hpt_deps cached_providers + + uncached_deps :: Set.Set UnitId + uncached_deps = Set.difference hpt_deps cached_providers {- - With the above shortcut, evaluation of the module graph will not be - triggered. + The special handling of the case that the dependency set is empty does not + change the result, but it avoids triggering evaluation of the module graph. -} -sortHomeUnitsByLikelihoodFor home_module_name_providers_map mod_name hpt_deps = - let - cached_module_providers = lookupWithDefaultUniqMap home_module_name_providers_map Set.empty mod_name - cached_providing_deps = Set.toList (Set.intersection hpt_deps cached_module_providers) - uncached_providing_deps = Set.toList (Set.difference hpt_deps cached_module_providers) - in cached_providing_deps ++ uncached_providing_deps -- | Locate a plugin module requested by the user, for a compiler -- plugin. This consults the same set of exposed packages as ===================================== compiler/GHC/Unit/Module/Graph.hs ===================================== @@ -206,7 +206,7 @@ data ModuleGraph = ModuleGraph -- Cached computation, whether any of the ModuleGraphNode are isHoleModule, -- This is only used for a hack in GHC.Iface.Load to do with backpack, please -- remove this at the earliest opportunity. - , mg_home_module_name_providers_map :: !HomeModuleNameProvidersMap + , mg_home_module_name_providers_map :: HomeModuleNameProvidersMap -- ^ For each module name, which home units provide it. } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/54eb5564af32c490e9493d966c67be0... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/54eb5564af32c490e9493d966c67be0... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Wolfgang Jeltsch (@jeltsch)