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

+3-3
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

+9-9
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

+1-1
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

+2-1
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

+7-6
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

+4-4
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

+3-2
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

+3-3
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

+4-4
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

+3-2
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,

src/libsyntax/print/pprust.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::print::pp::{self, Breaks};
1313
use crate::print::pp::Breaks::{Consistent, Inconsistent};
1414
use crate::ptr::P;
1515
use crate::std_inject;
16-
use crate::symbol::keywords;
16+
use crate::symbol::{keywords, sym};
1717
use crate::tokenstream::{self, TokenStream, TokenTree};
1818

1919
use rustc_target::spec::abi::{self, Abi};
@@ -89,13 +89,14 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
8989
// of the feature gate, so we fake them up here.
9090

9191
// #![feature(prelude_import)]
92-
let pi_nested = attr::mk_nested_word_item(ast::Ident::from_str("prelude_import"));
93-
let list = attr::mk_list_item(DUMMY_SP, ast::Ident::from_str("feature"), vec![pi_nested]);
92+
let pi_nested = attr::mk_nested_word_item(ast::Ident::with_empty_ctxt(sym::prelude_import));
93+
let list = attr::mk_list_item(
94+
DUMMY_SP, ast::Ident::with_empty_ctxt(sym::feature), vec![pi_nested]);
9495
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), list);
9596
s.print_attribute(&fake_attr)?;
9697

9798
// #![no_std]
98-
let no_std_meta = attr::mk_word_item(ast::Ident::from_str("no_std"));
99+
let no_std_meta = attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::no_std));
99100
let fake_attr = attr::mk_attr_inner(DUMMY_SP, attr::mk_attr_id(), no_std_meta);
100101
s.print_attribute(&fake_attr)?;
101102
}

src/libsyntax/std_inject.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ pub fn maybe_inject_crates_ref(
7777
None
7878
};
7979
krate.module.items.insert(0, P(ast::Item {
80-
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
81-
attr::mk_attr_id(),
82-
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
80+
attrs: vec![attr::mk_attr_outer(
81+
DUMMY_SP,
82+
attr::mk_attr_id(),
83+
attr::mk_word_item(ast::Ident::with_empty_ctxt(sym::macro_use))
84+
)],
8385
vis: dummy_spanned(ast::VisibilityKind::Inherited),
8486
node: ast::ItemKind::ExternCrate(alt_std_name.or(orig_name)),
8587
ident: ast::Ident::with_empty_ctxt(rename),

src/libsyntax/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl MutVisitor for EntryPointCleaner {
171171
EntryPointType::MainAttr |
172172
EntryPointType::Start =>
173173
item.map(|ast::Item {id, ident, attrs, node, vis, span, tokens}| {
174-
let allow_ident = Ident::from_str("allow");
174+
let allow_ident = Ident::with_empty_ctxt(sym::allow);
175175
let dc_nested = attr::mk_nested_word_item(Ident::from_str("dead_code"));
176176
let allow_dead_code_item = attr::mk_list_item(DUMMY_SP, allow_ident,
177177
vec![dc_nested]);
@@ -215,7 +215,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt<'_>,
215215
tests: Vec<Ident>,
216216
tested_submods: Vec<(Ident, Ident)>)
217217
-> (P<ast::Item>, Ident) {
218-
let super_ = Ident::from_str("super");
218+
let super_ = Ident::with_empty_ctxt(keywords::Super.name());
219219

220220
let items = tests.into_iter().map(|r| {
221221
cx.ext_cx.item_use_simple(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),

src/libsyntax_ext/env.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use syntax::ast::{self, Ident, GenericArg};
77
use syntax::ext::base::{self, *};
88
use syntax::ext::build::AstBuilder;
9-
use syntax::symbol::{keywords, Symbol};
9+
use syntax::symbol::{keywords, Symbol, sym};
1010
use syntax_pos::Span;
1111
use syntax::tokenstream;
1212

@@ -29,7 +29,8 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
2929
true,
3030
cx.std_path(&["option", "Option", "None"]),
3131
vec![GenericArg::Type(cx.ty_rptr(sp,
32-
cx.ty_ident(sp, Ident::from_str("str")),
32+
cx.ty_ident(sp,
33+
Ident::with_empty_ctxt(sym::str)),
3334
Some(lt),
3435
ast::Mutability::Immutable))],
3536
vec![]))

src/libsyntax_ext/proc_macro_decls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ fn mk_decls(
362362
});
363363
let span = DUMMY_SP.apply_mark(mark);
364364

365-
let hidden = cx.meta_list_item_word(span, Symbol::intern("hidden"));
366-
let doc = cx.meta_list(span, Symbol::intern("doc"), vec![hidden]);
365+
let hidden = cx.meta_list_item_word(span, sym::hidden);
366+
let doc = cx.meta_list(span, sym::doc, vec![hidden]);
367367
let doc_hidden = cx.attribute(span, doc);
368368

369-
let proc_macro = Ident::from_str("proc_macro");
369+
let proc_macro = Ident::with_empty_ctxt(sym::proc_macro);
370370
let krate = cx.item(span,
371371
proc_macro,
372372
Vec::new(),

src/libsyntax_pos/symbol.rs

+10
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ symbols! {
214214
document_private_items,
215215
dotdoteq_in_patterns,
216216
dotdot_in_tuple_patterns,
217+
double_braced_crate: "{{crate}}",
218+
double_braced_impl: "{{impl}}",
219+
double_braced_misc: "{{misc}}",
220+
double_braced_closure: "{{closure}}",
221+
double_braced_constructor: "{{constructor}}",
222+
double_braced_constant: "{{constant}}",
223+
double_braced_opaque: "{{opaque}}",
217224
dropck_eyepatch,
218225
dropck_parametricity,
219226
drop_types_in_const,
@@ -336,6 +343,7 @@ symbols! {
336343
match_default_bindings,
337344
may_dangle,
338345
message,
346+
meta,
339347
min_const_fn,
340348
min_const_unsafe_fn,
341349
mips_target_feature,
@@ -385,6 +393,7 @@ symbols! {
385393
option,
386394
Option,
387395
opt_out_copy,
396+
Output,
388397
overlapping_marker_traits,
389398
packed,
390399
panic_handler,
@@ -530,6 +539,7 @@ symbols! {
530539
static_nobundle,
531540
static_recursion,
532541
std,
542+
str,
533543
stmt_expr_attributes,
534544
stop_after_dataflow,
535545
struct_field_attributes,

0 commit comments

Comments
 (0)