about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-05-18 02:10:21 +0000
committerbors <bors@rust-lang.org>2019-05-18 02:10:21 +0000
commit548add7f61bfcbe3bea3f5ccefb53c84da8fefe4 (patch)
treec033c6bf9f7e7646613ea8ce0125c511fd2483c9 /src
parenta614cee22e8d79766c6a6d0f63c28f12eaec63f4 (diff)
parent4ab5fe3f97a260f2cb2b3c06a9a841a05a659e57 (diff)
downloadrust-548add7f61bfcbe3bea3f5ccefb53c84da8fefe4.tar.gz
rust-548add7f61bfcbe3bea3f5ccefb53c84da8fefe4.zip
Auto merge of #60910 - nnethercote:avoid-some-unnecessary-interning, r=petrochenkov
Avoid some unnecessary interning

r? @petrochenkov
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/lowering.rs6
-rw-r--r--src/librustc/hir/map/definitions.rs18
-rw-r--r--src/librustc/traits/project.rs2
-rw-r--r--src/librustc/util/common.rs3
-rw-r--r--src/librustc_allocator/expand.rs13
-rw-r--r--src/librustc_resolve/lib.rs8
-rw-r--r--src/librustdoc/clean/mod.rs5
-rw-r--r--src/libsyntax/attr/mod.rs6
-rw-r--r--src/libsyntax/ext/expand.rs8
-rw-r--r--src/libsyntax/parse/parser.rs5
-rw-r--r--src/libsyntax/print/pprust.rs9
-rw-r--r--src/libsyntax/std_inject.rs8
-rw-r--r--src/libsyntax/test.rs4
-rw-r--r--src/libsyntax_ext/env.rs5
-rw-r--r--src/libsyntax_ext/proc_macro_decls.rs6
-rw-r--r--src/libsyntax_pos/symbol.rs10
16 files changed, 67 insertions, 49 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 3a8b139236c..970f6ba0177 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -2218,7 +2218,7 @@ impl<'a> LoweringContext<'a> {
                         bindings: hir_vec![
                             hir::TypeBinding {
                                 hir_id: this.next_id(),
-                                ident: Ident::from_str(FN_OUTPUT_NAME),
+                                ident: Ident::with_empty_ctxt(FN_OUTPUT_NAME),
                                 ty: output
                                     .as_ref()
                                     .map(|ty| this.lower_ty(&ty, ImplTraitContext::disallowed()))
@@ -2543,7 +2543,7 @@ impl<'a> LoweringContext<'a> {
         let future_params = P(hir::GenericArgs {
             args: hir_vec![],
             bindings: hir_vec![hir::TypeBinding {
-                ident: Ident::from_str(FN_OUTPUT_NAME),
+                ident: Ident::with_empty_ctxt(FN_OUTPUT_NAME),
                 ty: output_ty,
                 hir_id: self.next_id(),
                 span,
@@ -4801,7 +4801,7 @@ impl<'a> LoweringContext<'a> {
                 let attr = {
                     // `allow(unreachable_code)`
                     let allow = {
-                        let allow_ident = Ident::from_str("allow").with_span_pos(e.span);
+                        let allow_ident = Ident::with_empty_ctxt(sym::allow).with_span_pos(e.span);
                         let uc_ident = Ident::from_str("unreachable_code").with_span_pos(e.span);
                         let uc_nested = attr::mk_nested_word_item(uc_ident);
                         attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index dc6cddc89f9..9cb85c4db47 100644
--- a/src/librustc/hir/map/definitions.rs
+++ b/src/librustc/hir/map/definitions.rs
@@ -17,7 +17,7 @@ use std::fmt::Write;
 use std::hash::Hash;
 use syntax::ast;
 use syntax::ext::hygiene::Mark;
-use syntax::symbol::{Symbol, InternedString};
+use syntax::symbol::{Symbol, sym, InternedString};
 use syntax_pos::{Span, DUMMY_SP};
 use crate::util::nodemap::NodeMap;
 
@@ -584,16 +584,16 @@ impl DefPathData {
                 return name
             }
             // note that this does not show up in user printouts
-            CrateRoot => "{{crate}}",
-            Impl => "{{impl}}",
-            Misc => "{{misc}}",
-            ClosureExpr => "{{closure}}",
-            Ctor => "{{constructor}}",
-            AnonConst => "{{constant}}",
-            ImplTrait => "{{opaque}}",
+            CrateRoot => sym::double_braced_crate,
+            Impl => sym::double_braced_impl,
+            Misc => sym::double_braced_misc,
+            ClosureExpr => sym::double_braced_closure,
+            Ctor => sym::double_braced_constructor,
+            AnonConst => sym::double_braced_constant,
+            ImplTrait => sym::double_braced_opaque,
         };
 
-        Symbol::intern(s).as_interned_str()
+        s.as_interned_str()
     }
 
     pub fn to_string(&self) -> String {
diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs
index f05a1937291..67e76f7625c 100644
--- a/src/librustc/traits/project.rs
+++ b/src/librustc/traits/project.rs
@@ -1421,7 +1421,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
                 projection_ty: ty::ProjectionTy::from_ref_and_name(
                     tcx,
                     trait_ref,
-                    Ident::from_str(FN_OUTPUT_NAME),
+                    Ident::with_empty_ctxt(FN_OUTPUT_NAME),
                 ),
                 ty: ret_type
             }
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index 26194176350..67eaa19c080 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -11,6 +11,7 @@ use std::time::{Duration, Instant};
 
 use std::sync::mpsc::{Sender};
 use syntax_pos::{SpanData};
+use syntax::symbol::{Symbol, sym};
 use rustc_macros::HashStable;
 use crate::ty::TyCtxt;
 use crate::dep_graph::{DepNode};
@@ -18,7 +19,7 @@ use lazy_static;
 use crate::session::Session;
 
 // The name of the associated type for `Fn` return types
-pub const FN_OUTPUT_NAME: &str = "Output";
+pub const FN_OUTPUT_NAME: Symbol = sym::Output;
 
 // Useful type to use with `Result<>` indicate that an error has already
 // been reported to the user, so no need to continue checking.
diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs
index 0200e6c53b6..585c6fde634 100644
--- a/src/librustc_allocator/expand.rs
+++ b/src/librustc_allocator/expand.rs
@@ -19,7 +19,7 @@ use syntax::{
     mut_visit::{self, MutVisitor},
     parse::ParseSess,
     ptr::P,
-    symbol::{Symbol, sym}
+    symbol::{keywords, Symbol, sym}
 };
 use syntax_pos::Span;
 
@@ -110,13 +110,14 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
             span,
             kind: AllocatorKind::Global,
             global: item.ident,
-            core: Ident::from_str("core"),
+            core: Ident::with_empty_ctxt(sym::core),
             cx: ExtCtxt::new(self.sess, ecfg, self.resolver),
         };
 
         // We will generate a new submodule. To `use` the static from that module, we need to get
         // the `super::...` path.
-        let super_path = f.cx.path(f.span, vec![Ident::from_str("super"), f.global]);
+        let super_path =
+            f.cx.path(f.span, vec![Ident::with_empty_ctxt(keywords::Super.name()), f.global]);
 
         // Generate the items in the submodule
         let mut items = vec![
@@ -236,7 +237,7 @@ impl AllocFnFactory<'_> {
     ) -> P<Expr> {
         match *ty {
             AllocatorTy::Layout => {
-                let usize = self.cx.path_ident(self.span, Ident::from_str("usize"));
+                let usize = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::usize));
                 let ty_usize = self.cx.ty_path(usize);
                 let size = ident();
                 let align = ident();
@@ -298,12 +299,12 @@ impl AllocFnFactory<'_> {
     }
 
     fn usize(&self) -> P<Ty> {
-        let usize = self.cx.path_ident(self.span, Ident::from_str("usize"));
+        let usize = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::usize));
         self.cx.ty_path(usize)
     }
 
     fn ptr_u8(&self) -> P<Ty> {
-        let u8 = self.cx.path_ident(self.span, Ident::from_str("u8"));
+        let u8 = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::u8));
         let ty_u8 = self.cx.ty_path(u8);
         self.cx.ty_ptr(self.span, ty_u8, Mutability::Mutable)
     }
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 678f4c23d3e..77e8cc3272c 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -1979,11 +1979,11 @@ impl<'a> Resolver<'a> {
                                        .collect();
 
         if !attr::contains_name(&krate.attrs, sym::no_core) {
-            extern_prelude.insert(Ident::from_str("core"), Default::default());
+            extern_prelude.insert(Ident::with_empty_ctxt(sym::core), Default::default());
             if !attr::contains_name(&krate.attrs, sym::no_std) {
-                extern_prelude.insert(Ident::from_str("std"), Default::default());
+                extern_prelude.insert(Ident::with_empty_ctxt(sym::std), Default::default());
                 if session.rust_2018() {
-                    extern_prelude.insert(Ident::from_str("meta"), Default::default());
+                    extern_prelude.insert(Ident::with_empty_ctxt(sym::meta), Default::default());
                 }
             }
         }
@@ -3374,7 +3374,7 @@ impl<'a> Resolver<'a> {
                     self.trait_map.insert(id, traits);
                 }
 
-                let mut std_path = vec![Segment::from_ident(Ident::from_str("std"))];
+                let mut std_path = vec![Segment::from_ident(Ident::with_empty_ctxt(sym::std))];
                 std_path.extend(path);
                 if self.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
                     let cl = CrateLint::No;
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index f9a43ccfbac..e9ccc61280b 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -929,8 +929,9 @@ impl Attributes {
         for attr in attrs.lists(sym::target_feature) {
             if attr.check_name(sym::enable) {
                 if let Some(feat) = attr.value_str() {
-                    let meta = attr::mk_name_value_item_str(Ident::from_str("target_feature"),
-                                                            dummy_spanned(feat));
+                    let meta = attr::mk_name_value_item_str(
+                        Ident::with_empty_ctxt(sym::target_feature),
+                        dummy_spanned(feat));
                     if let Ok(feat_cfg) = Cfg::parse(&meta) {
                         cfg &= feat_cfg;
                     }
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index d94a3165b0f..592b40df176 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
 use crate::parse::{self, ParseSess, PResult};
 use crate::parse::token::{self, Token};
 use crate::ptr::P;
-use crate::symbol::{keywords, Symbol};
+use crate::symbol::{keywords, Symbol, sym};
 use crate::ThinVec;
 use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
 use crate::GLOBALS;
@@ -323,7 +323,7 @@ impl Attribute {
         if self.is_sugared_doc {
             let comment = self.value_str().unwrap();
             let meta = mk_name_value_item_str(
-                Ident::from_str("doc"),
+                Ident::with_empty_ctxt(sym::doc),
                 dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
             let mut attr = if self.style == ast::AttrStyle::Outer {
                 mk_attr_outer(self.span, self.id, meta)
@@ -414,7 +414,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
     Attribute {
         id,
         style,
-        path: Path::from_ident(Ident::from_str("doc").with_span_pos(span)),
+        path: Path::from_ident(Ident::with_empty_ctxt(sym::doc).with_span_pos(span)),
         tokens: MetaItemKind::NameValue(lit).tokens(span),
         is_sugared_doc: true,
         span,
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index a286fd83e3c..019ebc8566f 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1522,19 +1522,19 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
                             let include_info = vec![
                                 ast::NestedMetaItem::MetaItem(
                                     attr::mk_name_value_item_str(
-                                        Ident::from_str("file"),
+                                        Ident::with_empty_ctxt(sym::file),
                                         dummy_spanned(file),
                                     ),
                                 ),
                                 ast::NestedMetaItem::MetaItem(
                                     attr::mk_name_value_item_str(
-                                        Ident::from_str("contents"),
+                                        Ident::with_empty_ctxt(sym::contents),
                                         dummy_spanned(src_interned),
                                     ),
                                 ),
                             ];
 
-                            let include_ident = Ident::from_str("include");
+                            let include_ident = Ident::with_empty_ctxt(sym::include);
                             let item = attr::mk_list_item(DUMMY_SP, include_ident, include_info);
                             items.push(ast::NestedMetaItem::MetaItem(item));
                         }
@@ -1600,7 +1600,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
                 }
             }
 
-            let meta = attr::mk_list_item(DUMMY_SP, Ident::from_str("doc"), items);
+            let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items);
             match at.style {
                 ast::AttrStyle::Inner => *at = attr::mk_spanned_attr_inner(at.span, at.id, meta),
                 ast::AttrStyle::Outer => *at = attr::mk_spanned_attr_outer(at.span, at.id, meta),
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 3d55267b8e8..24d120376de 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -352,7 +352,7 @@ impl TokenCursor {
         let body = TokenTree::Delimited(
             delim_span,
             token::Bracket,
-            [TokenTree::Token(sp, token::Ident(ast::Ident::from_str("doc"), false)),
+            [TokenTree::Token(sp, token::Ident(ast::Ident::with_empty_ctxt(sym::doc), false)),
              TokenTree::Token(sp, token::Eq),
              TokenTree::Token(sp, token::Literal(
                 token::StrRaw(Symbol::intern(&stripped), num_of_hashes), None))
@@ -7011,7 +7011,8 @@ impl<'a> Parser<'a> {
                     let attr = Attribute {
                         id: attr::mk_attr_id(),
                         style: ast::AttrStyle::Outer,
-                        path: ast::Path::from_ident(Ident::from_str("warn_directory_ownership")),
+                        path: ast::Path::from_ident(
+                            Ident::with_empty_ctxt(sym::warn_directory_ownership)),
                         tokens: TokenStream::empty(),
                         is_sugared_doc: false,
                         span: syntax_pos::DUMMY_SP,
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 86db7a673d4..cd86d94f4b8 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -13,7 +13,7 @@ use crate::print::pp::{self, Breaks};
 use crate::print::pp::Breaks::{Consistent, Inconsistent};
 use crate::ptr::P;
 use crate::std_inject;
-use crate::symbol::keywords;
+use crate::symbol::{keywords, sym};
 use crate::tokenstream::{self, TokenStream, TokenTree};
 
 use rustc_target::spec::abi::{self, Abi};
@@ -89,13 +89,14 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
         // of the feature gate, so we fake them up here.
 
         // #![feature(prelude_import)]
-        let pi_nested = attr::mk_nested_word_item(ast::Ident::from_str("prelude_import"));
-        let list = attr::mk_list_item(DUMMY_SP, ast::Ident::from_str("feature"), vec![pi_nested]);
+        let pi_nested = attr::mk_nested_word_item(ast::Ident::with_empty_ctxt(sym::prelude_import));
+        let list = attr::mk_list_item(
+            DUMMY_SP, ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]);
         let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
         s.print_attribute(&fake_attr)?;
 
         // #![no_std]
-        let no_std_meta = attr::mk_word_item(ast::Ident::from_str("no_std"));
+        let no_std_meta = attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::no_std));
         let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
         s.print_attribute(&fake_attr)?;
     }
diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs
index f08fdcc6fb5..6784a2abe55 100644
--- a/src/libsyntax/std_inject.rs
+++ b/src/libsyntax/std_inject.rs
@@ -77,9 +77,11 @@ pub fn maybe_inject_crates_ref(
             None
         };
         krate.module.items.insert(0, P(ast::Item {
-            attrs: vec![attr::mk_attr_outer(DUMMY_SP,
-                                            attr::mk_attr_id(),
-                                            attr::mk_word_item(ast::Ident::from_str("macro_use")))],
+            attrs: vec![attr::mk_attr_outer(
+                DUMMY_SP,
+                attr::mk_attr_id(),
+                attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::macro_use))
+            )],
             vis: dummy_spanned(ast::VisibilityKind::Inherited),
             node: ast::ItemKind::ExternCrate(alt_std_name.or(orig_name)),
             ident: ast::Ident::with_empty_ctxt(rename),
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs
index 21bc236d00e..3fd0790161c 100644
--- a/src/libsyntax/test.rs
+++ b/src/libsyntax/test.rs
@@ -171,7 +171,7 @@ impl MutVisitor for EntryPointCleaner {
             EntryPointType::MainAttr |
             EntryPointType::Start =>
                 item.map(|ast::Item {id, ident, attrs, node, vis, span, tokens}| {
-                    let allow_ident = Ident::from_str("allow");
+                    let allow_ident = Ident::with_empty_ctxt(sym::allow);
                     let dc_nested = attr::mk_nested_word_item(Ident::from_str("dead_code"));
                     let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
                                                                   vec![dc_nested]);
@@ -215,7 +215,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>,
                    tests: Vec<Ident>,
                    tested_submods: Vec<(Ident, Ident)>)
                    -> (P<ast::Item>, Ident) {
-    let super_ = Ident::from_str("super");
+    let super_ = Ident::with_empty_ctxt(keywords::Super.name());
 
     let items = tests.into_iter().map(|r| {
         cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),
diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs
index ccff4aec2c8..2127179eecb 100644
--- a/src/libsyntax_ext/env.rs
+++ b/src/libsyntax_ext/env.rs
@@ -6,7 +6,7 @@
 use syntax::ast::{self, Ident, GenericArg};
 use syntax::ext::base::{self, *};
 use syntax::ext::build::AstBuilder;
-use syntax::symbol::{keywords, Symbol};
+use syntax::symbol::{keywords, Symbol, sym};
 use syntax_pos::Span;
 use syntax::tokenstream;
 
@@ -29,7 +29,8 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
                                      true,
                                      cx.std_path(&["option", "Option", "None"]),
                                      vec![GenericArg::Type(cx.ty_rptr(sp,
-                                                     cx.ty_ident(sp, Ident::from_str("str")),
+                                                     cx.ty_ident(sp,
+                                                                 Ident::with_empty_ctxt(sym::str)),
                                                      Some(lt),
                                                      ast::Mutability::Immutable))],
                                      vec![]))
diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs
index 1eab739cf64..c582fb422c9 100644
--- a/src/libsyntax_ext/proc_macro_decls.rs
+++ b/src/libsyntax_ext/proc_macro_decls.rs
@@ -362,11 +362,11 @@ fn mk_decls(
     });
     let span = DUMMY_SP.apply_mark(mark);
 
-    let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden"));
-    let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]);
+    let hidden = cx.meta_list_item_word(span, sym::hidden);
+    let doc = cx.meta_list(span, sym::doc, vec![hidden]);
     let doc_hidden = cx.attribute(span, doc);
 
-    let proc_macro = Ident::from_str("proc_macro");
+    let proc_macro = Ident::with_empty_ctxt(sym::proc_macro);
     let krate = cx.item(span,
                         proc_macro,
                         Vec::new(),
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index c2a18c9df83..01b126f48b3 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -214,6 +214,13 @@ symbols! {
         document_private_items,
         dotdoteq_in_patterns,
         dotdot_in_tuple_patterns,
+        double_braced_crate: "{{crate}}",
+        double_braced_impl: "{{impl}}",
+        double_braced_misc: "{{misc}}",
+        double_braced_closure: "{{closure}}",
+        double_braced_constructor: "{{constructor}}",
+        double_braced_constant: "{{constant}}",
+        double_braced_opaque: "{{opaque}}",
         dropck_eyepatch,
         dropck_parametricity,
         drop_types_in_const,
@@ -336,6 +343,7 @@ symbols! {
         match_default_bindings,
         may_dangle,
         message,
+        meta,
         min_const_fn,
         min_const_unsafe_fn,
         mips_target_feature,
@@ -385,6 +393,7 @@ symbols! {
         option,
         Option,
         opt_out_copy,
+        Output,
         overlapping_marker_traits,
         packed,
         panic_handler,
@@ -530,6 +539,7 @@ symbols! {
         static_nobundle,
         static_recursion,
         std,
+        str,
         stmt_expr_attributes,
         stop_after_dataflow,
         struct_field_attributes,