Skip to content

Commit

Permalink
syntax: Pre-intern names of all built-in macros
Browse files Browse the repository at this point in the history
They always end up interned anyway
  • Loading branch information
petrochenkov committed Jul 7, 2019
1 parent 1ee0ce8 commit b6d522a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/libsyntax/ext/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ pub fn add_derived_markers<T>(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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl<'a> StringReader<'a> {
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
Expand Down
34 changes: 17 additions & 17 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ impl MultiItemModifier for BuiltinDerive {
}

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,
}
}
Expand All @@ -80,7 +80,7 @@ macro_rules! derive_traits {

$(
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")),
Expand All @@ -100,40 +100,40 @@ macro_rules! derive_traits {

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
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax_ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ impl server::Literal for Rustc<'_> {
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();
Expand Down
20 changes: 19 additions & 1 deletion src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ symbols! {
ArgumentV1,
arm_target_feature,
asm,
assert,
associated_consts,
associated_type_bounds,
associated_type_defaults,
Expand Down Expand Up @@ -184,8 +185,10 @@ symbols! {
cmp,
cmpxchg16b_target_feature,
cold,
column,
compile_error,
compiler_builtins,
concat,
concat_idents,
conservative_impl_trait,
console,
Expand All @@ -203,6 +206,7 @@ symbols! {
contents,
context,
convert,
Copy,
copy_closures,
core,
core_intrinsics,
Expand All @@ -217,8 +221,10 @@ symbols! {
custom_inner_attributes,
custom_test_frameworks,
c_variadic,
Debug,
declare_lint_pass,
decl_macro,
Decodable,
Default,
default_lib_allocator,
default_type_parameter_fallback,
Expand Down Expand Up @@ -253,9 +259,12 @@ symbols! {
eh_personality,
eh_unwind_resume,
enable,
Encodable,
env,
eq,
err,
Err,
Eq,
Equal,
except,
exclusive_range_pattern,
Expand Down Expand Up @@ -284,6 +293,7 @@ symbols! {
fmt_internals,
fn_must_use,
forbid,
format_args,
format_args_nl,
from,
From,
Expand Down Expand Up @@ -335,6 +345,8 @@ symbols! {
index_mut,
in_band_lifetimes,
include,
include_bytes,
include_str,
inclusive_range_syntax,
infer_outlives_requirements,
infer_static_outlives_requirements,
Expand Down Expand Up @@ -363,6 +375,7 @@ symbols! {
lhs,
lib,
lifetime,
line,
link,
linkage,
link_args,
Expand Down Expand Up @@ -402,6 +415,7 @@ symbols! {
mips_target_feature,
mmx_target_feature,
module,
module_path,
more_struct_aliases,
movbe_target_feature,
must_use,
Expand Down Expand Up @@ -447,6 +461,7 @@ symbols! {
optin_builtin_traits,
option,
Option,
option_env,
opt_out_copy,
or,
Ord,
Expand All @@ -462,6 +477,7 @@ symbols! {
parent_trait,
partial_cmp,
param_attrs,
PartialEq,
PartialOrd,
passes,
pat,
Expand Down Expand Up @@ -532,6 +548,8 @@ symbols! {
rust_2018_preview,
rust_begin_unwind,
rustc,
RustcDecodable,
RustcEncodable,
rustc_allocator,
rustc_allocator_nounwind,
rustc_allow_const_fn_ptr,
Expand Down Expand Up @@ -591,7 +609,6 @@ symbols! {
_Self,
self_in_typedefs,
self_struct_ctor,
Send,
should_panic,
simd,
simd_ffi,
Expand All @@ -613,6 +630,7 @@ symbols! {
static_recursion,
std,
str,
stringify,
stmt,
stmt_expr_attributes,
stop_after_dataflow,
Expand Down

0 comments on commit b6d522a

Please sign in to comment.