Skip to content

Commit e5284b0

Browse files
committed
Auto merge of #53384 - gootorov:use-servo-smallvec, r=michaelwoerister
Use optimized SmallVec implementation This PR replaces current SmallVec implementation with the one from the Servo project. Closes #51640 r? @Mark-Simulacrum
2 parents 35bf1ae + 4d81fe9 commit e5284b0

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

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

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

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

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ extern crate rustc_apfloat;
108108
extern crate byteorder;
109109
extern crate backtrace;
110110

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

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)