From b6d522a101982b4c6919391a378e799bd74a4da6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 23 Jun 2019 14:59:42 +0300 Subject: [PATCH] syntax: Pre-intern names of all built-in macros They always end up interned anyway --- src/libsyntax/ext/derive.rs | 6 ++--- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax_ext/deriving/mod.rs | 34 +++++++++++++------------- src/libsyntax_ext/lib.rs | 6 ++--- src/libsyntax_ext/proc_macro_server.rs | 4 +-- src/libsyntax_pos/symbol.rs | 20 ++++++++++++++- 6 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 3b4243ed24f..2a56f3dd756 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -63,11 +63,11 @@ pub fn add_derived_markers(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P let span = span.with_ctxt(cx.backtrace()); item.visit_attrs(|attrs| { - if names.contains(&Symbol::intern("Eq")) && names.contains(&Symbol::intern("PartialEq")) { - let meta = cx.meta_word(span, Symbol::intern("structural_match")); + if names.contains(&sym::Eq) && names.contains(&sym::PartialEq) { + let meta = cx.meta_word(span, sym::structural_match); attrs.push(cx.attribute(span, meta)); } - if names.contains(&Symbol::intern("Copy")) { + if names.contains(&sym::Copy) { let meta = cx.meta_word(span, sym::rustc_copy_clone_marker); attrs.push(cx.attribute(span, meta)); } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 1abbf0ff1ee..d0c4e8d6a56 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -613,7 +613,7 @@ fn scan_number(&mut self, c: char) -> (token::LitKind, Symbol) { if num_digits == 0 { self.err_span_(start_bpos, self.pos, "no valid digits found for number"); - return (token::Integer, Symbol::intern("0")); + return (token::Integer, sym::integer(0)); } // might be a float, but don't be greedy if this is actually an diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index f7889b9cac0..e491e93256d 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -61,10 +61,10 @@ fn expand(&self, } macro_rules! derive_traits { - ($( [$deprecation:expr] $name:expr => $func:path, )+) => { + ($( [$deprecation:expr] $name:ident => $func:path, )+) => { pub fn is_builtin_trait(name: ast::Name) -> bool { - match &*name.as_str() { - $( $name )|+ => true, + match name { + $( sym::$name )|+ => true, _ => false, } } @@ -80,7 +80,7 @@ pub fn register_builtin_derives(resolver: &mut dyn Resolver, edition: Edition) { $( resolver.add_builtin( - ast::Ident::with_empty_ctxt(Symbol::intern($name)), + ast::Ident::with_empty_ctxt(sym::$name), Lrc::new(SyntaxExtension { deprecation: $deprecation.map(|msg| Deprecation { since: Some(Symbol::intern("1.0.0")), @@ -100,40 +100,40 @@ pub fn register_builtin_derives(resolver: &mut dyn Resolver, edition: Edition) { derive_traits! { [None] - "Clone" => clone::expand_deriving_clone, + Clone => clone::expand_deriving_clone, [None] - "Hash" => hash::expand_deriving_hash, + Hash => hash::expand_deriving_hash, [None] - "RustcEncodable" => encodable::expand_deriving_rustc_encodable, + RustcEncodable => encodable::expand_deriving_rustc_encodable, [None] - "RustcDecodable" => decodable::expand_deriving_rustc_decodable, + RustcDecodable => decodable::expand_deriving_rustc_decodable, [None] - "PartialEq" => partial_eq::expand_deriving_partial_eq, + PartialEq => partial_eq::expand_deriving_partial_eq, [None] - "Eq" => eq::expand_deriving_eq, + Eq => eq::expand_deriving_eq, [None] - "PartialOrd" => partial_ord::expand_deriving_partial_ord, + PartialOrd => partial_ord::expand_deriving_partial_ord, [None] - "Ord" => ord::expand_deriving_ord, + Ord => ord::expand_deriving_ord, [None] - "Debug" => debug::expand_deriving_debug, + Debug => debug::expand_deriving_debug, [None] - "Default" => default::expand_deriving_default, + Default => default::expand_deriving_default, [None] - "Copy" => bounds::expand_deriving_copy, + Copy => bounds::expand_deriving_copy, // deprecated [Some("derive(Encodable) is deprecated in favor of derive(RustcEncodable)")] - "Encodable" => encodable::expand_deriving_encodable, + Encodable => encodable::expand_deriving_encodable, [Some("derive(Decodable) is deprecated in favor of derive(RustcDecodable)")] - "Decodable" => decodable::expand_deriving_decodable, + Decodable => decodable::expand_deriving_decodable, } /// Construct a name for the inner type parameter that can't collide with any type parameters of diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 1ca5cc47fa2..62530f4fe7b 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -74,14 +74,14 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, }; macro_rules! register { ($( $name:ident: $f:expr, )*) => { $( - register(Symbol::intern(stringify!($name)), SyntaxExtension::default( + register(sym::$name, SyntaxExtension::default( SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)), edition )); )* } } macro_rules! register_unstable { ($( [$feature:expr, $reason:expr, $issue:expr] $name:ident: $f:expr, )*) => { $( - register(Symbol::intern(stringify!($name)), SyntaxExtension { + register(sym::$name, SyntaxExtension { stability: Some(Stability::unstable( $feature, Some(Symbol::intern($reason)), $issue )), @@ -144,7 +144,7 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, // format_args uses `unstable` things internally. let allow_internal_unstable = Some([sym::fmt_internals][..].into()); - register(Symbol::intern("format_args"), SyntaxExtension { + register(sym::format_args, SyntaxExtension { allow_internal_unstable: allow_internal_unstable.clone(), ..SyntaxExtension::default( SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args)), edition diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs index c9d99e5831a..e5027354527 100644 --- a/src/libsyntax_ext/proc_macro_server.rs +++ b/src/libsyntax_ext/proc_macro_server.rs @@ -548,10 +548,10 @@ fn float(&mut self, n: &str) -> Self::Literal { self.lit(token::Float, Symbol::intern(n), None) } fn f32(&mut self, n: &str) -> Self::Literal { - self.lit(token::Float, Symbol::intern(n), Some(Symbol::intern("f32"))) + self.lit(token::Float, Symbol::intern(n), Some(sym::f32)) } fn f64(&mut self, n: &str) -> Self::Literal { - self.lit(token::Float, Symbol::intern(n), Some(Symbol::intern("f64"))) + self.lit(token::Float, Symbol::intern(n), Some(sym::f64)) } fn string(&mut self, string: &str) -> Self::Literal { let mut escaped = String::new(); diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 410f4b36b67..8bb622a6855 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -141,6 +141,7 @@ ArgumentV1, arm_target_feature, asm, + assert, associated_consts, associated_type_bounds, associated_type_defaults, @@ -184,8 +185,10 @@ cmp, cmpxchg16b_target_feature, cold, + column, compile_error, compiler_builtins, + concat, concat_idents, conservative_impl_trait, console, @@ -203,6 +206,7 @@ contents, context, convert, + Copy, copy_closures, core, core_intrinsics, @@ -217,8 +221,10 @@ custom_inner_attributes, custom_test_frameworks, c_variadic, + Debug, declare_lint_pass, decl_macro, + Decodable, Default, default_lib_allocator, default_type_parameter_fallback, @@ -253,9 +259,12 @@ eh_personality, eh_unwind_resume, enable, + Encodable, + env, eq, err, Err, + Eq, Equal, except, exclusive_range_pattern, @@ -284,6 +293,7 @@ fmt_internals, fn_must_use, forbid, + format_args, format_args_nl, from, From, @@ -335,6 +345,8 @@ index_mut, in_band_lifetimes, include, + include_bytes, + include_str, inclusive_range_syntax, infer_outlives_requirements, infer_static_outlives_requirements, @@ -363,6 +375,7 @@ lhs, lib, lifetime, + line, link, linkage, link_args, @@ -402,6 +415,7 @@ mips_target_feature, mmx_target_feature, module, + module_path, more_struct_aliases, movbe_target_feature, must_use, @@ -447,6 +461,7 @@ optin_builtin_traits, option, Option, + option_env, opt_out_copy, or, Ord, @@ -462,6 +477,7 @@ parent_trait, partial_cmp, param_attrs, + PartialEq, PartialOrd, passes, pat, @@ -532,6 +548,8 @@ rust_2018_preview, rust_begin_unwind, rustc, + RustcDecodable, + RustcEncodable, rustc_allocator, rustc_allocator_nounwind, rustc_allow_const_fn_ptr, @@ -591,7 +609,6 @@ _Self, self_in_typedefs, self_struct_ctor, - Send, should_panic, simd, simd_ffi, @@ -613,6 +630,7 @@ static_recursion, std, str, + stringify, stmt, stmt_expr_attributes, stop_after_dataflow, -- GitLab