Skip to content

Commit 5b9cc20

Browse files
committed
use indexmap instead of hashmap
1 parent ca2c55d commit 5b9cc20

File tree

5 files changed

+10
-71
lines changed

5 files changed

+10
-71
lines changed

compiler/rustc_middle/src/ich/hcx.rs

+2-41
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::ich;
22
use crate::middle::cstore::CrateStore;
3-
use crate::ty::{fast_reject, TyCtxt};
3+
use crate::ty::TyCtxt;
44

55
use rustc_ast as ast;
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6+
use rustc_data_structures::fx::FxHashSet;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_data_structures::sync::Lrc;
99
use rustc_hir as hir;
@@ -14,9 +14,6 @@ use rustc_span::source_map::SourceMap;
1414
use rustc_span::symbol::Symbol;
1515
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData};
1616

17-
use smallvec::SmallVec;
18-
use std::cmp::Ord;
19-
2017
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
2118
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
2219
ich::IGNORED_ATTRIBUTES.iter().copied().collect()
@@ -241,39 +238,3 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
241238
}
242239

243240
impl rustc_session::HashStableContext for StableHashingContext<'a> {}
244-
245-
pub fn hash_stable_trait_impls<'a>(
246-
hcx: &mut StableHashingContext<'a>,
247-
hasher: &mut StableHasher,
248-
blanket_impls: &[DefId],
249-
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
250-
) {
251-
{
252-
let mut blanket_impls: SmallVec<[_; 8]> =
253-
blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect();
254-
255-
if blanket_impls.len() > 1 {
256-
blanket_impls.sort_unstable();
257-
}
258-
259-
blanket_impls.hash_stable(hcx, hasher);
260-
}
261-
262-
{
263-
let mut keys: SmallVec<[_; 8]> =
264-
non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect();
265-
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
266-
keys.len().hash_stable(hcx, hasher);
267-
for (key, ref stable_key) in keys {
268-
stable_key.hash_stable(hcx, hasher);
269-
let mut impls: SmallVec<[_; 8]> =
270-
non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect();
271-
272-
if impls.len() > 1 {
273-
impls.sort_unstable();
274-
}
275-
276-
impls.hash_stable(hcx, hasher);
277-
}
278-
}
279-
}

compiler/rustc_middle/src/ich/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! ICH - Incremental Compilation Hash
22
3-
pub use self::hcx::{
4-
hash_stable_trait_impls, NodeIdHashingMode, StableHashingContext, StableHashingContextProvider,
5-
};
3+
pub use self::hcx::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider};
64
use rustc_span::symbol::{sym, Symbol};
75

86
mod hcx;

compiler/rustc_middle/src/traits/specialization_graph.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use crate::ich::{self, StableHashingContext};
21
use crate::ty::fast_reject::SimplifiedType;
32
use crate::ty::fold::TypeFoldable;
43
use crate::ty::{self, TyCtxt};
5-
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4+
use rustc_data_structures::fx::FxIndexMap;
75
use rustc_errors::ErrorReported;
86
use rustc_hir::def_id::{DefId, DefIdMap};
97
use rustc_span::symbol::Ident;
@@ -50,7 +48,7 @@ impl Graph {
5048

5149
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
5250
/// done in `TraitDef`.
53-
#[derive(Default, TyEncodable, TyDecodable, Debug)]
51+
#[derive(Default, TyEncodable, TyDecodable, Debug, HashStable)]
5452
pub struct Children {
5553
// Impls of a trait (or specializations of a given impl). To allow for
5654
// quicker lookup, the impls are indexed by a simplified version of their
@@ -62,7 +60,7 @@ pub struct Children {
6260
// together *all* the impls for a trait, and are populated prior to building
6361
// the specialization graph.
6462
/// Impls of the trait.
65-
pub non_blanket_impls: FxHashMap<SimplifiedType, Vec<DefId>>,
63+
pub non_blanket_impls: FxIndexMap<SimplifiedType, Vec<DefId>>,
6664

6765
/// Blanket impls associated with the trait.
6866
pub blanket_impls: Vec<DefId>,
@@ -235,11 +233,3 @@ pub fn ancestors(
235233
})
236234
}
237235
}
238-
239-
impl<'a> HashStable<StableHashingContext<'a>> for Children {
240-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
241-
let Children { ref non_blanket_impls, ref blanket_impls } = *self;
242-
243-
ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls);
244-
}
245-
}

compiler/rustc_middle/src/ty/trait_def.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::ich::{self, StableHashingContext};
21
use crate::traits::specialization_graph;
32
use crate::ty::fast_reject;
43
use crate::ty::fold::TypeFoldable;
@@ -7,8 +6,7 @@ use rustc_hir as hir;
76
use rustc_hir::def_id::DefId;
87
use rustc_hir::definitions::DefPathHash;
98

10-
use rustc_data_structures::fx::FxHashMap;
11-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
9+
use rustc_data_structures::fx::FxIndexMap;
1210
use rustc_errors::ErrorReported;
1311
use rustc_macros::HashStable;
1412

@@ -66,11 +64,11 @@ pub enum TraitSpecializationKind {
6664
AlwaysApplicable,
6765
}
6866

69-
#[derive(Default, Debug)]
67+
#[derive(Default, Debug, HashStable)]
7068
pub struct TraitImpls {
7169
blanket_impls: Vec<DefId>,
7270
/// Impls indexed by their simplified self type, for fast lookup.
73-
non_blanket_impls: FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
71+
non_blanket_impls: FxIndexMap<fast_reject::SimplifiedType, Vec<DefId>>,
7472
}
7573

7674
impl TraitImpls {
@@ -249,11 +247,3 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
249247

250248
impls
251249
}
252-
253-
impl<'a> HashStable<StableHashingContext<'a>> for TraitImpls {
254-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
255-
let TraitImpls { ref blanket_impls, ref non_blanket_impls } = *self;
256-
257-
ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls);
258-
}
259-
}

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl ChildrenExt for Children {
216216
}
217217

218218
fn iter_children(children: &mut Children) -> impl Iterator<Item = DefId> + '_ {
219-
let nonblanket = children.non_blanket_impls.iter_mut().flat_map(|(_, v)| v.iter());
219+
let nonblanket = children.non_blanket_impls.iter().flat_map(|(_, v)| v.iter());
220220
children.blanket_impls.iter().chain(nonblanket).cloned()
221221
}
222222

0 commit comments

Comments
 (0)