]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #53384 - gootorov:use-servo-smallvec, r=michaelwoerister
authorbors <bors@rust-lang.org>
Thu, 23 Aug 2018 14:40:22 +0000 (14:40 +0000)
committerbors <bors@rust-lang.org>
Thu, 23 Aug 2018 14:40:22 +0000 (14:40 +0000)
Use optimized SmallVec implementation

This PR replaces current SmallVec implementation with the one from the Servo project.

Closes https://github.com/rust-lang/rust/issues/51640

r? @Mark-Simulacrum

46 files changed:
src/Cargo.lock
src/librustc/Cargo.toml
src/librustc/dep_graph/graph.rs
src/librustc/hir/lowering.rs
src/librustc/infer/canonical/canonicalizer.rs
src/librustc/infer/canonical/mod.rs
src/librustc/lib.rs
src/librustc/mir/mod.rs
src/librustc/traits/query/dropck_outlives.rs
src/librustc/traits/query/evaluate_obligation.rs
src/librustc/traits/query/normalize.rs
src/librustc/traits/query/outlives_bounds.rs
src/librustc/traits/query/type_op/mod.rs
src/librustc/ty/inhabitedness/def_id_forest.rs
src/librustc/ty/mod.rs
src/librustc/ty/walk.rs
src/librustc_allocator/Cargo.toml
src/librustc_allocator/expand.rs
src/librustc_allocator/lib.rs
src/librustc_data_structures/Cargo.toml
src/librustc_data_structures/lib.rs
src/librustc_data_structures/small_vec.rs
src/librustc_mir/Cargo.toml
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/lib.rs
src/librustc_resolve/macros.rs
src/librustc_traits/Cargo.toml
src/librustc_traits/chalk_context.rs
src/librustc_traits/lib.rs
src/libserialize/Cargo.toml
src/libserialize/collection_impls.rs
src/libserialize/lib.rs
src/libsyntax/Cargo.toml
src/libsyntax/diagnostics/plugin.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/placeholders.rs
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/ext/tt/transcribe.rs
src/libsyntax/fold.rs
src/libsyntax/lib.rs
src/libsyntax/test.rs
src/libsyntax_ext/Cargo.toml
src/libsyntax_ext/global_asm.rs
src/libsyntax_ext/lib.rs
src/test/run-pass-fulldeps/auxiliary/issue-16723.rs

index eabd26c6e6707534f73df0c010ce99be341e617e..62e7a58cd36114018e45238489bf53426d404c7d 100644 (file)
@@ -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]]
@@ -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)",
 ]
 
@@ -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)",
@@ -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",
 ]
@@ -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)",
 ]
 
@@ -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",
 ]
@@ -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",
 ]
@@ -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"
@@ -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)",
@@ -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",
 ]
 
@@ -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",
 ]
@@ -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"
index 59b5b58e61eac533f1c3245b28880c1028405c85..fc5d4a9c92331bb606e535b23a9f5b55eca2168c 100644 (file)
@@ -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.
index e308f2924a05c571c0efa4a4a24cdfc704c8789e..a285399657177a3ade729dc2421f45363c82b390 100644 (file)
@@ -12,7 +12,7 @@
 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;
@@ -1025,7 +1025,7 @@ fn complete_eval_always_task(&mut self, key: DepNode, task: OpenTask) -> DepNode
         } = 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");
         }
index acfda4c0055fce59535a1f24dbd0d1b2e0c64d1e..cb05f7b44c3b96b783b3ed13fc2495324f421c08 100644 (file)
@@ -3178,18 +3178,18 @@ fn visit_path_segment(
     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);
@@ -3197,7 +3197,7 @@ fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
                 }
                 ids
             },
-            _ => OneVector::one(hir::ItemId { id: i.id }),
+            _ => smallvec![hir::ItemId { id: i.id }],
         }
     }
 
@@ -4297,7 +4297,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
     }
 
     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 {
@@ -4336,7 +4336,7 @@ fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
                 span: s.span,
             },
             StmtKind::Mac(..) => panic!("Shouldn't exist here"),
-        })
+        }]
     }
 
     fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
index 16c33e9adf8908c4567b09b2ac2dde5ed620f138..fbe9165ae97fa590c463241c63c0bd9746e6f4c2 100644 (file)
@@ -27,7 +27,7 @@
 
 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,
@@ -380,7 +380,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> Canonic
         // 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) {
@@ -395,7 +395,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> Canonic
 
                 // 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()
index cb1e39bb9f7428d033f52306b761ec2d84835fe1..2e57ef7b17d4491649cbff413fd09807b1987ac5 100644 (file)
@@ -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;
index a232bcd67102e7805543c90ec36c6ce2085035d4..d43ebf8d415a7d4db44924664b2856627fffb434 100644 (file)
 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)]
index 66a42cfb11a749116b9f0e76a1d36255db9d12fe..14981a700a32eda3ffccf3b0a41725e6009e8493 100644 (file)
@@ -24,7 +24,7 @@
 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;
index b479cafd1cea17f9ececd16525539fe1de88d0ee..3a0f7700824097078d16dda4dc19e3270c3ac742 100644 (file)
@@ -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;
index 93fcadceb1655a7af6cd1166fc10d7f622d0f124..6bd92678362544ac62522f02dcfbddd4ef7d8ffb 100644 (file)
@@ -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};
 
index 7b81989c6415b99898748f2f5d971e19d8068845..f8b3933e2a153c554115d32c8c39380abb71460a 100644 (file)
@@ -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};
index 868b8dfc885439389d083b231c5a044dd4838822..47c8ee357fbe846e340ece253e68827e406e6fb4 100644 (file)
@@ -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};
index be5e2838963ee2c906cd448b8f245ef8a8714a85..3b16dab22f2c27ac2d38dd24635db5eb34748831 100644 (file)
@@ -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;
index 3629709e6a48de19a1f0843f26d4b7f88099f353..c152c0fb8e94cea9ccdf9b272929902b93044756 100644 (file)
@@ -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};
@@ -83,14 +83,14 @@ pub fn intersection<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
         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) {
@@ -99,7 +99,7 @@ pub fn intersection<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
             }
 
             mem::swap(&mut next_ret, &mut ret.root_ids);
-            next_ret.drain(..);
+            next_ret.drain();
         }
         ret
     }
@@ -112,7 +112,7 @@ pub fn union<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
         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);
                 }
@@ -125,7 +125,7 @@ pub fn union<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
             }
 
             mem::swap(&mut next_ret, &mut ret.root_ids);
-            next_ret.drain(..);
+            next_ret.drain();
         }
         ret
     }
index 8d5006d17b3abe875827916ba5e57f5007259e82..77b4d32c397d7c402a011b86de79f249b1edf919 100644 (file)
@@ -55,7 +55,7 @@
 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};
 
@@ -2382,7 +2382,7 @@ pub fn walk(&'tcx self) -> TypeWalker<'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)
     }
 
index e2df7c32f587b51e686916e70d524a37b7f4e7f8..6d3ba22c57f27f346c10d9316253a268c8ed8806 100644 (file)
@@ -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.
@@ -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
@@ -67,7 +66,7 @@ fn next(&mut self) -> Option<Ty<'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()
index 83a918f2af83706ea4d4baf7a31fba915378a779..cd3ef6a1f043ce85c1935e7c3cb3289ea2e93db5 100644 (file)
@@ -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"] }
index da60f41ee680ecbfc628dbd6f2b9180d789a05ba..5999416cecf1528818defc81159bf7d8cc41ba54 100644 (file)
@@ -78,20 +78,20 @@ fn fold_item(&mut self, item: P<Item>) -> OneVector<P<Item>> {
             _ => {
                 self.handler
                     .span_err(item.span, "allocators must be statics");
-                return OneVector::one(item);
+                return smallvec![item];
             }
         }
 
         if self.in_submod > 0 {
             self.handler
                 .span_err(item.span, "`global_allocator` cannot be used in submodules");
-            return OneVector::one(item);
+            return smallvec![item];
         }
 
         if self.found {
             self.handler
                 .span_err(item.span, "cannot define more than one #[global_allocator]");
-            return OneVector::one(item);
+            return smallvec![item];
         }
         self.found = true;
 
index d020fe96335e91345fa20e09a3a111cfe5dac199..2a3404ee830343d10de823c8663c175394c9d7a6 100644 (file)
@@ -18,6 +18,8 @@
 extern crate rustc_target;
 extern crate syntax;
 extern crate syntax_pos;
+#[macro_use]
+extern crate smallvec;
 
 pub mod expand;
 
index fc5fe91c977d410057d189a3bd9ab425e9ed5b47..0376cf8115756bf43e89d0d2c31d61df566ae25f 100644 (file)
@@ -19,6 +19,7 @@ parking_lot_core = "0.2.8"
 rustc-rayon = "0.1.1"
 rustc-rayon-core = "0.1.1"
 rustc-hash = "1.0.1"
+smallvec = { version = "0.6.5", features = ["union"] }
 
 [dependencies.parking_lot]
 version = "0.5"
index c3ee48d20f6f5afad8610a4914771335e765b4c7..1eef7870c01b4df1206998db9a91e84ae785fe0b 100644 (file)
@@ -48,6 +48,8 @@
 extern crate rustc_rayon_core as rayon_core;
 extern crate rustc_hash;
 extern crate serialize;
+#[cfg_attr(test, macro_use)]
+extern crate smallvec;
 
 // See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
 #[allow(unused_extern_crates)]
index 689aad25b431d78566f635b96821e5bb4959bdf8..e4e6a3d1a9c6735d722af2a3e2fcad1705c345d6 100644 (file)
 //!
 //! The N above is determined by Array's implementor, by way of an associated constant.
 
-use std::ops::{Deref, DerefMut};
-use std::iter::{IntoIterator, FromIterator};
-use std::fmt::{self, Debug};
-use std::mem;
-use std::ptr;
-
-use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
-
-use accumulate_vec::{IntoIter, AccumulateVec};
-use array_vec::Array;
-
-pub struct SmallVec<A: Array>(AccumulateVec<A>);
+use smallvec::{Array, SmallVec};
 
 pub type OneVector<T> = SmallVec<[T; 1]>;
 
-impl<A> Clone for SmallVec<A>
-    where A: Array,
-          A::Element: Clone {
-    fn clone(&self) -> Self {
-        SmallVec(self.0.clone())
-    }
-}
-
-impl<A> Debug for SmallVec<A>
-    where A: Array + Debug,
-          A::Element: Debug {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.debug_tuple("SmallVec").field(&self.0).finish()
-    }
+pub trait ExpectOne<A: Array> {
+    fn expect_one(self, err: &'static str) -> A::Item;
 }
 
-impl<A: Array> SmallVec<A> {
-    pub fn new() -> Self {
-        SmallVec(AccumulateVec::new())
-    }
-
-    pub fn is_array(&self) -> bool {
-        self.0.is_array()
-    }
-
-    pub fn with_capacity(cap: usize) -> Self {
-        let mut vec = SmallVec::new();
-        vec.reserve(cap);
-        vec
-    }
-
-    pub fn one(el: A::Element) -> Self {
-        SmallVec(AccumulateVec::one(el))
-    }
-
-    pub fn many<I: IntoIterator<Item=A::Element>>(els: I) -> Self {
-        SmallVec(AccumulateVec::many(els))
-    }
-
-    pub fn expect_one(self, err: &'static str) -> A::Element {
+impl<A: Array> ExpectOne<A> for SmallVec<A> {
+    fn expect_one(self, err: &'static str) -> A::Item {
         assert!(self.len() == 1, err);
-        match self.0 {
-            AccumulateVec::Array(arr) => arr.into_iter().next().unwrap(),
-            AccumulateVec::Heap(vec) => vec.into_iter().next().unwrap(),
-        }
-    }
-
-    /// Will reallocate onto the heap if needed.
-    pub fn push(&mut self, el: A::Element) {
-        self.reserve(1);
-        match self.0 {
-            AccumulateVec::Array(ref mut array) => array.push(el),
-            AccumulateVec::Heap(ref mut vec) => vec.push(el),
-        }
-    }
-
-    pub fn reserve(&mut self, n: usize) {
-        match self.0 {
-            AccumulateVec::Array(_) => {
-                if self.len() + n > A::LEN {
-                    let len = self.len();
-                    let array = mem::replace(&mut self.0,
-                            AccumulateVec::Heap(Vec::with_capacity(len + n)));
-                    if let AccumulateVec::Array(array) = array {
-                        match self.0 {
-                            AccumulateVec::Heap(ref mut vec) => vec.extend(array),
-                            _ => unreachable!()
-                        }
-                    }
-                }
-            }
-            AccumulateVec::Heap(ref mut vec) => vec.reserve(n)
-        }
-    }
-
-    pub unsafe fn set_len(&mut self, len: usize) {
-        match self.0 {
-            AccumulateVec::Array(ref mut arr) => arr.set_len(len),
-            AccumulateVec::Heap(ref mut vec) => vec.set_len(len),
-        }
-    }
-
-    pub fn insert(&mut self, index: usize, element: A::Element) {
-        let len = self.len();
-
-        // Reserve space for shifting elements to the right
-        self.reserve(1);
-
-        assert!(index <= len);
-
-        unsafe {
-            // infallible
-            // The spot to put the new value
-            {
-                let p = self.as_mut_ptr().add(index);
-                // Shift everything over to make space. (Duplicating the
-                // `index`th element into two consecutive places.)
-                ptr::copy(p, p.offset(1), len - index);
-                // Write it in, overwriting the first copy of the `index`th
-                // element.
-                ptr::write(p, element);
-            }
-            self.set_len(len + 1);
-        }
-    }
-
-    pub fn truncate(&mut self, len: usize) {
-        unsafe {
-            while len < self.len() {
-                // Decrement len before the drop_in_place(), so a panic on Drop
-                // doesn't re-drop the just-failed value.
-                let newlen = self.len() - 1;
-                self.set_len(newlen);
-                ::std::ptr::drop_in_place(self.get_unchecked_mut(newlen));
-            }
-        }
-    }
-}
-
-impl<A: Array> Deref for SmallVec<A> {
-    type Target = AccumulateVec<A>;
-    fn deref(&self) -> &Self::Target {
-        &self.0
-    }
-}
-
-impl<A: Array> DerefMut for SmallVec<A> {
-    fn deref_mut(&mut self) -> &mut AccumulateVec<A> {
-        &mut self.0
-    }
-}
-
-impl<A: Array> FromIterator<A::Element> for SmallVec<A> {
-    fn from_iter<I>(iter: I) -> Self where I: IntoIterator<Item=A::Element> {
-        SmallVec(iter.into_iter().collect())
-    }
-}
-
-impl<A: Array> Extend<A::Element> for SmallVec<A> {
-    fn extend<I: IntoIterator<Item=A::Element>>(&mut self, iter: I) {
-        let iter = iter.into_iter();
-        self.reserve(iter.size_hint().0);
-        match self.0 {
-            AccumulateVec::Heap(ref mut vec) => vec.extend(iter),
-            _ => iter.for_each(|el| self.push(el))
-        }
-    }
-}
-
-impl<A: Array> IntoIterator for SmallVec<A> {
-    type Item = A::Element;
-    type IntoIter = IntoIter<A>;
-    fn into_iter(self) -> Self::IntoIter {
-        self.0.into_iter()
-    }
-}
-
-impl<A: Array> Default for SmallVec<A> {
-    fn default() -> SmallVec<A> {
-        SmallVec::new()
-    }
-}
-
-impl<A> Encodable for SmallVec<A>
-    where A: Array,
-          A::Element: Encodable {
-    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
-        s.emit_seq(self.len(), |s| {
-            for (i, e) in self.iter().enumerate() {
-                s.emit_seq_elt(i, |s| e.encode(s))?;
-            }
-            Ok(())
-        })
-    }
-}
-
-impl<A> Decodable for SmallVec<A>
-    where A: Array,
-          A::Element: Decodable {
-    fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> {
-        d.read_seq(|d, len| {
-            let mut vec = SmallVec::with_capacity(len);
-            // FIXME(#48994) - could just be collected into a Result<SmallVec, D::Error>
-            for i in 0..len {
-                vec.push(d.read_seq_elt(i, |d| Decodable::decode(d))?);
-            }
-            Ok(vec)
-        })
+        self.into_iter().next().unwrap()
     }
 }
 
 #[cfg(test)]
 mod tests {
     extern crate test;
-    use self::test::Bencher;
-
     use super::*;
 
-    #[test]
-    fn test_len() {
-        let v: OneVector<isize> = OneVector::new();
-        assert_eq!(0, v.len());
-
-        assert_eq!(1, OneVector::one(1).len());
-        assert_eq!(5, OneVector::many(vec![1, 2, 3, 4, 5]).len());
-    }
-
-    #[test]
-    fn test_push_get() {
-        let mut v = OneVector::new();
-        v.push(1);
-        assert_eq!(1, v.len());
-        assert_eq!(1, v[0]);
-        v.push(2);
-        assert_eq!(2, v.len());
-        assert_eq!(2, v[1]);
-        v.push(3);
-        assert_eq!(3, v.len());
-        assert_eq!(3, v[2]);
-    }
-
-    #[test]
-    fn test_from_iter() {
-        let v: OneVector<isize> = (vec![1, 2, 3]).into_iter().collect();
-        assert_eq!(3, v.len());
-        assert_eq!(1, v[0]);
-        assert_eq!(2, v[1]);
-        assert_eq!(3, v[2]);
-    }
-
-    #[test]
-    fn test_move_iter() {
-        let v = OneVector::new();
-        let v: Vec<isize> = v.into_iter().collect();
-        assert_eq!(v, Vec::new());
-
-        let v = OneVector::one(1);
-        assert_eq!(v.into_iter().collect::<Vec<_>>(), [1]);
-
-        let v = OneVector::many(vec![1, 2, 3]);
-        assert_eq!(v.into_iter().collect::<Vec<_>>(), [1, 2, 3]);
-    }
-
     #[test]
     #[should_panic]
     fn test_expect_one_zero() {
@@ -283,120 +45,12 @@ fn test_expect_one_zero() {
     #[test]
     #[should_panic]
     fn test_expect_one_many() {
-        OneVector::many(vec![1, 2]).expect_one("");
+        OneVector::from_vec(vec![1, 2]).expect_one("");
     }
 
     #[test]
     fn test_expect_one_one() {
-        assert_eq!(1, OneVector::one(1).expect_one(""));
-        assert_eq!(1, OneVector::many(vec![1]).expect_one(""));
-    }
-
-    #[bench]
-    fn fill_small_vec_1_10_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 1]> = SmallVec::with_capacity(10);
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_1_10_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 1]> = SmallVec::new();
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_8_10_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 8]> = SmallVec::with_capacity(10);
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_8_10_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 8]> = SmallVec::new();
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_32_10_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 32]> = SmallVec::with_capacity(10);
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_32_10_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 32]> = SmallVec::new();
-
-            sv.extend(0..10);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_1_50_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 1]> = SmallVec::with_capacity(50);
-
-            sv.extend(0..50);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_1_50_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 1]> = SmallVec::new();
-
-            sv.extend(0..50);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_8_50_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 8]> = SmallVec::with_capacity(50);
-
-            sv.extend(0..50);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_8_50_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 8]> = SmallVec::new();
-
-            sv.extend(0..50);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_32_50_with_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 32]> = SmallVec::with_capacity(50);
-
-            sv.extend(0..50);
-        })
-    }
-
-    #[bench]
-    fn fill_small_vec_32_50_wo_cap(b: &mut Bencher) {
-        b.iter(|| {
-            let mut sv: SmallVec<[usize; 32]> = SmallVec::new();
-
-            sv.extend(0..50);
-        })
+        assert_eq!(1, (smallvec![1] as OneVector<_>).expect_one(""));
+        assert_eq!(1, OneVector::from_vec(vec![1]).expect_one(""));
     }
 }
index 0fd1f92a516278e06669a63bc9d3e02f8cba4a84..2da0ede9d15ce45f702a6468f1c9514608175456 100644 (file)
@@ -25,3 +25,4 @@ syntax = { path = "../libsyntax" }
 syntax_pos = { path = "../libsyntax_pos" }
 byteorder = { version = "1.1", features = ["i128"] }
 rustc_apfloat = { path = "../librustc_apfloat" }
+smallvec = { version = "0.6.5", features = ["union"] }
index f96f612734904ce5c01a38be71e0bbfecc34660b..70b6c8f25805c4259cd8a062ad49887b8a2c8aad 100644 (file)
@@ -29,7 +29,7 @@
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::indexed_set::IdxSet;
 use rustc_data_structures::indexed_vec::Idx;
-use rustc_data_structures::small_vec::SmallVec;
+use smallvec::SmallVec;
 
 use std::rc::Rc;
 
index 6a8157df0ccff03cd6e93029e5b7e80f857366d4..617efed31d913f73c4e81653a134eb0307ef62fd 100644 (file)
@@ -61,6 +61,7 @@
 extern crate rustc_apfloat;
 extern crate byteorder;
 extern crate core;
+extern crate smallvec;
 
 // Once we can use edition 2018 in the compiler,
 // replace this with real try blocks.
index 0e843ae66da62ba9386f6cea401b602f9a5b10bd..879b4ea3fe579f8568aeb1b685af9760e46e932e 100644 (file)
@@ -43,6 +43,7 @@
 use std::cell::Cell;
 use std::mem;
 use rustc_data_structures::sync::Lrc;
+use rustc_data_structures::small_vec::ExpectOne;
 
 crate struct FromPrelude(bool);
 crate struct FromExpansion(bool);
index 3e1a6ca9aff7c33f40db6c5540cc8ee71428749d..cd21ee601a7d2d47ffe0204b78cdfaac12bbb4a5 100644 (file)
@@ -17,3 +17,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
 syntax = { path = "../libsyntax" }
 syntax_pos = { path = "../libsyntax_pos" }
 chalk-engine = { version = "0.7.0", default-features=false }
+smallvec = { version = "0.6.5", features = ["union"] }
index 4227144e204fbbf9bf7eef356830de21dd9e8c06..4c28df97bdf50a5024907237b2699463f6ca45b0 100644 (file)
@@ -25,7 +25,7 @@
 use rustc::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
 use rustc::ty::subst::Kind;
 use rustc::ty::{self, TyCtxt};
-use rustc_data_structures::small_vec::SmallVec;
+use smallvec::SmallVec;
 
 use std::fmt::{self, Debug};
 use std::marker::PhantomData;
index ba6b2c57bfac6a15f71b9058d578b75c90957e3b..700efbd6ba942deee32e9dc0d2c635866ab199d1 100644 (file)
@@ -28,6 +28,7 @@
 extern crate rustc_data_structures;
 extern crate syntax;
 extern crate syntax_pos;
+extern crate smallvec;
 
 mod chalk_context;
 mod dropck_outlives;
index a896c4a634c3660fef9501949ca8178114ae9274..66140d9c01f82b860e9e494d6a748c6c19edf3d3 100644 (file)
@@ -7,3 +7,6 @@ version = "0.0.0"
 name = "serialize"
 path = "lib.rs"
 crate-type = ["dylib", "rlib"]
+
+[dependencies]
+smallvec = { version = "0.6.5", features = ["union"] }
index 9748a5063925bc8d86a9dc2656ca7dfe531d2ac3..3e028d755c6d4a5dd89634954b8ad836bc1baa16 100644 (file)
 use std::rc::Rc;
 use std::sync::Arc;
 
+use smallvec::{Array, SmallVec};
+
+impl<A> Encodable for SmallVec<A>
+    where A: Array,
+          A::Item: Encodable
+{
+    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
+        s.emit_seq(self.len(), |s| {
+            for (i, e) in self.iter().enumerate() {
+                s.emit_seq_elt(i, |s| e.encode(s))?;
+            }
+            Ok(())
+        })
+    }
+}
+
+impl<A> Decodable for SmallVec<A>
+    where A: Array,
+          A::Item: Decodable
+{
+    fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> {
+        d.read_seq(|d, len| {
+            let mut vec = SmallVec::with_capacity(len);
+            // FIXME(#48994) - could just be collected into a Result<SmallVec, D::Error>
+            for i in 0..len {
+                vec.push(d.read_seq_elt(i, |d| Decodable::decode(d))?);
+            }
+            Ok(vec)
+        })
+    }
+}
+
 impl<T: Encodable> Encodable for LinkedList<T> {
     fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
         s.emit_seq(self.len(), |s| {
index 794fc095096a479c754f07e26562fc8ae6989ca7..1f6ee3d867b17b3c7225b31a84266de1f039df8a 100644 (file)
@@ -32,6 +32,8 @@
 pub use self::serialize::{SpecializationError, SpecializedEncoder, SpecializedDecoder};
 pub use self::serialize::{UseSpecializedEncodable, UseSpecializedDecodable};
 
+extern crate smallvec;
+
 mod serialize;
 mod collection_impls;
 
index d1a5ab0211b3b08f57c02c3a5e686e838fd011db..519cc7aa92c556e135423cc15780e1766ef90951 100644 (file)
@@ -17,3 +17,4 @@ syntax_pos = { path = "../libsyntax_pos" }
 rustc_errors = { path = "../librustc_errors" }
 rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_target = { path = "../librustc_target" }
+smallvec = { version = "0.6.5", features = ["union"] }
index d044efa3c38af20be7fcca1f01ad125520c4aaf4..c5a2cd5ac0b439f03d22ad39f9b44c488c612cbc 100644 (file)
@@ -131,7 +131,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
     let sym = Ident::with_empty_ctxt(Symbol::gensym(&format!(
         "__register_diagnostic_{}", code
     )));
-    MacEager::items(OneVector::many(vec![
+    MacEager::items(OneVector::from_vec(vec![
         ecx.item_mod(
             span,
             span,
@@ -214,7 +214,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
         ),
     );
 
-    MacEager::items(OneVector::many(vec![
+    MacEager::items(OneVector::from_vec(vec![
         P(ast::Item {
             ident: *name,
             attrs: Vec::new(),
index c9925b41498cff95d32e8f1ebb2af21085b40758..75d24df7b629fc850a697ecf79837df431c48634 100644 (file)
@@ -316,11 +316,11 @@ fn expand<'cx>(&self,
 // Use a macro because forwarding to a simple function has type system issues
 macro_rules! make_stmts_default {
     ($me:expr) => {
-        $me.make_expr().map(|e| OneVector::one(ast::Stmt {
+        $me.make_expr().map(|e| smallvec![ast::Stmt {
             id: ast::DUMMY_NODE_ID,
             span: e.span,
             node: ast::StmtKind::Expr(e),
-        }))
+        }])
     }
 }
 
@@ -548,11 +548,11 @@ fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> {
     }
 
     fn make_stmts(self: Box<DummyResult>) -> Option<OneVector<ast::Stmt>> {
-        Some(OneVector::one(ast::Stmt {
+        Some(smallvec![ast::Stmt {
             id: ast::DUMMY_NODE_ID,
             node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)),
             span: self.span,
-        }))
+        }])
     }
 
     fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
index 494f6d29832dda19946a167002a63b330558f12c..a2e84b508dc12be3d042e0ba0348358b30a8fb28 100644 (file)
@@ -37,6 +37,7 @@
 use std::collections::HashMap;
 use std::fs::File;
 use std::io::Read;
+use std::iter::FromIterator;
 use std::{iter, mem};
 use std::rc::Rc;
 use std::path::PathBuf;
@@ -131,7 +132,7 @@ fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
                 self.expand_fragment(AstFragment::$Kind(ast)).$make_ast()
             })*)*
             $($(fn $fold_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
-                self.expand_fragment(AstFragment::$Kind(OneVector::one(ast_elt))).$make_ast()
+                self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
             })*)*
         }
 
@@ -270,7 +271,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
 
         let orig_mod_span = krate.module.inner;
 
-        let krate_item = AstFragment::Items(OneVector::one(P(ast::Item {
+        let krate_item = AstFragment::Items(smallvec![P(ast::Item {
             attrs: krate.attrs,
             span: krate.span,
             node: ast::ItemKind::Mod(krate.module),
@@ -278,7 +279,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
             id: ast::DUMMY_NODE_ID,
             vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
             tokens: None,
-        })));
+        })]);
 
         match self.expand_fragment(krate_item).make_items().pop().map(P::into_inner) {
             Some(ast::Item { attrs, node: ast::ItemKind::Mod(module), .. }) => {
@@ -1404,7 +1405,7 @@ fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
                         ui
                     });
 
-                    OneVector::many(
+                    OneVector::from_iter(
                         self.fold_unnameable(item).into_iter()
                             .chain(self.fold_unnameable(use_item)))
                 } else {
index 18b4119fde8e49767d270bff3c14ce3cfece17fc..7a8ccfddf8eb65cda1440ab7969617b8df838323 100644 (file)
@@ -46,37 +46,37 @@ fn mac_placeholder() -> ast::Mac {
     match kind {
         AstFragmentKind::Expr => AstFragment::Expr(expr_placeholder()),
         AstFragmentKind::OptExpr => AstFragment::OptExpr(Some(expr_placeholder())),
-        AstFragmentKind::Items => AstFragment::Items(OneVector::one(P(ast::Item {
+        AstFragmentKind::Items => AstFragment::Items(smallvec![P(ast::Item {
             id, span, ident, vis, attrs,
             node: ast::ItemKind::Mac(mac_placeholder()),
             tokens: None,
-        }))),
-        AstFragmentKind::TraitItems => AstFragment::TraitItems(OneVector::one(ast::TraitItem {
+        })]),
+        AstFragmentKind::TraitItems => AstFragment::TraitItems(smallvec![ast::TraitItem {
             id, span, ident, attrs, generics,
             node: ast::TraitItemKind::Macro(mac_placeholder()),
             tokens: None,
-        })),
-        AstFragmentKind::ImplItems => AstFragment::ImplItems(OneVector::one(ast::ImplItem {
+        }]),
+        AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![ast::ImplItem {
             id, span, ident, vis, attrs, generics,
             node: ast::ImplItemKind::Macro(mac_placeholder()),
             defaultness: ast::Defaultness::Final,
             tokens: None,
-        })),
+        }]),
         AstFragmentKind::ForeignItems =>
-            AstFragment::ForeignItems(OneVector::one(ast::ForeignItem {
+            AstFragment::ForeignItems(smallvec![ast::ForeignItem {
                 id, span, ident, vis, attrs,
                 node: ast::ForeignItemKind::Macro(mac_placeholder()),
-            })),
+            }]),
         AstFragmentKind::Pat => AstFragment::Pat(P(ast::Pat {
             id, span, node: ast::PatKind::Mac(mac_placeholder()),
         })),
         AstFragmentKind::Ty => AstFragment::Ty(P(ast::Ty {
             id, span, node: ast::TyKind::Mac(mac_placeholder()),
         })),
-        AstFragmentKind::Stmts => AstFragment::Stmts(OneVector::one({
+        AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
             let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ThinVec::new()));
             ast::Stmt { id, span, node: ast::StmtKind::Mac(mac) }
-        })),
+        }]),
     }
 }
 
@@ -118,7 +118,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
     fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
         match item.node {
             ast::ItemKind::Mac(_) => return self.remove(item.id).make_items(),
-            ast::ItemKind::MacroDef(_) => return OneVector::one(item),
+            ast::ItemKind::MacroDef(_) => return smallvec![item],
             _ => {}
         }
 
index 7d98fa661c039f44000a51d6d9d79290ba0d6cad..dcdeee5c2e700d015f2a4a7861a98f4ff26703c8 100644 (file)
@@ -644,7 +644,7 @@ pub fn parse(
     // This MatcherPos instance is allocated on the stack. All others -- and
     // there are frequently *no* others! -- are allocated on the heap.
     let mut initial = initial_matcher_pos(ms, parser.span.lo());
-    let mut cur_items = OneVector::one(MatcherPosHandle::Ref(&mut initial));
+    let mut cur_items = smallvec![MatcherPosHandle::Ref(&mut initial)];
     let mut next_items = Vec::new();
 
     loop {
index d451227e77cf3d7ffac51dc2cea844fbf1c7f5a7..67a15b149f6d50bd4dff1b02cfc2522c67d2715b 100644 (file)
@@ -70,7 +70,7 @@ pub fn transcribe(cx: &ExtCtxt,
                   interp: Option<HashMap<Ident, Rc<NamedMatch>>>,
                   src: Vec<quoted::TokenTree>)
                   -> TokenStream {
-    let mut stack = OneVector::one(Frame::new(src));
+    let mut stack: OneVector<Frame> = smallvec![Frame::new(src)];
     let interpolations = interp.unwrap_or_else(HashMap::new); /* just a convenience */
     let mut repeats = Vec::new();
     let mut result: Vec<TokenStream> = Vec::new();
index 050d21674f91aff5767488fec87dd2cd117db37b..660056e15e06b61f669c6d3fc16a4c1d5c089166 100644 (file)
@@ -31,6 +31,7 @@
 use util::move_map::MoveMap;
 
 use rustc_data_structures::sync::Lrc;
+use rustc_data_structures::small_vec::ExpectOne;
 
 pub trait Folder : Sized {
     // Any additions to this trait should happen in form
@@ -962,7 +963,7 @@ pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind {
 
 pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T)
                                        -> OneVector<TraitItem> {
-    OneVector::one(TraitItem {
+    smallvec![TraitItem {
         id: folder.new_id(i.id),
         ident: folder.fold_ident(i.ident),
         attrs: fold_attrs(i.attrs, folder),
@@ -986,12 +987,12 @@ pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T)
         },
         span: folder.new_span(i.span),
         tokens: i.tokens,
-    })
+    }]
 }
 
 pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)
                                       -> OneVector<ImplItem> {
-    OneVector::one(ImplItem {
+    smallvec![ImplItem {
         id: folder.new_id(i.id),
         vis: folder.fold_vis(i.vis),
         ident: folder.fold_ident(i.ident),
@@ -1014,7 +1015,7 @@ pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)
         },
         span: folder.new_span(i.span),
         tokens: i.tokens,
-    })
+    }]
 }
 
 pub fn noop_fold_fn_header<T: Folder>(mut header: FnHeader, folder: &mut T) -> FnHeader {
@@ -1067,7 +1068,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
 
 // fold one item into possibly many items
 pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> OneVector<P<Item>> {
-    OneVector::one(i.map(|i| folder.fold_item_simple(i)))
+    smallvec![i.map(|i| folder.fold_item_simple(i))]
 }
 
 // fold one item into exactly one item
@@ -1089,7 +1090,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span,
 
 pub fn noop_fold_foreign_item<T: Folder>(ni: ForeignItem, folder: &mut T)
 -> OneVector<ForeignItem> {
-    OneVector::one(folder.fold_foreign_item_simple(ni))
+    smallvec![folder.fold_foreign_item_simple(ni)]
 }
 
 pub fn noop_fold_foreign_item_simple<T: Folder>(ni: ForeignItem, folder: &mut T) -> ForeignItem {
@@ -1377,7 +1378,7 @@ pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) ->
 
 pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> OneVector<StmtKind> {
     match node {
-        StmtKind::Local(local) => OneVector::one(StmtKind::Local(folder.fold_local(local))),
+        StmtKind::Local(local) => smallvec![StmtKind::Local(folder.fold_local(local))],
         StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),
         StmtKind::Expr(expr) => {
             folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect()
@@ -1385,9 +1386,9 @@ pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> OneVect
         StmtKind::Semi(expr) => {
             folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect()
         }
-        StmtKind::Mac(mac) => OneVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
+        StmtKind::Mac(mac) => smallvec![StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
             (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
-        }))),
+        }))],
     }
 }
 
index 366b91fc8286e83de50cc9b3add14bfd20766ac7..2aaab6aaa16d931942844d5f06e73ff3bb076b3d 100644 (file)
@@ -40,6 +40,8 @@
 extern crate rustc_data_structures;
 extern crate rustc_target;
 #[macro_use] extern crate scoped_tls;
+#[macro_use]
+extern crate smallvec;
 
 extern crate serialize as rustc_serialize; // used by deriving
 
index 988f50b4f0c9ed845d7d5d3ac0cd8386e06ea966..49ab0c2256e89674c3e983217f79daad314345bf 100644 (file)
@@ -41,6 +41,7 @@
 use OneVector;
 use symbol::{self, Symbol, keywords};
 use ThinVec;
+use rustc_data_structures::small_vec::ExpectOne;
 
 enum ShouldPanic {
     No,
@@ -183,7 +184,7 @@ fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
         if ident.name != keywords::Invalid.name() {
             self.cx.path.pop();
         }
-        OneVector::one(P(item))
+        smallvec![P(item)]
     }
 
     fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac }
@@ -235,7 +236,7 @@ fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
             EntryPointType::OtherMain => folded,
         };
 
-        OneVector::one(folded)
+        smallvec![folded]
     }
 
     fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac }
index 1676757d9b89da186cae413333749efe3a85f9fa..8dba34583bef3ff25b1d8045a77dfc1a938f8285 100644 (file)
@@ -15,4 +15,5 @@ rustc_errors = { path = "../librustc_errors" }
 syntax = { path = "../libsyntax" }
 syntax_pos = { path = "../libsyntax_pos" }
 rustc_data_structures = { path = "../librustc_data_structures" }
-rustc_target = { path = "../librustc_target" }
\ No newline at end of file
+rustc_target = { path = "../librustc_target" }
+smallvec = { version = "0.6.5", features = ["union"] }
index 56f28d04e9d5c4bd8bc8f09eb79cbcd851df2867..1130a50537d017150d48e7e8e761d51522ee91da 100644 (file)
@@ -18,8 +18,6 @@
 /// LLVM's `module asm "some assembly here"`. All of LLVM's caveats
 /// therefore apply.
 
-use rustc_data_structures::small_vec::OneVector;
-
 use syntax::ast;
 use syntax::source_map::respan;
 use syntax::ext::base;
@@ -52,7 +50,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
         None => return DummyResult::any(sp),
     };
 
-    MacEager::items(OneVector::one(P(ast::Item {
+    MacEager::items(smallvec![P(ast::Item {
         ident: ast::Ident::with_empty_ctxt(Symbol::intern("")),
         attrs: Vec::new(),
         id: ast::DUMMY_NODE_ID,
@@ -63,5 +61,5 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
         vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
         span: sp,
         tokens: None,
-    })))
+    })])
 }
index 1ba4ab474258c76939a18a9ee8e6d0c81b78a667..790a42007fb1db5d55a956e3de9143232e9a7998 100644 (file)
@@ -29,6 +29,8 @@
 extern crate rustc_data_structures;
 extern crate rustc_errors as errors;
 extern crate rustc_target;
+#[macro_use]
+extern crate smallvec;
 
 mod diagnostics;
 
index ff5d9a59bfa0071c497ecf19f07b8a729d034256..533d0ac490c413c5179e50de334c5b1f51100b90 100644 (file)
@@ -31,7 +31,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
 
 fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree])
           -> Box<MacResult+'static> {
-    MacEager::items(OneVector::many(vec![
+    MacEager::items(OneVector::from_vec(vec![
         quote_item!(cx, struct Struct1;).unwrap(),
         quote_item!(cx, struct Struct2;).unwrap()
     ]))