Skip to content

Commit 4d81fe9

Browse files
committed
Use optimized SmallVec implementation
1 parent e73077e commit 4d81fe9

File tree

46 files changed

+156
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+156
-434
lines changed

src/Cargo.lock

+14-4
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ dependencies = [
554554
"crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
555555
"parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
556556
"rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
557-
"smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
557+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
558558
]
559559

560560
[[package]]
@@ -1488,7 +1488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
14881488
dependencies = [
14891489
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
14901490
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1491-
"smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
1491+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
14921492
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
14931493
]
14941494

@@ -1925,6 +1925,7 @@ dependencies = [
19251925
"rustc_target 0.0.0",
19261926
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
19271927
"serialize 0.0.0",
1928+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
19281929
"syntax 0.0.0",
19291930
"syntax_pos 0.0.0",
19301931
"tempfile 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2086,6 +2087,7 @@ dependencies = [
20862087
"rustc_data_structures 0.0.0",
20872088
"rustc_errors 0.0.0",
20882089
"rustc_target 0.0.0",
2090+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
20892091
"syntax 0.0.0",
20902092
"syntax_pos 0.0.0",
20912093
]
@@ -2172,6 +2174,7 @@ dependencies = [
21722174
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
21732175
"rustc_cratesio_shim 0.0.0",
21742176
"serialize 0.0.0",
2177+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
21752178
"stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
21762179
]
21772180

@@ -2317,6 +2320,7 @@ dependencies = [
23172320
"rustc_errors 0.0.0",
23182321
"rustc_target 0.0.0",
23192322
"serialize 0.0.0",
2323+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
23202324
"syntax 0.0.0",
23212325
"syntax_pos 0.0.0",
23222326
]
@@ -2422,6 +2426,7 @@ dependencies = [
24222426
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
24232427
"rustc 0.0.0",
24242428
"rustc_data_structures 0.0.0",
2429+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
24252430
"syntax 0.0.0",
24262431
"syntax_pos 0.0.0",
24272432
]
@@ -2597,6 +2602,9 @@ dependencies = [
25972602
[[package]]
25982603
name = "serialize"
25992604
version = "0.0.0"
2605+
dependencies = [
2606+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
2607+
]
26002608

26012609
[[package]]
26022610
name = "shell-escape"
@@ -2615,7 +2623,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
26152623

26162624
[[package]]
26172625
name = "smallvec"
2618-
version = "0.6.3"
2626+
version = "0.6.5"
26192627
source = "registry+https://github.com/rust-lang/crates.io-index"
26202628
dependencies = [
26212629
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2771,6 +2779,7 @@ dependencies = [
27712779
"rustc_target 0.0.0",
27722780
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
27732781
"serialize 0.0.0",
2782+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
27742783
"syntax_pos 0.0.0",
27752784
]
27762785

@@ -2783,6 +2792,7 @@ dependencies = [
27832792
"rustc_data_structures 0.0.0",
27842793
"rustc_errors 0.0.0",
27852794
"rustc_target 0.0.0",
2795+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
27862796
"syntax 0.0.0",
27872797
"syntax_pos 0.0.0",
27882798
]
@@ -3327,7 +3337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
33273337
"checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
33283338
"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
33293339
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
3330-
"checksum smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "26df3bb03ca5eac2e64192b723d51f56c1b1e0860e7c766281f4598f181acdc8"
3340+
"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
33313341
"checksum socket2 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "962a516af4d3a7c272cb3a1d50a8cc4e5b41802e4ad54cfb7bee8ba61d37d703"
33323342
"checksum stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbc596e092fe5f598b12ef46cc03754085ac2f4d8c739ad61c4ae266cc3b3fa"
33333343
"checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423"

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ parking_lot = "0.5.5"
3333
byteorder = { version = "1.1", features = ["i128"]}
3434
chalk-engine = { version = "0.7.0", default-features=false }
3535
rustc_fs_util = { path = "../librustc_fs_util" }
36+
smallvec = { version = "0.6.5", features = ["union"] }
3637

3738
# Note that these dependencies are a lie, they're just here to get linkage to
3839
# work.

src/librustc/dep_graph/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use errors::DiagnosticBuilder;
1212
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
15-
use rustc_data_structures::small_vec::SmallVec;
15+
use smallvec::SmallVec;
1616
use rustc_data_structures::sync::{Lrc, Lock};
1717
use std::env;
1818
use std::hash::Hash;
@@ -1025,7 +1025,7 @@ impl CurrentDepGraph {
10251025
} = task {
10261026
debug_assert_eq!(node, key);
10271027
let krate_idx = self.node_to_node_index[&DepNode::new_no_params(DepKind::Krate)];
1028-
self.alloc_node(node, SmallVec::one(krate_idx))
1028+
self.alloc_node(node, smallvec![krate_idx])
10291029
} else {
10301030
bug!("complete_eval_always_task() - Expected eval always task to be popped");
10311031
}

src/librustc/hir/lowering.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3178,26 +3178,26 @@ impl<'a> LoweringContext<'a> {
31783178
fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
31793179
match i.node {
31803180
ItemKind::Use(ref use_tree) => {
3181-
let mut vec = OneVector::one(hir::ItemId { id: i.id });
3181+
let mut vec = smallvec![hir::ItemId { id: i.id }];
31823182
self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
31833183
vec
31843184
}
31853185
ItemKind::MacroDef(..) => OneVector::new(),
31863186
ItemKind::Fn(ref decl, ref header, ..) => {
3187-
let mut ids = OneVector::one(hir::ItemId { id: i.id });
3187+
let mut ids = smallvec![hir::ItemId { id: i.id }];
31883188
self.lower_impl_trait_ids(decl, header, &mut ids);
31893189
ids
31903190
},
31913191
ItemKind::Impl(.., None, _, ref items) => {
3192-
let mut ids = OneVector::one(hir::ItemId { id: i.id });
3192+
let mut ids = smallvec![hir::ItemId { id: i.id }];
31933193
for item in items {
31943194
if let ImplItemKind::Method(ref sig, _) = item.node {
31953195
self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids);
31963196
}
31973197
}
31983198
ids
31993199
},
3200-
_ => OneVector::one(hir::ItemId { id: i.id }),
3200+
_ => smallvec![hir::ItemId { id: i.id }],
32013201
}
32023202
}
32033203

@@ -4297,7 +4297,7 @@ impl<'a> LoweringContext<'a> {
42974297
}
42984298

42994299
fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
4300-
OneVector::one(match s.node {
4300+
smallvec![match s.node {
43014301
StmtKind::Local(ref l) => Spanned {
43024302
node: hir::StmtKind::Decl(
43034303
P(Spanned {
@@ -4336,7 +4336,7 @@ impl<'a> LoweringContext<'a> {
43364336
span: s.span,
43374337
},
43384338
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
4339-
})
4339+
}]
43404340
}
43414341

43424342
fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {

src/librustc/infer/canonical/canonicalizer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ty::{self, CanonicalVar, Lift, List, Ty, TyCtxt, TypeFlags};
2727

2828
use rustc_data_structures::fx::FxHashMap;
2929
use rustc_data_structures::indexed_vec::Idx;
30-
use rustc_data_structures::small_vec::SmallVec;
30+
use smallvec::SmallVec;
3131

3232
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
3333
/// Canonicalizes a query value `V`. When we canonicalize a query,
@@ -380,7 +380,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
380380
// avoid allocations in those cases. We also don't use `indices` to
381381
// determine if a kind has been seen before until the limit of 8 has
382382
// been exceeded, to also avoid allocations for `indices`.
383-
if var_values.is_array() {
383+
if !var_values.spilled() {
384384
// `var_values` is stack-allocated. `indices` isn't used yet. Do a
385385
// direct linear search of `var_values`.
386386
if let Some(idx) = var_values.iter().position(|&k| k == kind) {
@@ -395,7 +395,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
395395

396396
// If `var_values` has become big enough to be heap-allocated,
397397
// fill up `indices` to facilitate subsequent lookups.
398-
if !var_values.is_array() {
398+
if var_values.spilled() {
399399
assert!(indices.is_empty());
400400
*indices =
401401
var_values.iter()

src/librustc/infer/canonical/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
3535
use rustc_data_structures::indexed_vec::IndexVec;
36-
use rustc_data_structures::small_vec::SmallVec;
36+
use smallvec::SmallVec;
3737
use rustc_data_structures::sync::Lrc;
3838
use serialize::UseSpecializedDecodable;
3939
use std::ops::Index;

src/librustc/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ extern crate rustc_apfloat;
109109
extern crate byteorder;
110110
extern crate backtrace;
111111

112+
#[macro_use]
113+
extern crate smallvec;
114+
112115
// Note that librustc doesn't actually depend on these crates, see the note in
113116
// `Cargo.toml` for this crate about why these are here.
114117
#[allow(unused_extern_crates)]

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_apfloat::Float;
2424
use rustc_data_structures::graph::dominators::{dominators, Dominators};
2525
use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
2626
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
27-
use rustc_data_structures::small_vec::SmallVec;
27+
use smallvec::SmallVec;
2828
use rustc_data_structures::sync::Lrc;
2929
use rustc_data_structures::sync::ReadGuard;
3030
use rustc_serialize as serialize;

src/librustc/traits/query/dropck_outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use infer::at::At;
1212
use infer::InferOk;
13-
use rustc_data_structures::small_vec::SmallVec;
13+
use smallvec::SmallVec;
1414
use std::iter::FromIterator;
1515
use syntax::source_map::Span;
1616
use ty::subst::Kind;

src/librustc/traits/query/evaluate_obligation.rs

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

1111
use infer::InferCtxt;
12-
use rustc_data_structures::small_vec::SmallVec;
12+
use smallvec::SmallVec;
1313
use traits::{EvaluationResult, PredicateObligation, SelectionContext,
1414
TraitQueryMode, OverflowError};
1515

src/librustc/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use infer::at::At;
1616
use infer::{InferCtxt, InferOk};
1717
use mir::interpret::{ConstValue, GlobalId};
18-
use rustc_data_structures::small_vec::SmallVec;
18+
use smallvec::SmallVec;
1919
use traits::project::Normalized;
2020
use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
2121
use ty::fold::{TypeFoldable, TypeFolder};

src/librustc/traits/query/outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use infer::InferCtxt;
1212
use syntax::ast;
1313
use syntax::source_map::Span;
14-
use rustc_data_structures::small_vec::SmallVec;
14+
use smallvec::SmallVec;
1515
use traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
1616
use traits::query::NoSolution;
1717
use ty::{self, Ty, TyCtxt};

src/librustc/traits/query/type_op/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryRegionConstraint,
1212
QueryResult};
1313
use infer::{InferCtxt, InferOk};
14-
use rustc_data_structures::small_vec::SmallVec;
14+
use smallvec::SmallVec;
1515
use std::fmt;
1616
use std::rc::Rc;
1717
use traits::query::Fallible;

src/librustc/ty/inhabitedness/def_id_forest.rs

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

1111
use std::mem;
12-
use rustc_data_structures::small_vec::SmallVec;
12+
use smallvec::SmallVec;
1313
use syntax::ast::CRATE_NODE_ID;
1414
use ty::context::TyCtxt;
1515
use ty::{DefId, DefIdTree};
@@ -83,14 +83,14 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
8383
let mut next_ret = SmallVec::new();
8484
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
8585
for next_forest in iter {
86-
for id in ret.root_ids.drain(..) {
86+
for id in ret.root_ids.drain() {
8787
if next_forest.contains(tcx, id) {
8888
next_ret.push(id);
8989
} else {
9090
old_ret.push(id);
9191
}
9292
}
93-
ret.root_ids.extend(old_ret.drain(..));
93+
ret.root_ids.extend(old_ret.drain());
9494

9595
for id in next_forest.root_ids {
9696
if ret.contains(tcx, id) {
@@ -99,7 +99,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
9999
}
100100

101101
mem::swap(&mut next_ret, &mut ret.root_ids);
102-
next_ret.drain(..);
102+
next_ret.drain();
103103
}
104104
ret
105105
}
@@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
112112
let mut ret = DefIdForest::empty();
113113
let mut next_ret = SmallVec::new();
114114
for next_forest in iter {
115-
for id in ret.root_ids.drain(..) {
115+
for id in ret.root_ids.drain() {
116116
if !next_forest.contains(tcx, id) {
117117
next_ret.push(id);
118118
}
@@ -125,7 +125,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
125125
}
126126

127127
mem::swap(&mut next_ret, &mut ret.root_ids);
128-
next_ret.drain(..);
128+
next_ret.drain();
129129
}
130130
ret
131131
}

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use syntax::ext::hygiene::Mark;
5555
use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
5656
use syntax_pos::{DUMMY_SP, Span};
5757

58-
use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
58+
use smallvec;
5959
use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
6060
HashStable};
6161

@@ -2382,7 +2382,7 @@ impl<'tcx> TyS<'tcx> {
23822382
/// Iterator that walks the immediate children of `self`. Hence
23832383
/// `Foo<Bar<i32>, u32>` yields the sequence `[Bar<i32>, u32]`
23842384
/// (but not `i32`, like `walk`).
2385-
pub fn walk_shallow(&'tcx self) -> AccIntoIter<walk::TypeWalkerArray<'tcx>> {
2385+
pub fn walk_shallow(&'tcx self) -> smallvec::IntoIter<walk::TypeWalkerArray<'tcx>> {
23862386
walk::walk_shallow(self)
23872387
}
23882388

src/librustc/ty/walk.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
1414
use mir::interpret::ConstValue;
1515
use ty::{self, Ty};
16-
use rustc_data_structures::small_vec::SmallVec;
17-
use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
16+
use smallvec::{self, SmallVec};
1817

1918
// The TypeWalker's stack is hot enough that it's worth going to some effort to
2019
// avoid heap allocations.
@@ -28,7 +27,7 @@ pub struct TypeWalker<'tcx> {
2827

2928
impl<'tcx> TypeWalker<'tcx> {
3029
pub fn new(ty: Ty<'tcx>) -> TypeWalker<'tcx> {
31-
TypeWalker { stack: SmallVec::one(ty), last_subtree: 1, }
30+
TypeWalker { stack: smallvec![ty], last_subtree: 1, }
3231
}
3332

3433
/// Skips the subtree of types corresponding to the last type
@@ -67,7 +66,7 @@ impl<'tcx> Iterator for TypeWalker<'tcx> {
6766
}
6867
}
6968

70-
pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> AccIntoIter<TypeWalkerArray<'tcx>> {
69+
pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> smallvec::IntoIter<TypeWalkerArray<'tcx>> {
7170
let mut stack = SmallVec::new();
7271
push_subtypes(&mut stack, ty);
7372
stack.into_iter()

src/librustc_allocator/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ rustc_target = { path = "../librustc_target" }
1616
syntax = { path = "../libsyntax" }
1717
syntax_pos = { path = "../libsyntax_pos" }
1818
log = "0.4"
19+
smallvec = { version = "0.6.5", features = ["union"] }

0 commit comments

Comments
 (0)