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.
This commit is contained in:
Nicholas Nethercote 2019-10-21 17:14:03 +11:00
parent dddacf1eb3
commit 2da7a9c0d9
11 changed files with 46 additions and 51 deletions

View File

@ -59,7 +59,7 @@ use crate::ich::{Fingerprint, StableHashingContext};
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
use std::fmt;
use std::hash::Hash;
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
use crate::traits;
use crate::traits::query::{
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
@ -426,7 +426,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[anon] TraitSelect,
[] CompileCodegenUnit(InternedString),
[] CompileCodegenUnit(Symbol),
[eval_always] Analysis(CrateNum),
]);

View File

@ -1,6 +1,6 @@
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use crate::hir::HirId;
use syntax::symbol::{InternedString, Symbol};
use syntax::symbol::Symbol;
use syntax::attr::InlineAttr;
use syntax::source_map::Span;
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
@ -246,7 +246,7 @@ pub struct CodegenUnit<'tcx> {
/// name be unique amongst **all** crates. Therefore, it should
/// contain something unique to this crate (e.g., a module path)
/// as well as the crate name and disambiguator.
name: InternedString,
name: Symbol,
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
size_estimate: Option<usize>,
}
@ -294,7 +294,7 @@ impl_stable_hash_for!(enum self::Visibility {
});
impl<'tcx> CodegenUnit<'tcx> {
pub fn new(name: InternedString) -> CodegenUnit<'tcx> {
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
CodegenUnit {
name: name,
items: Default::default(),
@ -302,11 +302,11 @@ impl<'tcx> CodegenUnit<'tcx> {
}
}
pub fn name(&self) -> &InternedString {
&self.name
pub fn name(&self) -> Symbol {
self.name
}
pub fn set_name(&mut self, name: InternedString) {
pub fn set_name(&mut self, name: Symbol) {
self.name = name;
}
@ -474,7 +474,7 @@ impl CodegenUnitNameBuilder<'tcx> {
cnum: CrateNum,
components: I,
special_suffix: Option<S>)
-> InternedString
-> Symbol
where I: IntoIterator<Item=C>,
C: fmt::Display,
S: fmt::Display,
@ -487,7 +487,7 @@ impl CodegenUnitNameBuilder<'tcx> {
cgu_name
} else {
let cgu_name = &cgu_name.as_str()[..];
InternedString::intern(&CodegenUnit::mangle_name(cgu_name))
Symbol::intern(&CodegenUnit::mangle_name(cgu_name))
}
}
@ -497,7 +497,7 @@ impl CodegenUnitNameBuilder<'tcx> {
cnum: CrateNum,
components: I,
special_suffix: Option<S>)
-> InternedString
-> Symbol
where I: IntoIterator<Item=C>,
C: fmt::Display,
S: fmt::Display,
@ -543,6 +543,6 @@ impl CodegenUnitNameBuilder<'tcx> {
write!(cgu_name, ".{}", special_suffix).unwrap();
}
InternedString::intern(&cgu_name[..])
Symbol::intern(&cgu_name[..])
}
}

View File

@ -15,7 +15,7 @@ use crate::traits::query::{
};
use std::borrow::Cow;
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method
@ -924,7 +924,7 @@ rustc_queries! {
desc { "collect_and_partition_mono_items" }
}
query is_codegened_item(_: DefId) -> bool {}
query codegen_unit(_: InternedString) -> Arc<CodegenUnit<'tcx>> {
query codegen_unit(_: Symbol) -> Arc<CodegenUnit<'tcx>> {
no_force
desc { "codegen_unit" }
}

View File

@ -11,7 +11,7 @@ use crate::mir;
use std::fmt::Debug;
use std::hash::Hash;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
/// The `Key` trait controls what types can legally be used as the key
/// for a query.
@ -190,7 +190,7 @@ impl<'tcx> Key for traits::Environment<'tcx> {
}
}
impl Key for InternedString {
impl Key for Symbol {
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}

View File

@ -55,7 +55,6 @@ use std::ops::Deref;
use std::sync::Arc;
use std::any::type_name;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::symbol::InternedString;
use syntax::attr;
use syntax::ast;
use syntax::feature_gate;

View File

@ -36,7 +36,7 @@ use rustc_codegen_ssa::back::write::submit_codegened_module_to_llvm;
use std::ffi::CString;
use std::time::Instant;
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
use rustc::hir::CodegenFnAttrs;
use crate::value::Value;
@ -105,7 +105,7 @@ pub fn iter_globals(llmod: &'ll llvm::Module) -> ValueIter<'ll> {
pub fn compile_codegen_unit(
tcx: TyCtxt<'tcx>,
cgu_name: InternedString,
cgu_name: Symbol,
tx_to_llvm_workers: &std::sync::mpsc::Sender<Box<dyn std::any::Any + Send>>,
) {
let prof_timer = tcx.prof.generic_activity("codegen_module");
@ -131,7 +131,7 @@ pub fn compile_codegen_unit(
fn module_codegen(
tcx: TyCtxt<'_>,
cgu_name: InternedString,
cgu_name: Symbol,
) -> ModuleCodegen<ModuleLlvm> {
let cgu = tcx.codegen_unit(cgu_name);
// Instantiate monomorphizations without filling out definitions yet...

View File

@ -50,7 +50,6 @@ use rustc_codegen_ssa::CompiledModule;
use errors::{FatalError, Handler};
use rustc::dep_graph::WorkProduct;
use syntax_expand::allocator::AllocatorKind;
use syntax_pos::symbol::InternedString;
pub use llvm_util::target_features;
use std::any::Any;
use std::sync::Arc;
@ -123,7 +122,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
}
fn compile_codegen_unit(
&self, tcx: TyCtxt<'_>,
cgu_name: InternedString,
cgu_name: Symbol,
tx: &std::sync::mpsc::Sender<Box<dyn Any + Send>>,
) {
base::compile_codegen_unit(tcx, cgu_name, tx);

View File

@ -515,7 +515,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// unnecessarily.
if tcx.dep_graph.is_fully_enabled() {
for cgu in &codegen_units {
tcx.codegen_unit(cgu.name().clone());
tcx.codegen_unit(cgu.name());
}
}
@ -603,7 +603,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
match cgu_reuse {
CguReuse::No => {
let start_time = Instant::now();
backend.compile_codegen_unit(tcx, *cgu.name(), &ongoing_codegen.coordinator_send);
backend.compile_codegen_unit(tcx, cgu.name(), &ongoing_codegen.coordinator_send);
total_codegen_time += start_time.elapsed();
false
}

View File

@ -10,7 +10,7 @@ use rustc_codegen_utils::codegen_backend::CodegenBackend;
use std::sync::Arc;
use std::sync::mpsc;
use syntax_expand::allocator::AllocatorKind;
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
pub trait BackendTypes {
type Value: CodegenObject;
@ -50,7 +50,7 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
fn compile_codegen_unit(
&self,
tcx: TyCtxt<'_>,
cgu_name: InternedString,
cgu_name: Symbol,
tx_to_llvm_workers: &mpsc::Sender<Box<dyn std::any::Any + Send>>,
);
// If find_features is true this won't access `sess.crate_types` by assuming

View File

@ -27,7 +27,7 @@ use rustc::mir::mono::CodegenUnitNameBuilder;
use rustc::ty::TyCtxt;
use std::collections::BTreeSet;
use syntax::ast;
use syntax::symbol::{InternedString, Symbol, sym};
use syntax::symbol::{Symbol, sym};
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE};
@ -45,8 +45,8 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
.collect_and_partition_mono_items(LOCAL_CRATE)
.1
.iter()
.map(|cgu| *cgu.name())
.collect::<BTreeSet<InternedString>>();
.map(|cgu| cgu.name())
.collect::<BTreeSet<Symbol>>();
let ams = AssertModuleSource {
tcx,
@ -61,7 +61,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
struct AssertModuleSource<'tcx> {
tcx: TyCtxt<'tcx>,
available_cgus: BTreeSet<InternedString>,
available_cgus: BTreeSet<Symbol>,
}
impl AssertModuleSource<'tcx> {

View File

@ -96,7 +96,7 @@ use std::collections::hash_map::Entry;
use std::cmp;
use std::sync::Arc;
use syntax::symbol::InternedString;
use syntax::symbol::Symbol;
use rustc::hir::CodegenFnAttrFlags;
use rustc::hir::def::DefKind;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
@ -121,7 +121,7 @@ pub enum PartitioningStrategy {
}
// Anything we can't find a proper codegen unit for goes into this.
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> InternedString {
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))
}
@ -185,9 +185,7 @@ where
internalization_candidates: _,
} = post_inlining;
result.sort_by(|cgu1, cgu2| {
cgu1.name().cmp(cgu2.name())
});
result.sort_by_cached_key(|cgu| cgu.name().as_str());
result
}
@ -203,7 +201,7 @@ struct PreInliningPartitioning<'tcx> {
/// to keep track of that.
#[derive(Clone, PartialEq, Eq, Debug)]
enum MonoItemPlacement {
SingleCgu { cgu_name: InternedString },
SingleCgu { cgu_name: Symbol },
MultipleCgus,
}
@ -251,8 +249,8 @@ where
None => fallback_cgu_name(cgu_name_builder),
};
let codegen_unit = codegen_units.entry(codegen_unit_name.clone())
.or_insert_with(|| CodegenUnit::new(codegen_unit_name.clone()));
let codegen_unit = codegen_units.entry(codegen_unit_name)
.or_insert_with(|| CodegenUnit::new(codegen_unit_name));
let mut can_be_internalized = true;
let (linkage, visibility) = mono_item_linkage_and_visibility(
@ -273,8 +271,7 @@ where
// crate with just types (for example), we could wind up with no CGU.
if codegen_units.is_empty() {
let codegen_unit_name = fallback_cgu_name(cgu_name_builder);
codegen_units.insert(codegen_unit_name.clone(),
CodegenUnit::new(codegen_unit_name.clone()));
codegen_units.insert(codegen_unit_name, CodegenUnit::new(codegen_unit_name));
}
PreInliningPartitioning {
@ -492,7 +489,7 @@ fn merge_codegen_units<'tcx>(
// smallest into each other) we're sure to start off with a deterministic
// order (sorted by name). This'll mean that if two cgus have the same size
// the stable sort below will keep everything nice and deterministic.
codegen_units.sort_by_key(|cgu| *cgu.name());
codegen_units.sort_by_cached_key(|cgu| cgu.name().as_str());
// Merge the two smallest codegen units until the target size is reached.
while codegen_units.len() > target_cgu_count {
@ -537,7 +534,7 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
follow_inlining(*root, inlining_map, &mut reachable);
}
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name().clone());
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
// Add all monomorphizations that are not already there.
for mono_item in reachable {
@ -564,8 +561,8 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
Entry::Occupied(e) => {
let placement = e.into_mut();
debug_assert!(match *placement {
MonoItemPlacement::SingleCgu { ref cgu_name } => {
*cgu_name != *new_codegen_unit.name()
MonoItemPlacement::SingleCgu { cgu_name } => {
cgu_name != new_codegen_unit.name()
}
MonoItemPlacement::MultipleCgus => true,
});
@ -573,7 +570,7 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
}
Entry::Vacant(e) => {
e.insert(MonoItemPlacement::SingleCgu {
cgu_name: new_codegen_unit.name().clone()
cgu_name: new_codegen_unit.name()
});
}
}
@ -638,7 +635,7 @@ fn internalize_symbols<'tcx>(
// accessed from outside its defining codegen unit.
for cgu in &mut partitioning.codegen_units {
let home_cgu = MonoItemPlacement::SingleCgu {
cgu_name: cgu.name().clone()
cgu_name: cgu.name()
};
for (accessee, linkage_and_visibility) in cgu.items_mut() {
@ -717,7 +714,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
}
}
type CguNameCache = FxHashMap<(DefId, bool), InternedString>;
type CguNameCache = FxHashMap<(DefId, bool), Symbol>;
fn compute_codegen_unit_name(
tcx: TyCtxt<'_>,
@ -725,7 +722,7 @@ fn compute_codegen_unit_name(
def_id: DefId,
volatile: bool,
cache: &mut CguNameCache,
) -> InternedString {
) -> Symbol {
// Find the innermost module that is not nested within a function.
let mut current_def_id = def_id;
let mut cgu_def_id = None;
@ -777,7 +774,7 @@ fn compute_codegen_unit_name(
fn numbered_codegen_unit_name(
name_builder: &mut CodegenUnitNameBuilder<'_>,
index: usize,
) -> InternedString {
) -> Symbol {
name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index))
}
@ -929,7 +926,7 @@ fn collect_and_partition_mono_items(
for (&mono_item, &linkage) in cgu.items() {
item_to_cgus.entry(mono_item)
.or_default()
.push((cgu.name().clone(), linkage));
.push((cgu.name(), linkage));
}
}
@ -991,7 +988,7 @@ pub fn provide(providers: &mut Providers<'_>) {
providers.codegen_unit = |tcx, name| {
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
all.iter()
.find(|cgu| *cgu.name() == name)
.find(|cgu| cgu.name() == name)
.cloned()
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
};