Skip to content

Commit ab7cf71

Browse files
committed
Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=petrochenkov
Avoid more symbol interning r? @petrochenkov
2 parents be10e62 + 33a3206 commit ab7cf71

File tree

50 files changed

+299
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+299
-228
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,7 @@ dependencies = [
30093009
"rustc_cratesio_shim 0.0.0",
30103010
"rustc_data_structures 0.0.0",
30113011
"serialize 0.0.0",
3012+
"syntax_pos 0.0.0",
30123013
]
30133014

30143015
[[package]]

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 7 deletions
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());
@@ -2958,7 +2956,7 @@ impl<'a> LoweringContext<'a> {
29582956
ident: match f.ident {
29592957
Some(ident) => ident,
29602958
// FIXME(jseyfried): positional field hygiene
2961-
None => Ident::new(Symbol::intern(&index.to_string()), f.span),
2959+
None => Ident::new(sym::integer(index), f.span),
29622960
},
29632961
vis: self.lower_visibility(&f.vis, None),
29642962
ty: self.lower_ty(&f.ty, ImplTraitContext::disallowed()),
@@ -4177,9 +4175,7 @@ impl<'a> LoweringContext<'a> {
41774175
let unstable_span = this.sess.source_map().mark_span_with_reason(
41784176
CompilerDesugaringKind::TryBlock,
41794177
body.span,
4180-
Some(vec![
4181-
Symbol::intern("try_trait"),
4182-
].into()),
4178+
Some(vec![sym::try_trait].into()),
41834179
);
41844180
let mut block = this.lower_block(body, true).into_inner();
41854181
let tail = block.expr.take().map_or_else(

src/librustc/hir/map/def_collector.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::session::CrateDisambiguator;
55
use syntax::ast::*;
66
use syntax::ext::hygiene::Mark;
77
use syntax::visit;
8-
use syntax::symbol::kw;
9-
use syntax::symbol::Symbol;
8+
use syntax::symbol::{kw, sym};
109
use syntax::parse::token::{self, Token};
1110
use syntax_pos::Span;
1211

@@ -221,7 +220,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
221220
_: &'a Generics, _: NodeId, _: Span) {
222221
for (index, field) in data.fields().iter().enumerate() {
223222
let name = field.ident.map(|ident| ident.name)
224-
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
223+
.unwrap_or_else(|| sym::integer(index));
225224
let def = self.create_def(field.id,
226225
DefPathData::ValueNs(name.as_interned_str()),
227226
field.span);

src/librustc/middle/lang_items.rs

Lines changed: 2 additions & 2 deletions
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/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13161316

13171317
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
13181318
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
1319-
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
1319+
let interior = InteriorField(FieldIndex(i, sym::integer(i)));
13201320
let subcmt = Rc::new(
13211321
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
13221322
self.cat_pattern_(subcmt, &subpat, op)?;
@@ -1363,7 +1363,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13631363
};
13641364
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
13651365
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
1366-
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
1366+
let interior = InteriorField(FieldIndex(i, sym::integer(i)));
13671367
let subcmt = Rc::new(
13681368
self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
13691369
self.cat_pattern_(subcmt, &subpat, op)?;

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
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: &[_]| {

src/librustc/session/config.rs

Lines changed: 9 additions & 10 deletions
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::{sym, Symbol};
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

Lines changed: 2 additions & 4 deletions
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,
@@ -223,7 +221,7 @@ impl AllocFnFactory<'_> {
223221
}
224222

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

src/librustc_interface/util.rs

Lines changed: 1 addition & 1 deletion
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_lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,8 @@ impl KeywordIdents {
14391439
{
14401440
let next_edition = match cx.sess.edition() {
14411441
Edition::Edition2015 => {
1442-
match &ident.as_str()[..] {
1443-
"async" | "await" | "try" => Edition::Edition2018,
1442+
match ident.name {
1443+
kw::Async | kw::Await | kw::Try => Edition::Edition2018,
14441444

14451445
// rust-lang/rust#56327: Conservatively do not
14461446
// attempt to report occurrences of `dyn` within
@@ -1454,7 +1454,7 @@ impl KeywordIdents {
14541454
// its precise role in the parsed AST and thus are
14551455
// assured this is truly an attempt to use it as
14561456
// an identifier.
1457-
"dyn" if !under_macro => Edition::Edition2018,
1457+
kw::Dyn if !under_macro => Edition::Edition2018,
14581458

14591459
_ => return,
14601460
}

0 commit comments

Comments
 (0)