From 9876e38f5cce74bf06a0af699eef7ee6510727d9 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 5 Aug 2018 12:04:56 +0200 Subject: [PATCH] Move SmallVec and ThinVec out of libsyntax --- src/Cargo.lock | 1 + src/librustc/hir/lowering.rs | 25 +++--- src/librustc/hir/mod.rs | 2 +- src/librustc_allocator/Cargo.toml | 1 + src/librustc_allocator/expand.rs | 14 ++-- src/librustc_allocator/lib.rs | 1 + src/librustc_data_structures/lib.rs | 1 + src/librustc_data_structures/small_vec.rs | 65 +++++++++++++++ .../thin_vec.rs | 0 src/librustc_driver/pretty.rs | 10 +-- src/libsyntax/ast.rs | 2 +- src/libsyntax/attr/mod.rs | 2 +- src/libsyntax/config.rs | 12 +-- src/libsyntax/diagnostics/plugin.rs | 6 +- src/libsyntax/ext/base.rs | 57 ++++++------- src/libsyntax/ext/build.rs | 11 +-- src/libsyntax/ext/expand.rs | 44 +++++----- src/libsyntax/ext/placeholders.rs | 29 +++---- src/libsyntax/ext/quote.rs | 7 +- src/libsyntax/ext/source_util.rs | 6 +- src/libsyntax/ext/tt/macro_parser.rs | 14 ++-- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/fold.rs | 37 ++++----- src/libsyntax/lib.rs | 6 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/test.rs | 15 ++-- src/libsyntax/util/move_map.rs | 5 +- src/libsyntax/util/small_vector.rs | 81 ------------------- src/libsyntax_ext/asm.rs | 4 +- src/libsyntax_ext/concat_idents.rs | 4 +- src/libsyntax_ext/deriving/debug.rs | 4 +- src/libsyntax_ext/deriving/generic/mod.rs | 3 +- src/libsyntax_ext/global_asm.rs | 6 +- .../auxiliary/issue-16723.rs | 6 +- .../pprust-expr-roundtrip.rs | 3 +- 35 files changed, 245 insertions(+), 245 deletions(-) rename src/{libsyntax/util => librustc_data_structures}/thin_vec.rs (100%) delete mode 100644 src/libsyntax/util/small_vector.rs diff --git a/src/Cargo.lock b/src/Cargo.lock index 71d064a13f36a..be414f094dc56 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2048,6 +2048,7 @@ version = "0.0.0" dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", + "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", "syntax 0.0.0", diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6b66fd8a2b2ff..9ae5ab7f8be2e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -51,6 +51,8 @@ use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, ELIDED_LIFETIMES_IN_PATHS}; use middle::cstore::CrateStore; use rustc_data_structures::indexed_vec::IndexVec; +use rustc_data_structures::small_vec::OneVector; +use rustc_data_structures::thin_vec::ThinVec; use session::Session; use util::common::FN_OUTPUT_NAME; use util::nodemap::{DefIdMap, NodeMap}; @@ -71,7 +73,6 @@ use syntax::std_inject; use syntax::symbol::{keywords, Symbol}; use syntax::tokenstream::{Delimited, TokenStream, TokenTree}; use syntax::parse::token::Token; -use syntax::util::small_vector::SmallVector; use syntax::visit::{self, Visitor}; use syntax_pos::{Span, MultiSpan}; @@ -3136,12 +3137,12 @@ impl<'a> LoweringContext<'a> { &mut self, decl: &FnDecl, header: &FnHeader, - ids: &mut SmallVector, + ids: &mut OneVector, ) { if let Some(id) = header.asyncness.opt_return_id() { ids.push(hir::ItemId { id }); } - struct IdVisitor<'a> { ids: &'a mut SmallVector } + struct IdVisitor<'a> { ids: &'a mut OneVector } impl<'a, 'b> Visitor<'a> for IdVisitor<'b> { fn visit_ty(&mut self, ty: &'a Ty) { match ty.node { @@ -3174,21 +3175,21 @@ impl<'a> LoweringContext<'a> { } } - fn lower_item_id(&mut self, i: &Item) -> SmallVector { + fn lower_item_id(&mut self, i: &Item) -> OneVector { match i.node { ItemKind::Use(ref use_tree) => { - let mut vec = SmallVector::one(hir::ItemId { id: i.id }); + let mut vec = OneVector::one(hir::ItemId { id: i.id }); self.lower_item_id_use_tree(use_tree, i.id, &mut vec); vec } - ItemKind::MacroDef(..) => SmallVector::new(), + ItemKind::MacroDef(..) => OneVector::new(), ItemKind::Fn(ref decl, ref header, ..) => { - let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + let mut ids = OneVector::one(hir::ItemId { id: i.id }); self.lower_impl_trait_ids(decl, header, &mut ids); ids }, ItemKind::Impl(.., None, _, ref items) => { - let mut ids = SmallVector::one(hir::ItemId { id: i.id }); + let mut ids = OneVector::one(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); @@ -3196,14 +3197,14 @@ impl<'a> LoweringContext<'a> { } ids }, - _ => SmallVector::one(hir::ItemId { id: i.id }), + _ => OneVector::one(hir::ItemId { id: i.id }), } } fn lower_item_id_use_tree(&mut self, tree: &UseTree, base_id: NodeId, - vec: &mut SmallVector) + vec: &mut OneVector) { match tree.kind { UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec { @@ -4295,8 +4296,8 @@ impl<'a> LoweringContext<'a> { } } - fn lower_stmt(&mut self, s: &Stmt) -> SmallVector { - SmallVector::one(match s.node { + fn lower_stmt(&mut self, s: &Stmt) -> OneVector { + OneVector::one(match s.node { StmtKind::Local(ref l) => Spanned { node: hir::StmtKind::Decl( P(Spanned { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 0003790e6d552..899d91990e2b2 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -33,13 +33,13 @@ use syntax::ext::hygiene::SyntaxContext; use syntax::ptr::P; use syntax::symbol::{Symbol, keywords}; use syntax::tokenstream::TokenStream; -use syntax::util::ThinVec; use syntax::util::parser::ExprPrecedence; use ty::AdtKind; use ty::query::Providers; use rustc_data_structures::indexed_vec; use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope}; +use rustc_data_structures::thin_vec::ThinVec; use serialize::{self, Encoder, Encodable, Decoder, Decodable}; use std::collections::BTreeMap; diff --git a/src/librustc_allocator/Cargo.toml b/src/librustc_allocator/Cargo.toml index 1cbde181cafae..83a918f2af837 100644 --- a/src/librustc_allocator/Cargo.toml +++ b/src/librustc_allocator/Cargo.toml @@ -10,6 +10,7 @@ test = false [dependencies] rustc = { path = "../librustc" } +rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 05843852ee0de..676dbeeeeb00b 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -9,6 +9,7 @@ // except according to those terms. use rustc::middle::allocator::AllocatorKind; +use rustc_data_structures::small_vec::OneVector; use rustc_errors; use syntax::{ ast::{ @@ -28,8 +29,7 @@ use syntax::{ fold::{self, Folder}, parse::ParseSess, ptr::P, - symbol::Symbol, - util::small_vector::SmallVector, + symbol::Symbol }; use syntax_pos::Span; @@ -65,7 +65,7 @@ struct ExpandAllocatorDirectives<'a> { } impl<'a> Folder for ExpandAllocatorDirectives<'a> { - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { debug!("in submodule {}", self.in_submod); let name = if attr::contains_name(&item.attrs, "global_allocator") { @@ -78,20 +78,20 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { _ => { self.handler .span_err(item.span, "allocators must be statics"); - return SmallVector::one(item); + return OneVector::one(item); } } if self.in_submod > 0 { self.handler .span_err(item.span, "`global_allocator` cannot be used in submodules"); - return SmallVector::one(item); + return OneVector::one(item); } if self.found { self.handler .span_err(item.span, "cannot define more than one #[global_allocator]"); - return SmallVector::one(item); + return OneVector::one(item); } self.found = true; @@ -152,7 +152,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { let module = f.cx.monotonic_expander().fold_item(module).pop().unwrap(); // Return the item and new submodule - let mut ret = SmallVector::with_capacity(2); + let mut ret = OneVector::with_capacity(2); ret.push(item); ret.push(module); diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index b217d3665a245..c7dc336b1ca51 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -12,6 +12,7 @@ #[macro_use] extern crate log; extern crate rustc; +extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_target; extern crate syntax; diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index dd90cf7ae19e4..8c8cc8ce7a19a 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -74,6 +74,7 @@ pub mod sorted_map; pub mod stable_hasher; pub mod sync; pub mod tiny_list; +pub mod thin_vec; pub mod transitive_relation; pub mod tuple_slice; pub use ena::unify; diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs index 76b01beb4bad3..c12039cfdd009 100644 --- a/src/librustc_data_structures/small_vec.rs +++ b/src/librustc_data_structures/small_vec.rs @@ -29,6 +29,8 @@ use array_vec::Array; pub struct SmallVec(AccumulateVec); +pub type OneVector = SmallVec<[T; 1]>; + impl Clone for SmallVec where A: Array, A::Element: Clone { @@ -222,6 +224,69 @@ mod tests { use super::*; + #[test] + fn test_len() { + let v: OneVector = 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 = (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 = v.into_iter().collect(); + assert_eq!(v, Vec::new()); + + let v = OneVector::one(1); + assert_eq!(v.into_iter().collect::>(), [1]); + + let v = OneVector::many(vec![1, 2, 3]); + assert_eq!(v.into_iter().collect::>(), [1, 2, 3]); + } + + #[test] + #[should_panic] + fn test_expect_one_zero() { + let _: isize = OneVector::new().expect_one(""); + } + + #[test] + #[should_panic] + fn test_expect_one_many() { + OneVector::many(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(|| { diff --git a/src/libsyntax/util/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs similarity index 100% rename from src/libsyntax/util/thin_vec.rs rename to src/librustc_data_structures/thin_vec.rs diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 3e74aef9e7345..a66392833f695 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -24,6 +24,8 @@ use rustc::session::Session; use rustc::session::config::{Input, OutputFilenames}; use rustc_borrowck as borrowck; use rustc_borrowck::graphviz as borrowck_dot; +use rustc_data_structures::small_vec::OneVector; +use rustc_data_structures::thin_vec::ThinVec; use rustc_metadata::cstore::CStore; use rustc_mir::util::{write_mir_pretty, write_mir_graphviz}; @@ -33,8 +35,6 @@ use syntax::fold::{self, Folder}; use syntax::print::{pprust}; use syntax::print::pprust::PrintState; use syntax::ptr::P; -use syntax::util::ThinVec; -use syntax::util::small_vector::SmallVector; use syntax_pos::{self, FileName}; use graphviz as dot; @@ -727,7 +727,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_item_kind(i, s)) } - fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, i: ast::TraitItem) -> OneVector { let is_const = match i.node { ast::TraitItemKind::Const(..) => true, ast::TraitItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => @@ -737,7 +737,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { self.run(is_const, |s| fold::noop_fold_trait_item(i, s)) } - fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, i: ast::ImplItem) -> OneVector { let is_const = match i.node { ast::ImplItemKind::Const(..) => true, ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) => @@ -785,7 +785,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> { node: ast::ExprKind::Loop(P(empty_block), None), id: self.sess.next_node_id(), span: syntax_pos::DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); let loop_stmt = ast::Stmt { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 28c1e4324de7a..17e3d88a9099d 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,6 @@ pub use self::UnsafeSource::*; pub use self::GenericArgs::*; pub use symbol::{Ident, Symbol as Name}; -pub use util::ThinVec; pub use util::parser::ExprPrecedence; use syntax_pos::{Span, DUMMY_SP}; @@ -25,6 +24,7 @@ use ptr::P; use rustc_data_structures::indexed_vec; use rustc_data_structures::indexed_vec::Idx; use symbol::{Symbol, keywords}; +use ThinVec; use tokenstream::{ThinTokenStream, TokenStream}; use serialize::{self, Encoder, Decoder}; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index b3b173db70b89..879f555ba03ee 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -33,8 +33,8 @@ use parse::{self, ParseSess, PResult}; use parse::token::{self, Token}; use ptr::P; use symbol::Symbol; +use ThinVec; use tokenstream::{TokenStream, TokenTree, Delimited}; -use util::ThinVec; use GLOBALS; use std::iter; diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 3364378913952..4fe78bf829a1c 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -15,9 +15,9 @@ use ast; use codemap::Spanned; use edition::Edition; use parse::{token, ParseSess}; +use OneVector; use ptr::P; -use util::small_vector::SmallVector; /// A folder that strips out items that do not belong in the current configuration. pub struct StripUnconfigured<'a> { @@ -319,22 +319,22 @@ impl<'a> fold::Folder for StripUnconfigured<'a> { Some(P(fold::noop_fold_expr(expr, self))) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { match self.configure_stmt(stmt) { Some(stmt) => fold::noop_fold_stmt(stmt, self), - None => return SmallVector::new(), + None => return OneVector::new(), } } - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { fold::noop_fold_item(configure!(self, item), self) } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { fold::noop_fold_impl_item(configure!(self, item), self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { fold::noop_fold_trait_item(configure!(self, item), self) } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 72ce2740190d4..6a5a2a5e500ff 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -19,9 +19,9 @@ use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::build::AstBuilder; use parse::token; use ptr::P; +use OneVector; use symbol::{keywords, Symbol}; use tokenstream::{TokenTree}; -use util::small_vector::SmallVector; use diagnostics::metadata::output_metadata; @@ -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(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ ecx.item_mod( span, span, @@ -214,7 +214,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ), ); - MacEager::items(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ P(ast::Item { ident: *name, attrs: Vec::new(), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index de391ee4219a4..482d8c2cf9866 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -22,8 +22,9 @@ use fold::{self, Folder}; use parse::{self, parser, DirectoryOwnership}; use parse::token; use ptr::P; +use OneVector; use symbol::{keywords, Ident, Symbol}; -use util::small_vector::SmallVector; +use ThinVec; use std::collections::HashMap; use std::iter; @@ -315,7 +316,7 @@ impl IdentMacroExpander for F // 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| SmallVector::one(ast::Stmt { + $me.make_expr().map(|e| OneVector::one(ast::Stmt { id: ast::DUMMY_NODE_ID, span: e.span, node: ast::StmtKind::Expr(e), @@ -331,22 +332,22 @@ pub trait MacResult { None } /// Create zero or more items. - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { None } /// Create zero or more impl items. - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { None } /// Create zero or more trait items. - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { None } /// Create zero or more items in an `extern {}` block - fn make_foreign_items(self: Box) -> Option> { None } + fn make_foreign_items(self: Box) -> Option> { None } /// Create a pattern. fn make_pat(self: Box) -> Option> { @@ -357,7 +358,7 @@ pub trait MacResult { /// /// By default this attempts to create an expression statement, /// returning None if that fails. - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { make_stmts_default!(self) } @@ -393,11 +394,11 @@ macro_rules! make_MacEager { make_MacEager! { expr: P, pat: P, - items: SmallVector>, - impl_items: SmallVector, - trait_items: SmallVector, - foreign_items: SmallVector, - stmts: SmallVector, + items: OneVector>, + impl_items: OneVector, + trait_items: OneVector, + foreign_items: OneVector, + stmts: OneVector, ty: P, } @@ -406,23 +407,23 @@ impl MacResult for MacEager { self.expr } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { self.items } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { self.impl_items } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { self.trait_items } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { self.foreign_items } - fn make_stmts(self: Box) -> Option> { + fn make_stmts(self: Box) -> Option> { match self.stmts.as_ref().map_or(0, |s| s.len()) { 0 => make_stmts_default!(self), _ => self.stmts, @@ -482,7 +483,7 @@ impl DummyResult { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))), span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } @@ -513,41 +514,41 @@ impl MacResult for DummyResult { Some(P(DummyResult::raw_pat(self.span))) } - fn make_items(self: Box) -> Option>> { + fn make_items(self: Box) -> Option>> { // this code needs a comment... why not always just return the Some() ? if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_impl_items(self: Box) -> Option> { + fn make_impl_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_trait_items(self: Box) -> Option> { + fn make_trait_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_foreign_items(self: Box) -> Option> { + fn make_foreign_items(self: Box) -> Option> { if self.expr_only { None } else { - Some(SmallVector::new()) + Some(OneVector::new()) } } - fn make_stmts(self: Box) -> Option> { - Some(SmallVector::one(ast::Stmt { + fn make_stmts(self: Box) -> Option> { + Some(OneVector::one(ast::Stmt { id: ast::DUMMY_NODE_ID, node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)), span: self.span, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6135650766569..1a17aa3e8fb64 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -16,6 +16,7 @@ use codemap::{dummy_spanned, respan, Spanned}; use ext::base::ExtCtxt; use ptr::P; use symbol::{Symbol, keywords}; +use ThinVec; // Transitional re-exports so qquote can find the paths it is looking for mod syntax { @@ -519,7 +520,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -547,7 +548,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -564,7 +565,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { init: None, id: ast::DUMMY_NODE_ID, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -603,7 +604,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, node, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } @@ -678,7 +679,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { expr: e, span, is_shorthand: false, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), } } fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec) -> P { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 12941a8566987..f7ea781e02115 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -26,12 +26,12 @@ use parse::{DirectoryOwnership, PResult, ParseSess}; use parse::token::{self, Token}; use parse::parser::Parser; use ptr::P; +use OneVector; use symbol::Symbol; use symbol::keywords; use syntax_pos::{Span, DUMMY_SP, FileName}; use syntax_pos::hygiene::ExpnFormat; use tokenstream::{TokenStream, TokenTree}; -use util::small_vector::SmallVector; use visit::{self, Visitor}; use std::collections::HashMap; @@ -131,7 +131,7 @@ macro_rules! ast_fragments { 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(SmallVector::one(ast_elt))).$make_ast() + self.expand_fragment(AstFragment::$Kind(OneVector::one(ast_elt))).$make_ast() })*)* } @@ -148,15 +148,15 @@ ast_fragments! { Expr(P) { "expression"; one fn fold_expr; fn visit_expr; fn make_expr; } Pat(P) { "pattern"; one fn fold_pat; fn visit_pat; fn make_pat; } Ty(P) { "type"; one fn fold_ty; fn visit_ty; fn make_ty; } - Stmts(SmallVector) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; } - Items(SmallVector>) { "item"; many fn fold_item; fn visit_item; fn make_items; } - TraitItems(SmallVector) { + Stmts(OneVector) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; } + Items(OneVector>) { "item"; many fn fold_item; fn visit_item; fn make_items; } + TraitItems(OneVector) { "trait item"; many fn fold_trait_item; fn visit_trait_item; fn make_trait_items; } - ImplItems(SmallVector) { + ImplItems(OneVector) { "impl item"; many fn fold_impl_item; fn visit_impl_item; fn make_impl_items; } - ForeignItems(SmallVector) { + ForeignItems(OneVector) { "foreign item"; many fn fold_foreign_item; fn visit_foreign_item; fn make_foreign_items; } } @@ -279,7 +279,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let orig_mod_span = krate.module.inner; - let krate_item = AstFragment::Items(SmallVector::one(P(ast::Item { + let krate_item = AstFragment::Items(OneVector::one(P(ast::Item { attrs: krate.attrs, span: krate.span, node: ast::ItemKind::Mod(krate.module), @@ -989,28 +989,28 @@ impl<'a> Parser<'a> { -> PResult<'a, AstFragment> { Ok(match kind { AstFragmentKind::Items => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while let Some(item) = self.parse_item()? { items.push(item); } AstFragment::Items(items) } AstFragmentKind::TraitItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { items.push(self.parse_trait_item(&mut false)?); } AstFragment::TraitItems(items) } AstFragmentKind::ImplItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { items.push(self.parse_impl_item(&mut false)?); } AstFragment::ImplItems(items) } AstFragmentKind::ForeignItems => { - let mut items = SmallVector::new(); + let mut items = OneVector::new(); while self.token != token::Eof { if let Some(item) = self.parse_foreign_item()? { items.push(item); @@ -1019,7 +1019,7 @@ impl<'a> Parser<'a> { AstFragment::ForeignItems(items) } AstFragmentKind::Stmts => { - let mut stmts = SmallVector::new(); + let mut stmts = OneVector::new(); while self.token != token::Eof && // won't make progress on a `}` self.token != token::CloseDelim(token::Brace) { @@ -1086,12 +1086,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { /// Folds the item allowing tests to be expanded because they are still nameable. /// This should probably only be called with module items - fn fold_nameable(&mut self, item: P) -> SmallVector> { + fn fold_nameable(&mut self, item: P) -> OneVector> { fold::noop_fold_item(item, self) } /// Folds the item but doesn't allow tests to occur within it - fn fold_unnameable(&mut self, item: P) -> SmallVector> { + fn fold_unnameable(&mut self, item: P) -> OneVector> { let was_nameable = mem::replace(&mut self.tests_nameable, false); let items = fold::noop_fold_item(item, self); self.tests_nameable = was_nameable; @@ -1254,10 +1254,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { }) } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { let mut stmt = match self.cfg.configure_stmt(stmt) { Some(stmt) => stmt, - None => return SmallVector::new(), + None => return OneVector::new(), }; // we'll expand attributes on expressions separately @@ -1313,7 +1313,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { result } - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { let item = configure!(self, item); let (attr, traits, mut item) = self.classify_item(item); @@ -1422,7 +1422,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { ui }); - SmallVector::many( + OneVector::many( self.fold_unnameable(item).into_iter() .chain(self.fold_unnameable(use_item))) } else { @@ -1433,7 +1433,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { let item = configure!(self, item); let (attr, traits, item) = self.classify_item(item); @@ -1453,7 +1453,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { let item = configure!(self, item); let (attr, traits, item) = self.classify_item(item); @@ -1490,7 +1490,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { } fn fold_foreign_item(&mut self, - foreign_item: ast::ForeignItem) -> SmallVector { + foreign_item: ast::ForeignItem) -> OneVector { let (attr, traits, foreign_item) = self.classify_item(foreign_item); if attr.is_some() || !traits.is_empty() { diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 968cf508edaaa..1dc9bae8848f3 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -16,9 +16,10 @@ use ext::hygiene::Mark; use tokenstream::TokenStream; use fold::*; use ptr::P; +use OneVector; use symbol::keywords; +use ThinVec; use util::move_map::MoveMap; -use util::small_vector::SmallVector; use std::collections::HashMap; @@ -38,31 +39,31 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { let span = DUMMY_SP; let expr_placeholder = || P(ast::Expr { id, span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), node: ast::ExprKind::Mac(mac_placeholder()), }); match kind { AstFragmentKind::Expr => AstFragment::Expr(expr_placeholder()), AstFragmentKind::OptExpr => AstFragment::OptExpr(Some(expr_placeholder())), - AstFragmentKind::Items => AstFragment::Items(SmallVector::one(P(ast::Item { + AstFragmentKind::Items => AstFragment::Items(OneVector::one(P(ast::Item { id, span, ident, vis, attrs, node: ast::ItemKind::Mac(mac_placeholder()), tokens: None, }))), - AstFragmentKind::TraitItems => AstFragment::TraitItems(SmallVector::one(ast::TraitItem { + AstFragmentKind::TraitItems => AstFragment::TraitItems(OneVector::one(ast::TraitItem { id, span, ident, attrs, generics, node: ast::TraitItemKind::Macro(mac_placeholder()), tokens: None, })), - AstFragmentKind::ImplItems => AstFragment::ImplItems(SmallVector::one(ast::ImplItem { + AstFragmentKind::ImplItems => AstFragment::ImplItems(OneVector::one(ast::ImplItem { id, span, ident, vis, attrs, generics, node: ast::ImplItemKind::Macro(mac_placeholder()), defaultness: ast::Defaultness::Final, tokens: None, })), AstFragmentKind::ForeignItems => - AstFragment::ForeignItems(SmallVector::one(ast::ForeignItem { + AstFragment::ForeignItems(OneVector::one(ast::ForeignItem { id, span, ident, vis, attrs, node: ast::ForeignItemKind::Macro(mac_placeholder()), })), @@ -72,8 +73,8 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment { AstFragmentKind::Ty => AstFragment::Ty(P(ast::Ty { id, span, node: ast::TyKind::Mac(mac_placeholder()), })), - AstFragmentKind::Stmts => AstFragment::Stmts(SmallVector::one({ - let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::ThinVec::new())); + AstFragmentKind::Stmts => AstFragment::Stmts(OneVector::one({ + let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ThinVec::new())); ast::Stmt { id, span, node: ast::StmtKind::Mac(mac) } })), } @@ -114,31 +115,31 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> { } impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { - fn fold_item(&mut self, item: P) -> SmallVector> { + fn fold_item(&mut self, item: P) -> OneVector> { match item.node { ast::ItemKind::Mac(_) => return self.remove(item.id).make_items(), - ast::ItemKind::MacroDef(_) => return SmallVector::one(item), + ast::ItemKind::MacroDef(_) => return OneVector::one(item), _ => {} } noop_fold_item(item, self) } - fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector { match item.node { ast::TraitItemKind::Macro(_) => self.remove(item.id).make_trait_items(), _ => noop_fold_trait_item(item, self), } } - fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector { match item.node { ast::ImplItemKind::Macro(_) => self.remove(item.id).make_impl_items(), _ => noop_fold_impl_item(item, self), } } - fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> SmallVector { + fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> OneVector { match item.node { ast::ForeignItemKind::Macro(_) => self.remove(item.id).make_foreign_items(), _ => noop_fold_foreign_item(item, self), @@ -159,7 +160,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { } } - fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector { + fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector { let (style, mut stmts) = match stmt.node { ast::StmtKind::Mac(mac) => (mac.1, self.remove(stmt.id).make_stmts()), _ => return noop_fold_stmt(stmt, self), diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 1ace4d4a880e2..bc891700fc1b6 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -34,6 +34,7 @@ pub mod rt { use parse::token::{self, Token}; use ptr::P; use symbol::Symbol; + use ThinVec; use tokenstream::{self, TokenTree, TokenStream}; @@ -274,7 +275,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(self.clone())), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }).to_tokens(cx) } } @@ -305,7 +306,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(dummy_spanned(lit))), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); if *self >= 0 { return lit.to_tokens(cx); @@ -314,7 +315,7 @@ pub mod rt { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Unary(ast::UnOp::Neg, lit), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }).to_tokens(cx) } } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 0c36c072a0302..9b7e0fe1ae55c 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -17,9 +17,9 @@ use parse::{token, DirectoryOwnership}; use parse; use print::pprust; use ptr::P; +use OneVector; use symbol::Symbol; use tokenstream; -use util::small_vector::SmallVector; use std::fs::File; use std::io::prelude::*; @@ -111,8 +111,8 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T Some(panictry!(self.p.parse_expr())) } fn make_items(mut self: Box>) - -> Option>> { - let mut ret = SmallVector::new(); + -> Option>> { + let mut ret = OneVector::new(); while self.p.token != token::Eof { match panictry!(self.p.parse_item()) { Some(item) => ret.push(item), diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 3046525b7144c..82f88d1d8643e 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -92,9 +92,9 @@ use parse::{Directory, ParseSess}; use parse::parser::{Parser, PathStyle}; use parse::token::{self, DocComment, Nonterminal, Token}; use print::pprust; +use OneVector; use symbol::keywords; use tokenstream::TokenStream; -use util::small_vector::SmallVector; use std::mem; use std::ops::{Deref, DerefMut}; @@ -440,10 +440,10 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool { /// A `ParseResult`. Note that matches are kept track of through the items generated. fn inner_parse_loop<'a>( sess: &ParseSess, - cur_items: &mut SmallVector>, + cur_items: &mut OneVector>, next_items: &mut Vec>, - eof_items: &mut SmallVector>, - bb_items: &mut SmallVector>, + eof_items: &mut OneVector>, + bb_items: &mut OneVector>, token: &Token, span: syntax_pos::Span, ) -> ParseResult<()> { @@ -644,15 +644,15 @@ 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 = SmallVector::one(MatcherPosHandle::Ref(&mut initial)); + let mut cur_items = OneVector::one(MatcherPosHandle::Ref(&mut initial)); let mut next_items = Vec::new(); loop { // Matcher positions black-box parsed by parser.rs (`parser`) - let mut bb_items = SmallVector::new(); + let mut bb_items = OneVector::new(); // Matcher positions that would be valid if the macro invocation was over now - let mut eof_items = SmallVector::new(); + let mut eof_items = OneVector::new(); assert!(next_items.is_empty()); // Process `cur_items` until either we have finished the input or we need to get some diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 1cdb6b0e5c902..d451227e77cf3 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -15,9 +15,9 @@ use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; use ext::tt::quoted; use fold::noop_fold_tt; use parse::token::{self, Token, NtTT}; +use OneVector; use syntax_pos::{Span, DUMMY_SP}; use tokenstream::{TokenStream, TokenTree, Delimited}; -use util::small_vector::SmallVector; use std::rc::Rc; use rustc_data_structures::sync::Lrc; @@ -70,7 +70,7 @@ pub fn transcribe(cx: &ExtCtxt, interp: Option>>, src: Vec) -> TokenStream { - let mut stack = SmallVector::one(Frame::new(src)); + let mut stack = OneVector::one(Frame::new(src)); let interpolations = interp.unwrap_or_else(HashMap::new); /* just a convenience */ let mut repeats = Vec::new(); let mut result: Vec = Vec::new(); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 9d5982c1e2861..3209939d9b14d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -24,9 +24,10 @@ use syntax_pos::Span; use codemap::{Spanned, respan}; use parse::token::{self, Token}; use ptr::P; +use OneVector; use symbol::keywords; +use ThinVec; use tokenstream::*; -use util::small_vector::SmallVector; use util::move_map::MoveMap; use rustc_data_structures::sync::Lrc; @@ -60,7 +61,7 @@ pub trait Folder : Sized { noop_fold_use_tree(use_tree, self) } - fn fold_foreign_item(&mut self, ni: ForeignItem) -> SmallVector { + fn fold_foreign_item(&mut self, ni: ForeignItem) -> OneVector { noop_fold_foreign_item(ni, self) } @@ -68,7 +69,7 @@ pub trait Folder : Sized { noop_fold_foreign_item_simple(ni, self) } - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { noop_fold_item(i, self) } @@ -88,11 +89,11 @@ pub trait Folder : Sized { noop_fold_item_kind(i, self) } - fn fold_trait_item(&mut self, i: TraitItem) -> SmallVector { + fn fold_trait_item(&mut self, i: TraitItem) -> OneVector { noop_fold_trait_item(i, self) } - fn fold_impl_item(&mut self, i: ImplItem) -> SmallVector { + fn fold_impl_item(&mut self, i: ImplItem) -> OneVector { noop_fold_impl_item(i, self) } @@ -108,7 +109,7 @@ pub trait Folder : Sized { noop_fold_block(b, self) } - fn fold_stmt(&mut self, s: Stmt) -> SmallVector { + fn fold_stmt(&mut self, s: Stmt) -> OneVector { noop_fold_stmt(s, self) } @@ -960,8 +961,8 @@ pub fn noop_fold_item_kind(i: ItemKind, folder: &mut T) -> ItemKind { } pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) - -> SmallVector { - SmallVector::one(TraitItem { + -> OneVector { + OneVector::one(TraitItem { id: folder.new_id(i.id), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), @@ -989,8 +990,8 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) } pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) - -> SmallVector { - SmallVector::one(ImplItem { + -> OneVector { + OneVector::one(ImplItem { id: folder.new_id(i.id), vis: folder.fold_vis(i.vis), ident: folder.fold_ident(i.ident), @@ -1065,8 +1066,8 @@ pub fn noop_fold_crate(Crate {module, attrs, span}: Crate, } // fold one item into possibly many items -pub fn noop_fold_item(i: P, folder: &mut T) -> SmallVector> { - SmallVector::one(i.map(|i| folder.fold_item_simple(i))) +pub fn noop_fold_item(i: P, folder: &mut T) -> OneVector> { + OneVector::one(i.map(|i| folder.fold_item_simple(i))) } // fold one item into exactly one item @@ -1087,8 +1088,8 @@ pub fn noop_fold_item_simple(Item {id, ident, attrs, node, vis, span, } pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) --> SmallVector { - SmallVector::one(folder.fold_foreign_item_simple(ni)) +-> OneVector { + OneVector::one(folder.fold_foreign_item_simple(ni)) } pub fn noop_fold_foreign_item_simple(ni: ForeignItem, folder: &mut T) -> ForeignItem { @@ -1366,7 +1367,7 @@ pub fn noop_fold_exprs(es: Vec>, folder: &mut T) -> Vec(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVector { +pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> OneVector { let id = folder.new_id(id); let span = folder.new_span(span); noop_fold_stmt_kind(node, folder).into_iter().map(|node| { @@ -1374,9 +1375,9 @@ pub fn noop_fold_stmt(Stmt {node, span, id}: Stmt, folder: &mut T) -> }).collect() } -pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> SmallVector { +pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> OneVector { match node { - StmtKind::Local(local) => SmallVector::one(StmtKind::Local(folder.fold_local(local))), + StmtKind::Local(local) => OneVector::one(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() @@ -1384,7 +1385,7 @@ pub fn noop_fold_stmt_kind(node: StmtKind, folder: &mut T) -> SmallVe StmtKind::Semi(expr) => { folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect() } - StmtKind::Mac(mac) => SmallVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| { + StmtKind::Mac(mac) => OneVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| { (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into()) }))), } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index c8e60620248b3..7937799272c66 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -43,6 +43,8 @@ extern crate serialize as rustc_serialize; // used by deriving use rustc_data_structures::sync::Lock; use rustc_data_structures::bitvec::BitVector; +pub use rustc_data_structures::small_vec::OneVector; +pub use rustc_data_structures::thin_vec::ThinVec; use ast::AttrId; // A variant of 'try!' that panics on an Err. This is used as a crutch on the @@ -122,12 +124,8 @@ pub mod util { pub mod parser; #[cfg(test)] pub mod parser_testing; - pub mod small_vector; pub mod move_map; - mod thin_vec; - pub use self::thin_vec::ThinVec; - mod rc_slice; pub use self::rc_slice::RcSlice; } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9011b6e48b974..27b0f23315180 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -53,9 +53,9 @@ use util::parser::{AssocOp, Fixity}; use print::pprust; use ptr::P; use parse::PResult; +use ThinVec; use tokenstream::{self, Delimited, ThinTokenStream, TokenTree, TokenStream}; use symbol::{Symbol, keywords}; -use util::ThinVec; use std::borrow::Cow; use std::cmp; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index d8b8d13a38c2e..41701f4b9c94d 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -38,8 +38,9 @@ use parse::{token, ParseSess}; use print::pprust; use ast::{self, Ident}; use ptr::P; +use OneVector; use symbol::{self, Symbol, keywords}; -use util::small_vector::SmallVector; +use ThinVec; enum ShouldPanic { No, @@ -115,7 +116,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { folded } - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { let ident = i.ident; if ident.name != keywords::Invalid.name() { self.cx.path.push(ident); @@ -182,7 +183,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { if ident.name != keywords::Invalid.name() { self.cx.path.pop(); } - SmallVector::one(P(item)) + OneVector::one(P(item)) } fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac } @@ -194,7 +195,7 @@ struct EntryPointCleaner { } impl fold::Folder for EntryPointCleaner { - fn fold_item(&mut self, i: P) -> SmallVector> { + fn fold_item(&mut self, i: P) -> OneVector> { self.depth += 1; let folded = fold::noop_fold_item(i, self).expect_one("noop did something"); self.depth -= 1; @@ -234,7 +235,7 @@ impl fold::Folder for EntryPointCleaner { EntryPointType::OtherMain => folded, }; - SmallVector::one(folded) + OneVector::one(folded) } fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { mac } @@ -675,10 +676,10 @@ fn mk_test_descs(cx: &TestCtxt) -> P { mk_test_desc_and_fn_rec(cx, test) }).collect()), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })), span: DUMMY_SP, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }) } diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/move_map.rs index 8cc37afa354ff..eb2c5a2458c15 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/move_map.rs @@ -9,8 +9,7 @@ // except according to those terms. use std::ptr; - -use util::small_vector::SmallVector; +use OneVector; pub trait MoveMap: Sized { fn move_map(self, mut f: F) -> Self where F: FnMut(T) -> T { @@ -78,7 +77,7 @@ impl MoveMap for ::ptr::P<[T]> { } } -impl MoveMap for SmallVector { +impl MoveMap for OneVector { fn move_flat_map(mut self, mut f: F) -> Self where F: FnMut(T) -> I, I: IntoIterator diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs deleted file mode 100644 index 31e675836fc72..0000000000000 --- a/src/libsyntax/util/small_vector.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use rustc_data_structures::small_vec::SmallVec; - -pub type SmallVector = SmallVec<[T; 1]>; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_len() { - let v: SmallVector = SmallVector::new(); - assert_eq!(0, v.len()); - - assert_eq!(1, SmallVector::one(1).len()); - assert_eq!(5, SmallVector::many(vec![1, 2, 3, 4, 5]).len()); - } - - #[test] - fn test_push_get() { - let mut v = SmallVector::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: SmallVector = (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 = SmallVector::new(); - let v: Vec = v.into_iter().collect(); - assert_eq!(v, Vec::new()); - - let v = SmallVector::one(1); - assert_eq!(v.into_iter().collect::>(), [1]); - - let v = SmallVector::many(vec![1, 2, 3]); - assert_eq!(v.into_iter().collect::>(), [1, 2, 3]); - } - - #[test] - #[should_panic] - fn test_expect_one_zero() { - let _: isize = SmallVector::new().expect_one(""); - } - - #[test] - #[should_panic] - fn test_expect_one_many() { - SmallVector::many(vec![1, 2]).expect_one(""); - } - - #[test] - fn test_expect_one_one() { - assert_eq!(1, SmallVector::one(1).expect_one("")); - assert_eq!(1, SmallVector::many(vec![1]).expect_one("")); - } -} diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 4ebb1fcb65393..026ddccd7be97 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -12,6 +12,8 @@ // use self::State::*; +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast; use syntax::ext::base; use syntax::ext::base::*; @@ -263,6 +265,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, ctxt: cx.backtrace(), })), span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index a3c5c3df66e4c..c8cc11e43545a 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast; use syntax::ext::base::*; use syntax::ext::base; @@ -68,7 +70,7 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path::from_ident(self.ident)), span: self.ident.span, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), })) } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index c2a7dea331673..df9c351ef1c95 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -12,6 +12,8 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; +use rustc_data_structures::thin_vec::ThinVec; + use syntax::ast::{self, Ident}; use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; @@ -139,7 +141,7 @@ fn stmt_let_undescore(cx: &mut ExtCtxt, sp: Span, expr: P) -> ast::St init: Some(expr), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e0f985c26c7a1..41759c375b8ee 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -191,6 +191,7 @@ use std::cell::RefCell; use std::iter; use std::vec; +use rustc_data_structures::thin_vec::ThinVec; use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; @@ -1624,7 +1625,7 @@ impl<'a> TraitDef<'a> { ident: ident.unwrap(), pat, is_shorthand: false, - attrs: ast::ThinVec::new(), + attrs: ThinVec::new(), }, } }) diff --git a/src/libsyntax_ext/global_asm.rs b/src/libsyntax_ext/global_asm.rs index 40ecd6e1519c3..7290b701e4dec 100644 --- a/src/libsyntax_ext/global_asm.rs +++ b/src/libsyntax_ext/global_asm.rs @@ -18,6 +18,8 @@ /// 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::codemap::respan; use syntax::ext::base; @@ -28,8 +30,6 @@ use syntax::symbol::Symbol; use syntax_pos::Span; use syntax::tokenstream; -use syntax::util::small_vector::SmallVector; - pub const MACRO: &'static str = "global_asm"; pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, @@ -52,7 +52,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt, None => return DummyResult::any(sp), }; - MacEager::items(SmallVector::one(P(ast::Item { + MacEager::items(OneVector::one(P(ast::Item { ident: ast::Ident::with_empty_ctxt(Symbol::intern("")), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs index 7f8a741465b30..ff5d9a59bfa00 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs @@ -15,12 +15,12 @@ extern crate syntax; extern crate rustc; +extern crate rustc_data_structures; extern crate rustc_plugin; extern crate syntax_pos; -use syntax::ast; +use rustc_data_structures::small_vec::OneVector; use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; -use syntax::util::small_vector::SmallVector; use syntax::tokenstream; use rustc_plugin::Registry; @@ -31,7 +31,7 @@ pub fn plugin_registrar(reg: &mut Registry) { fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree]) -> Box { - MacEager::items(SmallVector::many(vec![ + MacEager::items(OneVector::many(vec![ quote_item!(cx, struct Struct1;).unwrap(), quote_item!(cx, struct Struct2;).unwrap() ])) diff --git a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs index bbd81e790b838..3da50f1696545 100644 --- a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs @@ -30,8 +30,10 @@ #![feature(rustc_private)] +extern crate rustc_data_structures; extern crate syntax; +use rustc_data_structures::thin_vec::ThinVec; use syntax::ast::*; use syntax::codemap::{Spanned, DUMMY_SP, FileName}; use syntax::codemap::FilePathMapping; @@ -39,7 +41,6 @@ use syntax::fold::{self, Folder}; use syntax::parse::{self, ParseSess}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::util::ThinVec; fn parse_expr(ps: &ParseSess, src: &str) -> P {