Skip to content

Commit 548add7

Browse files
committed
Auto merge of #60910 - nnethercote:avoid-some-unnecessary-interning, r=petrochenkov
Avoid some unnecessary interning r? @petrochenkov
2 parents a614cee + 4ab5fe3 commit 548add7

File tree

16 files changed

+67
-49
lines changed

16 files changed

+67
-49
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ impl<'a> LoweringContext<'a> {
22182218
bindings: hir_vec![
22192219
hir::TypeBinding {
22202220
hir_id: this.next_id(),
2221-
ident: Ident::from_str(FN_OUTPUT_NAME),
2221+
ident: Ident::with_empty_ctxt(FN_OUTPUT_NAME),
22222222
ty: output
22232223
.as_ref()
22242224
.map(|ty| this.lower_ty(&ty, ImplTraitContext::disallowed()))
@@ -2543,7 +2543,7 @@ impl<'a> LoweringContext<'a> {
25432543
let future_params = P(hir::GenericArgs {
25442544
args: hir_vec![],
25452545
bindings: hir_vec![hir::TypeBinding {
2546-
ident: Ident::from_str(FN_OUTPUT_NAME),
2546+
ident: Ident::with_empty_ctxt(FN_OUTPUT_NAME),
25472547
ty: output_ty,
25482548
hir_id: self.next_id(),
25492549
span,
@@ -4801,7 +4801,7 @@ impl<'a> LoweringContext<'a> {
48014801
let attr = {
48024802
// `allow(unreachable_code)`
48034803
let allow = {
4804-
let allow_ident = Ident::from_str("allow").with_span_pos(e.span);
4804+
let allow_ident = Ident::with_empty_ctxt(sym::allow).with_span_pos(e.span);
48054805
let uc_ident = Ident::from_str("unreachable_code").with_span_pos(e.span);
48064806
let uc_nested = attr::mk_nested_word_item(uc_ident);
48074807
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])

src/librustc/hir/map/definitions.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::fmt::Write;
1717
use std::hash::Hash;
1818
use syntax::ast;
1919
use syntax::ext::hygiene::Mark;
20-
use syntax::symbol::{Symbol, InternedString};
20+
use syntax::symbol::{Symbol, sym, InternedString};
2121
use syntax_pos::{Span, DUMMY_SP};
2222
use crate::util::nodemap::NodeMap;
2323

@@ -584,16 +584,16 @@ impl DefPathData {
584584
return name
585585
}
586586
// note that this does not show up in user printouts
587-
CrateRoot => "{{crate}}",
588-
Impl => "{{impl}}",
589-
Misc => "{{misc}}",
590-
ClosureExpr => "{{closure}}",
591-
Ctor => "{{constructor}}",
592-
AnonConst => "{{constant}}",
593-
ImplTrait => "{{opaque}}",
587+
CrateRoot => sym::double_braced_crate,
588+
Impl => sym::double_braced_impl,
589+
Misc => sym::double_braced_misc,
590+
ClosureExpr => sym::double_braced_closure,
591+
Ctor => sym::double_braced_constructor,
592+
AnonConst => sym::double_braced_constant,
593+
ImplTrait => sym::double_braced_opaque,
594594
};
595595

596-
Symbol::intern(s).as_interned_str()
596+
s.as_interned_str()
597597
}
598598

599599
pub fn to_string(&self) -> String {

src/librustc/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
14211421
projection_ty: ty::ProjectionTy::from_ref_and_name(
14221422
tcx,
14231423
trait_ref,
1424-
Ident::from_str(FN_OUTPUT_NAME),
1424+
Ident::with_empty_ctxt(FN_OUTPUT_NAME),
14251425
),
14261426
ty: ret_type
14271427
}

src/librustc/util/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ use std::time::{Duration, Instant};
1111

1212
use std::sync::mpsc::{Sender};
1313
use syntax_pos::{SpanData};
14+
use syntax::symbol::{Symbol, sym};
1415
use rustc_macros::HashStable;
1516
use crate::ty::TyCtxt;
1617
use crate::dep_graph::{DepNode};
1718
use lazy_static;
1819
use crate::session::Session;
1920

2021
// The name of the associated type for `Fn` return types
21-
pub const FN_OUTPUT_NAME: &str = "Output";
22+
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
2223

2324
// Useful type to use with `Result<>` indicate that an error has already
2425
// been reported to the user, so no need to continue checking.

src/librustc_allocator/expand.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::{
1919
mut_visit::{self, MutVisitor},
2020
parse::ParseSess,
2121
ptr::P,
22-
symbol::{Symbol, sym}
22+
symbol::{keywords, Symbol, sym}
2323
};
2424
use syntax_pos::Span;
2525

@@ -110,13 +110,14 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
110110
span,
111111
kind: AllocatorKind::Global,
112112
global: item.ident,
113-
core: Ident::from_str("core"),
113+
core: Ident::with_empty_ctxt(sym::core),
114114
cx: ExtCtxt::new(self.sess, ecfg, self.resolver),
115115
};
116116

117117
// We will generate a new submodule. To `use` the static from that module, we need to get
118118
// the `super::...` path.
119-
let super_path = f.cx.path(f.span, vec![Ident::from_str("super"), f.global]);
119+
let super_path =
120+
f.cx.path(f.span, vec![Ident::with_empty_ctxt(keywords::Super.name()), f.global]);
120121

121122
// Generate the items in the submodule
122123
let mut items = vec![
@@ -236,7 +237,7 @@ impl AllocFnFactory<'_> {
236237
) -> P<Expr> {
237238
match *ty {
238239
AllocatorTy::Layout => {
239-
let usize = self.cx.path_ident(self.span, Ident::from_str("usize"));
240+
let usize = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::usize));
240241
let ty_usize = self.cx.ty_path(usize);
241242
let size = ident();
242243
let align = ident();
@@ -298,12 +299,12 @@ impl AllocFnFactory<'_> {
298299
}
299300

300301
fn usize(&self) -> P<Ty> {
301-
let usize = self.cx.path_ident(self.span, Ident::from_str("usize"));
302+
let usize = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::usize));
302303
self.cx.ty_path(usize)
303304
}
304305

305306
fn ptr_u8(&self) -> P<Ty> {
306-
let u8 = self.cx.path_ident(self.span, Ident::from_str("u8"));
307+
let u8 = self.cx.path_ident(self.span, Ident::with_empty_ctxt(sym::u8));
307308
let ty_u8 = self.cx.ty_path(u8);
308309
self.cx.ty_ptr(self.span, ty_u8, Mutability::Mutable)
309310
}

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,11 +1979,11 @@ impl<'a> Resolver<'a> {
19791979
.collect();
19801980

19811981
if !attr::contains_name(&krate.attrs, sym::no_core) {
1982-
extern_prelude.insert(Ident::from_str("core"), Default::default());
1982+
extern_prelude.insert(Ident::with_empty_ctxt(sym::core), Default::default());
19831983
if !attr::contains_name(&krate.attrs, sym::no_std) {
1984-
extern_prelude.insert(Ident::from_str("std"), Default::default());
1984+
extern_prelude.insert(Ident::with_empty_ctxt(sym::std), Default::default());
19851985
if session.rust_2018() {
1986-
extern_prelude.insert(Ident::from_str("meta"), Default::default());
1986+
extern_prelude.insert(Ident::with_empty_ctxt(sym::meta), Default::default());
19871987
}
19881988
}
19891989
}
@@ -3374,7 +3374,7 @@ impl<'a> Resolver<'a> {
33743374
self.trait_map.insert(id, traits);
33753375
}
33763376

3377-
let mut std_path = vec![Segment::from_ident(Ident::from_str("std"))];
3377+
let mut std_path = vec![Segment::from_ident(Ident::with_empty_ctxt(sym::std))];
33783378
std_path.extend(path);
33793379
if self.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
33803380
let cl = CrateLint::No;

src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,9 @@ impl Attributes {
929929
for attr in attrs.lists(sym::target_feature) {
930930
if attr.check_name(sym::enable) {
931931
if let Some(feat) = attr.value_str() {
932-
let meta = attr::mk_name_value_item_str(Ident::from_str("target_feature"),
933-
dummy_spanned(feat));
932+
let meta = attr::mk_name_value_item_str(
933+
Ident::with_empty_ctxt(sym::target_feature),
934+
dummy_spanned(feat));
934935
if let Ok(feat_cfg) = Cfg::parse(&meta) {
935936
cfg &= feat_cfg;
936937
}

src/libsyntax/attr/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
2222
use crate::parse::{self, ParseSess, PResult};
2323
use crate::parse::token::{self, Token};
2424
use crate::ptr::P;
25-
use crate::symbol::{keywords, Symbol};
25+
use crate::symbol::{keywords, Symbol, sym};
2626
use crate::ThinVec;
2727
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
2828
use crate::GLOBALS;
@@ -323,7 +323,7 @@ impl Attribute {
323323
if self.is_sugared_doc {
324324
let comment = self.value_str().unwrap();
325325
let meta = mk_name_value_item_str(
326-
Ident::from_str("doc"),
326+
Ident::with_empty_ctxt(sym::doc),
327327
dummy_spanned(Symbol::intern(&strip_doc_comment_decoration(&comment.as_str()))));
328328
let mut attr = if self.style == ast::AttrStyle::Outer {
329329
mk_attr_outer(self.span, self.id, meta)
@@ -414,7 +414,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
414414
Attribute {
415415
id,
416416
style,
417-
path: Path::from_ident(Ident::from_str("doc").with_span_pos(span)),
417+
path: Path::from_ident(Ident::with_empty_ctxt(sym::doc).with_span_pos(span)),
418418
tokens: MetaItemKind::NameValue(lit).tokens(span),
419419
is_sugared_doc: true,
420420
span,

src/libsyntax/ext/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,19 +1522,19 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
15221522
let include_info = vec![
15231523
ast::NestedMetaItem::MetaItem(
15241524
attr::mk_name_value_item_str(
1525-
Ident::from_str("file"),
1525+
Ident::with_empty_ctxt(sym::file),
15261526
dummy_spanned(file),
15271527
),
15281528
),
15291529
ast::NestedMetaItem::MetaItem(
15301530
attr::mk_name_value_item_str(
1531-
Ident::from_str("contents"),
1531+
Ident::with_empty_ctxt(sym::contents),
15321532
dummy_spanned(src_interned),
15331533
),
15341534
),
15351535
];
15361536

1537-
let include_ident = Ident::from_str("include");
1537+
let include_ident = Ident::with_empty_ctxt(sym::include);
15381538
let item = attr::mk_list_item(DUMMY_SP, include_ident, include_info);
15391539
items.push(ast::NestedMetaItem::MetaItem(item));
15401540
}
@@ -1600,7 +1600,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16001600
}
16011601
}
16021602

1603-
let meta = attr::mk_list_item(DUMMY_SP, Ident::from_str("doc"), items);
1603+
let meta = attr::mk_list_item(DUMMY_SP, Ident::with_empty_ctxt(sym::doc), items);
16041604
match at.style {
16051605
ast::AttrStyle::Inner => *at = attr::mk_spanned_attr_inner(at.span, at.id, meta),
16061606
ast::AttrStyle::Outer => *at = attr::mk_spanned_attr_outer(at.span, at.id, meta),

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl TokenCursor {
352352
let body = TokenTree::Delimited(
353353
delim_span,
354354
token::Bracket,
355-
[TokenTree::Token(sp, token::Ident(ast::Ident::from_str("doc"), false)),
355+
[TokenTree::Token(sp, token::Ident(ast::Ident::with_empty_ctxt(sym::doc), false)),
356356
TokenTree::Token(sp, token::Eq),
357357
TokenTree::Token(sp, token::Literal(
358358
token::StrRaw(Symbol::intern(&stripped), num_of_hashes), None))
@@ -7011,7 +7011,8 @@ impl<'a> Parser<'a> {
70117011
let attr = Attribute {
70127012
id: attr::mk_attr_id(),
70137013
style: ast::AttrStyle::Outer,
7014-
path: ast::Path::from_ident(Ident::from_str("warn_directory_ownership")),
7014+
path: ast::Path::from_ident(
7015+
Ident::with_empty_ctxt(sym::warn_directory_ownership)),
70157016
tokens: TokenStream::empty(),
70167017
is_sugared_doc: false,
70177018
span: syntax_pos::DUMMY_SP,

0 commit comments

Comments
 (0)