Skip to content

Commit 57822f9

Browse files
authored
Rollup merge of rust-lang#61813 - matthewjasper:remove-unnecessary-symbol-ops, r=petrochenkov
Remove some unnecessary symbol interner ops * Don't gensym symbols that don't need to worry about colliding with other symbols * Use symbol constants instead of interning string literals in a few places. * Don't generate a module in `__register_diagnostic` r? @petrochenkov
2 parents 2396a15 + 5c84cd3 commit 57822f9

File tree

6 files changed

+40
-53
lines changed

6 files changed

+40
-53
lines changed

src/librustc_resolve/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a> Resolver<'a> {
305305
}
306306

307307
// Empty groups `a::b::{}` are turned into synthetic `self` imports
308-
// `a::b::c::{self as __dummy}`, so that their prefixes are correctly
308+
// `a::b::c::{self as _}`, so that their prefixes are correctly
309309
// resolved and checked for privacy/stability/etc.
310310
if items.is_empty() && !empty_for_self(&prefix) {
311311
let new_span = prefix[prefix.len() - 1].ident.span;
@@ -314,7 +314,7 @@ impl<'a> Resolver<'a> {
314314
Ident::new(kw::SelfLower, new_span)
315315
),
316316
kind: ast::UseTreeKind::Simple(
317-
Some(Ident::from_str_and_span("__dummy", new_span).gensym()),
317+
Some(Ident::new(kw::Underscore, new_span)),
318318
ast::DUMMY_NODE_ID,
319319
ast::DUMMY_NODE_ID,
320320
),

src/librustc_resolve/lib.rs

+20-25
Original file line numberDiff line numberDiff line change
@@ -1519,37 +1519,32 @@ impl<'a> NameBinding<'a> {
15191519
///
15201520
/// All other types are defined somewhere and possibly imported, but the primitive ones need
15211521
/// special handling, since they have no place of origin.
1522-
#[derive(Default)]
15231522
struct PrimitiveTypeTable {
15241523
primitive_types: FxHashMap<Name, PrimTy>,
15251524
}
15261525

15271526
impl PrimitiveTypeTable {
15281527
fn new() -> PrimitiveTypeTable {
1529-
let mut table = PrimitiveTypeTable::default();
1530-
1531-
table.intern("bool", Bool);
1532-
table.intern("char", Char);
1533-
table.intern("f32", Float(FloatTy::F32));
1534-
table.intern("f64", Float(FloatTy::F64));
1535-
table.intern("isize", Int(IntTy::Isize));
1536-
table.intern("i8", Int(IntTy::I8));
1537-
table.intern("i16", Int(IntTy::I16));
1538-
table.intern("i32", Int(IntTy::I32));
1539-
table.intern("i64", Int(IntTy::I64));
1540-
table.intern("i128", Int(IntTy::I128));
1541-
table.intern("str", Str);
1542-
table.intern("usize", Uint(UintTy::Usize));
1543-
table.intern("u8", Uint(UintTy::U8));
1544-
table.intern("u16", Uint(UintTy::U16));
1545-
table.intern("u32", Uint(UintTy::U32));
1546-
table.intern("u64", Uint(UintTy::U64));
1547-
table.intern("u128", Uint(UintTy::U128));
1548-
table
1549-
}
1550-
1551-
fn intern(&mut self, string: &str, primitive_type: PrimTy) {
1552-
self.primitive_types.insert(Symbol::intern(string), primitive_type);
1528+
let mut table = FxHashMap::default();
1529+
1530+
table.insert(sym::bool, Bool);
1531+
table.insert(sym::char, Char);
1532+
table.insert(sym::f32, Float(FloatTy::F32));
1533+
table.insert(sym::f64, Float(FloatTy::F64));
1534+
table.insert(sym::isize, Int(IntTy::Isize));
1535+
table.insert(sym::i8, Int(IntTy::I8));
1536+
table.insert(sym::i16, Int(IntTy::I16));
1537+
table.insert(sym::i32, Int(IntTy::I32));
1538+
table.insert(sym::i64, Int(IntTy::I64));
1539+
table.insert(sym::i128, Int(IntTy::I128));
1540+
table.insert(sym::str, Str);
1541+
table.insert(sym::usize, Uint(UintTy::Usize));
1542+
table.insert(sym::u8, Uint(UintTy::U8));
1543+
table.insert(sym::u16, Uint(UintTy::U16));
1544+
table.insert(sym::u32, Uint(UintTy::U32));
1545+
table.insert(sym::u64, Uint(UintTy::U64));
1546+
table.insert(sym::u128, Uint(UintTy::U128));
1547+
Self { primitive_types: table }
15531548
}
15541549
}
15551550

src/libsyntax/diagnostics/plugin.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>,
120120
}
121121
});
122122

123-
let span = span.apply_mark(ecx.current_expansion.mark);
124-
125-
let name = Ident::from_str_and_span(&format!("__register_diagnostic_{}", code), span).gensym();
126-
127-
MacEager::items(smallvec![
128-
ecx.item_mod(
129-
span,
130-
span,
131-
name,
132-
vec![],
133-
vec![],
134-
)
135-
])
123+
MacEager::items(smallvec![])
136124
}
137125

138126
#[allow(deprecated)]

src/libsyntax/ext/tt/macro_rules.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ pub fn compile(
249249
def: &ast::Item,
250250
edition: Edition
251251
) -> SyntaxExtension {
252-
let lhs_nm = ast::Ident::from_str("lhs").gensym();
253-
let rhs_nm = ast::Ident::from_str("rhs").gensym();
252+
let lhs_nm = ast::Ident::new(sym::lhs, def.span);
253+
let rhs_nm = ast::Ident::new(sym::rhs, def.span);
254+
let tt_spec = ast::Ident::new(sym::tt, def.span);
254255

255256
// Parse the macro_rules! invocation
256257
let body = match def.node {
@@ -266,9 +267,9 @@ pub fn compile(
266267
let argument_gram = vec![
267268
quoted::TokenTree::Sequence(DelimSpan::dummy(), Lrc::new(quoted::SequenceRepetition {
268269
tts: vec![
269-
quoted::TokenTree::MetaVarDecl(def.span, lhs_nm, ast::Ident::from_str("tt")),
270+
quoted::TokenTree::MetaVarDecl(def.span, lhs_nm, tt_spec),
270271
quoted::TokenTree::token(token::FatArrow, def.span),
271-
quoted::TokenTree::MetaVarDecl(def.span, rhs_nm, ast::Ident::from_str("tt")),
272+
quoted::TokenTree::MetaVarDecl(def.span, rhs_nm, tt_spec),
272273
],
273274
separator: Some(Token::new(
274275
if body.legacy { token::Semi } else { token::Comma }, def.span
@@ -1115,10 +1116,9 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
11151116
tok: &quoted::TokenTree) -> Result<(), String> {
11161117
debug!("has_legal_fragment_specifier({:?})", tok);
11171118
if let quoted::TokenTree::MetaVarDecl(_, _, ref frag_spec) = *tok {
1118-
let frag_name = frag_spec.as_str();
11191119
let frag_span = tok.span();
1120-
if !is_legal_fragment_specifier(sess, features, attrs, &frag_name, frag_span) {
1121-
return Err(frag_name.to_string());
1120+
if !is_legal_fragment_specifier(sess, features, attrs, frag_spec.name, frag_span) {
1121+
return Err(frag_spec.to_string());
11221122
}
11231123
}
11241124
Ok(())
@@ -1127,7 +1127,7 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
11271127
fn is_legal_fragment_specifier(_sess: &ParseSess,
11281128
_features: &Features,
11291129
_attrs: &[ast::Attribute],
1130-
frag_name: &str,
1130+
frag_name: Symbol,
11311131
_frag_span: Span) -> bool {
11321132
/*
11331133
* If new fragment specifiers are invented in nightly, `_sess`,
@@ -1136,9 +1136,9 @@ fn is_legal_fragment_specifier(_sess: &ParseSess,
11361136
* this function.
11371137
*/
11381138
match frag_name {
1139-
"item" | "block" | "stmt" | "expr" | "pat" | "lifetime" |
1140-
"path" | "ty" | "ident" | "meta" | "tt" | "vis" | "literal" |
1141-
"" => true,
1139+
sym::item | sym::block | sym::stmt | sym::expr | sym::pat |
1140+
sym::lifetime | sym::path | sym::ty | sym::ident | sym::meta | sym::tt |
1141+
sym::vis | sym::literal | kw::Invalid => true,
11421142
_ => false,
11431143
}
11441144
}

src/libsyntax/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
327327
// }
328328
let sp = ignored_span(cx, DUMMY_SP);
329329
let ecx = &cx.ext_cx;
330-
let test_id = ecx.ident_of("test").gensym();
330+
let test_id = Ident::with_empty_ctxt(sym::test);
331331

332332
// test::test_main_static(...)
333333
let mut test_runner = cx.test_runner.clone().unwrap_or(
@@ -350,7 +350,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
350350
let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp,
351351
test_id,
352352
vec![],
353-
ast::ItemKind::ExternCrate(Some(sym::test))
353+
ast::ItemKind::ExternCrate(None)
354354
));
355355

356356
// pub fn main() { ... }

src/libsyntax_pos/symbol.rs

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ symbols! {
157157
bin,
158158
bind_by_move_pattern_guards,
159159
block,
160+
bool,
160161
borrowck_graphviz_postflow,
161162
borrowck_graphviz_preflow,
162163
box_patterns,
@@ -171,6 +172,7 @@ symbols! {
171172
cfg_target_has_atomic,
172173
cfg_target_thread_local,
173174
cfg_target_vendor,
175+
char,
174176
clone,
175177
Clone,
176178
clone_closures,
@@ -351,6 +353,7 @@ symbols! {
351353
label_break_value,
352354
lang,
353355
lang_items,
356+
lhs,
354357
lib,
355358
lifetime,
356359
link,
@@ -511,6 +514,7 @@ symbols! {
511514
result,
512515
Result,
513516
Return,
517+
rhs,
514518
rlib,
515519
rt,
516520
rtm_target_feature,

0 commit comments

Comments
 (0)