Skip to content

Commit 29e6aab

Browse files
committedAug 29, 2018
Auto merge of #53659 - nnethercote:rm-AccumulateVec, r=Mark-Simulacrum
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
·
1.90.01.30.0
2 parents 9d69e81 + 8cecfa6 commit 29e6aab

File tree

13 files changed

+40
-301
lines changed

13 files changed

+40
-301
lines changed
 

‎src/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
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
]

‎src/librustc/ich/hcx.rs‎

Lines changed: 4 additions & 4 deletions
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();

‎src/librustc/ich/impls_syntax.rs‎

Lines changed: 2 additions & 2 deletions
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())

‎src/librustc/traits/structural_impls.rs‎

Lines changed: 3 additions & 3 deletions
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

‎src/librustc/ty/context.rs‎

Lines changed: 4 additions & 4 deletions
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

‎src/librustc/ty/structural_impls.rs‎

Lines changed: 4 additions & 4 deletions
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

‎src/librustc/ty/subst.rs‎

Lines changed: 6 additions & 14 deletions
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.

‎src/librustc_data_structures/accumulate_vec.rs‎

Lines changed: 0 additions & 242 deletions
This file was deleted.

‎src/librustc_data_structures/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ extern crate rustc_cratesio_shim;
6161
pub use rustc_serialize::hex::ToHex;
6262

6363
pub mod svh;
64-
pub mod accumulate_vec;
6564
pub mod array_vec;
6665
pub mod base_n;
6766
pub mod bitslice;

‎src/librustc_data_structures/small_vec.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! A vector type intended to be used for collecting from iterators onto the stack.
11+
//! A vector type intended to be used for small vectors.
1212
//!
13-
//! Space for up to N elements is provided on the stack. If more elements are collected, Vec is
14-
//! used to store the values on the heap. SmallVec is similar to AccumulateVec, but adds
15-
//! the ability to push elements.
13+
//! Space for up to N elements is provided on the stack. If more elements are collected, Vec is
14+
//! used to store the values on the heap.
1615
//!
1716
//! The N above is determined by Array's implementor, by way of an associated constant.
1817

‎src/librustc_typeck/Cargo.toml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ crate-type = ["dylib"]
1010
test = false
1111

1212
[dependencies]
13-
log = "0.4"
14-
syntax = { path = "../libsyntax" }
1513
arena = { path = "../libarena" }
14+
log = "0.4"
1615
rustc = { path = "../librustc" }
1716
rustc_data_structures = { path = "../librustc_data_structures" }
17+
rustc_errors = { path = "../librustc_errors" }
1818
rustc_platform_intrinsics = { path = "../librustc_platform_intrinsics" }
1919
rustc_target = { path = "../librustc_target" }
20+
smallvec = { version = "0.6.5", features = ["union"] }
21+
syntax = { path = "../libsyntax" }
2022
syntax_pos = { path = "../libsyntax_pos" }
21-
rustc_errors = { path = "../librustc_errors" }

‎src/librustc_typeck/astconv.rs‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//! representation. The main routine here is `ast_ty_to_ty()`: each use
1313
//! is parameterized by an instance of `AstConv`.
1414
15-
use rustc_data_structures::accumulate_vec::AccumulateVec;
16-
use rustc_data_structures::array_vec::ArrayVec;
15+
use smallvec::SmallVec;
1716
use hir::{self, GenericArg, GenericArgs};
1817
use hir::def::Def;
1918
use hir::def_id::DefId;
@@ -431,18 +430,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
431430
// We manually build up the substitution, rather than using convenience
432431
// methods in subst.rs so that we can iterate over the arguments and
433432
// parameters in lock-step linearly, rather than trying to match each pair.
434-
let mut substs: AccumulateVec<[Kind<'tcx>; 8]> = if count <= 8 {
435-
AccumulateVec::Array(ArrayVec::new())
436-
} else {
437-
AccumulateVec::Heap(Vec::with_capacity(count))
438-
};
439-
440-
fn push_kind<'tcx>(substs: &mut AccumulateVec<[Kind<'tcx>; 8]>, kind: Kind<'tcx>) {
441-
match substs {
442-
AccumulateVec::Array(ref mut arr) => arr.push(kind),
443-
AccumulateVec::Heap(ref mut vec) => vec.push(kind),
444-
}
445-
}
433+
let mut substs: SmallVec<[Kind<'tcx>; 8]> = SmallVec::with_capacity(count);
446434

447435
// Iterate over each segment of the path.
448436
while let Some((def_id, defs)) = stack.pop() {
@@ -451,7 +439,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
451439
// If we have already computed substitutions for parents, we can use those directly.
452440
while let Some(&param) = params.peek() {
453441
if let Some(&kind) = parent_substs.get(param.index as usize) {
454-
push_kind(&mut substs, kind);
442+
substs.push(kind);
455443
params.next();
456444
} else {
457445
break;
@@ -463,7 +451,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
463451
if let Some(&param) = params.peek() {
464452
if param.index == 0 {
465453
if let GenericParamDefKind::Type { .. } = param.kind {
466-
push_kind(&mut substs, self_ty.map(|ty| ty.into())
454+
substs.push(self_ty.map(|ty| ty.into())
467455
.unwrap_or_else(|| inferred_kind(None, param, true)));
468456
params.next();
469457
}
@@ -487,7 +475,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
487475
match (arg, &param.kind) {
488476
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime)
489477
| (GenericArg::Type(_), GenericParamDefKind::Type { .. }) => {
490-
push_kind(&mut substs, provided_kind(param, arg));
478+
substs.push(provided_kind(param, arg));
491479
args.next();
492480
params.next();
493481
}
@@ -501,7 +489,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
501489
(GenericArg::Type(_), GenericParamDefKind::Lifetime) => {
502490
// We expected a lifetime argument, but got a type
503491
// argument. That means we're inferring the lifetimes.
504-
push_kind(&mut substs, inferred_kind(None, param, infer_types));
492+
substs.push(inferred_kind(None, param, infer_types));
505493
params.next();
506494
}
507495
}
@@ -518,7 +506,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
518506
match param.kind {
519507
GenericParamDefKind::Lifetime | GenericParamDefKind::Type { .. } => {
520508
let kind = inferred_kind(Some(&substs), param, infer_types);
521-
push_kind(&mut substs, kind);
509+
substs.push(kind);
522510
}
523511
}
524512
args.next();
@@ -1041,7 +1029,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10411029
.chain(auto_traits.into_iter().map(ty::ExistentialPredicate::AutoTrait))
10421030
.chain(existential_projections
10431031
.map(|x| ty::ExistentialPredicate::Projection(*x.skip_binder())))
1044-
.collect::<AccumulateVec<[_; 8]>>();
1032+
.collect::<SmallVec<[_; 8]>>();
10451033
v.sort_by(|a, b| a.stable_cmp(tcx, b));
10461034
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
10471035

‎src/librustc_typeck/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern crate rustc_platform_intrinsics as intrinsics;
9696
extern crate rustc_data_structures;
9797
extern crate rustc_errors as errors;
9898
extern crate rustc_target;
99+
extern crate smallvec;
99100

100101
use rustc::hir;
101102
use rustc::lint;

0 commit comments

Comments
 (0)
Please sign in to comment.