Remove OneVector

This commit is contained in:
ljedrz 2018-08-30 11:42:16 +02:00
parent beff387601
commit 130a32fa72
22 changed files with 134 additions and 177 deletions

View File

@ -2177,6 +2177,7 @@ dependencies = [
"rustc_typeck 0.0.0",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"syntax 0.0.0",
"syntax_ext 0.0.0",
"syntax_pos 0.0.0",

View File

@ -52,7 +52,6 @@ use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
use middle::cstore::CrateStore;
use rustc_data_structures::fx::FxHashSet;
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;
@ -62,6 +61,7 @@ use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;
use std::mem;
use smallvec::SmallVec;
use syntax::attr;
use syntax::ast;
use syntax::ast::*;
@ -307,7 +307,7 @@ enum AnonymousLifetimeMode {
PassThrough,
}
struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut OneVector<hir::ItemId> }
struct ImplTraitTypeIdVisitor<'a> { ids: &'a mut SmallVec<[hir::ItemId; 1]> }
impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> {
fn visit_ty(&mut self, ty: &'a Ty) {
@ -1901,9 +1901,9 @@ impl<'a> LoweringContext<'a> {
)
}
fn lower_local(&mut self, l: &Local) -> (P<hir::Local>, OneVector<hir::ItemId>) {
fn lower_local(&mut self, l: &Local) -> (P<hir::Local>, SmallVec<[hir::ItemId; 1]>) {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
let mut ids = OneVector::<hir::ItemId>::new();
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
@ -3211,7 +3211,7 @@ impl<'a> LoweringContext<'a> {
&mut self,
decl: &FnDecl,
header: &FnHeader,
ids: &mut OneVector<hir::ItemId>,
ids: &mut SmallVec<[hir::ItemId; 1]>,
) {
if let Some(id) = header.asyncness.opt_return_id() {
ids.push(hir::ItemId { id });
@ -3223,14 +3223,14 @@ impl<'a> LoweringContext<'a> {
}
}
fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
fn lower_item_id(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
match i.node {
ItemKind::Use(ref use_tree) => {
let mut vec = smallvec![hir::ItemId { id: i.id }];
self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
vec
}
ItemKind::MacroDef(..) => OneVector::new(),
ItemKind::MacroDef(..) => SmallVec::new(),
ItemKind::Fn(ref decl, ref header, ..) => {
let mut ids = smallvec![hir::ItemId { id: i.id }];
self.lower_fn_impl_trait_ids(decl, header, &mut ids);
@ -3268,7 +3268,7 @@ impl<'a> LoweringContext<'a> {
fn lower_item_id_use_tree(&mut self,
tree: &UseTree,
base_id: NodeId,
vec: &mut OneVector<hir::ItemId>)
vec: &mut SmallVec<[hir::ItemId; 1]>)
{
match tree.kind {
UseTreeKind::Nested(ref nested_vec) => for &(ref nested, id) in nested_vec {
@ -4369,11 +4369,11 @@ impl<'a> LoweringContext<'a> {
}
}
fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> {
smallvec![match s.node {
StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l);
let mut ids: OneVector<hir::Stmt> = item_ids
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
.into_iter()
.map(|item_id| Spanned {
node: hir::StmtKind::Decl(

View File

@ -9,8 +9,8 @@
// except according to those terms.
use rustc::middle::allocator::AllocatorKind;
use rustc_data_structures::small_vec::OneVector;
use rustc_errors;
use smallvec::SmallVec;
use syntax::{
ast::{
self, Arg, Attribute, Crate, Expr, FnHeader, Generics, Ident, Item, ItemKind,
@ -65,7 +65,7 @@ struct ExpandAllocatorDirectives<'a> {
}
impl<'a> Folder for ExpandAllocatorDirectives<'a> {
fn fold_item(&mut self, item: P<Item>) -> OneVector<P<Item>> {
fn fold_item(&mut self, item: P<Item>) -> SmallVec<[P<Item>; 1]> {
debug!("in submodule {}", self.in_submod);
let name = if attr::contains_name(&item.attrs, "global_allocator") {
@ -152,11 +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 = OneVector::with_capacity(2);
ret.push(item);
ret.push(module);
return ret;
smallvec![item, module]
}
// If we enter a submodule, take note.

View File

@ -50,7 +50,6 @@ extern crate rustc_rayon as rayon;
extern crate rustc_rayon_core as rayon_core;
extern crate rustc_hash;
extern crate serialize;
#[cfg_attr(test, macro_use)]
extern crate smallvec;
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
@ -72,7 +71,6 @@ pub mod owning_ref;
pub mod ptr_key;
pub mod sip128;
pub mod small_c_str;
pub mod small_vec;
pub mod snapshot_map;
pub use ena::snapshot_vec;
pub mod sorted_map;

View File

@ -1,55 +0,0 @@
// Copyright 2016 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.
//! A vector type intended to be used for small vectors.
//!
//! Space for up to N elements is provided on the stack. If more elements are collected, Vec is
//! used to store the values on the heap.
//!
//! The N above is determined by Array's implementor, by way of an associated constant.
use smallvec::{Array, SmallVec};
pub type OneVector<T> = SmallVec<[T; 1]>;
pub trait ExpectOne<A: Array> {
fn expect_one(self, err: &'static str) -> A::Item;
}
impl<A: Array> ExpectOne<A> for SmallVec<A> {
fn expect_one(self, err: &'static str) -> A::Item {
assert!(self.len() == 1, err);
self.into_iter().next().unwrap()
}
}
#[cfg(test)]
mod tests {
extern crate test;
use super::*;
#[test]
#[should_panic]
fn test_expect_one_zero() {
let _: isize = OneVector::new().expect_one("");
}
#[test]
#[should_panic]
fn test_expect_one_many() {
OneVector::from_vec(vec![1, 2]).expect_one("");
}
#[test]
fn test_expect_one_one() {
assert_eq!(1, (smallvec![1] as OneVector<_>).expect_one(""));
assert_eq!(1, OneVector::from_vec(vec![1]).expect_one(""));
}
}

View File

@ -35,5 +35,6 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" }
rustc_typeck = { path = "../librustc_typeck" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
smallvec = { version = "0.6.5", features = ["union"] }
syntax_ext = { path = "../libsyntax_ext" }
syntax_pos = { path = "../libsyntax_pos" }

View File

@ -58,6 +58,7 @@ extern crate rustc_codegen_utils;
extern crate rustc_typeck;
extern crate scoped_tls;
extern crate serialize;
extern crate smallvec;
#[macro_use]
extern crate log;
extern crate syntax;

View File

@ -24,7 +24,6 @@ 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;
@ -38,6 +37,7 @@ use syntax::ptr::P;
use syntax_pos::{self, FileName};
use graphviz as dot;
use smallvec::SmallVec;
use std::cell::Cell;
use std::fs::File;
@ -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) -> OneVector<ast::TraitItem> {
fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
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) -> OneVector<ast::ImplItem> {
fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> {
let is_const = match i.node {
ast::ImplItemKind::Const(..) => true,
ast::ImplItemKind::Method(ast::MethodSig { ref decl, ref header, .. }, _) =>

View File

@ -42,7 +42,6 @@ use errors::Applicability;
use std::cell::Cell;
use std::mem;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::small_vec::ExpectOne;
#[derive(Clone, Copy)]
crate struct FromPrelude(bool);
@ -190,7 +189,9 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
}
}
EliminateCrateVar(self, item.span).fold_item(item).expect_one("")
let ret = EliminateCrateVar(self, item.span).fold_item(item);
assert!(ret.len() == 1);
ret.into_iter().next().unwrap()
}
fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool {

View File

@ -15,7 +15,7 @@ use ast;
use source_map::Spanned;
use edition::Edition;
use parse::{token, ParseSess};
use OneVector;
use smallvec::SmallVec;
use errors::Applicability;
use ptr::P;
@ -338,22 +338,23 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
Some(P(fold::noop_fold_expr(expr, self)))
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
match self.configure_stmt(stmt) {
Some(stmt) => fold::noop_fold_stmt(stmt, self),
None => return OneVector::new(),
None => return SmallVec::new(),
}
}
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
fold::noop_fold_item(configure!(self, item), self)
}
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]>
{
fold::noop_fold_impl_item(configure!(self, item), self)
}
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
fold::noop_fold_trait_item(configure!(self, item), self)
}

View File

@ -19,7 +19,6 @@ 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};
@ -131,7 +130,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
let sym = Ident::with_empty_ctxt(Symbol::gensym(&format!(
"__register_diagnostic_{}", code
)));
MacEager::items(OneVector::from_vec(vec![
MacEager::items(smallvec![
ecx.item_mod(
span,
span,
@ -139,7 +138,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
Vec::new(),
Vec::new()
)
]))
])
}
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
@ -214,7 +213,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
),
);
MacEager::items(OneVector::from_vec(vec![
MacEager::items(smallvec![
P(ast::Item {
ident: *name,
attrs: Vec::new(),
@ -227,5 +226,5 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
span,
tokens: None,
})
]))
])
}

View File

@ -22,7 +22,7 @@ use fold::{self, Folder};
use parse::{self, parser, DirectoryOwnership};
use parse::token;
use ptr::P;
use OneVector;
use smallvec::SmallVec;
use symbol::{keywords, Ident, Symbol};
use ThinVec;
@ -332,22 +332,22 @@ pub trait MacResult {
None
}
/// Create zero or more items.
fn make_items(self: Box<Self>) -> Option<OneVector<P<ast::Item>>> {
fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
None
}
/// Create zero or more impl items.
fn make_impl_items(self: Box<Self>) -> Option<OneVector<ast::ImplItem>> {
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
None
}
/// Create zero or more trait items.
fn make_trait_items(self: Box<Self>) -> Option<OneVector<ast::TraitItem>> {
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
None
}
/// Create zero or more items in an `extern {}` block
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> { None }
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> { None }
/// Create a pattern.
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
@ -358,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<Self>) -> Option<OneVector<ast::Stmt>> {
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
make_stmts_default!(self)
}
@ -394,11 +394,11 @@ macro_rules! make_MacEager {
make_MacEager! {
expr: P<ast::Expr>,
pat: P<ast::Pat>,
items: OneVector<P<ast::Item>>,
impl_items: OneVector<ast::ImplItem>,
trait_items: OneVector<ast::TraitItem>,
foreign_items: OneVector<ast::ForeignItem>,
stmts: OneVector<ast::Stmt>,
items: SmallVec<[P<ast::Item>; 1]>,
impl_items: SmallVec<[ast::ImplItem; 1]>,
trait_items: SmallVec<[ast::TraitItem; 1]>,
foreign_items: SmallVec<[ast::ForeignItem; 1]>,
stmts: SmallVec<[ast::Stmt; 1]>,
ty: P<ast::Ty>,
}
@ -407,23 +407,23 @@ impl MacResult for MacEager {
self.expr
}
fn make_items(self: Box<Self>) -> Option<OneVector<P<ast::Item>>> {
fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
self.items
}
fn make_impl_items(self: Box<Self>) -> Option<OneVector<ast::ImplItem>> {
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
self.impl_items
}
fn make_trait_items(self: Box<Self>) -> Option<OneVector<ast::TraitItem>> {
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
self.trait_items
}
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> {
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> {
self.foreign_items
}
fn make_stmts(self: Box<Self>) -> Option<OneVector<ast::Stmt>> {
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
match self.stmts.as_ref().map_or(0, |s| s.len()) {
0 => make_stmts_default!(self),
_ => self.stmts,
@ -514,40 +514,40 @@ impl MacResult for DummyResult {
Some(P(DummyResult::raw_pat(self.span)))
}
fn make_items(self: Box<DummyResult>) -> Option<OneVector<P<ast::Item>>> {
fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
// this code needs a comment... why not always just return the Some() ?
if self.expr_only {
None
} else {
Some(OneVector::new())
Some(SmallVec::new())
}
}
fn make_impl_items(self: Box<DummyResult>) -> Option<OneVector<ast::ImplItem>> {
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
if self.expr_only {
None
} else {
Some(OneVector::new())
Some(SmallVec::new())
}
}
fn make_trait_items(self: Box<DummyResult>) -> Option<OneVector<ast::TraitItem>> {
fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
if self.expr_only {
None
} else {
Some(OneVector::new())
Some(SmallVec::new())
}
}
fn make_foreign_items(self: Box<Self>) -> Option<OneVector<ast::ForeignItem>> {
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> {
if self.expr_only {
None
} else {
Some(OneVector::new())
Some(SmallVec::new())
}
}
fn make_stmts(self: Box<DummyResult>) -> Option<OneVector<ast::Stmt>> {
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVec<[ast::Stmt; 1]>> {
Some(smallvec![ast::Stmt {
id: ast::DUMMY_NODE_ID,
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)),

View File

@ -25,7 +25,7 @@ use parse::{DirectoryOwnership, PResult, ParseSess};
use parse::token::{self, Token};
use parse::parser::Parser;
use ptr::P;
use OneVector;
use smallvec::SmallVec;
use symbol::Symbol;
use symbol::keywords;
use syntax_pos::{Span, DUMMY_SP, FileName};
@ -147,15 +147,19 @@ ast_fragments! {
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(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>) {
Stmts(SmallVec<[ast::Stmt; 1]>) {
"statement"; many fn fold_stmt; fn visit_stmt; fn make_stmts;
}
Items(SmallVec<[P<ast::Item>; 1]>) {
"item"; many fn fold_item; fn visit_item; fn make_items;
}
TraitItems(SmallVec<[ast::TraitItem; 1]>) {
"trait item"; many fn fold_trait_item; fn visit_trait_item; fn make_trait_items;
}
ImplItems(OneVector<ast::ImplItem>) {
ImplItems(SmallVec<[ast::ImplItem; 1]>) {
"impl item"; many fn fold_impl_item; fn visit_impl_item; fn make_impl_items;
}
ForeignItems(OneVector<ast::ForeignItem>) {
ForeignItems(SmallVec<[ast::ForeignItem; 1]>) {
"foreign item"; many fn fold_foreign_item; fn visit_foreign_item; fn make_foreign_items;
}
}
@ -980,28 +984,28 @@ impl<'a> Parser<'a> {
-> PResult<'a, AstFragment> {
Ok(match kind {
AstFragmentKind::Items => {
let mut items = OneVector::new();
let mut items = SmallVec::new();
while let Some(item) = self.parse_item()? {
items.push(item);
}
AstFragment::Items(items)
}
AstFragmentKind::TraitItems => {
let mut items = OneVector::new();
let mut items = SmallVec::new();
while self.token != token::Eof {
items.push(self.parse_trait_item(&mut false)?);
}
AstFragment::TraitItems(items)
}
AstFragmentKind::ImplItems => {
let mut items = OneVector::new();
let mut items = SmallVec::new();
while self.token != token::Eof {
items.push(self.parse_impl_item(&mut false)?);
}
AstFragment::ImplItems(items)
}
AstFragmentKind::ForeignItems => {
let mut items = OneVector::new();
let mut items = SmallVec::new();
while self.token != token::Eof {
if let Some(item) = self.parse_foreign_item()? {
items.push(item);
@ -1010,7 +1014,7 @@ impl<'a> Parser<'a> {
AstFragment::ForeignItems(items)
}
AstFragmentKind::Stmts => {
let mut stmts = OneVector::new();
let mut stmts = SmallVec::new();
while self.token != token::Eof &&
// won't make progress on a `}`
self.token != token::CloseDelim(token::Brace) {
@ -1245,10 +1249,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
})
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
let mut stmt = match self.cfg.configure_stmt(stmt) {
Some(stmt) => stmt,
None => return OneVector::new(),
None => return SmallVec::new(),
};
// we'll expand attributes on expressions separately
@ -1303,7 +1307,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
result
}
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
let item = configure!(self, item);
let (attr, traits, item, together_with) = self.classify_item(item);
@ -1378,7 +1382,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}
}
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
let item = configure!(self, item);
let (attr, traits, item, together_with) = self.classify_item(item);
@ -1397,7 +1401,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
}
}
fn fold_impl_item(&mut self, item: ast::ImplItem) -> OneVector<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> {
let item = configure!(self, item);
let (attr, traits, item, together_with) = self.classify_item(item);
@ -1432,8 +1436,9 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
noop_fold_foreign_mod(self.cfg.configure_foreign_mod(foreign_mod), self)
}
fn fold_foreign_item(&mut self,
foreign_item: ast::ForeignItem) -> OneVector<ast::ForeignItem> {
fn fold_foreign_item(&mut self, foreign_item: ast::ForeignItem)
-> SmallVec<[ast::ForeignItem; 1]>
{
let (attr, traits, foreign_item, together_with) = self.classify_item(foreign_item);
if attr.is_some() || !traits.is_empty() {

View File

@ -16,7 +16,7 @@ use ext::hygiene::Mark;
use tokenstream::TokenStream;
use fold::*;
use ptr::P;
use OneVector;
use smallvec::SmallVec;
use symbol::keywords;
use ThinVec;
use util::move_map::MoveMap;
@ -115,7 +115,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
}
impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
fn fold_item(&mut self, item: P<ast::Item>) -> OneVector<P<ast::Item>> {
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
match item.node {
ast::ItemKind::Mac(_) => return self.remove(item.id).make_items(),
ast::ItemKind::MacroDef(_) => return smallvec![item],
@ -125,21 +125,21 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
noop_fold_item(item, self)
}
fn fold_trait_item(&mut self, item: ast::TraitItem) -> OneVector<ast::TraitItem> {
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVec<[ast::TraitItem; 1]> {
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) -> OneVector<ast::ImplItem> {
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVec<[ast::ImplItem; 1]> {
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) -> OneVector<ast::ForeignItem> {
fn fold_foreign_item(&mut self, item: ast::ForeignItem) -> SmallVec<[ast::ForeignItem; 1]> {
match item.node {
ast::ForeignItemKind::Macro(_) => self.remove(item.id).make_foreign_items(),
_ => noop_fold_foreign_item(item, self),
@ -160,7 +160,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
}
}
fn fold_stmt(&mut self, stmt: ast::Stmt) -> OneVector<ast::Stmt> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
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

@ -17,7 +17,7 @@ use parse::{token, DirectoryOwnership};
use parse;
use print::pprust;
use ptr::P;
use OneVector;
use smallvec::SmallVec;
use symbol::Symbol;
use tokenstream;
@ -110,9 +110,9 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
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<OneVector<P<ast::Item>>> {
let mut ret = OneVector::new();
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
let mut ret = SmallVec::new();
while self.p.token != token::Eof {
match panictry!(self.p.parse_item()) {
Some(item) => ret.push(item),

View File

@ -92,7 +92,7 @@ use parse::{Directory, ParseSess};
use parse::parser::{Parser, PathStyle};
use parse::token::{self, DocComment, Nonterminal, Token};
use print::pprust;
use OneVector;
use smallvec::SmallVec;
use symbol::keywords;
use tokenstream::{DelimSpan, TokenStream};
@ -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 OneVector<MatcherPosHandle<'a>>,
cur_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
next_items: &mut Vec<MatcherPosHandle<'a>>,
eof_items: &mut OneVector<MatcherPosHandle<'a>>,
bb_items: &mut OneVector<MatcherPosHandle<'a>>,
eof_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
bb_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
token: &Token,
span: syntax_pos::Span,
) -> ParseResult<()> {
@ -649,10 +649,10 @@ pub fn parse(
loop {
// Matcher positions black-box parsed by parser.rs (`parser`)
let mut bb_items = OneVector::new();
let mut bb_items = SmallVec::new();
// Matcher positions that would be valid if the macro invocation was over now
let mut eof_items = OneVector::new();
let mut eof_items = SmallVec::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,7 +15,7 @@ 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 smallvec::SmallVec;
use syntax_pos::DUMMY_SP;
use tokenstream::{TokenStream, TokenTree, Delimited, DelimSpan};
@ -70,7 +70,7 @@ pub fn transcribe(cx: &ExtCtxt,
interp: Option<FxHashMap<Ident, Rc<NamedMatch>>>,
src: Vec<quoted::TokenTree>)
-> TokenStream {
let mut stack: OneVector<Frame> = smallvec![Frame::new(src)];
let mut stack: SmallVec<[Frame; 1]> = smallvec![Frame::new(src)];
let interpolations = interp.unwrap_or_else(FxHashMap::default); /* just a convenience */
let mut repeats = Vec::new();
let mut result: Vec<TokenStream> = Vec::new();

View File

@ -24,14 +24,24 @@ use syntax_pos::Span;
use source_map::{Spanned, respan};
use parse::token::{self, Token};
use ptr::P;
use OneVector;
use smallvec::{Array, SmallVec};
use symbol::keywords;
use ThinVec;
use tokenstream::*;
use util::move_map::MoveMap;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::small_vec::ExpectOne;
pub trait ExpectOne<A: Array> {
fn expect_one(self, err: &'static str) -> A::Item;
}
impl<A: Array> ExpectOne<A> for SmallVec<A> {
fn expect_one(self, err: &'static str) -> A::Item {
assert!(self.len() == 1, err);
self.into_iter().next().unwrap()
}
}
pub trait Folder : Sized {
// Any additions to this trait should happen in form
@ -62,7 +72,7 @@ pub trait Folder : Sized {
noop_fold_use_tree(use_tree, self)
}
fn fold_foreign_item(&mut self, ni: ForeignItem) -> OneVector<ForeignItem> {
fn fold_foreign_item(&mut self, ni: ForeignItem) -> SmallVec<[ForeignItem; 1]> {
noop_fold_foreign_item(ni, self)
}
@ -70,7 +80,7 @@ pub trait Folder : Sized {
noop_fold_foreign_item_simple(ni, self)
}
fn fold_item(&mut self, i: P<Item>) -> OneVector<P<Item>> {
fn fold_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
noop_fold_item(i, self)
}
@ -90,11 +100,11 @@ pub trait Folder : Sized {
noop_fold_item_kind(i, self)
}
fn fold_trait_item(&mut self, i: TraitItem) -> OneVector<TraitItem> {
fn fold_trait_item(&mut self, i: TraitItem) -> SmallVec<[TraitItem; 1]> {
noop_fold_trait_item(i, self)
}
fn fold_impl_item(&mut self, i: ImplItem) -> OneVector<ImplItem> {
fn fold_impl_item(&mut self, i: ImplItem) -> SmallVec<[ImplItem; 1]> {
noop_fold_impl_item(i, self)
}
@ -110,7 +120,7 @@ pub trait Folder : Sized {
noop_fold_block(b, self)
}
fn fold_stmt(&mut self, s: Stmt) -> OneVector<Stmt> {
fn fold_stmt(&mut self, s: Stmt) -> SmallVec<[Stmt; 1]> {
noop_fold_stmt(s, self)
}
@ -974,8 +984,7 @@ pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind {
}
}
pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T)
-> OneVector<TraitItem> {
pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T) -> SmallVec<[TraitItem; 1]> {
smallvec![TraitItem {
id: folder.new_id(i.id),
ident: folder.fold_ident(i.ident),
@ -1003,8 +1012,7 @@ 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)
-> OneVector<ImplItem> {
pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)-> SmallVec<[ImplItem; 1]> {
smallvec![ImplItem {
id: folder.new_id(i.id),
vis: folder.fold_vis(i.vis),
@ -1080,7 +1088,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate,
}
// fold one item into possibly many items
pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> OneVector<P<Item>> {
pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> SmallVec<[P<Item>; 1]> {
smallvec![i.map(|i| folder.fold_item_simple(i))]
}
@ -1102,7 +1110,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)
-> OneVector<ForeignItem> {
-> SmallVec<[ForeignItem; 1]>
{
smallvec![folder.fold_foreign_item_simple(ni)]
}
@ -1381,7 +1390,8 @@ 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) -> OneVector<Stmt> {
pub fn noop_fold_stmt<T: Folder>(Stmt {node, span, id}: Stmt, folder: &mut T) -> SmallVec<[Stmt; 1]>
{
let id = folder.new_id(id);
let span = folder.new_span(span);
noop_fold_stmt_kind(node, folder).into_iter().map(|node| {
@ -1389,7 +1399,7 @@ 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) -> OneVector<StmtKind> {
pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVec<[StmtKind; 1]> {
match node {
StmtKind::Local(local) => smallvec![StmtKind::Local(folder.fold_local(local))],
StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),

View File

@ -47,7 +47,6 @@ extern crate serialize as rustc_serialize; // used by deriving
use rustc_data_structures::sync::Lock;
use rustc_data_structures::bit_set::GrowableBitSet;
pub use rustc_data_structures::small_vec::OneVector;
pub use rustc_data_structures::thin_vec::ThinVec;
use ast::AttrId;

View File

@ -33,15 +33,14 @@ use ext::hygiene::{self, Mark, SyntaxContext};
use fold::Folder;
use feature_gate::Features;
use util::move_map::MoveMap;
use fold;
use fold::{self, ExpectOne};
use parse::{token, ParseSess};
use print::pprust;
use ast::{self, Ident};
use ptr::P;
use OneVector;
use smallvec::SmallVec;
use symbol::{self, Symbol, keywords};
use ThinVec;
use rustc_data_structures::small_vec::ExpectOne;
struct Test {
span: Span,
@ -113,7 +112,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
folded
}
fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
fn fold_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
let ident = i.ident;
if ident.name != keywords::Invalid.name() {
self.cx.path.push(ident);
@ -171,7 +170,7 @@ struct EntryPointCleaner {
}
impl fold::Folder for EntryPointCleaner {
fn fold_item(&mut self, i: P<ast::Item>) -> OneVector<P<ast::Item>> {
fn fold_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
self.depth += 1;
let folded = fold::noop_fold_item(i, self).expect_one("noop did something");
self.depth -= 1;

View File

@ -9,7 +9,7 @@
// except according to those terms.
use std::ptr;
use OneVector;
use smallvec::{Array, SmallVec};
pub trait MoveMap<T>: Sized {
fn move_map<F>(self, mut f: F) -> Self where F: FnMut(T) -> T {
@ -77,7 +77,7 @@ impl<T> MoveMap<T> for ::ptr::P<[T]> {
}
}
impl<T> MoveMap<T> for OneVector<T> {
impl<T, A: Array<Item = T>> MoveMap<T> for SmallVec<A> {
fn move_flat_map<F, I>(mut self, mut f: F) -> Self
where F: FnMut(T) -> I,
I: IntoIterator<Item=T>

View File

@ -17,9 +17,10 @@ extern crate syntax;
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_plugin;
#[macro_use] extern crate smallvec;
extern crate syntax_pos;
use rustc_data_structures::small_vec::OneVector;
use smallvec::SmallVec;
use syntax::ext::base::{ExtCtxt, MacResult, MacEager};
use syntax::tokenstream;
use rustc_plugin::Registry;
@ -31,8 +32,8 @@ pub fn plugin_registrar(reg: &mut Registry) {
fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree])
-> Box<MacResult+'static> {
MacEager::items(OneVector::from_vec(vec![
MacEager::items(smallvec![
quote_item!(cx, struct Struct1;).unwrap(),
quote_item!(cx, struct Struct2;).unwrap()
]))
])
}