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

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

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

r? @Mark-Simulacrum

1  2 
src/librustc/hir/lowering.rs
src/librustc/lib.rs
src/librustc_mir/lib.rs
src/librustc_resolve/macros.rs
src/libsyntax/ext/expand.rs
src/libsyntax/fold.rs
src/libsyntax/lib.rs

index acfda4c0055fce59535a1f24dbd0d1b2e0c64d1e,db07a3b883e0a06ce4290cd56d442faac13d4607..cb05f7b44c3b96b783b3ed13fc2495324f421c08
@@@ -3178,18 -3178,18 +3178,18 @@@ impl<'a> LoweringContext<'a> 
      fn lower_item_id(&mut self, i: &Item) -> OneVector<hir::ItemId> {
          match i.node {
              ItemKind::Use(ref use_tree) => {
-                 let mut vec = OneVector::one(hir::ItemId { id: i.id });
+                 let mut vec = smallvec![hir::ItemId { id: i.id }];
                  self.lower_item_id_use_tree(use_tree, i.id, &mut vec);
                  vec
              }
              ItemKind::MacroDef(..) => OneVector::new(),
              ItemKind::Fn(ref decl, ref header, ..) => {
-                 let mut ids = OneVector::one(hir::ItemId { id: i.id });
+                 let mut ids = smallvec![hir::ItemId { id: i.id }];
                  self.lower_impl_trait_ids(decl, header, &mut ids);
                  ids
              },
              ItemKind::Impl(.., None, _, ref items) => {
-                 let mut ids = OneVector::one(hir::ItemId { id: i.id });
+                 let mut ids = smallvec![hir::ItemId { id: i.id }];
                  for item in items {
                      if let ImplItemKind::Method(ref sig, _) = item.node {
                          self.lower_impl_trait_ids(&sig.decl, &sig.header, &mut ids);
                  }
                  ids
              },
-             _ => OneVector::one(hir::ItemId { id: i.id }),
+             _ => smallvec![hir::ItemId { id: i.id }],
          }
      }
  
                      hir::LoopSource::Loop,
                  )
              }),
 -            ExprKind::Catch(ref body) => {
 +            ExprKind::TryBlock(ref body) => {
                  self.with_catch_scope(body.id, |this| {
                      let unstable_span =
 -                        this.allow_internal_unstable(CompilerDesugaringKind::Catch, body.span);
 +                        this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span);
                      let mut block = this.lower_block(body, true).into_inner();
                      let tail = block.expr.take().map_or_else(
                          || {
      }
  
      fn lower_stmt(&mut self, s: &Stmt) -> OneVector<hir::Stmt> {
-         OneVector::one(match s.node {
+         smallvec![match s.node {
              StmtKind::Local(ref l) => Spanned {
                  node: hir::StmtKind::Decl(
                      P(Spanned {
                  span: s.span,
              },
              StmtKind::Mac(..) => panic!("Shouldn't exist here"),
-         })
+         }]
      }
  
      fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
diff --combined src/librustc/lib.rs
index a232bcd67102e7805543c90ec36c6ce2085035d4,b1d515464b9d09efc6d0bd0e2c74354ac400d766..d43ebf8d415a7d4db44924664b2856627fffb434
@@@ -65,6 -65,7 +65,6 @@@
  #![feature(trace_macros)]
  #![feature(trusted_len)]
  #![feature(vec_remove_item)]
 -#![feature(catch_expr)]
  #![feature(step_trait)]
  #![feature(integer_atomics)]
  #![feature(test)]
@@@ -108,6 -109,9 +108,9 @@@ extern crate rustc_apfloat
  extern crate byteorder;
  extern crate backtrace;
  
+ #[macro_use]
+ extern crate smallvec;
  // Note that librustc doesn't actually depend on these crates, see the note in
  // `Cargo.toml` for this crate about why these are here.
  #[allow(unused_extern_crates)]
diff --combined src/librustc_mir/lib.rs
index 6a8157df0ccff03cd6e93029e5b7e80f857366d4,d36dbaa0608265425768bf35037f9f8370ff316f..617efed31d913f73c4e81653a134eb0307ef62fd
@@@ -21,6 -21,7 +21,6 @@@ Rust MIR: a lowered representation of R
  #![feature(slice_sort_by_cached_key)]
  #![feature(box_patterns)]
  #![feature(box_syntax)]
 -#![feature(catch_expr)]
  #![feature(crate_visibility_modifier)]
  #![feature(const_fn)]
  #![feature(core_intrinsics)]
@@@ -61,15 -62,8 +61,16 @@@ extern crate log_settings
  extern crate rustc_apfloat;
  extern crate byteorder;
  extern crate core;
+ extern crate smallvec;
  
 +// Once we can use edition 2018 in the compiler,
 +// replace this with real try blocks.
 +macro_rules! try_block {
 +    ($($inside:tt)*) => (
 +        (||{ ::std::ops::Try::from_ok({ $($inside)* }) })()
 +    )
 +}
 +
  mod diagnostics;
  
  mod borrow_check;
index 0e843ae66da62ba9386f6cea401b602f9a5b10bd,dd6e632803bea4c7df9fdeddc8541cf43d5bbbab..879b4ea3fe579f8568aeb1b685af9760e46e932e
@@@ -43,6 -43,7 +43,7 @@@ use errors::Applicability
  use std::cell::Cell;
  use std::mem;
  use rustc_data_structures::sync::Lrc;
+ use rustc_data_structures::small_vec::ExpectOne;
  
  crate struct FromPrelude(bool);
  crate struct FromExpansion(bool);
@@@ -368,6 -369,17 +369,6 @@@ impl<'a, 'cl> Resolver<'a, 'cl> 
  
          let def = def?;
  
 -        if path.segments.len() > 1 {
 -            if kind != MacroKind::Bang {
 -                if def != Def::NonMacroAttr(NonMacroAttrKind::Tool) &&
 -                   !self.session.features_untracked().proc_macro_path_invoc {
 -                    let msg = format!("non-ident {} paths are unstable", kind.descr());
 -                    emit_feature_err(&self.session.parse_sess, "proc_macro_path_invoc",
 -                                     path.span, GateIssue::Language, &msg);
 -                }
 -            }
 -        }
 -
          match def {
              Def::Macro(def_id, macro_kind) => {
                  self.unused_macros.remove(&def_id);
              Def::NonMacroAttr(attr_kind) => {
                  if kind == MacroKind::Attr {
                      let features = self.session.features_untracked();
 -                    if attr_kind == NonMacroAttrKind::Tool && !features.tool_attributes {
 -                        feature_err(&self.session.parse_sess, "tool_attributes", path.span,
 -                                    GateIssue::Language, "tool attributes are unstable").emit();
 -                    }
                      if attr_kind == NonMacroAttrKind::Custom {
                          assert!(path.segments.len() == 1);
                          let name = path.segments[0].ident.name.as_str();
index 494f6d29832dda19946a167002a63b330558f12c,276ce73d2d50114e8dda2e2e4e688f7091d05c3a..a2e84b508dc12be3d042e0ba0348358b30a8fb28
@@@ -37,6 -37,7 +37,7 @@@ use visit::{self, Visitor}
  use std::collections::HashMap;
  use std::fs::File;
  use std::io::Read;
+ use std::iter::FromIterator;
  use std::{iter, mem};
  use std::rc::Rc;
  use std::path::PathBuf;
@@@ -131,7 -132,7 +132,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(OneVector::one(ast_elt))).$make_ast()
+                 self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
              })*)*
          }
  
@@@ -270,7 -271,7 +271,7 @@@ impl<'a, 'b> MacroExpander<'a, 'b> 
  
          let orig_mod_span = krate.module.inner;
  
-         let krate_item = AstFragment::Items(OneVector::one(P(ast::Item {
+         let krate_item = AstFragment::Items(smallvec![P(ast::Item {
              attrs: krate.attrs,
              span: krate.span,
              node: ast::ItemKind::Mod(krate.module),
              id: ast::DUMMY_NODE_ID,
              vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
              tokens: None,
-         })));
+         })]);
  
          match self.expand_fragment(krate_item).make_items().pop().map(P::into_inner) {
              Some(ast::Item { attrs, node: ast::ItemKind::Mod(module), .. }) => {
              None => return,
          };
  
 -        fragment.visit_with(&mut DisallowModules {
 +        fragment.visit_with(&mut DisallowMacros {
              span,
              parse_sess: self.cx.parse_sess,
          });
  
 -        struct DisallowModules<'a> {
 +        struct DisallowMacros<'a> {
              span: Span,
              parse_sess: &'a ParseSess,
          }
  
 -        impl<'ast, 'a> Visitor<'ast> for DisallowModules<'a> {
 +        impl<'ast, 'a> Visitor<'ast> for DisallowMacros<'a> {
              fn visit_item(&mut self, i: &'ast ast::Item) {
 -                let name = match i.node {
 -                    ast::ItemKind::Mod(_) => Some("modules"),
 -                    ast::ItemKind::MacroDef(_) => Some("macro definitions"),
 -                    _ => None,
 -                };
 -                if let Some(name) = name {
 +                if let ast::ItemKind::MacroDef(_) = i.node {
                      emit_feature_err(
                          self.parse_sess,
                          "proc_macro_gen",
                          self.span,
                          GateIssue::Language,
 -                        &format!("procedural macros cannot expand to {}", name),
 +                        &format!("procedural macros cannot expand to macro definitions"),
                      );
                  }
                  visit::walk_item(self, i);
@@@ -1404,7 -1410,7 +1405,7 @@@ impl<'a, 'b> Folder for InvocationColle
                          ui
                      });
  
-                     OneVector::many(
+                     OneVector::from_iter(
                          self.fold_unnameable(item).into_iter()
                              .chain(self.fold_unnameable(use_item)))
                  } else {
diff --combined src/libsyntax/fold.rs
index 050d21674f91aff5767488fec87dd2cd117db37b,07b8b80c131f98c2e9704b9ee33e54b652d2b198..660056e15e06b61f669c6d3fc16a4c1d5c089166
@@@ -31,6 -31,7 +31,7 @@@ use tokenstream::*
  use util::move_map::MoveMap;
  
  use rustc_data_structures::sync::Lrc;
+ use rustc_data_structures::small_vec::ExpectOne;
  
  pub trait Folder : Sized {
      // Any additions to this trait should happen in form
@@@ -962,7 -963,7 +963,7 @@@ pub fn noop_fold_item_kind<T: Folder>(i
  
  pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T)
                                         -> OneVector<TraitItem> {
-     OneVector::one(TraitItem {
+     smallvec![TraitItem {
          id: folder.new_id(i.id),
          ident: folder.fold_ident(i.ident),
          attrs: fold_attrs(i.attrs, folder),
          },
          span: folder.new_span(i.span),
          tokens: i.tokens,
-     })
+     }]
  }
  
  pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T)
                                        -> OneVector<ImplItem> {
-     OneVector::one(ImplItem {
+     smallvec![ImplItem {
          id: folder.new_id(i.id),
          vis: folder.fold_vis(i.vis),
          ident: folder.fold_ident(i.ident),
          },
          span: folder.new_span(i.span),
          tokens: i.tokens,
-     })
+     }]
  }
  
  pub fn noop_fold_fn_header<T: Folder>(mut header: FnHeader, folder: &mut T) -> FnHeader {
@@@ -1067,7 -1068,7 +1068,7 @@@ pub fn noop_fold_crate<T: Folder>(Crat
  
  // fold one item into possibly many items
  pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> OneVector<P<Item>> {
-     OneVector::one(i.map(|i| folder.fold_item_simple(i)))
+     smallvec![i.map(|i| folder.fold_item_simple(i))]
  }
  
  // fold one item into exactly one item
@@@ -1089,7 -1090,7 +1090,7 @@@ pub fn noop_fold_item_simple<T: Folder>
  
  pub fn noop_fold_foreign_item<T: Folder>(ni: ForeignItem, folder: &mut T)
  -> OneVector<ForeignItem> {
-     OneVector::one(folder.fold_foreign_item_simple(ni))
+     smallvec![folder.fold_foreign_item_simple(ni)]
  }
  
  pub fn noop_fold_foreign_item_simple<T: Folder>(ni: ForeignItem, folder: &mut T) -> ForeignItem {
@@@ -1351,7 -1352,7 +1352,7 @@@ pub fn noop_fold_expr<T: Folder>(Expr {
              }
              ExprKind::Yield(ex) => ExprKind::Yield(ex.map(|x| folder.fold_expr(x))),
              ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
 -            ExprKind::Catch(body) => ExprKind::Catch(folder.fold_block(body)),
 +            ExprKind::TryBlock(body) => ExprKind::TryBlock(folder.fold_block(body)),
          },
          id: folder.new_id(id),
          span: folder.new_span(span),
@@@ -1377,7 -1378,7 +1378,7 @@@ pub fn noop_fold_stmt<T: Folder>(Stmt {
  
  pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> OneVector<StmtKind> {
      match node {
-         StmtKind::Local(local) => OneVector::one(StmtKind::Local(folder.fold_local(local))),
+         StmtKind::Local(local) => smallvec![StmtKind::Local(folder.fold_local(local))],
          StmtKind::Item(item) => folder.fold_item(item).into_iter().map(StmtKind::Item).collect(),
          StmtKind::Expr(expr) => {
              folder.fold_opt_expr(expr).into_iter().map(StmtKind::Expr).collect()
          StmtKind::Semi(expr) => {
              folder.fold_opt_expr(expr).into_iter().map(StmtKind::Semi).collect()
          }
-         StmtKind::Mac(mac) => OneVector::one(StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
+         StmtKind::Mac(mac) => smallvec![StmtKind::Mac(mac.map(|(mac, semi, attrs)| {
              (folder.fold_mac(mac), semi, fold_attrs(attrs.into(), folder).into())
-         }))),
+         }))],
      }
  }
  
diff --combined src/libsyntax/lib.rs
index 366b91fc8286e83de50cc9b3add14bfd20766ac7,b11726e4cc03bca73650f5cb711d81d724159bff..2aaab6aaa16d931942844d5f06e73ff3bb076b3d
@@@ -26,8 -26,8 +26,8 @@@
  #![feature(rustc_diagnostic_macros)]
  #![feature(slice_sort_by_cached_key)]
  #![feature(str_escape)]
 +#![feature(try_trait)]
  #![feature(unicode_internals)]
 -#![feature(catch_expr)]
  
  #![recursion_limit="256"]
  
@@@ -40,6 -40,8 +40,8 @@@ extern crate syntax_pos
  extern crate rustc_data_structures;
  extern crate rustc_target;
  #[macro_use] extern crate scoped_tls;
+ #[macro_use]
+ extern crate smallvec;
  
  extern crate serialize as rustc_serialize; // used by deriving