[Git][ghc/ghc][wip/jeltsch/more-efficient-home-unit-imports-finding] 2 commits: Add output of debugging info to `findImportedModuleNoHsc`
Wolfgang Jeltsch pushed to branch wip/jeltsch/more-efficient-home-unit-imports-finding at Glasgow Haskell Compiler / GHC Commits: 4c979d15 by Wolfgang Jeltsch at 2026-04-28T16:31:45+03:00 Add output of debugging info to `findImportedModuleNoHsc` - - - - - 08bfb0b5 by fendor at 2026-04-28T16:32:44+03:00 Resolve two bugs These bugs made the following tests fail: * `boot1` * `multipleHomeUnits_reexport` * `t25139` - - - - - 1 changed file: - compiler/GHC/Unit/Finder.hs Changes: ===================================== compiler/GHC/Unit/Finder.hs ===================================== @@ -214,7 +214,6 @@ findImportedModuleNoHsc fc fopts ue complete_home_units mb_home_unit mod_name mb | otherwise -> pprPanic "findImportModule" (ppr mod_name $$ ppr mb_pkg $$ ppr (homeUnitId <$> mb_home_unit) $$ ppr uid $$ ppr (map fst all_opts)) OtherPkg _ -> pkg_import where - cached_module_providers = M.findWithDefault Set.empty mod_name (cu_providers complete_home_units) mb_home_unit_id = homeUnitId <$> mb_home_unit all_opts = case mb_home_unit_id of Nothing -> other_fopts @@ -249,21 +248,42 @@ findImportedModuleNoHsc fc fopts ue complete_home_units mb_home_unit mod_name mb units = case mb_home_unit_id of Nothing -> ue_homeUnitState ue Just home_unit_id -> HUG.homeUnitEnv_units $ ue_findHomeUnitEnv home_unit_id ue + hpt_deps :: Set.Set UnitId hpt_deps = homeUnitDepends units + + -- TODO: this predicate is wrong, we need something more focused + sorted_deps = case finder_lookupHomeInterfaces fopts of + True -> Set.toList hpt_deps + False -> sortHomeUnitsByLikelihoodFor complete_home_units mb_home_unit_id mod_name hpt_deps + + other_fopts = + [ (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue))) + | uid <- sorted_deps + ] + +sortHomeUnitsByLikelihoodFor :: CompleteUnits -> Maybe UnitId -> ModuleName -> Set.Set UnitId -> [UnitId] +sortHomeUnitsByLikelihoodFor complete_home_units mb_home_unit_id mod_name hpt_deps = + let + cached_module_providers = M.findWithDefault Set.empty mod_name (cu_providers complete_home_units) cached_providing_deps = Set.intersection cached_module_providers hpt_deps other_cached_providing_deps = Set.toList $ maybe cached_providing_deps (\u -> Set.delete u cached_providing_deps) mb_home_unit_id uncached_providing_deps = - let candidates = Set.difference hpt_deps (cu_inventory complete_home_units) + let candidates = Set.difference hpt_deps cached_module_providers excluded = maybe cached_providing_deps (\u -> Set.insert u cached_providing_deps) mb_home_unit_id in Set.toList (Set.difference candidates excluded) - other_providing_deps = other_cached_providing_deps ++ uncached_providing_deps - other_fopts = - [ (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue))) - | uid <- other_providing_deps - ] + + all_deps = other_cached_providing_deps ++ uncached_providing_deps + in + assertPpr + (hpt_deps == Set.fromList all_deps) + ( text "Sorting must not remove HomeUnits" + $$ text "Module:" <+> ppr mod_name + $$ text "Original:" <+> ppr hpt_deps + $$ text "Sorted: " <+> ppr (Set.fromList all_deps)) + all_deps -- | Locate a plugin module requested by the user, for a compiler -- plugin. This consults the same set of exposed packages as View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/48eb7156920d3a5b6ce2fd7ea8be3c6... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/48eb7156920d3a5b6ce2fd7ea8be3c6... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Wolfgang Jeltsch (@jeltsch)