1
Fork 0

use indexmap instead of hashmap

This commit is contained in:
lcnr 2021-09-16 17:53:50 +02:00
parent ca2c55d264
commit 5b9cc2068f
5 changed files with 10 additions and 71 deletions

View file

@ -1,9 +1,9 @@
use crate::ich;
use crate::middle::cstore::CrateStore;
use crate::ty::{fast_reject, TyCtxt};
use crate::ty::TyCtxt;
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
@ -14,9 +14,6 @@ use rustc_span::source_map::SourceMap;
use rustc_span::symbol::Symbol;
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData};
use smallvec::SmallVec;
use std::cmp::Ord;
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
ich::IGNORED_ATTRIBUTES.iter().copied().collect()
@ -241,39 +238,3 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
}
impl rustc_session::HashStableContext for StableHashingContext<'a> {}
pub fn hash_stable_trait_impls<'a>(
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher,
blanket_impls: &[DefId],
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
) {
{
let mut blanket_impls: SmallVec<[_; 8]> =
blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect();
if blanket_impls.len() > 1 {
blanket_impls.sort_unstable();
}
blanket_impls.hash_stable(hcx, hasher);
}
{
let mut keys: SmallVec<[_; 8]> =
non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect();
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
keys.len().hash_stable(hcx, hasher);
for (key, ref stable_key) in keys {
stable_key.hash_stable(hcx, hasher);
let mut impls: SmallVec<[_; 8]> =
non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect();
if impls.len() > 1 {
impls.sort_unstable();
}
impls.hash_stable(hcx, hasher);
}
}
}

View file

@ -1,8 +1,6 @@
//! ICH - Incremental Compilation Hash
pub use self::hcx::{
hash_stable_trait_impls, NodeIdHashingMode, StableHashingContext, StableHashingContextProvider,
};
pub use self::hcx::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider};
use rustc_span::symbol::{sym, Symbol};
mod hcx;

View file

@ -1,9 +1,7 @@
use crate::ich::{self, StableHashingContext};
use crate::ty::fast_reject::SimplifiedType;
use crate::ty::fold::TypeFoldable;
use crate::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::ErrorReported;
use rustc_hir::def_id::{DefId, DefIdMap};
use rustc_span::symbol::Ident;
@ -50,7 +48,7 @@ impl Graph {
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
/// done in `TraitDef`.
#[derive(Default, TyEncodable, TyDecodable, Debug)]
#[derive(Default, TyEncodable, TyDecodable, Debug, HashStable)]
pub struct Children {
// Impls of a trait (or specializations of a given impl). To allow for
// quicker lookup, the impls are indexed by a simplified version of their
@ -62,7 +60,7 @@ pub struct Children {
// together *all* the impls for a trait, and are populated prior to building
// the specialization graph.
/// Impls of the trait.
pub non_blanket_impls: FxHashMap<SimplifiedType, Vec<DefId>>,
pub non_blanket_impls: FxIndexMap<SimplifiedType, Vec<DefId>>,
/// Blanket impls associated with the trait.
pub blanket_impls: Vec<DefId>,
@ -235,11 +233,3 @@ pub fn ancestors(
})
}
}
impl<'a> HashStable<StableHashingContext<'a>> for Children {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let Children { ref non_blanket_impls, ref blanket_impls } = *self;
ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls);
}
}

View file

@ -1,4 +1,3 @@
use crate::ich::{self, StableHashingContext};
use crate::traits::specialization_graph;
use crate::ty::fast_reject;
use crate::ty::fold::TypeFoldable;
@ -7,8 +6,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathHash;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::ErrorReported;
use rustc_macros::HashStable;
@ -66,11 +64,11 @@ pub enum TraitSpecializationKind {
AlwaysApplicable,
}
#[derive(Default, Debug)]
#[derive(Default, Debug, HashStable)]
pub struct TraitImpls {
blanket_impls: Vec<DefId>,
/// Impls indexed by their simplified self type, for fast lookup.
non_blanket_impls: FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
non_blanket_impls: FxIndexMap<fast_reject::SimplifiedType, Vec<DefId>>,
}
impl TraitImpls {
@ -249,11 +247,3 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
impls
}
impl<'a> HashStable<StableHashingContext<'a>> for TraitImpls {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let TraitImpls { ref blanket_impls, ref non_blanket_impls } = *self;
ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls);
}
}

View file

@ -216,7 +216,7 @@ impl ChildrenExt for Children {
}
fn iter_children(children: &mut Children) -> impl Iterator<Item = DefId> + '_ {
let nonblanket = children.non_blanket_impls.iter_mut().flat_map(|(_, v)| v.iter());
let nonblanket = children.non_blanket_impls.iter().flat_map(|(_, v)| v.iter());
children.blanket_impls.iter().chain(nonblanket).cloned()
}