From 26451ef7b5e00887dc8f27717ff34262df23d655 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 22 May 2019 12:42:23 +1000 Subject: Avoid unnecessary internings. Most involving `Symbol::intern` on string literals. --- src/libsyntax_ext/asm.rs | 4 ++-- src/libsyntax_ext/assert.rs | 4 ++-- src/libsyntax_ext/deriving/clone.rs | 4 ++-- src/libsyntax_ext/deriving/cmp/eq.rs | 8 ++++---- src/libsyntax_ext/deriving/cmp/ord.rs | 4 ++-- src/libsyntax_ext/deriving/cmp/partial_eq.rs | 4 ++-- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 6 +++--- src/libsyntax_ext/deriving/debug.rs | 5 +++-- src/libsyntax_ext/deriving/default.rs | 4 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 5 ++--- src/libsyntax_ext/deriving/mod.rs | 2 +- src/libsyntax_ext/lib.rs | 18 +++++++----------- src/libsyntax_ext/proc_macro_decls.rs | 6 +++--- src/libsyntax_ext/proc_macro_server.rs | 4 ++-- src/libsyntax_ext/test.rs | 15 ++++++--------- src/libsyntax_ext/test_case.rs | 11 ++++------- 16 files changed, 47 insertions(+), 57 deletions(-) (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 704665e0a84..4d7083c1a79 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -11,7 +11,7 @@ use syntax::ext::base::{self, *}; use syntax::feature_gate; use syntax::parse::{self, token}; use syntax::ptr::P; -use syntax::symbol::{Symbol, sym}; +use syntax::symbol::{kw, sym, Symbol}; use syntax::ast::AsmDialect; use syntax_pos::Span; use syntax::tokenstream; @@ -93,7 +93,7 @@ fn parse_inline_asm<'a>( }) .unwrap_or(tts.len()); let mut p = cx.new_parser_from_tts(&tts[first_colon..]); - let mut asm = Symbol::intern(""); + let mut asm = kw::Invalid; let mut asm_str_style = None; let mut outputs = Vec::new(); let mut inputs = Vec::new(); diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index a11cd9c6f76..13342c8e28e 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -8,7 +8,7 @@ use syntax::parse::token::{self, Token}; use syntax::parse::parser::Parser; use syntax::print::pprust; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::{sym, Symbol}; use syntax::tokenstream::{TokenStream, TokenTree}; use syntax_pos::{Span, DUMMY_SP}; @@ -27,7 +27,7 @@ pub fn expand_assert<'cx>( let sp = sp.apply_mark(cx.current_expansion.mark); let panic_call = Mac_ { - path: Path::from_ident(Ident::new(Symbol::intern("panic"), sp)), + path: Path::from_ident(Ident::new(sym::panic, sp)), tts: custom_message.unwrap_or_else(|| { TokenStream::from(TokenTree::Token( DUMMY_SP, diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index a39e0a6e973..417dd2525d6 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -7,7 +7,7 @@ use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::{Symbol, kw, sym}; +use syntax::symbol::{kw, sym}; use syntax_pos::Span; pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, @@ -76,7 +76,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, _ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"), } - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index a1035ff641f..e7d7f136e18 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem, GenericArg}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use syntax_pos::Span; pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, @@ -14,9 +14,9 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - let inline = cx.meta_word(span, Symbol::intern("inline")); - let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden")); - let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]); + let inline = cx.meta_word(span, sym::inline); + let hidden = cx.meta_list_item_word(span, sym::hidden); + let doc = cx.meta_list(span, sym::doc, vec![hidden]); let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)]; let trait_def = TraitDef { span, diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index e4f939c151f..282cfa5a4bf 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use syntax_pos::Span; pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>, @@ -14,7 +14,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 07026ae3739..6172f27261e 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -6,7 +6,7 @@ use syntax::ast::{BinOpKind, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use syntax_pos::Span; pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, @@ -62,7 +62,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, macro_rules! md { ($name:expr, $f:ident) => { { - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; MethodDef { name: $name, diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index e99abeb118e..abfa79c2b4d 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -8,7 +8,7 @@ use syntax::ast::{self, BinOpKind, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use syntax_pos::Span; pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, @@ -18,7 +18,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, push: &mut dyn FnMut(Annotatable)) { macro_rules! md { ($name:expr, $op:expr, $equal:expr) => { { - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; MethodDef { name: $name, @@ -42,7 +42,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, vec![Box::new(ordering_ty)], PathKind::Std)); - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; let partial_cmp_def = MethodDef { diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 2fc1fc9140d..dec4c2dfc3b 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -9,6 +9,7 @@ use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; +use syntax::symbol::sym; use syntax_pos::{DUMMY_SP, Span}; pub fn expand_deriving_debug(cx: &mut ExtCtxt<'_>, @@ -82,7 +83,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> let expr = cx.expr_method_call(span, builder_expr.clone(), - Ident::from_str("field"), + Ident::with_empty_ctxt(sym::field), vec![field]); // Use `let _ = expr;` to avoid triggering the @@ -106,7 +107,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> let field = cx.expr_addr_of(field.span, field); let expr = cx.expr_method_call(span, builder_expr.clone(), - Ident::from_str("field"), + Ident::with_empty_ctxt(sym::field), vec![name, field]); stmts.push(stmt_let_undescore(cx, span, expr)); } diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index 6db0a29165a..b42dde16420 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -6,7 +6,7 @@ use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use syntax::span_err; use syntax_pos::Span; @@ -15,7 +15,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - let inline = cx.meta_word(span, Symbol::intern("inline")); + let inline = cx.meta_word(span, sym::inline); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 0689eb50f9c..7e3082a87d9 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -666,14 +666,13 @@ impl<'a> TraitDef<'a> { let self_type = cx.ty_path(path); let attr = cx.attribute(self.span, - cx.meta_word(self.span, - Symbol::intern("automatically_derived"))); + cx.meta_word(self.span, sym::automatically_derived)); // Just mark it now since we know that it'll end up used downstream attr::mark_used(&attr); let opt_trait_ref = Some(trait_ref); let unused_qual = { let word = cx.meta_list_item_word(self.span, Symbol::intern("unused_qualifications")); - cx.attribute(self.span, cx.meta_list(self.span, Symbol::intern("allow"), vec![word])) + cx.attribute(self.span, cx.meta_list(self.span, sym::allow, vec![word])) }; let mut a = vec![attr, unused_qual]; diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index c27de692d88..eff71bc969e 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -145,7 +145,7 @@ fn call_intrinsic(cx: &ExtCtxt<'_>, span = span.with_ctxt(cx.backtrace()); } else { // Avoid instability errors with user defined curstom derives, cc #36316 let mut info = cx.current_expansion.mark.expn_info().unwrap(); - info.allow_internal_unstable = Some(vec![Symbol::intern("core_intrinsics")].into()); + info.allow_internal_unstable = Some(vec![sym::core_intrinsics].into()); let mark = Mark::fresh(Mark::root()); mark.set_expn_info(info); span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index e5fc7aab61d..fc001544275 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -42,8 +42,8 @@ pub mod proc_macro_impl; use rustc_data_structures::sync::Lrc; use syntax::ast; use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier}; -use syntax::symbol::Symbol; use syntax::edition::Edition; +use syntax::symbol::{sym, Symbol}; pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, user_exts: Vec, @@ -93,30 +93,26 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, assert: assert::expand_assert, } - register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand))); - register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test))); - register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench))); + register(sym::test_case, MultiModifier(Box::new(test_case::expand))); + register(sym::test, MultiModifier(Box::new(test::expand_test))); + register(sym::bench, MultiModifier(Box::new(test::expand_bench))); // format_args uses `unstable` things internally. register(Symbol::intern("format_args"), NormalTT { expander: Box::new(format::expand_format_args), def_info: None, - allow_internal_unstable: Some(vec![ - Symbol::intern("fmt_internals"), - ].into()), + allow_internal_unstable: Some(vec![sym::fmt_internals].into()), allow_internal_unsafe: false, local_inner_macros: false, unstable_feature: None, edition, }); - register(Symbol::intern("format_args_nl"), + register(sym::format_args_nl, NormalTT { expander: Box::new(format::expand_format_args_nl), def_info: None, - allow_internal_unstable: Some(vec![ - Symbol::intern("fmt_internals"), - ].into()), + allow_internal_unstable: Some(vec![sym::fmt_internals].into()), allow_internal_unsafe: false, local_inner_macros: false, unstable_feature: None, diff --git a/src/libsyntax_ext/proc_macro_decls.rs b/src/libsyntax_ext/proc_macro_decls.rs index a485bb19808..5b8f4f35f2d 100644 --- a/src/libsyntax_ext/proc_macro_decls.rs +++ b/src/libsyntax_ext/proc_macro_decls.rs @@ -351,9 +351,9 @@ fn mk_decls( mark.set_expn_info(ExpnInfo { call_site: DUMMY_SP, def_site: None, - format: MacroAttribute(Symbol::intern("proc_macro")), + format: MacroAttribute(sym::proc_macro), allow_internal_unstable: Some(vec![ - Symbol::intern("rustc_attrs"), + sym::rustc_attrs, Symbol::intern("proc_macro_internals"), ].into()), allow_internal_unsafe: false, @@ -420,7 +420,7 @@ fn mk_decls( ast::Mutability::Immutable, cx.expr_vec_slice(span, decls), ).map(|mut i| { - let attr = cx.meta_word(span, Symbol::intern("rustc_proc_macro_decls")); + let attr = cx.meta_word(span, sym::rustc_proc_macro_decls); i.attrs.push(cx.attribute(span, attr)); i.vis = respan(span, ast::VisibilityKind::Public); i diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs index beac92894b7..53730d2d080 100644 --- a/src/libsyntax_ext/proc_macro_server.rs +++ b/src/libsyntax_ext/proc_macro_server.rs @@ -14,7 +14,7 @@ use syntax::parse::lexer::comments; use syntax::parse::{self, token, ParseSess}; use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint}; use syntax_pos::hygiene::{SyntaxContext, Transparency}; -use syntax_pos::symbol::{kw, Symbol}; +use syntax_pos::symbol::{kw, sym, Symbol}; use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span}; trait FromInternal { @@ -159,7 +159,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec)> escaped.extend(ch.escape_debug()); } let stream = vec![ - Ident(ast::Ident::new(Symbol::intern("doc"), span), false), + Ident(ast::Ident::new(sym::doc, span), false), Eq, Token::lit(token::Str, Symbol::intern(&escaped), None), ] diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index 8ee61a3f67f..c20dc6cb2d7 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -65,11 +65,8 @@ pub fn expand_test_or_bench( mark.set_expn_info(ExpnInfo { call_site: DUMMY_SP, def_site: None, - format: MacroAttribute(Symbol::intern("test")), - allow_internal_unstable: Some(vec![ - Symbol::intern("rustc_attrs"), - Symbol::intern("test"), - ].into()), + format: MacroAttribute(sym::test), + allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::test].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: cx.parse_sess.edition, @@ -130,11 +127,11 @@ pub fn expand_test_or_bench( let mut test_const = cx.item(sp, ast::Ident::new(item.ident.name, sp).gensym(), vec![ // #[cfg(test)] - cx.attribute(attr_sp, cx.meta_list(attr_sp, Symbol::intern("cfg"), vec![ - cx.meta_list_item_word(attr_sp, Symbol::intern("test")) + cx.attribute(attr_sp, cx.meta_list(attr_sp, sym::cfg, vec![ + cx.meta_list_item_word(attr_sp, sym::test) ])), // #[rustc_test_marker] - cx.attribute(attr_sp, cx.meta_word(attr_sp, Symbol::intern("rustc_test_marker"))), + cx.attribute(attr_sp, cx.meta_word(attr_sp, sym::rustc_test_marker)), ], // const $ident: test::TestDescAndFn = ast::ItemKind::Const(cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), @@ -180,7 +177,7 @@ pub fn expand_test_or_bench( let test_extern = cx.item(sp, test_id, vec![], - ast::ItemKind::ExternCrate(Some(Symbol::intern("test"))) + ast::ItemKind::ExternCrate(Some(sym::test)) ); log::debug!("Synthetic test item:\n{}\n", pprust::item_to_string(&test_const)); diff --git a/src/libsyntax_ext/test_case.rs b/src/libsyntax_ext/test_case.rs index 5b1ae167ce3..cffecdd0f18 100644 --- a/src/libsyntax_ext/test_case.rs +++ b/src/libsyntax_ext/test_case.rs @@ -14,7 +14,7 @@ use syntax::ext::build::AstBuilder; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ast; use syntax::source_map::respan; -use syntax::symbol::{Symbol, sym}; +use syntax::symbol::sym; use syntax_pos::{DUMMY_SP, Span}; use syntax::source_map::{ExpnInfo, MacroAttribute}; use syntax::feature_gate; @@ -40,11 +40,8 @@ pub fn expand( mark.set_expn_info(ExpnInfo { call_site: DUMMY_SP, def_site: None, - format: MacroAttribute(Symbol::intern("test_case")), - allow_internal_unstable: Some(vec![ - Symbol::intern("test"), - Symbol::intern("rustc_attrs"), - ].into()), + format: MacroAttribute(sym::test_case), + allow_internal_unstable: Some(vec![sym::test, sym::rustc_attrs].into()), allow_internal_unsafe: false, local_inner_macros: false, edition: ecx.parse_sess.edition, @@ -59,7 +56,7 @@ pub fn expand( item.ident = item.ident.gensym(); item.attrs.push( ecx.attribute(sp, - ecx.meta_word(sp, Symbol::intern("rustc_test_marker"))) + ecx.meta_word(sp, sym::rustc_test_marker)) ); item }); -- cgit 1.4.1-3-g733a5 From 58c68d00fd1702b74e67dcb6f6f54483c066ef31 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 22 May 2019 14:41:15 +1000 Subject: Pass symbols to `ExtCtxt::std_path` instead of strings. Because this function is hot. Also remove the dead `ty_option` function. --- src/libsyntax/ext/base.rs | 4 +-- src/libsyntax/ext/build.rs | 38 ++++++++++----------------- src/libsyntax_ext/deriving/clone.rs | 6 ++--- src/libsyntax_ext/deriving/cmp/eq.rs | 4 +-- src/libsyntax_ext/deriving/cmp/ord.rs | 4 +-- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 27 ++++++++++--------- src/libsyntax_ext/deriving/default.rs | 5 ++-- src/libsyntax_ext/deriving/hash.rs | 3 ++- src/libsyntax_ext/deriving/mod.rs | 2 +- src/libsyntax_ext/env.rs | 4 +-- src/libsyntax_ext/format.rs | 10 +++---- src/libsyntax_pos/symbol.rs | 21 +++++++++++++++ 12 files changed, 71 insertions(+), 57 deletions(-) (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index dbec379e769..d72193ffe12 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> { pub fn ident_of(&self, st: &str) -> ast::Ident { ast::Ident::from_str(st) } - pub fn std_path(&self, components: &[&str]) -> Vec { + pub fn std_path(&self, components: &[Symbol]) -> Vec { let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark); iter::once(Ident::new(kw::DollarCrate, def_site)) - .chain(components.iter().map(|s| self.ident_of(s))) + .chain(components.iter().map(|&s| Ident::with_empty_ctxt(s))) .collect() } pub fn name_of(&self, st: &str) -> ast::Name { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index ad8fb12deb7..9c0ffc1f6e8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -3,11 +3,11 @@ use crate::attr; use crate::source_map::{dummy_spanned, respan, Spanned}; use crate::ext::base::ExtCtxt; use crate::ptr::P; -use crate::symbol::{Symbol, kw}; +use crate::symbol::{kw, sym, Symbol}; use crate::ThinVec; use rustc_target::spec::abi::Abi; -use syntax_pos::{Pos, Span, DUMMY_SP}; +use syntax_pos::{Pos, Span}; pub trait AstBuilder { // paths @@ -49,7 +49,6 @@ pub trait AstBuilder { ty: P, mutbl: ast::Mutability) -> P; - fn ty_option(&self, ty: P) -> P; fn ty_infer(&self, sp: Span) -> P; fn typaram(&self, @@ -425,15 +424,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } - fn ty_option(&self, ty: P) -> P { - self.ty_path( - self.path_all(DUMMY_SP, - true, - self.std_path(&["option", "Option"]), - vec![ast::GenericArg::Type(ty)], - Vec::new())) - } - fn ty_infer(&self, span: Span) -> P { self.ty(span, ast::TyKind::Infer) } @@ -735,7 +725,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::Array(exprs)) } fn expr_vec_ng(&self, sp: Span) -> P { - self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]), + self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]), Vec::new()) } fn expr_vec_slice(&self, sp: Span, exprs: Vec>) -> P { @@ -751,12 +741,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn expr_some(&self, sp: Span, expr: P) -> P { - let some = self.std_path(&["option", "Option", "Some"]); + let some = self.std_path(&[sym::option, sym::Option, sym::Some]); self.expr_call_global(sp, some, vec![expr]) } fn expr_none(&self, sp: Span) -> P { - let none = self.std_path(&["option", "Option", "None"]); + let none = self.std_path(&[sym::option, sym::Option, sym::None]); let none = self.path_global(sp, none); self.expr_path(none) } @@ -780,7 +770,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple); self.expr_call_global( span, - self.std_path(&["rt", "begin_panic"]), + self.std_path(&[sym::rt, sym::begin_panic]), vec![ self.expr_str(span, msg), expr_loc_ptr]) @@ -791,19 +781,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_ok(&self, sp: Span, expr: P) -> P { - let ok = self.std_path(&["result", "Result", "Ok"]); + let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); self.expr_call_global(sp, ok, vec![expr]) } fn expr_err(&self, sp: Span, expr: P) -> P { - let err = self.std_path(&["result", "Result", "Err"]); + let err = self.std_path(&[sym::result, sym::Result, sym::Err]); self.expr_call_global(sp, err, vec![expr]) } fn expr_try(&self, sp: Span, head: P) -> P { - let ok = self.std_path(&["result", "Result", "Ok"]); + let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); let ok_path = self.path_global(sp, ok); - let err = self.std_path(&["result", "Result", "Err"]); + let err = self.std_path(&[sym::result, sym::Result, sym::Err]); let err_path = self.path_global(sp, err); let binding_variable = self.ident_of("__try_var"); @@ -867,25 +857,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn pat_some(&self, span: Span, pat: P) -> P { - let some = self.std_path(&["option", "Option", "Some"]); + let some = self.std_path(&[sym::option, sym::Option, sym::Some]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, vec![pat]) } fn pat_none(&self, span: Span) -> P { - let some = self.std_path(&["option", "Option", "None"]); + let some = self.std_path(&[sym::option, sym::Option, sym::None]); let path = self.path_global(span, some); self.pat_path(span, path) } fn pat_ok(&self, span: Span, pat: P) -> P { - let some = self.std_path(&["result", "Result", "Ok"]); + let some = self.std_path(&[sym::result, sym::Result, sym::Ok]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, vec![pat]) } fn pat_err(&self, span: Span, pat: P) -> P { - let some = self.std_path(&["result", "Result", "Err"]); + let some = self.std_path(&[sym::result, sym::Result, sym::Err]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, vec![pat]) } diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 417dd2525d6..b3b6328e2ca 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -7,7 +7,7 @@ use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::{kw, sym}; +use syntax::symbol::{kw, sym, Symbol}; use syntax_pos::Span; pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, @@ -115,7 +115,7 @@ fn cs_clone_shallow(name: &str, // set the expn ID so we can use the unstable struct. let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, - cx.std_path(&["clone", helper_name]), + cx.std_path(&[sym::clone, Symbol::intern(helper_name)]), vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } @@ -157,7 +157,7 @@ fn cs_clone(name: &str, -> P { let ctor_path; let all_fields; - let fn_path = cx.std_path(&["clone", "Clone", "clone"]); + let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]); let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| { let args = vec![cx.expr_addr_of(field.span, field.self_.clone())]; cx.expr_call_global(field.span, fn_path.clone(), args) diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index e7d7f136e18..1d981e0ff79 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem, GenericArg}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::sym; +use syntax::symbol::{sym, Symbol}; use syntax_pos::Span; pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, @@ -54,7 +54,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>, // set the expn ID so we can use the unstable struct. let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, - cx.std_path(&["cmp", helper_name]), + cx.std_path(&[sym::cmp, Symbol::intern(helper_name)]), vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 282cfa5a4bf..b25a9e4c50f 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -55,9 +55,9 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>, pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P { let test_id = cx.ident_of("cmp").gensym(); - let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); + let equals_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal])); - let cmp_path = cx.std_path(&["cmp", "Ord", "cmp"]); + let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]); // Builds: // diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index abfa79c2b4d..3980741f252 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -8,7 +8,7 @@ use syntax::ast::{self, BinOpKind, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::sym; +use syntax::symbol::{sym, Symbol}; use syntax_pos::Span; pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>, @@ -114,11 +114,11 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>, pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P { let test_id = cx.ident_of("cmp").gensym(); - let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"])); + let ordering = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal])); let ordering_expr = cx.expr_path(ordering.clone()); let equals_expr = cx.expr_some(span, ordering_expr); - let partial_cmp_path = cx.std_path(&["cmp", "PartialOrd", "partial_cmp"]); + let partial_cmp_path = cx.std_path(&[sym::cmp, sym::PartialOrd, sym::partial_cmp]); // Builds: // @@ -188,7 +188,8 @@ fn cs_op(less: bool, span: Span, substr: &Substructure<'_>) -> P { let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| { - cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name]))) + cx.expr_path(cx.path_global( + span, cx.std_path(&[sym::cmp, sym::Ordering, Symbol::intern(name)]))) }; let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P, other_fs: &[P], default| { @@ -198,9 +199,9 @@ fn cs_op(less: bool, }; // `PartialOrd::partial_cmp(self.fi, other.fi)` - let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", - "PartialOrd", - "partial_cmp"]))); + let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::cmp, + sym::PartialOrd, + sym::partial_cmp]))); let cmp = cx.expr_call(span, cmp_path, vec![cx.expr_addr_of(span, self_f), @@ -208,9 +209,9 @@ fn cs_op(less: bool, let default = ordering_path(cx, default); // `Option::unwrap_or(_, Ordering::Equal)` - let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&["option", - "Option", - "unwrap_or"]))); + let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::option, + sym::Option, + sym::unwrap_or]))); cx.expr_call(span, unwrap_path, vec![cmp, default]) }; @@ -256,9 +257,9 @@ fn cs_op(less: bool, // `Ordering::then_with(Option::unwrap_or(..), ..)` let then_with_path = cx.expr_path(cx.path_global(span, - cx.std_path(&["cmp", - "Ordering", - "then_with"]))); + cx.std_path(&[sym::cmp, + sym::Ordering, + sym::then_with]))); cx.expr_call(span, then_with_path, vec![par_cmp, cx.lambda0(span, subexpr)]) }, |cx, args| { diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index b42dde16420..fd8e87e2fef 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -6,7 +6,7 @@ use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; -use syntax::symbol::sym; +use syntax::symbol::{kw, sym}; use syntax::span_err; use syntax_pos::Span; @@ -47,7 +47,8 @@ fn default_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P { - let default_ident = cx.std_path(&["default", "Default", "default"]); + // Note that `kw::Default` is "default" and `sym::Default` is "Default"! + let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]); let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new()); return match *substr.fields { diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index 0d4f2ddc3be..e7f99d45782 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -6,6 +6,7 @@ use syntax::ast::{Expr, MetaItem, Mutability}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; +use syntax::symbol::sym; use syntax_pos::Span; pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>, @@ -60,7 +61,7 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu }; let call_hash = |span, thing_expr| { let hash_path = { - let strs = cx.std_path(&["hash", "Hash", "hash"]); + let strs = cx.std_path(&[sym::hash, sym::Hash, sym::hash]); cx.expr_path(cx.path_global(span, strs)) }; diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index eff71bc969e..ac41f30e6b3 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -150,7 +150,7 @@ fn call_intrinsic(cx: &ExtCtxt<'_>, mark.set_expn_info(info); span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); } - let path = cx.std_path(&["intrinsics", intrinsic]); + let path = cx.std_path(&[sym::intrinsics, Symbol::intern(intrinsic)]); let call = cx.expr_call_global(span, path, args); cx.expr_block(P(ast::Block { diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 72a66ae3845..b7f2ecf0f91 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -27,7 +27,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>, let lt = cx.lifetime(sp, Ident::with_empty_ctxt(kw::StaticLifetime)); cx.expr_path(cx.path_all(sp, true, - cx.std_path(&["option", "Option", "None"]), + cx.std_path(&[sym::option, sym::Option, sym::None]), vec![GenericArg::Type(cx.ty_rptr(sp, cx.ty_ident(sp, Ident::with_empty_ctxt(sym::str)), @@ -37,7 +37,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>, } Ok(s) => { cx.expr_call_global(sp, - cx.std_path(&["option", "Option", "Some"]), + cx.std_path(&[sym::option, sym::Option, sym::Some]), vec![cx.expr_str(sp, Symbol::intern(&s))]) } }; diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 9e54c0634b6..b5be45547cf 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -387,7 +387,7 @@ impl<'a, 'b> Context<'a, 'b> { } fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec { - ecx.std_path(&["fmt", "rt", "v1", s]) + ecx.std_path(&[sym::fmt, sym::rt, sym::v1, Symbol::intern(s)]) } fn build_count(&self, c: parse::Count<'_>) -> P { @@ -644,7 +644,7 @@ impl<'a, 'b> Context<'a, 'b> { ("new_v1_formatted", vec![pieces, args_slice, fmt]) }; - let path = self.ecx.std_path(&["fmt", "Arguments", fn_name]); + let path = self.ecx.std_path(&[sym::fmt, sym::Arguments, Symbol::intern(fn_name)]); self.ecx.expr_call_global(self.macsp, path, fn_args) } @@ -675,14 +675,14 @@ impl<'a, 'b> Context<'a, 'b> { } } Count => { - let path = ecx.std_path(&["fmt", "ArgumentV1", "from_usize"]); + let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::from_usize]); return ecx.expr_call_global(macsp, path, vec![arg]); } }; - let path = ecx.std_path(&["fmt", trait_, "fmt"]); + let path = ecx.std_path(&[sym::fmt, Symbol::intern(trait_), sym::fmt]); let format_fn = ecx.path_global(sp, path); - let path = ecx.std_path(&["fmt", "ArgumentV1", "new"]); + let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::new]); ecx.expr_call_global(macsp, path, vec![arg, ecx.expr_path(format_fn)]) } } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 30b342a11d8..ce75094de59 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -132,6 +132,8 @@ symbols! { always, any, arbitrary_self_types, + Arguments, + ArgumentV1, arm_target_feature, asm, associated_consts, @@ -145,6 +147,7 @@ symbols! { automatically_derived, avx512_target_feature, await_macro, + begin_panic, bench, bin, bind_by_move_pattern_guards, @@ -164,9 +167,11 @@ symbols! { cfg_target_thread_local, cfg_target_vendor, clone, + Clone, clone_closures, clone_from, closure_to_fn_coercion, + cmp, cmpxchg16b_target_feature, cold, compile_error, @@ -200,6 +205,7 @@ symbols! { custom_test_frameworks, c_variadic, decl_macro, + Default, default_lib_allocator, default_type_parameter_fallback, default_type_params, @@ -234,6 +240,7 @@ symbols! { enable, err, Err, + Equal, except, exclusive_range_pattern, exhaustive_integer_patterns, @@ -256,6 +263,7 @@ symbols! { field, field_init_shorthand, file, + fmt, fmt_internals, fn_must_use, forbid, @@ -265,6 +273,7 @@ symbols! { from_error, from_generator, from_ok, + from_usize, fundamental, future, Future, @@ -275,6 +284,8 @@ symbols! { global_allocator, global_asm, globs, + hash, + Hash, hexagon_target_feature, hidden, homogeneous_aggregate, @@ -371,6 +382,7 @@ symbols! { negate_unsigned, never, never_type, + new, next, __next, nll, @@ -405,6 +417,8 @@ symbols! { option, Option, opt_out_copy, + Ord, + Ordering, Output, overlapping_marker_traits, packed, @@ -413,6 +427,8 @@ symbols! { panic_impl, panic_implementation, panic_runtime, + partial_cmp, + PartialOrd, passes, path, pattern_parentheses, @@ -473,6 +489,7 @@ symbols! { Result, Return, rlib, + rt, rtm_target_feature, rust, rust_2015_preview, @@ -576,6 +593,7 @@ symbols! { test_case, test_removed_feature, test_runner, + then_with, thread_local, tool_attributes, tool_lints, @@ -615,12 +633,15 @@ symbols! { untagged_unions, unwind, unwind_attributes, + unwrap_or, used, use_extern_macros, use_nested_groups, usize, v1, val, + vec, + Vec, vis, visible_private_types, volatile, -- cgit 1.4.1-3-g733a5