Skip to content

Commit 8cecfa6

Browse files
committed
Remove AccumulateVec and its uses.
It's basically just a less capable version of `SmallVec`.
1 parent 7061b27 commit 8cecfa6

File tree

13 files changed

+40
-301
lines changed

13 files changed

+40
-301
lines changed

Diff for: src/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@ dependencies = [
23542354
"rustc_errors 0.0.0",
23552355
"rustc_platform_intrinsics 0.0.0",
23562356
"rustc_target 0.0.0",
2357+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
23572358
"syntax 0.0.0",
23582359
"syntax_pos 0.0.0",
23592360
]

Diff for: src/librustc/ich/hcx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use syntax_pos::hygiene;
3434
use rustc_data_structures::stable_hasher::{HashStable,
3535
StableHasher, StableHasherResult,
3636
ToStableHashKey};
37-
use rustc_data_structures::accumulate_vec::AccumulateVec;
3837
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
38+
use smallvec::SmallVec;
3939

4040
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
4141
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
@@ -405,7 +405,7 @@ pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
405405
R: std_hash::BuildHasher,
406406
{
407407
{
408-
let mut blanket_impls: AccumulateVec<[_; 8]> = blanket_impls
408+
let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls
409409
.iter()
410410
.map(|&def_id| hcx.def_path_hash(def_id))
411411
.collect();
@@ -418,15 +418,15 @@ pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
418418
}
419419

420420
{
421-
let mut keys: AccumulateVec<[_; 8]> =
421+
let mut keys: SmallVec<[_; 8]> =
422422
non_blanket_impls.keys()
423423
.map(|k| (k, k.map_def(|d| hcx.def_path_hash(d))))
424424
.collect();
425425
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
426426
keys.len().hash_stable(hcx, hasher);
427427
for (key, ref stable_key) in keys {
428428
stable_key.hash_stable(hcx, hasher);
429-
let mut impls : AccumulateVec<[_; 8]> = non_blanket_impls[key]
429+
let mut impls : SmallVec<[_; 8]> = non_blanket_impls[key]
430430
.iter()
431431
.map(|&impl_id| hcx.def_path_hash(impl_id))
432432
.collect();

Diff for: src/librustc/ich/impls_syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use syntax_pos::SourceFile;
2525

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

28+
use smallvec::SmallVec;
2829
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
2930
StableHasher, StableHasherResult};
30-
use rustc_data_structures::accumulate_vec::AccumulateVec;
3131

3232
impl<'a> HashStable<StableHashingContext<'a>> for InternedString {
3333
#[inline]
@@ -207,7 +207,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
207207
}
208208

209209
// Some attributes are always ignored during hashing.
210-
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
210+
let filtered: SmallVec<[&ast::Attribute; 8]> = self
211211
.iter()
212212
.filter(|attr| {
213213
!attr.is_sugared_doc && !hcx.is_ignored_attr(attr.name())

Diff for: src/librustc/traits/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use chalk_engine;
12-
use rustc_data_structures::accumulate_vec::AccumulateVec;
12+
use smallvec::SmallVec;
1313
use traits;
1414
use traits::project::Normalized;
1515
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
@@ -624,7 +624,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<traits::Goal<'tcx>> {
624624
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
625625
let v = self.iter()
626626
.map(|t| t.fold_with(folder))
627-
.collect::<AccumulateVec<[_; 8]>>();
627+
.collect::<SmallVec<[_; 8]>>();
628628
folder.tcx().intern_goals(&v)
629629
}
630630

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

Diff for: src/librustc/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use ty::BindingMode;
5252
use ty::CanonicalTy;
5353
use util::nodemap::{DefIdSet, ItemLocalMap};
5454
use util::nodemap::{FxHashMap, FxHashSet};
55-
use rustc_data_structures::accumulate_vec::AccumulateVec;
55+
use smallvec::SmallVec;
5656
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5757
StableHasher, StableHasherResult,
5858
StableVec};
@@ -2840,7 +2840,7 @@ pub trait InternIteratorElement<T, R>: Sized {
28402840
impl<T, R> InternIteratorElement<T, R> for T {
28412841
type Output = R;
28422842
fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> Self::Output {
2843-
f(&iter.collect::<AccumulateVec<[_; 8]>>())
2843+
f(&iter.collect::<SmallVec<[_; 8]>>())
28442844
}
28452845
}
28462846

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

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

Diff for: src/librustc/ty/structural_impls.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use mir::interpret::{ConstValue, ConstEvalErr};
1717
use ty::{self, Lift, Ty, TyCtxt};
1818
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
19-
use rustc_data_structures::accumulate_vec::AccumulateVec;
2019
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
20+
use smallvec::SmallVec;
2121
use mir::interpret;
2222

2323
use std::rc::Rc;
@@ -741,7 +741,7 @@ BraceStructTypeFoldableImpl! {
741741

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

@@ -760,7 +760,7 @@ EnumTypeFoldableImpl! {
760760

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

@@ -1016,7 +1016,7 @@ BraceStructTypeFoldableImpl! {
10161016

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

Diff for: src/librustc/ty/subst.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1717

1818
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
1919
use syntax_pos::{Span, DUMMY_SP};
20-
use rustc_data_structures::accumulate_vec::AccumulateVec;
21-
use rustc_data_structures::array_vec::ArrayVec;
2220
use rustc_data_structures::indexed_vec::Idx;
21+
use smallvec::SmallVec;
2322

2423
use core::intrinsics;
2524
use std::cmp::Ordering;
@@ -203,11 +202,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
203202
{
204203
let defs = tcx.generics_of(def_id);
205204
let count = defs.count();
206-
let mut substs = if count <= 8 {
207-
AccumulateVec::Array(ArrayVec::new())
208-
} else {
209-
AccumulateVec::Heap(Vec::with_capacity(count))
210-
};
205+
let mut substs = SmallVec::with_capacity(count);
211206
Substs::fill_item(&mut substs, tcx, defs, &mut mk_kind);
212207
tcx.intern_substs(&substs)
213208
}
@@ -227,7 +222,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
227222
})
228223
}
229224

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

243-
fn fill_single<F>(substs: &mut AccumulateVec<[Kind<'tcx>; 8]>,
238+
fn fill_single<F>(substs: &mut SmallVec<[Kind<'tcx>; 8]>,
244239
defs: &ty::Generics,
245240
mk_kind: &mut F)
246241
where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
247242
{
248243
for param in &defs.params {
249244
let kind = mk_kind(param, substs);
250245
assert_eq!(param.index as usize, substs.len());
251-
match *substs {
252-
AccumulateVec::Array(ref mut arr) => arr.push(kind),
253-
AccumulateVec::Heap(ref mut vec) => vec.push(kind),
254-
}
246+
substs.push(kind);
255247
}
256248
}
257249

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

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

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

0 commit comments

Comments
 (0)