Skip to content

Commit 2da7a9c

Browse files
committed
Use Symbol for codegen unit names.
This is a straightforward replacement except for two places where we have to convert to `LocalInternedString` to get a stable sort.
1 parent dddacf1 commit 2da7a9c

File tree

11 files changed

+46
-51
lines changed

11 files changed

+46
-51
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::ich::{Fingerprint, StableHashingContext};
5959
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
6060
use std::fmt;
6161
use std::hash::Hash;
62-
use syntax_pos::symbol::InternedString;
62+
use syntax_pos::symbol::Symbol;
6363
use crate::traits;
6464
use crate::traits::query::{
6565
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
@@ -426,7 +426,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
426426

427427
[anon] TraitSelect,
428428

429-
[] CompileCodegenUnit(InternedString),
429+
[] CompileCodegenUnit(Symbol),
430430

431431
[eval_always] Analysis(CrateNum),
432432
]);

src/librustc/mir/mono.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
22
use crate::hir::HirId;
3-
use syntax::symbol::{InternedString, Symbol};
3+
use syntax::symbol::Symbol;
44
use syntax::attr::InlineAttr;
55
use syntax::source_map::Span;
66
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
@@ -246,7 +246,7 @@ pub struct CodegenUnit<'tcx> {
246246
/// name be unique amongst **all** crates. Therefore, it should
247247
/// contain something unique to this crate (e.g., a module path)
248248
/// as well as the crate name and disambiguator.
249-
name: InternedString,
249+
name: Symbol,
250250
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
251251
size_estimate: Option<usize>,
252252
}
@@ -294,19 +294,19 @@ impl_stable_hash_for!(enum self::Visibility {
294294
});
295295

296296
impl<'tcx> CodegenUnit<'tcx> {
297-
pub fn new(name: InternedString) -> CodegenUnit<'tcx> {
297+
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
298298
CodegenUnit {
299299
name: name,
300300
items: Default::default(),
301301
size_estimate: None,
302302
}
303303
}
304304

305-
pub fn name(&self) -> &InternedString {
306-
&self.name
305+
pub fn name(&self) -> Symbol {
306+
self.name
307307
}
308308

309-
pub fn set_name(&mut self, name: InternedString) {
309+
pub fn set_name(&mut self, name: Symbol) {
310310
self.name = name;
311311
}
312312

@@ -474,7 +474,7 @@ impl CodegenUnitNameBuilder<'tcx> {
474474
cnum: CrateNum,
475475
components: I,
476476
special_suffix: Option<S>)
477-
-> InternedString
477+
-> Symbol
478478
where I: IntoIterator<Item=C>,
479479
C: fmt::Display,
480480
S: fmt::Display,
@@ -487,7 +487,7 @@ impl CodegenUnitNameBuilder<'tcx> {
487487
cgu_name
488488
} else {
489489
let cgu_name = &cgu_name.as_str()[..];
490-
InternedString::intern(&CodegenUnit::mangle_name(cgu_name))
490+
Symbol::intern(&CodegenUnit::mangle_name(cgu_name))
491491
}
492492
}
493493

@@ -497,7 +497,7 @@ impl CodegenUnitNameBuilder<'tcx> {
497497
cnum: CrateNum,
498498
components: I,
499499
special_suffix: Option<S>)
500-
-> InternedString
500+
-> Symbol
501501
where I: IntoIterator<Item=C>,
502502
C: fmt::Display,
503503
S: fmt::Display,
@@ -543,6 +543,6 @@ impl CodegenUnitNameBuilder<'tcx> {
543543
write!(cgu_name, ".{}", special_suffix).unwrap();
544544
}
545545

546-
InternedString::intern(&cgu_name[..])
546+
Symbol::intern(&cgu_name[..])
547547
}
548548
}

src/librustc/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::traits::query::{
1515
};
1616

1717
use std::borrow::Cow;
18-
use syntax_pos::symbol::InternedString;
18+
use syntax_pos::symbol::Symbol;
1919

2020
// Each of these queries corresponds to a function pointer field in the
2121
// `Providers` struct for requesting a value of that type, and a method
@@ -924,7 +924,7 @@ rustc_queries! {
924924
desc { "collect_and_partition_mono_items" }
925925
}
926926
query is_codegened_item(_: DefId) -> bool {}
927-
query codegen_unit(_: InternedString) -> Arc<CodegenUnit<'tcx>> {
927+
query codegen_unit(_: Symbol) -> Arc<CodegenUnit<'tcx>> {
928928
no_force
929929
desc { "codegen_unit" }
930930
}

src/librustc/ty/query/keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::mir;
1111
use std::fmt::Debug;
1212
use std::hash::Hash;
1313
use syntax_pos::{Span, DUMMY_SP};
14-
use syntax_pos::symbol::InternedString;
14+
use syntax_pos::symbol::Symbol;
1515

1616
/// The `Key` trait controls what types can legally be used as the key
1717
/// for a query.
@@ -190,7 +190,7 @@ impl<'tcx> Key for traits::Environment<'tcx> {
190190
}
191191
}
192192

193-
impl Key for InternedString {
193+
impl Key for Symbol {
194194
fn query_crate(&self) -> CrateNum {
195195
LOCAL_CRATE
196196
}

src/librustc/ty/query/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use std::ops::Deref;
5555
use std::sync::Arc;
5656
use std::any::type_name;
5757
use syntax_pos::{Span, DUMMY_SP};
58-
use syntax_pos::symbol::InternedString;
5958
use syntax::attr;
6059
use syntax::ast;
6160
use syntax::feature_gate;

src/librustc_codegen_llvm/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_codegen_ssa::back::write::submit_codegened_module_to_llvm;
3636

3737
use std::ffi::CString;
3838
use std::time::Instant;
39-
use syntax_pos::symbol::InternedString;
39+
use syntax_pos::symbol::Symbol;
4040
use rustc::hir::CodegenFnAttrs;
4141

4242
use crate::value::Value;
@@ -105,7 +105,7 @@ pub fn iter_globals(llmod: &'ll llvm::Module) -> ValueIter<'ll> {
105105

106106
pub fn compile_codegen_unit(
107107
tcx: TyCtxt<'tcx>,
108-
cgu_name: InternedString,
108+
cgu_name: Symbol,
109109
tx_to_llvm_workers: &std::sync::mpsc::Sender<Box<dyn std::any::Any + Send>>,
110110
) {
111111
let prof_timer = tcx.prof.generic_activity("codegen_module");
@@ -131,7 +131,7 @@ pub fn compile_codegen_unit(
131131

132132
fn module_codegen(
133133
tcx: TyCtxt<'_>,
134-
cgu_name: InternedString,
134+
cgu_name: Symbol,
135135
) -> ModuleCodegen<ModuleLlvm> {
136136
let cgu = tcx.codegen_unit(cgu_name);
137137
// Instantiate monomorphizations without filling out definitions yet...

src/librustc_codegen_llvm/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use rustc_codegen_ssa::CompiledModule;
5050
use errors::{FatalError, Handler};
5151
use rustc::dep_graph::WorkProduct;
5252
use syntax_expand::allocator::AllocatorKind;
53-
use syntax_pos::symbol::InternedString;
5453
pub use llvm_util::target_features;
5554
use std::any::Any;
5655
use std::sync::Arc;
@@ -123,7 +122,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
123122
}
124123
fn compile_codegen_unit(
125124
&self, tcx: TyCtxt<'_>,
126-
cgu_name: InternedString,
125+
cgu_name: Symbol,
127126
tx: &std::sync::mpsc::Sender<Box<dyn Any + Send>>,
128127
) {
129128
base::compile_codegen_unit(tcx, cgu_name, tx);

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
515515
// unnecessarily.
516516
if tcx.dep_graph.is_fully_enabled() {
517517
for cgu in &codegen_units {
518-
tcx.codegen_unit(cgu.name().clone());
518+
tcx.codegen_unit(cgu.name());
519519
}
520520
}
521521

@@ -603,7 +603,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
603603
match cgu_reuse {
604604
CguReuse::No => {
605605
let start_time = Instant::now();
606-
backend.compile_codegen_unit(tcx, *cgu.name(), &ongoing_codegen.coordinator_send);
606+
backend.compile_codegen_unit(tcx, cgu.name(), &ongoing_codegen.coordinator_send);
607607
total_codegen_time += start_time.elapsed();
608608
false
609609
}

src/librustc_codegen_ssa/traits/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
1010
use std::sync::Arc;
1111
use std::sync::mpsc;
1212
use syntax_expand::allocator::AllocatorKind;
13-
use syntax_pos::symbol::InternedString;
13+
use syntax_pos::symbol::Symbol;
1414

1515
pub trait BackendTypes {
1616
type Value: CodegenObject;
@@ -50,7 +50,7 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
5050
fn compile_codegen_unit(
5151
&self,
5252
tcx: TyCtxt<'_>,
53-
cgu_name: InternedString,
53+
cgu_name: Symbol,
5454
tx_to_llvm_workers: &mpsc::Sender<Box<dyn std::any::Any + Send>>,
5555
);
5656
// If find_features is true this won't access `sess.crate_types` by assuming

src/librustc_incremental/assert_module_sources.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::mir::mono::CodegenUnitNameBuilder;
2727
use rustc::ty::TyCtxt;
2828
use std::collections::BTreeSet;
2929
use syntax::ast;
30-
use syntax::symbol::{InternedString, Symbol, sym};
30+
use syntax::symbol::{Symbol, sym};
3131
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
3232
ATTR_EXPECTED_CGU_REUSE};
3333

@@ -45,8 +45,8 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
4545
.collect_and_partition_mono_items(LOCAL_CRATE)
4646
.1
4747
.iter()
48-
.map(|cgu| *cgu.name())
49-
.collect::<BTreeSet<InternedString>>();
48+
.map(|cgu| cgu.name())
49+
.collect::<BTreeSet<Symbol>>();
5050

5151
let ams = AssertModuleSource {
5252
tcx,
@@ -61,7 +61,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
6161

6262
struct AssertModuleSource<'tcx> {
6363
tcx: TyCtxt<'tcx>,
64-
available_cgus: BTreeSet<InternedString>,
64+
available_cgus: BTreeSet<Symbol>,
6565
}
6666

6767
impl AssertModuleSource<'tcx> {

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use std::collections::hash_map::Entry;
9696
use std::cmp;
9797
use std::sync::Arc;
9898

99-
use syntax::symbol::InternedString;
99+
use syntax::symbol::Symbol;
100100
use rustc::hir::CodegenFnAttrFlags;
101101
use rustc::hir::def::DefKind;
102102
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
@@ -121,7 +121,7 @@ pub enum PartitioningStrategy {
121121
}
122122

123123
// Anything we can't find a proper codegen unit for goes into this.
124-
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> InternedString {
124+
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
125125
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))
126126
}
127127

@@ -185,9 +185,7 @@ where
185185
internalization_candidates: _,
186186
} = post_inlining;
187187

188-
result.sort_by(|cgu1, cgu2| {
189-
cgu1.name().cmp(cgu2.name())
190-
});
188+
result.sort_by_cached_key(|cgu| cgu.name().as_str());
191189

192190
result
193191
}
@@ -203,7 +201,7 @@ struct PreInliningPartitioning<'tcx> {
203201
/// to keep track of that.
204202
#[derive(Clone, PartialEq, Eq, Debug)]
205203
enum MonoItemPlacement {
206-
SingleCgu { cgu_name: InternedString },
204+
SingleCgu { cgu_name: Symbol },
207205
MultipleCgus,
208206
}
209207

@@ -251,8 +249,8 @@ where
251249
None => fallback_cgu_name(cgu_name_builder),
252250
};
253251

254-
let codegen_unit = codegen_units.entry(codegen_unit_name.clone())
255-
.or_insert_with(|| CodegenUnit::new(codegen_unit_name.clone()));
252+
let codegen_unit = codegen_units.entry(codegen_unit_name)
253+
.or_insert_with(|| CodegenUnit::new(codegen_unit_name));
256254

257255
let mut can_be_internalized = true;
258256
let (linkage, visibility) = mono_item_linkage_and_visibility(
@@ -273,8 +271,7 @@ where
273271
// crate with just types (for example), we could wind up with no CGU.
274272
if codegen_units.is_empty() {
275273
let codegen_unit_name = fallback_cgu_name(cgu_name_builder);
276-
codegen_units.insert(codegen_unit_name.clone(),
277-
CodegenUnit::new(codegen_unit_name.clone()));
274+
codegen_units.insert(codegen_unit_name, CodegenUnit::new(codegen_unit_name));
278275
}
279276

280277
PreInliningPartitioning {
@@ -492,7 +489,7 @@ fn merge_codegen_units<'tcx>(
492489
// smallest into each other) we're sure to start off with a deterministic
493490
// order (sorted by name). This'll mean that if two cgus have the same size
494491
// the stable sort below will keep everything nice and deterministic.
495-
codegen_units.sort_by_key(|cgu| *cgu.name());
492+
codegen_units.sort_by_cached_key(|cgu| cgu.name().as_str());
496493

497494
// Merge the two smallest codegen units until the target size is reached.
498495
while codegen_units.len() > target_cgu_count {
@@ -537,7 +534,7 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
537534
follow_inlining(*root, inlining_map, &mut reachable);
538535
}
539536

540-
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name().clone());
537+
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
541538

542539
// Add all monomorphizations that are not already there.
543540
for mono_item in reachable {
@@ -564,16 +561,16 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
564561
Entry::Occupied(e) => {
565562
let placement = e.into_mut();
566563
debug_assert!(match *placement {
567-
MonoItemPlacement::SingleCgu { ref cgu_name } => {
568-
*cgu_name != *new_codegen_unit.name()
564+
MonoItemPlacement::SingleCgu { cgu_name } => {
565+
cgu_name != new_codegen_unit.name()
569566
}
570567
MonoItemPlacement::MultipleCgus => true,
571568
});
572569
*placement = MonoItemPlacement::MultipleCgus;
573570
}
574571
Entry::Vacant(e) => {
575572
e.insert(MonoItemPlacement::SingleCgu {
576-
cgu_name: new_codegen_unit.name().clone()
573+
cgu_name: new_codegen_unit.name()
577574
});
578575
}
579576
}
@@ -638,7 +635,7 @@ fn internalize_symbols<'tcx>(
638635
// accessed from outside its defining codegen unit.
639636
for cgu in &mut partitioning.codegen_units {
640637
let home_cgu = MonoItemPlacement::SingleCgu {
641-
cgu_name: cgu.name().clone()
638+
cgu_name: cgu.name()
642639
};
643640

644641
for (accessee, linkage_and_visibility) in cgu.items_mut() {
@@ -717,15 +714,15 @@ fn characteristic_def_id_of_mono_item<'tcx>(
717714
}
718715
}
719716

720-
type CguNameCache = FxHashMap<(DefId, bool), InternedString>;
717+
type CguNameCache = FxHashMap<(DefId, bool), Symbol>;
721718

722719
fn compute_codegen_unit_name(
723720
tcx: TyCtxt<'_>,
724721
name_builder: &mut CodegenUnitNameBuilder<'_>,
725722
def_id: DefId,
726723
volatile: bool,
727724
cache: &mut CguNameCache,
728-
) -> InternedString {
725+
) -> Symbol {
729726
// Find the innermost module that is not nested within a function.
730727
let mut current_def_id = def_id;
731728
let mut cgu_def_id = None;
@@ -777,7 +774,7 @@ fn compute_codegen_unit_name(
777774
fn numbered_codegen_unit_name(
778775
name_builder: &mut CodegenUnitNameBuilder<'_>,
779776
index: usize,
780-
) -> InternedString {
777+
) -> Symbol {
781778
name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index))
782779
}
783780

@@ -929,7 +926,7 @@ fn collect_and_partition_mono_items(
929926
for (&mono_item, &linkage) in cgu.items() {
930927
item_to_cgus.entry(mono_item)
931928
.or_default()
932-
.push((cgu.name().clone(), linkage));
929+
.push((cgu.name(), linkage));
933930
}
934931
}
935932

@@ -991,7 +988,7 @@ pub fn provide(providers: &mut Providers<'_>) {
991988
providers.codegen_unit = |tcx, name| {
992989
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
993990
all.iter()
994-
.find(|cgu| *cgu.name() == name)
991+
.find(|cgu| cgu.name() == name)
995992
.cloned()
996993
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
997994
};

0 commit comments

Comments
 (0)