Skip to content

Commit 87c7099

Browse files
committed
Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=<try>
Avoid more symbol interning r? @ghost
2 parents 1cc822c + 899720f commit 87c7099

38 files changed

+165
-162
lines changed

src/librustc/hir/lowering.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,7 @@ impl<'a> LoweringContext<'a> {
11451145
let unstable_span = self.sess.source_map().mark_span_with_reason(
11461146
CompilerDesugaringKind::Async,
11471147
span,
1148-
Some(vec![
1149-
Symbol::intern("gen_future"),
1150-
].into()),
1148+
Some(vec![sym::gen_future].into()),
11511149
);
11521150
let gen_future = self.expr_std_path(
11531151
unstable_span, &[sym::future, sym::from_generator], None, ThinVec::new());
@@ -4179,9 +4177,7 @@ impl<'a> LoweringContext<'a> {
41794177
let unstable_span = this.sess.source_map().mark_span_with_reason(
41804178
CompilerDesugaringKind::TryBlock,
41814179
body.span,
4182-
Some(vec![
4183-
Symbol::intern("try_trait"),
4184-
].into()),
4180+
Some(vec![sym::try_trait].into()),
41854181
);
41864182
let mut block = this.lower_block(body, true).into_inner();
41874183
let tail = block.expr.take().map_or_else(

src/librustc/middle/lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
210210
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
211211
attrs.iter().find_map(|attr| Some(match attr {
212212
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
213-
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span),
214-
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span),
213+
_ if attr.check_name(sym::panic_handler) => (sym::panic_impl, attr.span),
214+
_ if attr.check_name(sym::alloc_error_handler) => (sym::oom, attr.span),
215215
_ => return None,
216216
}))
217217
}

src/librustc/middle/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a, 'tcx> Index<'tcx> {
437437
reason: Some(Symbol::intern(reason)),
438438
issue: 27812,
439439
},
440-
feature: Symbol::intern("rustc_private"),
440+
feature: sym::rustc_private,
441441
rustc_depr: None,
442442
const_stability: None,
443443
promotable: false,
@@ -880,7 +880,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
880880
// FIXME: only remove `libc` when `stdbuild` is active.
881881
// FIXME: remove special casing for `test`.
882882
remaining_lib_features.remove(&Symbol::intern("libc"));
883-
remaining_lib_features.remove(&Symbol::intern("test"));
883+
remaining_lib_features.remove(&sym::test);
884884

885885
let check_features =
886886
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {

src/librustc/session/config.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::source_map::{FileName, FilePathMapping};
1919
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
2020
use syntax::parse::token;
2121
use syntax::parse;
22-
use syntax::symbol::Symbol;
22+
use syntax::symbol::{Symbol, sym};
2323
use syntax::feature_gate::UnstableFeatures;
2424
use errors::emitter::HumanReadableErrorType;
2525

@@ -1503,31 +1503,31 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
15031503
Some(Symbol::intern(vendor)),
15041504
));
15051505
if sess.target.target.options.has_elf_tls {
1506-
ret.insert((Symbol::intern("target_thread_local"), None));
1506+
ret.insert((sym::target_thread_local, None));
15071507
}
15081508
for &i in &[8, 16, 32, 64, 128] {
15091509
if i >= min_atomic_width && i <= max_atomic_width {
15101510
let s = i.to_string();
15111511
ret.insert((
1512-
Symbol::intern("target_has_atomic"),
1512+
sym::target_has_atomic,
15131513
Some(Symbol::intern(&s)),
15141514
));
15151515
if &s == wordsz {
15161516
ret.insert((
1517-
Symbol::intern("target_has_atomic"),
1517+
sym::target_has_atomic,
15181518
Some(Symbol::intern("ptr")),
15191519
));
15201520
}
15211521
}
15221522
}
15231523
if atomic_cas {
1524-
ret.insert((Symbol::intern("target_has_atomic"), Some(Symbol::intern("cas"))));
1524+
ret.insert((sym::target_has_atomic, Some(Symbol::intern("cas"))));
15251525
}
15261526
if sess.opts.debug_assertions {
15271527
ret.insert((Symbol::intern("debug_assertions"), None));
15281528
}
15291529
if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
1530-
ret.insert((Symbol::intern("proc_macro"), None));
1530+
ret.insert((sym::proc_macro, None));
15311531
}
15321532
ret
15331533
}
@@ -1547,7 +1547,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
15471547
let default_cfg = default_configuration(sess);
15481548
// If the user wants a test runner, then add the test cfg
15491549
if sess.opts.test {
1550-
user_cfg.insert((Symbol::intern("test"), None));
1550+
user_cfg.insert((sym::test, None));
15511551
}
15521552
user_cfg.extend(default_cfg.iter().cloned());
15531553
user_cfg
@@ -2702,7 +2702,7 @@ mod tests {
27022702
use std::path::PathBuf;
27032703
use super::{Externs, OutputType, OutputTypes};
27042704
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel};
2705-
use syntax::symbol::Symbol;
2705+
use syntax::symbol::sym;
27062706
use syntax::edition::{Edition, DEFAULT_EDITION};
27072707
use syntax;
27082708
use super::Options;
@@ -2744,15 +2744,14 @@ mod tests {
27442744
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
27452745
let sess = build_session(sessopts, None, registry);
27462746
let cfg = build_configuration(&sess, to_crate_config(cfg));
2747-
assert!(cfg.contains(&(Symbol::intern("test"), None)));
2747+
assert!(cfg.contains(&(sym::test, None)));
27482748
});
27492749
}
27502750

27512751
// When the user supplies --test and --cfg test, don't implicitly add
27522752
// another --cfg test
27532753
#[test]
27542754
fn test_switch_implies_cfg_test_unless_cfg_test() {
2755-
use syntax::symbol::sym;
27562755
syntax::with_default_globals(|| {
27572756
let matches = &match optgroups().parse(&["--test".to_string(),
27582757
"--cfg=test".to_string()]) {

src/librustc_allocator/expand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
9191
call_site: item.span, // use the call site of the static
9292
def_site: None,
9393
format: MacroAttribute(Symbol::intern(name)),
94-
allow_internal_unstable: Some(vec![
95-
Symbol::intern("rustc_attrs"),
96-
].into()),
94+
allow_internal_unstable: Some(vec![sym::rustc_attrs].into()),
9795
allow_internal_unsafe: false,
9896
local_inner_macros: false,
9997
edition: self.sess.edition,
@@ -224,7 +222,7 @@ impl AllocFnFactory<'_> {
224222
}
225223

226224
fn attrs(&self) -> Vec<Attribute> {
227-
let special = Symbol::intern("rustc_std_internal_symbol");
225+
let special = sym::rustc_std_internal_symbol;
228226
let special = self.cx.meta_word(self.span, special);
229227
vec![self.cx.attribute(self.span, special)]
230228
}

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn add_configuration(
6868
sess: &Session,
6969
codegen_backend: &dyn CodegenBackend,
7070
) {
71-
let tf = Symbol::intern("target_feature");
71+
let tf = sym::target_feature;
7272

7373
cfg.extend(
7474
codegen_backend

src/librustc_metadata/cstore_impl.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ impl cstore::CStore {
439439
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
440440
let ext = SyntaxExtension::ProcMacro {
441441
expander: Box::new(BangProcMacro { client }),
442-
allow_internal_unstable: Some(vec![
443-
Symbol::intern("proc_macro_def_site"),
444-
].into()),
442+
allow_internal_unstable: Some(vec![sym::proc_macro_def_site].into()),
445443
edition: data.root.edition,
446444
};
447445
return LoadedMacro::ProcMacro(Lrc::new(ext));

src/librustc_typeck/check/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -2698,16 +2698,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
26982698

26992699
fn resolve_place_op(&self, op: PlaceOp, is_mut: bool) -> (Option<DefId>, ast::Ident) {
27002700
let (tr, name) = match (op, is_mut) {
2701-
(PlaceOp::Deref, false) =>
2702-
(self.tcx.lang_items().deref_trait(), "deref"),
2703-
(PlaceOp::Deref, true) =>
2704-
(self.tcx.lang_items().deref_mut_trait(), "deref_mut"),
2705-
(PlaceOp::Index, false) =>
2706-
(self.tcx.lang_items().index_trait(), "index"),
2707-
(PlaceOp::Index, true) =>
2708-
(self.tcx.lang_items().index_mut_trait(), "index_mut"),
2701+
(PlaceOp::Deref, false) => (self.tcx.lang_items().deref_trait(), sym::deref),
2702+
(PlaceOp::Deref, true) => (self.tcx.lang_items().deref_mut_trait(), sym::deref_mut),
2703+
(PlaceOp::Index, false) => (self.tcx.lang_items().index_trait(), sym::index),
2704+
(PlaceOp::Index, true) => (self.tcx.lang_items().index_mut_trait(), sym::index_mut),
27092705
};
2710-
(tr, ast::Ident::from_str(name))
2706+
(tr, ast::Ident::with_empty_ctxt(name))
27112707
}
27122708

27132709
fn try_overloaded_place_op(&self,
@@ -4949,7 +4945,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49494945
// This is less than ideal, it will not suggest a return type span on any
49504946
// method called `main`, regardless of whether it is actually the entry point,
49514947
// but it will still present it as the reason for the expected type.
4952-
Some((decl, ident, ident.name != Symbol::intern("main")))
4948+
Some((decl, ident, ident.name != sym::main))
49534949
}),
49544950
Node::TraitItem(&hir::TraitItem {
49554951
ident, node: hir::TraitItemKind::Method(hir::MethodSig {

src/libsyntax/ext/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> {
969969
pub fn ident_of(&self, st: &str) -> ast::Ident {
970970
ast::Ident::from_str(st)
971971
}
972-
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
972+
pub fn std_path(&self, components: &[Symbol]) -> Vec<ast::Ident> {
973973
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
974974
iter::once(Ident::new(keywords::DollarCrate.name(), def_site))
975-
.chain(components.iter().map(|s| self.ident_of(s)))
975+
.chain(components.iter().map(|&s| Ident::with_empty_ctxt(s)))
976976
.collect()
977977
}
978978
pub fn name_of(&self, st: &str) -> ast::Name {

src/libsyntax/ext/build.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::attr;
33
use crate::source_map::{dummy_spanned, respan, Spanned};
44
use crate::ext::base::ExtCtxt;
55
use crate::ptr::P;
6-
use crate::symbol::{Symbol, keywords};
6+
use crate::symbol::{Symbol, keywords, sym};
77
use crate::ThinVec;
88

99
use rustc_target::spec::abi::Abi;
@@ -429,7 +429,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
429429
self.ty_path(
430430
self.path_all(DUMMY_SP,
431431
true,
432-
self.std_path(&["option", "Option"]),
432+
self.std_path(&[sym::option, sym::Option]),
433433
vec![ast::GenericArg::Type(ty)],
434434
Vec::new()))
435435
}
@@ -735,7 +735,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
735735
self.expr(sp, ast::ExprKind::Array(exprs))
736736
}
737737
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
738-
self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
738+
self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]),
739739
Vec::new())
740740
}
741741
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
@@ -751,12 +751,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
751751

752752

753753
fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
754-
let some = self.std_path(&["option", "Option", "Some"]);
754+
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
755755
self.expr_call_global(sp, some, vec![expr])
756756
}
757757

758758
fn expr_none(&self, sp: Span) -> P<ast::Expr> {
759-
let none = self.std_path(&["option", "Option", "None"]);
759+
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
760760
let none = self.path_global(sp, none);
761761
self.expr_path(none)
762762
}
@@ -780,7 +780,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
780780
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
781781
self.expr_call_global(
782782
span,
783-
self.std_path(&["rt", "begin_panic"]),
783+
self.std_path(&[sym::rt, sym::begin_panic]),
784784
vec![
785785
self.expr_str(span, msg),
786786
expr_loc_ptr])
@@ -791,19 +791,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
791791
}
792792

793793
fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
794-
let ok = self.std_path(&["result", "Result", "Ok"]);
794+
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
795795
self.expr_call_global(sp, ok, vec![expr])
796796
}
797797

798798
fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
799-
let err = self.std_path(&["result", "Result", "Err"]);
799+
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
800800
self.expr_call_global(sp, err, vec![expr])
801801
}
802802

803803
fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
804-
let ok = self.std_path(&["result", "Result", "Ok"]);
804+
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
805805
let ok_path = self.path_global(sp, ok);
806-
let err = self.std_path(&["result", "Result", "Err"]);
806+
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
807807
let err_path = self.path_global(sp, err);
808808

809809
let binding_variable = self.ident_of("__try_var");
@@ -867,25 +867,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
867867
}
868868

869869
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
870-
let some = self.std_path(&["option", "Option", "Some"]);
870+
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
871871
let path = self.path_global(span, some);
872872
self.pat_tuple_struct(span, path, vec![pat])
873873
}
874874

875875
fn pat_none(&self, span: Span) -> P<ast::Pat> {
876-
let some = self.std_path(&["option", "Option", "None"]);
876+
let some = self.std_path(&[sym::option, sym::Option, sym::None]);
877877
let path = self.path_global(span, some);
878878
self.pat_path(span, path)
879879
}
880880

881881
fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
882-
let some = self.std_path(&["result", "Result", "Ok"]);
882+
let some = self.std_path(&[sym::result, sym::Result, sym::Ok]);
883883
let path = self.path_global(span, some);
884884
self.pat_tuple_struct(span, path, vec![pat])
885885
}
886886

887887
fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
888-
let some = self.std_path(&["result", "Result", "Err"]);
888+
let some = self.std_path(&[sym::result, sym::Result, sym::Err]);
889889
let path = self.path_global(span, some);
890890
self.pat_tuple_struct(span, path, vec![pat])
891891
}

src/libsyntax/ext/derive.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
5858
call_site: span,
5959
def_site: None,
6060
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
61-
allow_internal_unstable: Some(vec![
62-
Symbol::intern("rustc_attrs"),
63-
Symbol::intern("structural_match"),
64-
].into()),
61+
allow_internal_unstable: Some(vec![sym::rustc_attrs, sym::structural_match].into()),
6562
allow_internal_unsafe: false,
6663
local_inner_macros: false,
6764
edition: cx.parse_sess.edition,
@@ -74,7 +71,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
7471
attrs.push(cx.attribute(span, meta));
7572
}
7673
if names.contains(&Symbol::intern("Copy")) {
77-
let meta = cx.meta_word(span, Symbol::intern("rustc_copy_clone_marker"));
74+
let meta = cx.meta_word(span, sym::rustc_copy_clone_marker);
7875
attrs.push(cx.attribute(span, meta));
7976
}
8077
});

src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
938938
}
939939
BuiltinDerive(func) => {
940940
expn_info.allow_internal_unstable = Some(vec![
941-
Symbol::intern("rustc_attrs"),
941+
sym::rustc_attrs,
942942
Symbol::intern("derive_clone_copy"),
943943
Symbol::intern("derive_eq"),
944944
Symbol::intern("libstd_sys_internals"), // RustcDeserialize and RustcSerialize

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub fn compile(
396396
future this will become a hard error. Please use `allow_internal_unstable(\
397397
foo, bar)` to only allow the `foo` and `bar` features",
398398
);
399-
vec![Symbol::intern("allow_internal_unstable_backcompat_hack")].into()
399+
vec![sym::allow_internal_unstable_backcompat_hack].into()
400400
})
401401
);
402402
let allow_internal_unsafe = attr::contains_name(&def.attrs, sym::allow_internal_unsafe);

src/libsyntax/parse/lexer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ast::{self, Ident};
22
use crate::parse::{token, ParseSess};
3-
use crate::symbol::Symbol;
3+
use crate::symbol::{Symbol, sym};
44
use crate::parse::unescape;
55
use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char};
66

@@ -753,7 +753,7 @@ impl<'a> StringReader<'a> {
753753
}
754754
_ => {
755755
// just a 0
756-
return token::Integer(self.name_from(start_bpos));
756+
return token::Integer(sym::n0);
757757
}
758758
}
759759
} else if c.is_digit(10) {

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6336,7 +6336,7 @@ impl<'a> Parser<'a> {
63366336
VisibilityKind::Inherited => {}
63376337
_ => {
63386338
let is_macro_rules: bool = match self.token {
6339-
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"),
6339+
token::Ident(sid, _) => sid.name == sym::macro_rules,
63406340
_ => false,
63416341
};
63426342
let mut err = if is_macro_rules {

0 commit comments

Comments
 (0)