Skip to content

Remove some unnecessary symbol interner ops #61813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'a> Resolver<'a> {
}

// 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;
Expand All @@ -314,7 +314,7 @@ impl<'a> Resolver<'a> {
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)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this code is buggy (#61826), but this change shouldn't make it more buggy since the import is ty::Visibility::Invisible.

ast::DUMMY_NODE_ID,
ast::DUMMY_NODE_ID,
),
Expand Down
45 changes: 20 additions & 25 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,37 +1518,32 @@ impl<'a> NameBinding<'a> {
///
/// 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();

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);
let mut table = FxHashMap::default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a neat hashmap! { ... } macro in maplit that we could perhaps use to make this less boiler-platey?


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 }
}
}

Expand Down
14 changes: 1 addition & 13 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,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)]
Expand Down
22 changes: 11 additions & 11 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -1115,10 +1116,9 @@ fn has_legal_fragment_specifier(sess: &ParseSess,
tok: &quoted::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(())
Expand All @@ -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`,
Expand All @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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() { ... }
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ symbols! {
bin,
bind_by_move_pattern_guards,
block,
bool,
borrowck_graphviz_postflow,
borrowck_graphviz_preflow,
box_patterns,
Expand All @@ -171,6 +172,7 @@ symbols! {
cfg_target_has_atomic,
cfg_target_thread_local,
cfg_target_vendor,
char,
clone,
Clone,
clone_closures,
Expand Down Expand Up @@ -347,6 +349,7 @@ symbols! {
label_break_value,
lang,
lang_items,
lhs,
lib,
lifetime,
link,
Expand Down Expand Up @@ -505,6 +508,7 @@ symbols! {
result,
Result,
Return,
rhs,
rlib,
rt,
rtm_target_feature,
Expand Down