Skip to content

Commit

Permalink
Use optimized SmallVec implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gootorov committed Aug 23, 2018
1 parent e73077e commit 4d81fe9
Show file tree
Hide file tree
Showing 46 changed files with 156 additions and 434 deletions.
18 changes: 14 additions & 4 deletions src/Cargo.lock
Expand Up @@ -554,7 +554,7 @@ dependencies = [
"crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand Down Expand Up @@ -1488,7 +1488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand Down Expand Up @@ -1925,6 +1925,7 @@ dependencies = [
"rustc_target 0.0.0",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 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",
"tempfile 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2086,6 +2087,7 @@ dependencies = [
"rustc_data_structures 0.0.0",
"rustc_errors 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 Expand Up @@ -2172,6 +2174,7 @@ dependencies = [
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_cratesio_shim 0.0.0",
"serialize 0.0.0",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand Down Expand Up @@ -2317,6 +2320,7 @@ dependencies = [
"rustc_errors 0.0.0",
"rustc_target 0.0.0",
"serialize 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 Expand Up @@ -2422,6 +2426,7 @@ dependencies = [
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc_data_structures 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 Expand Up @@ -2597,6 +2602,9 @@ dependencies = [
[[package]]
name = "serialize"
version = "0.0.0"
dependencies = [
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

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

[[package]]
name = "smallvec"
version = "0.6.3"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2771,6 +2779,7 @@ dependencies = [
"rustc_target 0.0.0",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"syntax_pos 0.0.0",
]

Expand All @@ -2783,6 +2792,7 @@ dependencies = [
"rustc_data_structures 0.0.0",
"rustc_errors 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 Expand Up @@ -3327,7 +3337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
"checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537"
"checksum smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "26df3bb03ca5eac2e64192b723d51f56c1b1e0860e7c766281f4598f181acdc8"
"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
"checksum socket2 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "962a516af4d3a7c272cb3a1d50a8cc4e5b41802e4ad54cfb7bee8ba61d37d703"
"checksum stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbc596e092fe5f598b12ef46cc03754085ac2f4d8c739ad61c4ae266cc3b3fa"
"checksum string_cache 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25d70109977172b127fe834e5449e5ab1740b9ba49fa18a2020f509174f25423"
Expand Down
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Expand Up @@ -33,6 +33,7 @@ parking_lot = "0.5.5"
byteorder = { version = "1.1", features = ["i128"]}
chalk-engine = { version = "0.7.0", default-features=false }
rustc_fs_util = { path = "../librustc_fs_util" }
smallvec = { version = "0.6.5", features = ["union"] }

# Note that these dependencies are a lie, they're just here to get linkage to
# work.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/graph.rs
Expand Up @@ -12,7 +12,7 @@ use errors::DiagnosticBuilder;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use rustc_data_structures::sync::{Lrc, Lock};
use std::env;
use std::hash::Hash;
Expand Down Expand Up @@ -1025,7 +1025,7 @@ impl CurrentDepGraph {
} = task {
debug_assert_eq!(node, key);
let krate_idx = self.node_to_node_index[&DepNode::new_no_params(DepKind::Krate)];
self.alloc_node(node, SmallVec::one(krate_idx))
self.alloc_node(node, smallvec![krate_idx])
} else {
bug!("complete_eval_always_task() - Expected eval always task to be popped");
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/lowering.rs
Expand Up @@ -3178,26 +3178,26 @@ impl<'a> LoweringContext<'a> {
fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
match i.node {
ItemKind::Use(ref use_tree) => {
let mut vec = OneVector::one(hir::ItemId { id: i.id });
let mut vec = smallvec![hir::ItemId { id: i.id }];
self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
vec
}
ItemKind::MacroDef(..) => OneVector::new(),
ItemKind::Fn(ref decl, ref header, ..) => {
let mut ids = OneVector::one(hir::ItemId { id: i.id });
let mut ids = smallvec![hir::ItemId { id: i.id }];
self.lower_impl_trait_ids(decl, header, &mut ids);
ids
},
ItemKind::Impl(.., None, _, ref items) => {
let mut ids = OneVector::one(hir::ItemId { id: i.id });
let mut ids = smallvec![hir::ItemId { id: i.id }];
for item in items {
if let ImplItemKind::Method(ref sig, _) = item.node {
self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids);
}
}
ids
},
_ => OneVector::one(hir::ItemId { id: i.id }),
_ => smallvec![hir::ItemId { id: i.id }],
}
}

Expand Down Expand Up @@ -4297,7 +4297,7 @@ impl<'a> LoweringContext<'a> {
}

fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
OneVector::one(match s.node {
smallvec![match s.node {
StmtKind::Local(ref l) => Spanned {
node: hir::StmtKind::Decl(
P(Spanned {
Expand Down Expand Up @@ -4336,7 +4336,7 @@ impl<'a> LoweringContext<'a> {
span: s.span,
},
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
})
}]
}

fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/canonical/canonicalizer.rs
Expand Up @@ -27,7 +27,7 @@ use ty::{self, CanonicalVar, Lift, List, Ty, TyCtxt, TypeFlags};

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;

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

// If `var_values` has become big enough to be heap-allocated,
// fill up `indices` to facilitate subsequent lookups.
if !var_values.is_array() {
if var_values.spilled() {
assert!(indices.is_empty());
*indices =
var_values.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/canonical/mod.rs
Expand Up @@ -33,7 +33,7 @@

use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use rustc_data_structures::sync::Lrc;
use serialize::UseSpecializedDecodable;
use std::ops::Index;
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/lib.rs
Expand Up @@ -109,6 +109,9 @@ extern crate rustc_apfloat;
extern crate byteorder;
extern crate backtrace;

#[macro_use]
extern crate smallvec;

// Note that librustc doesn't actually depend on these crates, see the note in
// `Cargo.toml` for this crate about why these are here.
#[allow(unused_extern_crates)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Expand Up @@ -24,7 +24,7 @@ use rustc_apfloat::Float;
use rustc_data_structures::graph::dominators::{dominators, Dominators};
use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::sync::ReadGuard;
use rustc_serialize as serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/query/dropck_outlives.rs
Expand Up @@ -10,7 +10,7 @@

use infer::at::At;
use infer::InferOk;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use std::iter::FromIterator;
use syntax::source_map::Span;
use ty::subst::Kind;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/query/evaluate_obligation.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use infer::InferCtxt;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use traits::{EvaluationResult, PredicateObligation, SelectionContext,
TraitQueryMode, OverflowError};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/query/normalize.rs
Expand Up @@ -15,7 +15,7 @@
use infer::at::At;
use infer::{InferCtxt, InferOk};
use mir::interpret::{ConstValue, GlobalId};
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use traits::project::Normalized;
use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
use ty::fold::{TypeFoldable, TypeFolder};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/query/outlives_bounds.rs
Expand Up @@ -11,7 +11,7 @@
use infer::InferCtxt;
use syntax::ast;
use syntax::source_map::Span;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
use traits::query::NoSolution;
use ty::{self, Ty, TyCtxt};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/query/type_op/mod.rs
Expand Up @@ -11,7 +11,7 @@
use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryRegionConstraint,
QueryResult};
use infer::{InferCtxt, InferOk};
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use std::fmt;
use std::rc::Rc;
use traits::query::Fallible;
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/inhabitedness/def_id_forest.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use std::mem;
use rustc_data_structures::small_vec::SmallVec;
use smallvec::SmallVec;
use syntax::ast::CRATE_NODE_ID;
use ty::context::TyCtxt;
use ty::{DefId, DefIdTree};
Expand Down Expand Up @@ -83,14 +83,14 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
let mut next_ret = SmallVec::new();
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
for next_forest in iter {
for id in ret.root_ids.drain(..) {
for id in ret.root_ids.drain() {
if next_forest.contains(tcx, id) {
next_ret.push(id);
} else {
old_ret.push(id);
}
}
ret.root_ids.extend(old_ret.drain(..));
ret.root_ids.extend(old_ret.drain());

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

mem::swap(&mut next_ret, &mut ret.root_ids);
next_ret.drain(..);
next_ret.drain();
}
ret
}
Expand All @@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
let mut ret = DefIdForest::empty();
let mut next_ret = SmallVec::new();
for next_forest in iter {
for id in ret.root_ids.drain(..) {
for id in ret.root_ids.drain() {
if !next_forest.contains(tcx, id) {
next_ret.push(id);
}
Expand All @@ -125,7 +125,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
}

mem::swap(&mut next_ret, &mut ret.root_ids);
next_ret.drain(..);
next_ret.drain();
}
ret
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Expand Up @@ -55,7 +55,7 @@ use syntax::ext::hygiene::Mark;
use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
use syntax_pos::{DUMMY_SP, Span};

use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
use smallvec;
use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
HashStable};

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

Expand Down
7 changes: 3 additions & 4 deletions src/librustc/ty/walk.rs
Expand Up @@ -13,8 +13,7 @@

use mir::interpret::ConstValue;
use ty::{self, Ty};
use rustc_data_structures::small_vec::SmallVec;
use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
use smallvec::{self, SmallVec};

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

impl<'tcx> TypeWalker<'tcx> {
pub fn new(ty: Ty<'tcx>) -> TypeWalker<'tcx> {
TypeWalker { stack: SmallVec::one(ty), last_subtree: 1, }
TypeWalker { stack: smallvec![ty], last_subtree: 1, }
}

/// Skips the subtree of types corresponding to the last type
Expand Down Expand Up @@ -67,7 +66,7 @@ impl<'tcx> Iterator for TypeWalker<'tcx> {
}
}

pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> AccIntoIter<TypeWalkerArray<'tcx>> {
pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> smallvec::IntoIter<TypeWalkerArray<'tcx>> {
let mut stack = SmallVec::new();
push_subtypes(&mut stack, ty);
stack.into_iter()
Expand Down
1 change: 1 addition & 0 deletions src/librustc_allocator/Cargo.toml
Expand Up @@ -16,3 +16,4 @@ rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
log = "0.4"
smallvec = { version = "0.6.5", features = ["union"] }

0 comments on commit 4d81fe9

Please sign in to comment.