Rollup merge of #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
This commit is contained in:
commit
be09427b11
@ -305,7 +305,7 @@ fn build_reduced_graph_for_use_tree(
|
||||
}
|
||||
|
||||
// Empty groups `a::b::{}` are turned into synthetic `self` imports
|
||||
// `a::b::c::{self as __dummy}`, so that their prefixes are correctly
|
||||
// `a::b::c::{self as _}`, so that their prefixes are correctly
|
||||
// resolved and checked for privacy/stability/etc.
|
||||
if items.is_empty() && !empty_for_self(&prefix) {
|
||||
let new_span = prefix[prefix.len() - 1].ident.span;
|
||||
@ -314,7 +314,7 @@ fn build_reduced_graph_for_use_tree(
|
||||
Ident::new(kw::SelfLower, new_span)
|
||||
),
|
||||
kind: ast::UseTreeKind::Simple(
|
||||
Some(Ident::from_str_and_span("__dummy", new_span).gensym()),
|
||||
Some(Ident::new(kw::Underscore, new_span)),
|
||||
ast::DUMMY_NODE_ID,
|
||||
ast::DUMMY_NODE_ID,
|
||||
),
|
||||
|
@ -1519,37 +1519,32 @@ fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding<'
|
||||
///
|
||||
/// All other types are defined somewhere and possibly imported, but the primitive ones need
|
||||
/// special handling, since they have no place of origin.
|
||||
#[derive(Default)]
|
||||
struct PrimitiveTypeTable {
|
||||
primitive_types: FxHashMap<Name, PrimTy>,
|
||||
}
|
||||
|
||||
impl PrimitiveTypeTable {
|
||||
fn new() -> PrimitiveTypeTable {
|
||||
let mut table = PrimitiveTypeTable::default();
|
||||
let mut table = FxHashMap::default();
|
||||
|
||||
table.intern("bool", Bool);
|
||||
table.intern("char", Char);
|
||||
table.intern("f32", Float(FloatTy::F32));
|
||||
table.intern("f64", Float(FloatTy::F64));
|
||||
table.intern("isize", Int(IntTy::Isize));
|
||||
table.intern("i8", Int(IntTy::I8));
|
||||
table.intern("i16", Int(IntTy::I16));
|
||||
table.intern("i32", Int(IntTy::I32));
|
||||
table.intern("i64", Int(IntTy::I64));
|
||||
table.intern("i128", Int(IntTy::I128));
|
||||
table.intern("str", Str);
|
||||
table.intern("usize", Uint(UintTy::Usize));
|
||||
table.intern("u8", Uint(UintTy::U8));
|
||||
table.intern("u16", Uint(UintTy::U16));
|
||||
table.intern("u32", Uint(UintTy::U32));
|
||||
table.intern("u64", Uint(UintTy::U64));
|
||||
table.intern("u128", Uint(UintTy::U128));
|
||||
table
|
||||
}
|
||||
|
||||
fn intern(&mut self, string: &str, primitive_type: PrimTy) {
|
||||
self.primitive_types.insert(Symbol::intern(string), primitive_type);
|
||||
table.insert(sym::bool, Bool);
|
||||
table.insert(sym::char, Char);
|
||||
table.insert(sym::f32, Float(FloatTy::F32));
|
||||
table.insert(sym::f64, Float(FloatTy::F64));
|
||||
table.insert(sym::isize, Int(IntTy::Isize));
|
||||
table.insert(sym::i8, Int(IntTy::I8));
|
||||
table.insert(sym::i16, Int(IntTy::I16));
|
||||
table.insert(sym::i32, Int(IntTy::I32));
|
||||
table.insert(sym::i64, Int(IntTy::I64));
|
||||
table.insert(sym::i128, Int(IntTy::I128));
|
||||
table.insert(sym::str, Str);
|
||||
table.insert(sym::usize, Uint(UintTy::Usize));
|
||||
table.insert(sym::u8, Uint(UintTy::U8));
|
||||
table.insert(sym::u16, Uint(UintTy::U16));
|
||||
table.insert(sym::u32, Uint(UintTy::U32));
|
||||
table.insert(sym::u64, Uint(UintTy::U64));
|
||||
table.insert(sym::u128, Uint(UintTy::U128));
|
||||
Self { primitive_types: table }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,19 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>,
|
||||
}
|
||||
});
|
||||
|
||||
let span = span.apply_mark(ecx.current_expansion.mark);
|
||||
|
||||
let name = Ident::from_str_and_span(&format!("__register_diagnostic_{}", code), span).gensym();
|
||||
|
||||
MacEager::items(smallvec![
|
||||
ecx.item_mod(
|
||||
span,
|
||||
span,
|
||||
name,
|
||||
vec![],
|
||||
vec![],
|
||||
)
|
||||
])
|
||||
MacEager::items(smallvec![])
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
|
@ -249,8 +249,9 @@ pub fn compile(
|
||||
def: &ast::Item,
|
||||
edition: Edition
|
||||
) -> SyntaxExtension {
|
||||
let lhs_nm = ast::Ident::from_str("lhs").gensym();
|
||||
let rhs_nm = ast::Ident::from_str("rhs").gensym();
|
||||
let lhs_nm = ast::Ident::new(sym::lhs, def.span);
|
||||
let rhs_nm = ast::Ident::new(sym::rhs, def.span);
|
||||
let tt_spec = ast::Ident::new(sym::tt, def.span);
|
||||
|
||||
// Parse the macro_rules! invocation
|
||||
let body = match def.node {
|
||||
@ -266,9 +267,9 @@ pub fn compile(
|
||||
let argument_gram = vec![
|
||||
quoted::TokenTree::Sequence(DelimSpan::dummy(), Lrc::new(quoted::SequenceRepetition {
|
||||
tts: vec![
|
||||
quoted::TokenTree::MetaVarDecl(def.span, lhs_nm, ast::Ident::from_str("tt")),
|
||||
quoted::TokenTree::MetaVarDecl(def.span, lhs_nm, tt_spec),
|
||||
quoted::TokenTree::token(token::FatArrow, def.span),
|
||||
quoted::TokenTree::MetaVarDecl(def.span, rhs_nm, ast::Ident::from_str("tt")),
|
||||
quoted::TokenTree::MetaVarDecl(def.span, rhs_nm, tt_spec),
|
||||
],
|
||||
separator: Some(Token::new(
|
||||
if body.legacy { token::Semi } else { token::Comma }, def.span
|
||||
@ -1115,10 +1116,9 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
|
||||
tok: "ed::TokenTree) -> Result<(), String> {
|
||||
debug!("has_legal_fragment_specifier({:?})", tok);
|
||||
if let quoted::TokenTree::MetaVarDecl(_, _, ref frag_spec) = *tok {
|
||||
let frag_name = frag_spec.as_str();
|
||||
let frag_span = tok.span();
|
||||
if !is_legal_fragment_specifier(sess, features, attrs, &frag_name, frag_span) {
|
||||
return Err(frag_name.to_string());
|
||||
if !is_legal_fragment_specifier(sess, features, attrs, frag_spec.name, frag_span) {
|
||||
return Err(frag_spec.to_string());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@ -1127,7 +1127,7 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
|
||||
fn is_legal_fragment_specifier(_sess: &ParseSess,
|
||||
_features: &Features,
|
||||
_attrs: &[ast::Attribute],
|
||||
frag_name: &str,
|
||||
frag_name: Symbol,
|
||||
_frag_span: Span) -> bool {
|
||||
/*
|
||||
* If new fragment specifiers are invented in nightly, `_sess`,
|
||||
@ -1136,9 +1136,9 @@ fn is_legal_fragment_specifier(_sess: &ParseSess,
|
||||
* this function.
|
||||
*/
|
||||
match frag_name {
|
||||
"item" | "block" | "stmt" | "expr" | "pat" | "lifetime" |
|
||||
"path" | "ty" | "ident" | "meta" | "tt" | "vis" | "literal" |
|
||||
"" => true,
|
||||
sym::item | sym::block | sym::stmt | sym::expr | sym::pat |
|
||||
sym::lifetime | sym::path | sym::ty | sym::ident | sym::meta | sym::tt |
|
||||
sym::vis | sym::literal | kw::Invalid => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||
// }
|
||||
let sp = ignored_span(cx, DUMMY_SP);
|
||||
let ecx = &cx.ext_cx;
|
||||
let test_id = ecx.ident_of("test").gensym();
|
||||
let test_id = Ident::with_empty_ctxt(sym::test);
|
||||
|
||||
// test::test_main_static(...)
|
||||
let mut test_runner = cx.test_runner.clone().unwrap_or(
|
||||
@ -350,7 +350,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||
let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp,
|
||||
test_id,
|
||||
vec![],
|
||||
ast::ItemKind::ExternCrate(Some(sym::test))
|
||||
ast::ItemKind::ExternCrate(None)
|
||||
));
|
||||
|
||||
// pub fn main() { ... }
|
||||
|
@ -157,6 +157,7 @@
|
||||
bin,
|
||||
bind_by_move_pattern_guards,
|
||||
block,
|
||||
bool,
|
||||
borrowck_graphviz_postflow,
|
||||
borrowck_graphviz_preflow,
|
||||
box_patterns,
|
||||
@ -171,6 +172,7 @@
|
||||
cfg_target_has_atomic,
|
||||
cfg_target_thread_local,
|
||||
cfg_target_vendor,
|
||||
char,
|
||||
clone,
|
||||
Clone,
|
||||
clone_closures,
|
||||
@ -351,6 +353,7 @@
|
||||
label_break_value,
|
||||
lang,
|
||||
lang_items,
|
||||
lhs,
|
||||
lib,
|
||||
lifetime,
|
||||
link,
|
||||
@ -511,6 +514,7 @@
|
||||
result,
|
||||
Result,
|
||||
Return,
|
||||
rhs,
|
||||
rlib,
|
||||
rt,
|
||||
rtm_target_feature,
|
||||
|
Loading…
Reference in New Issue
Block a user