Auto merge of #106977 - michaelwoerister:unord_id_collections, r=oli-obk
Use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc) This PR changes the `rustc_data_structures::define_id_collections!` macro to use `UnordMap` and `UnordSet` instead of `FxHashMap` and `FxHashSet`. This should account for a large portion of hash-maps being used in places where they can cause trouble. The changes required are moderate but non-zero: - In some places the collections are extracted into sorted vecs. - There are a few instances where for-loops have been changed to extends. ~~Let's see what the performance impact is. With a bit more refactoring, we might be able to get rid of some of the additional sorting -- but the change set is already big enough. Unless there's a performance impact, I'd like to do further changes in subsequent PRs.~~ Performance does not seem to be negatively affected ([perf-run here](https://github.com/rust-lang/rust/pull/106977#issuecomment-1396776699)). Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533). r? `@ghost`
This commit is contained in:
commit
005fc0f00f
18 changed files with 393 additions and 118 deletions
|
@ -38,7 +38,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::Node;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_macros::HashStable;
|
||||
|
@ -436,7 +436,7 @@ pub struct CrateVariancesMap<'tcx> {
|
|||
/// For each item with generics, maps to a vector of the variance
|
||||
/// of its generics. If an item has no generics, it will have no
|
||||
/// entry.
|
||||
pub variances: FxHashMap<DefId, &'tcx [ty::Variance]>,
|
||||
pub variances: DefIdMap<&'tcx [ty::Variance]>,
|
||||
}
|
||||
|
||||
// Contains information needed to resolve types and (in the future) look up
|
||||
|
|
|
@ -6,7 +6,12 @@ use crate::{
|
|||
GenericArgKind, InternalSubsts, SubstsRef, Ty, UserSubsts,
|
||||
},
|
||||
};
|
||||
use rustc_data_structures::{fx::FxHashMap, sync::Lrc, unord::UnordSet, vec_map::VecMap};
|
||||
use rustc_data_structures::{
|
||||
fx::FxHashMap,
|
||||
sync::Lrc,
|
||||
unord::{UnordItems, UnordSet},
|
||||
vec_map::VecMap,
|
||||
};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::{
|
||||
|
@ -20,11 +25,7 @@ use rustc_macros::HashStable;
|
|||
use rustc_middle::mir::FakeReadCause;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
use std::{
|
||||
collections::hash_map::{self, Entry},
|
||||
hash::Hash,
|
||||
iter,
|
||||
};
|
||||
use std::{collections::hash_map::Entry, hash::Hash, iter};
|
||||
|
||||
use super::RvalueScopes;
|
||||
|
||||
|
@ -567,8 +568,15 @@ impl<'a, V> LocalTableInContext<'a, V> {
|
|||
self.data.get(&id.local_id)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> hash_map::Iter<'_, hir::ItemLocalId, V> {
|
||||
self.data.iter()
|
||||
pub fn items(
|
||||
&'a self,
|
||||
) -> UnordItems<(hir::ItemLocalId, &'a V), impl Iterator<Item = (hir::ItemLocalId, &'a V)>>
|
||||
{
|
||||
self.data.items().map(|(id, value)| (*id, value))
|
||||
}
|
||||
|
||||
pub fn items_in_stable_order(&self) -> Vec<(ItemLocalId, &'a V)> {
|
||||
self.data.to_sorted_stable_ord()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -605,6 +613,16 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
|
|||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||
self.data.remove(&id.local_id)
|
||||
}
|
||||
|
||||
pub fn extend(
|
||||
&mut self,
|
||||
items: UnordItems<(hir::HirId, V), impl Iterator<Item = (hir::HirId, V)>>,
|
||||
) {
|
||||
self.data.extend(items.map(|(id, value)| {
|
||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||
(id.local_id, value)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue