Skip to content

Commit

Permalink
Remove StableVec.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jun 1, 2021
1 parent e291be3 commit 2737780
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 41 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
32 changes: 0 additions & 32 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_hir/src/hir.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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]>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Expand Up @@ -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" }
}

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/query/mod.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 2737780

Please sign in to comment.