Auto merge of #53085 - ljedrz:cleanup_syntax_structures, r=ljedrz

Move SmallVector and ThinVec out of libsyntax

- move `libsyntax::util::SmallVector` tests to `librustc_data_structures::small_vec`
- remove `libsyntax::util::SmallVector`
- move `libsyntax::util::thin_vec` to `librustc_data_structures::thin_vec`

Other than moving these data structures where they belong it allows modules using `SmallVector<T>` (`SmallVec<[T; 1]>`) to specify their own length (e.g. 8 or 32) independently from `libsyntax`.
This commit is contained in:
bors 2018-08-14 15:09:37 +00:00
commit 23f09bbed4
35 changed files with 245 additions and 245 deletions

View File

@ -2049,6 +2049,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",

View File

@ -51,6 +51,8 @@
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::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 @@ fn lower_impl_trait_ids(
&mut self,
decl: &FnDecl,
header: &FnHeader,
ids: &mut SmallVector<hir::ItemId>,
ids: &mut OneVector<hir::ItemId>,
) {
if let Some(id) = header.asyncness.opt_return_id() {
ids.push(hir::ItemId { id });
}
struct IdVisitor<'a> { ids: &'a mut SmallVector<hir::ItemId> }
struct IdVisitor<'a> { ids: &'a mut OneVector<hir::ItemId> }
impl<'a, 'b> Visitor<'a> for IdVisitor<'b> {
fn visit_ty(&mut self, ty: &'a Ty) {
match ty.node {
@ -3174,21 +3175,21 @@ fn visit_path_segment(
}
}
fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> {
fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
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 @@ fn lower_item_id(&mut self, i: &Item) -> SmallVector<hir::ItemId> {
}
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<hir::ItemId>)
vec: &mut OneVector<hir::ItemId>)
{
match tree.kind {
UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec {
@ -4295,8 +4296,8 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
}
}
fn lower_stmt(&mut self, s: &Stmt) -> SmallVector<hir::Stmt> {
SmallVector::one(match s.node {
fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
OneVector::one(match s.node {
StmtKind::Local(ref l) => Spanned {
node: hir::StmtKind::Decl(
P(Spanned {

View File

@ -33,13 +33,13 @@
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;

View File

@ -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" }

View File

@ -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 @@
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<Item>) -> SmallVector<P<Item>> {
fn fold_item(&mut self, item: P<Item>) -> OneVector<P<Item>> {
debug!("in submodule {}", self.in_submod);
let name = if attr::contains_name(&item.attrs, "global_allocator") {
@ -78,20 +78,20 @@ fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> {
_ => {
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 @@ fn fold_item(&mut self, item: P<Item>) -> SmallVector<P<Item>> {
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);

View File

@ -13,6 +13,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;

View File

@ -79,6 +79,7 @@
#[macro_use] 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;

View File

@ -29,6 +29,8 @@
pub struct SmallVec<A: Array>(AccumulateVec<A>);
pub type OneVector<T> = SmallVec<[T; 1]>;
impl<A> Clone for SmallVec<A>
where A: Array,
A::Element: Clone {
@ -227,6 +229,69 @@ mod tests {
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() {
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(|| {

View File

@ -24,6 +24,8 @@
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::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 @@ fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
self.run(is_const, |s| fold::noop_fold_item_kind(i, s))
}
fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem> {
fn fold_trait_item(&mut self, i: ast::TraitItem) -> OneVector<ast::TraitItem> {
let is_const = match i.node {
ast::TraitItemKind::Const(..) => true,
ast::TraitItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) =>
@ -737,7 +737,7 @@ fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem>
self.run(is_const, |s| fold::noop_fold_trait_item(i, s))
}
fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector<ast::ImplItem> {
fn fold_impl_item(&mut self, i: ast::ImplItem) -> OneVector<ast::ImplItem> {
let is_const = match i.node {
ast::ImplItemKind::Const(..) => true,
ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) =>
@ -785,7 +785,7 @@ fn block_to_stmt(b: ast::Block, sess: &Session) -> ast::Stmt {
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 {

View File

@ -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 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};

View File

@ -33,8 +33,8 @@
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;

View File

@ -15,9 +15,9 @@
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 @@ fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
Some(P(fold::noop_fold_expr(expr, self)))
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
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<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
fold::noop_fold_item(configure!(self, item), self)
}
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
fold::noop_fold_impl_item(configure!(self, item), self)
}
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
fold::noop_fold_trait_item(configure!(self, item), self)
}

View File

@ -19,9 +19,9 @@
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(),

View File

@ -22,8 +22,9 @@
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 @@ 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| 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 @@ fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
None
}
/// Create zero or more items.
fn make_items(self: Box<Self>) -> Option<SmallVector<P<ast::Item>>> {
fn make_items(self: Box<Self>) -> Option<OneVector<P<ast::Item>>> {
None
}
/// Create zero or more impl items.
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
fn make_impl_items(self: Box<Self>) -> Option<OneVector<ast::ImplItem>> {
None
}
/// Create zero or more trait items.
fn make_trait_items(self: Box<Self>) -> Option<SmallVector<ast::TraitItem>> {
fn make_trait_items(self: Box<Self>) -> Option<OneVector<ast::TraitItem>> {
None
}
/// Create zero or more items in an `extern {}` block
fn make_foreign_items(self: Box<Self>) -> Option<SmallVector<ast::ForeignItem>> { None }
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> { None }
/// Create a pattern.
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
@ -357,7 +358,7 @@ fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
///
/// By default this attempts to create an expression statement,
/// returning None if that fails.
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
fn make_stmts(self: Box<Self>) -> Option<OneVector<ast::Stmt>> {
make_stmts_default!(self)
}
@ -393,11 +394,11 @@ pub fn $fld(v: $t) -> Box<dyn MacResult> {
make_MacEager! {
expr: P<ast::Expr>,
pat: P<ast::Pat>,
items: SmallVector<P<ast::Item>>,
impl_items: SmallVector<ast::ImplItem>,
trait_items: SmallVector<ast::TraitItem>,
foreign_items: SmallVector<ast::ForeignItem>,
stmts: SmallVector<ast::Stmt>,
items: OneVector<P<ast::Item>>,
impl_items: OneVector<ast::ImplItem>,
trait_items: OneVector<ast::TraitItem>,
foreign_items: OneVector<ast::ForeignItem>,
stmts: OneVector<ast::Stmt>,
ty: P<ast::Ty>,
}
@ -406,23 +407,23 @@ fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
self.expr
}
fn make_items(self: Box<Self>) -> Option<SmallVector<P<ast::Item>>> {
fn make_items(self: Box<Self>) -> Option<OneVector<P<ast::Item>>> {
self.items
}
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
fn make_impl_items(self: Box<Self>) -> Option<OneVector<ast::ImplItem>> {
self.impl_items
}
fn make_trait_items(self: Box<Self>) -> Option<SmallVector<ast::TraitItem>> {
fn make_trait_items(self: Box<Self>) -> Option<OneVector<ast::TraitItem>> {
self.trait_items
}
fn make_foreign_items(self: Box<Self>) -> Option<SmallVector<ast::ForeignItem>> {
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> {
self.foreign_items
}
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
fn make_stmts(self: Box<Self>) -> Option<OneVector<ast::Stmt>> {
match self.stmts.as_ref().map_or(0, |s| s.len()) {
0 => make_stmts_default!(self),
_ => self.stmts,
@ -482,7 +483,7 @@ pub fn raw_expr(sp: Span) -> P<ast::Expr> {
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 @@ fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
Some(P(DummyResult::raw_pat(self.span)))
}
fn make_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Item>>> {
fn make_items(self: Box<DummyResult>) -> Option<OneVector<P<ast::Item>>> {
// 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<DummyResult>) -> Option<SmallVector<ast::ImplItem>> {
fn make_impl_items(self: Box<DummyResult>) -> Option<OneVector<ast::ImplItem>> {
if self.expr_only {
None
} else {
Some(SmallVector::new())
Some(OneVector::new())
}
}
fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVector<ast::TraitItem>> {
fn make_trait_items(self: Box<DummyResult>) -> Option<OneVector<ast::TraitItem>> {
if self.expr_only {
None
} else {
Some(SmallVector::new())
Some(OneVector::new())
}
}
fn make_foreign_items(self: Box<Self>) -> Option<SmallVector<ast::ForeignItem>> {
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> {
if self.expr_only {
None
} else {
Some(SmallVector::new())
Some(OneVector::new())
}
}
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<ast::Stmt>> {
Some(SmallVector::one(ast::Stmt {
fn make_stmts(self: Box<DummyResult>) -> Option<OneVector<ast::Stmt>> {
Some(OneVector::one(ast::Stmt {
id: ast::DUMMY_NODE_ID,
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)),
span: self.span,

View File

@ -16,6 +16,7 @@
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 @@ fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
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 @@ fn stmt_let_typed(&self,
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 @@ fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt {
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 @@ fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> {
id: ast::DUMMY_NODE_ID,
node,
span,
attrs: ast::ThinVec::new(),
attrs: ThinVec::new(),
})
}
@ -678,7 +679,7 @@ fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::Field {
expr: e,
span,
is_shorthand: false,
attrs: ast::ThinVec::new(),
attrs: ThinVec::new(),
}
}
fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr> {

View File

@ -26,12 +26,12 @@
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 @@ 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(SmallVector::one(ast_elt))).$make_ast()
self.expand_fragment(AstFragment::$Kind(OneVector::one(ast_elt))).$make_ast()
})*)*
}
@ -148,15 +148,15 @@ impl<'a> MacResult for ::ext::tt::macro_rules::ParserAnyMacro<'a> {
Expr(P<ast::Expr>) { "expression"; one fn fold_expr; fn visit_expr; fn make_expr; }
Pat(P<ast::Pat>) { "pattern"; one fn fold_pat; fn visit_pat; fn make_pat; }
Ty(P<ast::Ty>) { "type"; one fn fold_ty; fn visit_ty; fn make_ty; }
Stmts(SmallVector<ast::Stmt>) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; }
Items(SmallVector<P<ast::Item>>) { "item"; many fn fold_item; fn visit_item; fn make_items; }
TraitItems(SmallVector<ast::TraitItem>) {
Stmts(OneVector<ast::Stmt>) { "statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts; }
Items(OneVector<P<ast::Item>>) { "item"; many fn fold_item; fn visit_item; fn make_items; }
TraitItems(OneVector<ast::TraitItem>) {
"trait item"; many fn fold_trait_item; fn visit_trait_item; fn make_trait_items;
}
ImplItems(SmallVector<ast::ImplItem>) {
ImplItems(OneVector<ast::ImplItem>) {
"impl item"; many fn fold_impl_item; fn visit_impl_item; fn make_impl_items;
}
ForeignItems(SmallVector<ast::ForeignItem>) {
ForeignItems(OneVector<ast::ForeignItem>) {
"foreign item"; many fn fold_foreign_item; fn visit_foreign_item; fn make_foreign_items;
}
}
@ -279,7 +279,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(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 @@ pub fn parse_ast_fragment(&mut self, kind: AstFragmentKind, macro_legacy_warning
-> 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 @@ pub fn parse_ast_fragment(&mut self, kind: AstFragmentKind, macro_legacy_warning
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 @@ fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> A
/// 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<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_nameable(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
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<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_unnameable(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
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 @@ fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
})
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
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 @@ fn fold_block(&mut self, block: P<Block>) -> P<Block> {
result
}
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
let item = configure!(self, item);
let (attr, traits, mut item) = self.classify_item(item);
@ -1422,7 +1422,7 @@ fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
ui
});
SmallVector::many(
OneVector::many(
self.fold_unnameable(item).into_iter()
.chain(self.fold_unnameable(use_item)))
} else {
@ -1433,7 +1433,7 @@ fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
}
}
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
let item = configure!(self, item);
let (attr, traits, item) = self.classify_item(item);
@ -1453,7 +1453,7 @@ fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitIte
}
}
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
let item = configure!(self, item);
let (attr, traits, item) = self.classify_item(item);
@ -1490,7 +1490,7 @@ fn fold_foreign_mod(&mut self, foreign_mod: ast::ForeignMod) -> ast::ForeignMod
}
fn fold_foreign_item(&mut self,
foreign_item: ast::ForeignItem) -> SmallVector<ast::ForeignItem> {
foreign_item: ast::ForeignItem) -> OneVector<ast::ForeignItem> {
let (attr, traits, foreign_item) = self.classify_item(foreign_item);
if attr.is_some() || !traits.is_empty() {

View File

@ -16,9 +16,10 @@
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 @@ fn mac_placeholder() -> ast::Mac {
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 @@ fn mac_placeholder() -> ast::Mac {
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 @@ fn remove(&mut self, id: ast::NodeId) -> AstFragment {
}
impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
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 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<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
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<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
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<ast::ForeignItem> {
fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> OneVector<ast::ForeignItem> {
match item.node {
ast::ForeignItemKind::Macro(_) => self.remove(item.id).make_foreign_items(),
_ => noop_fold_foreign_item(item, self),
@ -159,7 +160,7 @@ fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
}
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
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),

View File

@ -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 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
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 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
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 @@ fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
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)
}
}

View File

@ -17,9 +17,9 @@
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 @@ fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
Some(panictry!(self.p.parse_expr()))
}
fn make_items(mut self: Box<ExpandResult<'a>>)
-> Option<SmallVector<P<ast::Item>>> {
let mut ret = SmallVector::new();
-> Option<OneVector<P<ast::Item>>> {
let mut ret = OneVector::new();
while self.p.token != token::Eof {
match panictry!(self.p.parse_item()) {
Some(item) => ret.push(item),

View File

@ -92,9 +92,9 @@
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<MatcherPosHandle<'a>>,
cur_items: &mut OneVector<MatcherPosHandle<'a>>,
next_items: &mut Vec<MatcherPosHandle<'a>>,
eof_items: &mut SmallVector<MatcherPosHandle<'a>>,
bb_items: &mut SmallVector<MatcherPosHandle<'a>>,
eof_items: &mut OneVector<MatcherPosHandle<'a>>,
bb_items: &mut OneVector<MatcherPosHandle<'a>>,
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

View File

@ -15,9 +15,9 @@
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<HashMap<Ident, Rc<NamedMatch>>>,
src: Vec<quoted::TokenTree>)
-> 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<TokenStream> = Vec::new();

View File

@ -24,9 +24,10 @@
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 @@ fn fold_use_tree(&mut self, use_tree: UseTree) -> UseTree {
noop_fold_use_tree(use_tree, self)
}
fn fold_foreign_item(&mut self, ni: ForeignItem) -> SmallVector<ForeignItem> {
fn fold_foreign_item(&mut self, ni: ForeignItem) -> OneVector<ForeignItem> {
noop_fold_foreign_item(ni, self)
}
@ -68,7 +69,7 @@ fn fold_foreign_item_simple(&mut self, ni: ForeignItem) -> ForeignItem {
noop_fold_foreign_item_simple(ni, self)
}
fn fold_item(&mut self, i: P<Item>) -> SmallVector<P<Item>> {
fn fold_item(&mut self, i: P<Item>) -> OneVector<P<Item>> {
noop_fold_item(i, self)
}
@ -88,11 +89,11 @@ fn fold_item_kind(&mut self, i: ItemKind) -> ItemKind {
noop_fold_item_kind(i, self)
}
fn fold_trait_item(&mut self, i: TraitItem) -> SmallVector<TraitItem> {
fn fold_trait_item(&mut self, i: TraitItem) -> OneVector<TraitItem> {
noop_fold_trait_item(i, self)
}
fn fold_impl_item(&mut self, i: ImplItem) -> SmallVector<ImplItem> {
fn fold_impl_item(&mut self, i: ImplItem) -> OneVector<ImplItem> {
noop_fold_impl_item(i, self)
}
@ -108,7 +109,7 @@ fn fold_block(&mut self, b: P<Block>) -> P<Block> {
noop_fold_block(b, self)
}
fn fold_stmt(&mut self, s: Stmt) -> SmallVector<Stmt> {
fn fold_stmt(&mut self, s: Stmt) -> OneVector<Stmt> {
noop_fold_stmt(s, self)
}
@ -960,8 +961,8 @@ 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)
-> SmallVector<TraitItem> {
SmallVector::one(TraitItem {
-> OneVector<TraitItem> {
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<T: Folder>(i: TraitItem, folder: &mut T)
}
pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)
-> SmallVector<ImplItem> {
SmallVector::one(ImplItem {
-> OneVector<ImplItem> {
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<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) -> SmallVector<P<Item>> {
SmallVector::one(i.map(|i| folder.fold_item_simple(i)))
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)))
}
// fold one item into exactly one item
@ -1087,8 +1088,8 @@ 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)
-> SmallVector<ForeignItem> {
SmallVector::one(folder.fold_foreign_item_simple(ni))
-> OneVector<ForeignItem> {
OneVector::one(folder.fold_foreign_item_simple(ni))
}
pub fn noop_fold_foreign_item_simple<T: Folder>(ni: ForeignItem, folder: &mut T) -> ForeignItem {
@ -1366,7 +1367,7 @@ pub fn noop_fold_exprs<T: Folder>(es: Vec<P<Expr>>, folder: &mut T) -> Vec<P<Exp
es.move_flat_map(|e| folder.fold_opt_expr(e))
}
pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVector<Stmt> {
pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) -> OneVector<Stmt> {
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<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) ->
}).collect()
}
pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVector<StmtKind> {
pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> OneVector<StmtKind> {
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<T: Folder>(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())
}))),
}

View File

@ -45,6 +45,8 @@
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
@ -124,12 +126,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;
}

View File

@ -53,9 +53,9 @@
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;

View File

@ -38,8 +38,9 @@
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 @@ fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
folded
}
fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
let ident = i.ident;
if ident.name != keywords::Invalid.name() {
self.cx.path.push(ident);
@ -182,7 +183,7 @@ fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
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<ast::Item>) -> SmallVector<P<ast::Item>> {
fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
self.depth += 1;
let folded = fold::noop_fold_item(i, self).expect_one("noop did something");
self.depth -= 1;
@ -234,7 +235,7 @@ fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
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<ast::Expr> {
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(),
})
}

View File

@ -9,8 +9,7 @@
// except according to those terms.
use std::ptr;
use util::small_vector::SmallVector;
use OneVector;
pub trait MoveMap<T>: Sized {
fn move_map<F>(self, mut f: F) -> Self where F: FnMut(T) -> T {
@ -78,7 +77,7 @@ fn move_flat_map<F, I>(self, f: F) -> Self
}
}
impl<T> MoveMap<T> for SmallVector<T> {
impl<T> MoveMap<T> for OneVector<T> {
fn move_flat_map<F, I>(mut self, mut f: F) -> Self
where F: FnMut(T) -> I,
I: IntoIterator<Item=T>

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<T> = SmallVec<[T; 1]>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_len() {
let v: SmallVector<isize> = 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<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 = SmallVector::new();
let v: Vec<isize> = v.into_iter().collect();
assert_eq!(v, Vec::new());
let v = SmallVector::one(1);
assert_eq!(v.into_iter().collect::<Vec<_>>(), [1]);
let v = SmallVector::many(vec![1, 2, 3]);
assert_eq!(v.into_iter().collect::<Vec<_>>(), [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(""));
}
}

View File

@ -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(),
}))
}

View File

@ -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 @@ fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
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(),
}))
}

View File

@ -12,6 +12,8 @@
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::Expr>) -> 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,

View File

@ -191,6 +191,7 @@
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 @@ fn create_struct_pattern
ident: ident.unwrap(),
pat,
is_shorthand: false,
attrs: ast::ThinVec::new(),
attrs: ThinVec::new(),
},
}
})

View File

@ -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_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,

View File

@ -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<MacResult+'static> {
MacEager::items(SmallVector::many(vec![
MacEager::items(OneVector::many(vec![
quote_item!(cx, struct Struct1;).unwrap(),
quote_item!(cx, struct Struct2;).unwrap()
]))

View File

@ -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::parse::{self, ParseSess};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::util::ThinVec;
fn parse_expr(ps: &ParseSess, src: &str) -> P<Expr> {