From d577cbc2def66692ccc63c3319cc206838bc1762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zal=C3=A1n=20B=C3=A1lint=20L=C3=A9vai?= Date: Sun, 9 Aug 2026 16:11:03 +0100 Subject: [PATCH] Fix visible_parent_map fallback map merging perf regression --- .../src/rmeta/decoder/cstore_impl.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index a9d524711a141..3f73b14fb85ee 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::mem; use std::sync::Arc; -use rustc_data_structures::unord::ExtendUnord; +use rustc_data_structures::fx::FxHashMap; use rustc_hir::attrs::Deprecation; use rustc_hir::def::{CtorKind, DefKind}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE}; @@ -473,7 +473,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { // the former. // This is a rudimentary check that does not catch all cases, // just the easiest. - let mut fallback_map: DefIdMap = Default::default(); + let mut fallback_map: FxHashMap = Default::default(); // Issue 46112: We want the map to prefer the shortest // paths when reporting the path to an item. Therefore we @@ -574,10 +574,16 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { // We must extend the fallback map with items from the visible parent map // as the extend call overrides existing entries from the latter map, // which we prefer over fallback entries. - let mut merged_visible_parent_map = fallback_map; - merged_visible_parent_map.extend_unord(visible_parent_map.into_items()); + // FIXME: The Unord* APIs lack an efficient way of merging + // the values of one map for only the missing keys of the other map, + // which is required to merge the fallback map into the visible parent map. + // In the meantime, use an "ordered" map internally for fallback entries. + #[allow(rustc::potential_query_instability)] + for (child, parent) in fallback_map { + visible_parent_map.entry(child).or_insert(parent); + } - merged_visible_parent_map + visible_parent_map }, dependency_formats: |tcx, ()| Arc::new(crate::dependency_format::calculate(tcx)),