Skip to content

Commit

Permalink
Auto merge of #53659 - nnethercote:rm-AccumulateVec, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Remove `AccumulateVec` and its uses.

It's basically just a less capable version of `SmallVec`.

FWIW, the only use of `ArrayVec` is now within `HybridIdxSet`.

r? @Mark-Simulacrum
  • Loading branch information
bors committed Aug 29, 2018
2 parents 9d69e81 + 8cecfa6 commit 29e6aab
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 301 deletions.
1 change: 1 addition & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,7 @@ dependencies = [
"rustc_errors 0.0.0",
"rustc_platform_intrinsics 0.0.0",
"rustc_target 0.0.0",
"smallvec 0.6.5 (registry+/~https://github.com/rust-lang/crates.io-index)",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use syntax_pos::hygiene;
use rustc_data_structures::stable_hasher::{HashStable,
StableHasher, StableHasherResult,
ToStableHashKey};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use smallvec::SmallVec;

fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
R: std_hash::BuildHasher,
{
{
let mut blanket_impls: AccumulateVec<[_; 8]> = blanket_impls
let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls
.iter()
.map(|&def_id| hcx.def_path_hash(def_id))
.collect();
Expand All @@ -418,15 +418,15 @@ pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
}

{
let mut keys: AccumulateVec<[_; 8]> =
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 : AccumulateVec<[_; 8]> = non_blanket_impls[key]
let mut impls : SmallVec<[_; 8]> = non_blanket_impls[key]
.iter()
.map(|&impl_id| hcx.def_path_hash(impl_id))
.collect();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use syntax_pos::SourceFile;

use hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};

use smallvec::SmallVec;
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
StableHasher, StableHasherResult};
use rustc_data_structures::accumulate_vec::AccumulateVec;

impl<'a> HashStable<StableHashingContext<'a>> for InternedString {
#[inline]
Expand Down Expand Up @@ -207,7 +207,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
}

// Some attributes are always ignored during hashing.
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
let filtered: SmallVec<[&ast::Attribute; 8]> = self
.iter()
.filter(|attr| {
!attr.is_sugared_doc && !hcx.is_ignored_attr(attr.name())
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use chalk_engine;
use rustc_data_structures::accumulate_vec::AccumulateVec;
use smallvec::SmallVec;
use traits;
use traits::project::Normalized;
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
Expand Down Expand Up @@ -624,7 +624,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<traits::Goal<'tcx>> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter()
.map(|t| t.fold_with(folder))
.collect::<AccumulateVec<[_; 8]>>();
.collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_goals(&v)
}

Expand Down Expand Up @@ -662,7 +662,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<traits::Clause<'tcx>> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter()
.map(|t| t.fold_with(folder))
.collect::<AccumulateVec<[_; 8]>>();
.collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_clauses(&v)
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use ty::BindingMode;
use ty::CanonicalTy;
use util::nodemap::{DefIdSet, ItemLocalMap};
use util::nodemap::{FxHashMap, FxHashSet};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use smallvec::SmallVec;
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
StableHasher, StableHasherResult,
StableVec};
Expand Down Expand Up @@ -2840,7 +2840,7 @@ pub trait InternIteratorElement<T, R>: Sized {
impl<T, R> InternIteratorElement<T, R> for T {
type Output = R;
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
f(&iter.collect::<AccumulateVec<[_; 8]>>())
f(&iter.collect::<SmallVec<[_; 8]>>())
}
}

Expand All @@ -2849,14 +2849,14 @@ impl<'a, T, R> InternIteratorElement<T, R> for &'a T
{
type Output = R;
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
f(&iter.cloned().collect::<AccumulateVec<[_; 8]>>())
f(&iter.cloned().collect::<SmallVec<[_; 8]>>())
}
}

impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
type Output = Result<R, E>;
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
Ok(f(&iter.collect::<Result<AccumulateVec<[_; 8]>, _>>()?))
Ok(f(&iter.collect::<Result<SmallVec<[_; 8]>, _>>()?))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use mir::interpret::{ConstValue, ConstEvalErr};
use ty::{self, Lift, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use smallvec::SmallVec;
use mir::interpret;

use std::rc::Rc;
Expand Down Expand Up @@ -741,7 +741,7 @@ BraceStructTypeFoldableImpl! {

impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_existential_predicates(&v)
}

Expand All @@ -760,7 +760,7 @@ EnumTypeFoldableImpl! {

impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_type_list(&v)
}

Expand Down Expand Up @@ -1016,7 +1016,7 @@ BraceStructTypeFoldableImpl! {

impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_predicates(&v)
}

Expand Down
20 changes: 6 additions & 14 deletions src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};

use serialize::{self, Encodable, Encoder, Decodable, Decoder};
use syntax_pos::{Span, DUMMY_SP};
use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::array_vec::ArrayVec;
use rustc_data_structures::indexed_vec::Idx;
use smallvec::SmallVec;

use core::intrinsics;
use std::cmp::Ordering;
Expand Down Expand Up @@ -203,11 +202,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
{
let defs = tcx.generics_of(def_id);
let count = defs.count();
let mut substs = if count <= 8 {
AccumulateVec::Array(ArrayVec::new())
} else {
AccumulateVec::Heap(Vec::with_capacity(count))
};
let mut substs = SmallVec::with_capacity(count);
Substs::fill_item(&mut substs, tcx, defs, &mut mk_kind);
tcx.intern_substs(&substs)
}
Expand All @@ -227,7 +222,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
})
}

fn fill_item<F>(substs: &mut AccumulateVec<[Kind<'tcx>; 8]>,
fn fill_item<F>(substs: &mut SmallVec<[Kind<'tcx>; 8]>,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
defs: &ty::Generics,
mk_kind: &mut F)
Expand All @@ -240,18 +235,15 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
Substs::fill_single(substs, defs, mk_kind)
}

fn fill_single<F>(substs: &mut AccumulateVec<[Kind<'tcx>; 8]>,
fn fill_single<F>(substs: &mut SmallVec<[Kind<'tcx>; 8]>,
defs: &ty::Generics,
mk_kind: &mut F)
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
{
for param in &defs.params {
let kind = mk_kind(param, substs);
assert_eq!(param.index as usize, substs.len());
match *substs {
AccumulateVec::Array(ref mut arr) => arr.push(kind),
AccumulateVec::Heap(ref mut vec) => vec.push(kind),
}
substs.push(kind);
}
}

Expand Down Expand Up @@ -325,7 +317,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {

impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let params: AccumulateVec<[_; 8]> = self.iter().map(|k| k.fold_with(folder)).collect();
let params: SmallVec<[_; 8]> = self.iter().map(|k| k.fold_with(folder)).collect();

// If folding doesn't change the substs, it's faster to avoid
// calling `mk_substs` and instead reuse the existing substs.
Expand Down
Loading

0 comments on commit 29e6aab

Please sign in to comment.