Remove StableVec.

This commit is contained in:
Camille GILLOT 2021-05-11 10:38:54 +02:00
parent e291be3649
commit 273778086c
6 changed files with 8 additions and 41 deletions

View file

@ -44,7 +44,6 @@ use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::StableVec;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
@ -506,7 +505,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
for (k, v) in self.resolver.trait_map().into_iter() {
if let Some(Some(hir_id)) = self.node_id_to_hir_id.get(k) {
let map = trait_map.entry(hir_id.owner).or_default();
map.insert(hir_id.local_id, StableVec::new(v.to_vec()));
map.insert(hir_id.local_id, v.into_boxed_slice());
}
}

View file

@ -550,35 +550,3 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>(
entries.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
entries.hash_stable(hcx, hasher);
}
/// A vector container that makes sure that its items are hashed in a stable
/// order.
#[derive(Debug)]
pub struct StableVec<T>(Vec<T>);
impl<T> StableVec<T> {
pub fn new(v: Vec<T>) -> Self {
StableVec(v)
}
}
impl<T> ::std::ops::Deref for StableVec<T> {
type Target = Vec<T>;
fn deref(&self) -> &Vec<T> {
&self.0
}
}
impl<T, HCX> HashStable<HCX> for StableVec<T>
where
T: HashStable<HCX> + ToStableHashKey<HCX>,
{
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
let StableVec(ref v) = *self;
let mut sorted: Vec<_> = v.iter().map(|x| x.to_stable_hash_key(hcx)).collect();
sorted.sort_unstable();
sorted.hash_stable(hcx, hasher);
}
}

View file

@ -11,7 +11,6 @@ pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
pub use rustc_ast::{CaptureBy, Movability, Mutability};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::StableVec;
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
use rustc_macros::HashStable_Generic;
use rustc_span::source_map::Spanned;
@ -662,7 +661,7 @@ pub struct Crate<'hir> {
/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
pub trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, StableVec<TraitCandidate>>>,
pub trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Box<[TraitCandidate]>>>,
/// Collected attributes from HIR nodes.
pub attrs: BTreeMap<HirId, &'hir [Attribute]>,

View file

@ -1127,7 +1127,7 @@ rustc_queries! {
desc { "computing whether impls specialize one another" }
}
query in_scope_traits_map(_: LocalDefId)
-> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
-> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
desc { "traits in scope at a block" }
}

View file

@ -31,7 +31,7 @@ use rustc_attr as attr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableVec};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
use rustc_errors::ErrorReported;
@ -2651,8 +2651,10 @@ impl<'tcx> TyCtxt<'tcx> {
struct_lint_level(self.sess, lint, level, src, None, decorate);
}
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx StableVec<TraitCandidate>> {
self.in_scope_traits_map(id.owner).and_then(|map| map.get(&id.local_id))
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> {
let map = self.in_scope_traits_map(id.owner)?;
let candidates = map.get(&id.local_id)?;
Some(&*candidates)
}
pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> {

View file

@ -34,7 +34,6 @@ use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::util::AlwaysRequiresDrop;
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::stable_hasher::StableVec;
use rustc_data_structures::steal::Steal;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::Lrc;