Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1fa9449

Browse files
committedAug 17, 2018
Auto merge of #53356 - michaelwoerister:itlto, r=alexcrichton
Preliminary work for incremental ThinLTO (CGU name edition) Bring back the first half of #52266 but hopefully without the performance regression.
2 parents c8c587f + d662083 commit 1fa9449

File tree

21 files changed

+331
-172
lines changed

21 files changed

+331
-172
lines changed
 

‎src/librustc/mir/mono.rs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use hir::def_id::DefId;
11+
use hir::def_id::{DefId, CrateNum};
1212
use syntax::ast::NodeId;
13-
use syntax::symbol::InternedString;
13+
use syntax::symbol::{Symbol, InternedString};
1414
use ty::{Instance, TyCtxt};
1515
use util::nodemap::FxHashMap;
1616
use rustc_data_structures::base_n;
1717
use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
1818
StableHasher};
1919
use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
20+
use std::fmt;
2021
use std::hash::Hash;
2122

2223
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
@@ -239,3 +240,95 @@ impl Stats {
239240
self.fn_stats.extend(stats.fn_stats);
240241
}
241242
}
243+
244+
pub struct CodegenUnitNameBuilder<'a, 'gcx: 'tcx, 'tcx: 'a> {
245+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
246+
cache: FxHashMap<CrateNum, String>,
247+
}
248+
249+
impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
250+
251+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self {
252+
CodegenUnitNameBuilder {
253+
tcx,
254+
cache: FxHashMap(),
255+
}
256+
}
257+
258+
/// CGU names should fulfill the following requirements:
259+
/// - They should be able to act as a file name on any kind of file system
260+
/// - They should not collide with other CGU names, even for different versions
261+
/// of the same crate.
262+
///
263+
/// Consequently, we don't use special characters except for '.' and '-' and we
264+
/// prefix each name with the crate-name and crate-disambiguator.
265+
///
266+
/// This function will build CGU names of the form:
267+
///
268+
/// ```
269+
/// <crate-name>.<crate-disambiguator>(-<component>)*[.<special-suffix>]
270+
/// ```
271+
///
272+
/// The '.' before `<special-suffix>` makes sure that names with a special
273+
/// suffix can never collide with a name built out of regular Rust
274+
/// identifiers (e.g. module paths).
275+
pub fn build_cgu_name<I, C, S>(&mut self,
276+
cnum: CrateNum,
277+
components: I,
278+
special_suffix: Option<S>)
279+
-> InternedString
280+
where I: IntoIterator<Item=C>,
281+
C: fmt::Display,
282+
S: fmt::Display,
283+
{
284+
let cgu_name = self.build_cgu_name_no_mangle(cnum,
285+
components,
286+
special_suffix);
287+
288+
if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
289+
cgu_name
290+
} else {
291+
let cgu_name = &cgu_name.as_str()[..];
292+
Symbol::intern(&CodegenUnit::mangle_name(cgu_name)).as_interned_str()
293+
}
294+
}
295+
296+
/// Same as `CodegenUnit::build_cgu_name()` but will never mangle the
297+
/// resulting name.
298+
pub fn build_cgu_name_no_mangle<I, C, S>(&mut self,
299+
cnum: CrateNum,
300+
components: I,
301+
special_suffix: Option<S>)
302+
-> InternedString
303+
where I: IntoIterator<Item=C>,
304+
C: fmt::Display,
305+
S: fmt::Display,
306+
{
307+
use std::fmt::Write;
308+
309+
let mut cgu_name = String::with_capacity(64);
310+
311+
// Start out with the crate name and disambiguator
312+
let tcx = self.tcx;
313+
let crate_prefix = self.cache.entry(cnum).or_insert_with(|| {
314+
let crate_disambiguator = format!("{}", tcx.crate_disambiguator(cnum));
315+
// Using a shortened disambiguator of about 40 bits
316+
format!("{}.{}", tcx.crate_name(cnum), &crate_disambiguator[0 .. 8])
317+
});
318+
319+
write!(cgu_name, "{}", crate_prefix).unwrap();
320+
321+
// Add the components
322+
for component in components {
323+
write!(cgu_name, "-{}", component).unwrap();
324+
}
325+
326+
if let Some(special_suffix) = special_suffix {
327+
// We add a dot in here so it cannot clash with anything in a regular
328+
// Rust identifier
329+
write!(cgu_name, ".{}", special_suffix).unwrap();
330+
}
331+
332+
Symbol::intern(&cgu_name[..]).as_interned_str()
333+
}
334+
}

‎src/librustc/session/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
2424
use util::common::{duration_to_secs_str, ErrorReported};
2525
use util::common::ProfileQueriesMsg;
2626

27+
use rustc_data_structures::base_n;
2728
use rustc_data_structures::sync::{self, Lrc, Lock, LockCell, OneThread, Once, RwLock};
2829

2930
use syntax::ast::NodeId;
@@ -48,6 +49,7 @@ use std;
4849
use std::cell::{self, Cell, RefCell};
4950
use std::collections::HashMap;
5051
use std::env;
52+
use std::fmt;
5153
use std::io::Write;
5254
use std::path::{Path, PathBuf};
5355
use std::time::Duration;
@@ -1221,6 +1223,14 @@ impl CrateDisambiguator {
12211223
}
12221224
}
12231225

1226+
impl fmt::Display for CrateDisambiguator {
1227+
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
1228+
let (a, b) = self.0.as_value();
1229+
let as_u128 = a as u128 | ((b as u128) << 64);
1230+
f.write_str(&base_n::encode(as_u128, base_n::CASE_INSENSITIVE))
1231+
}
1232+
}
1233+
12241234
impl From<Fingerprint> for CrateDisambiguator {
12251235
fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
12261236
CrateDisambiguator(fingerprint)

‎src/librustc_codegen_llvm/back/link.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ use std::process::{Output, Stdio};
4646
use std::str;
4747
use syntax::attr;
4848

49-
/// The LLVM module name containing crate-metadata. This includes a `.` on
50-
/// purpose, so it cannot clash with the name of a user-defined module.
51-
pub const METADATA_MODULE_NAME: &'static str = "crate.metadata";
52-
53-
// same as for metadata above, but for allocator shim
54-
pub const ALLOCATOR_MODULE_NAME: &'static str = "crate.allocator";
55-
5649
pub use rustc_codegen_utils::link::{find_crate_name, filename_for_input, default_output_for_target,
5750
invalid_output_for_target, build_link_meta, out_filename,
5851
check_file_is_writeable};

‎src/librustc_codegen_llvm/back/lto.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn fat_lto(cgcx: &CodegenContext,
242242
let llvm = module.llvm().expect("can't lto pre-codegened modules");
243243
(&llvm.llcx, llvm.llmod())
244244
};
245-
info!("using {:?} as a base module", module.llmod_id);
245+
info!("using {:?} as a base module", module.name);
246246

247247
// The linking steps below may produce errors and diagnostics within LLVM
248248
// which we'd like to handle and print, so set up our diagnostic handlers
@@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext,
257257
for module in modules {
258258
let llvm = module.llvm().expect("can't lto pre-codegened modules");
259259
let buffer = ModuleBuffer::new(llvm.llmod());
260-
let llmod_id = CString::new(&module.llmod_id[..]).unwrap();
260+
let llmod_id = CString::new(&module.name[..]).unwrap();
261261
serialized_modules.push((SerializedModule::Local(buffer), llmod_id));
262262
}
263263

@@ -384,9 +384,9 @@ fn thin_lto(diag_handler: &Handler,
384384
// the most expensive portion of this small bit of global
385385
// analysis!
386386
for (i, module) in modules.iter().enumerate() {
387-
info!("local module: {} - {}", i, module.llmod_id);
387+
info!("local module: {} - {}", i, module.name);
388388
let llvm = module.llvm().expect("can't lto precodegened module");
389-
let name = CString::new(module.llmod_id.clone()).unwrap();
389+
let name = CString::new(module.name.clone()).unwrap();
390390
let buffer = ThinBuffer::new(llvm.llmod());
391391
thin_modules.push(llvm::ThinLTOModule {
392392
identifier: name.as_ptr(),
@@ -395,7 +395,7 @@ fn thin_lto(diag_handler: &Handler,
395395
});
396396
thin_buffers.push(buffer);
397397
module_names.push(name);
398-
timeline.record(&module.llmod_id);
398+
timeline.record(&module.name);
399399
}
400400

401401
// FIXME: All upstream crates are deserialized internally in the
@@ -668,7 +668,6 @@ impl ThinModule {
668668
llcx,
669669
tm,
670670
}),
671-
llmod_id: self.name().to_string(),
672671
name: self.name().to_string(),
673672
kind: ModuleKind::Regular,
674673
};

‎src/librustc_codegen_llvm/back/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
728728

729729
if config.emit_bc_compressed {
730730
let dst = bc_out.with_extension(RLIB_BYTECODE_EXTENSION);
731-
let data = bytecode::encode(&module.llmod_id, data);
731+
let data = bytecode::encode(&module.name, data);
732732
if let Err(e) = fs::write(&dst, data) {
733733
diag_handler.err(&format!("failed to write bytecode: {}", e));
734734
}
@@ -1338,7 +1338,6 @@ fn execute_work_item(cgcx: &CodegenContext,
13381338
assert_eq!(bytecode_compressed.is_some(), config.emit_bc_compressed);
13391339

13401340
Ok(WorkItemResult::Compiled(CompiledModule {
1341-
llmod_id: module.llmod_id.clone(),
13421341
name: module_name,
13431342
kind: ModuleKind::Regular,
13441343
pre_existing: true,

‎src/librustc_codegen_llvm/base.rs

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use metadata;
3636
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
3737
use rustc::middle::lang_items::StartFnLangItem;
3838
use rustc::middle::weak_lang_items;
39-
use rustc::mir::mono::{Linkage, Visibility, Stats};
39+
use rustc::mir::mono::{Linkage, Visibility, Stats, CodegenUnitNameBuilder};
4040
use rustc::middle::cstore::{EncodedMetadata};
4141
use rustc::ty::{self, Ty, TyCtxt};
4242
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf};
@@ -742,19 +742,23 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
742742

743743
let crate_hash = tcx.crate_hash(LOCAL_CRATE);
744744
let link_meta = link::build_link_meta(crate_hash);
745+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
745746

746747
// Codegen the metadata.
747748
tcx.sess.profiler(|p| p.start_activity(ProfileCategory::Codegen));
748-
let llmod_id = "metadata";
749-
let metadata_llvm_module = ModuleLlvm::new(tcx.sess, llmod_id);
749+
750+
let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
751+
&["crate"],
752+
Some("metadata")).as_str()
753+
.to_string();
754+
let metadata_llvm_module = ModuleLlvm::new(tcx.sess, &metadata_cgu_name);
750755
let metadata = time(tcx.sess, "write metadata", || {
751756
write_metadata(tcx, &metadata_llvm_module, &link_meta)
752757
});
753758
tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen));
754759

755760
let metadata_module = ModuleCodegen {
756-
name: link::METADATA_MODULE_NAME.to_string(),
757-
llmod_id: llmod_id.to_string(),
761+
name: metadata_cgu_name,
758762
source: ModuleSource::Codegened(metadata_llvm_module),
759763
kind: ModuleKind::Metadata,
760764
};
@@ -833,20 +837,22 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
833837
let allocator_module = if any_dynamic_crate {
834838
None
835839
} else if let Some(kind) = *tcx.sess.allocator_kind.get() {
836-
unsafe {
837-
let llmod_id = "allocator";
838-
let modules = ModuleLlvm::new(tcx.sess, llmod_id);
839-
time(tcx.sess, "write allocator module", || {
840+
let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
841+
&["crate"],
842+
Some("allocator")).as_str()
843+
.to_string();
844+
let modules = ModuleLlvm::new(tcx.sess, &llmod_id);
845+
time(tcx.sess, "write allocator module", || {
846+
unsafe {
840847
allocator::codegen(tcx, &modules, kind)
841-
});
848+
}
849+
});
842850

843-
Some(ModuleCodegen {
844-
name: link::ALLOCATOR_MODULE_NAME.to_string(),
845-
llmod_id: llmod_id.to_string(),
846-
source: ModuleSource::Codegened(modules),
847-
kind: ModuleKind::Allocator,
848-
})
849-
}
851+
Some(ModuleCodegen {
852+
name: llmod_id,
853+
source: ModuleSource::Codegened(modules),
854+
kind: ModuleKind::Allocator,
855+
})
850856
} else {
851857
None
852858
};
@@ -889,21 +895,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
889895
// succeed it means that none of the dependencies has changed
890896
// and we can safely re-use.
891897
if let Some(dep_node_index) = tcx.dep_graph.try_mark_green(tcx, dep_node) {
892-
// Append ".rs" to LLVM module identifier.
893-
//
894-
// LLVM code generator emits a ".file filename" directive
895-
// for ELF backends. Value of the "filename" is set as the
896-
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
897-
// crashes if the module identifier is same as other symbols
898-
// such as a function name in the module.
899-
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
900-
let llmod_id = format!("{}.rs", cgu.name());
901-
902898
let module = ModuleCodegen {
903899
name: cgu.name().to_string(),
904900
source: ModuleSource::Preexisting(buf),
905901
kind: ModuleKind::Regular,
906-
llmod_id,
907902
};
908903
tcx.dep_graph.mark_loaded_from_cache(dep_node_index, true);
909904
write::submit_codegened_module_to_llvm(tcx, module, 0);
@@ -1212,21 +1207,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12121207
{
12131208
let cgu_name = cgu.name().to_string();
12141209

1215-
// Append ".rs" to LLVM module identifier.
1216-
//
1217-
// LLVM code generator emits a ".file filename" directive
1218-
// for ELF backends. Value of the "filename" is set as the
1219-
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
1220-
// crashes if the module identifier is same as other symbols
1221-
// such as a function name in the module.
1222-
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
1223-
let llmod_id = format!("{}-{}.rs",
1224-
cgu.name(),
1225-
tcx.crate_disambiguator(LOCAL_CRATE)
1226-
.to_fingerprint().to_hex());
1227-
12281210
// Instantiate monomorphizations without filling out definitions yet...
1229-
let llvm_module = ModuleLlvm::new(tcx.sess, &llmod_id);
1211+
let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name);
12301212
let stats = {
12311213
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
12321214
let mono_items = cx.codegen_unit
@@ -1282,7 +1264,6 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12821264
name: cgu_name,
12831265
source: ModuleSource::Codegened(llvm_module),
12841266
kind: ModuleKind::Regular,
1285-
llmod_id,
12861267
})
12871268
}
12881269
}

‎src/librustc_codegen_llvm/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ struct ModuleCodegen {
269269
/// unique amongst **all** crates. Therefore, it should contain
270270
/// something unique to this crate (e.g., a module path) as well
271271
/// as the crate name and disambiguator.
272+
/// We currently generate these names via CodegenUnit::build_cgu_name().
272273
name: String,
273-
llmod_id: String,
274274
source: ModuleSource,
275275
kind: ModuleKind,
276276
}
@@ -317,7 +317,6 @@ impl ModuleCodegen {
317317
};
318318

319319
CompiledModule {
320-
llmod_id: self.llmod_id,
321320
name: self.name.clone(),
322321
kind: self.kind,
323322
pre_existing,
@@ -331,7 +330,6 @@ impl ModuleCodegen {
331330
#[derive(Debug)]
332331
struct CompiledModule {
333332
name: String,
334-
llmod_id: String,
335333
kind: ModuleKind,
336334
pre_existing: bool,
337335
object: Option<PathBuf>,

‎src/librustc_incremental/assert_module_sources.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
//! the HIR doesn't change as a result of the annotations, which might
2828
//! perturb the reuse results.
2929
30+
use rustc::hir::def_id::LOCAL_CRATE;
3031
use rustc::dep_graph::{DepNode, DepConstructor};
31-
use rustc::mir::mono::CodegenUnit;
32+
use rustc::mir::mono::CodegenUnitNameBuilder;
3233
use rustc::ty::TyCtxt;
3334
use syntax::ast;
34-
use syntax_pos::symbol::Symbol;
3535
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED};
3636

3737
const MODULE: &'static str = "module";
@@ -72,34 +72,71 @@ impl<'a, 'tcx> AssertModuleSource<'a, 'tcx> {
7272
return;
7373
}
7474

75-
let mname = self.field(attr, MODULE);
76-
let mangled_cgu_name = CodegenUnit::mangle_name(&mname.as_str());
77-
let mangled_cgu_name = Symbol::intern(&mangled_cgu_name).as_interned_str();
75+
let user_path = self.field(attr, MODULE).as_str().to_string();
76+
let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string();
77+
78+
if !user_path.starts_with(&crate_name) {
79+
let msg = format!("Found malformed codegen unit name `{}`. \
80+
Codegen units names must always start with the name of the \
81+
crate (`{}` in this case).", user_path, crate_name);
82+
self.tcx.sess.span_fatal(attr.span, &msg);
83+
}
84+
85+
// Split of the "special suffix" if there is one.
86+
let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind(".") {
87+
(&user_path[..index], Some(&user_path[index + 1 ..]))
88+
} else {
89+
(&user_path[..], None)
90+
};
91+
92+
let mut cgu_path_components = user_path.split("-").collect::<Vec<_>>();
93+
94+
// Remove the crate name
95+
assert_eq!(cgu_path_components.remove(0), crate_name);
96+
97+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(self.tcx);
98+
let cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
99+
cgu_path_components,
100+
cgu_special_suffix);
101+
102+
debug!("mapping '{}' to cgu name '{}'", self.field(attr, MODULE), cgu_name);
78103

79104
let dep_node = DepNode::new(self.tcx,
80-
DepConstructor::CompileCodegenUnit(mangled_cgu_name));
105+
DepConstructor::CompileCodegenUnit(cgu_name));
81106

82107
if let Some(loaded_from_cache) = self.tcx.dep_graph.was_loaded_from_cache(&dep_node) {
83108
match (disposition, loaded_from_cache) {
84109
(Disposition::Reused, false) => {
85110
self.tcx.sess.span_err(
86111
attr.span,
87112
&format!("expected module named `{}` to be Reused but is Codegened",
88-
mname));
113+
user_path));
89114
}
90115
(Disposition::Codegened, true) => {
91116
self.tcx.sess.span_err(
92117
attr.span,
93118
&format!("expected module named `{}` to be Codegened but is Reused",
94-
mname));
119+
user_path));
95120
}
96121
(Disposition::Reused, true) |
97122
(Disposition::Codegened, false) => {
98123
// These are what we would expect.
99124
}
100125
}
101126
} else {
102-
self.tcx.sess.span_err(attr.span, &format!("no module named `{}`", mname));
127+
let available_cgus = self.tcx
128+
.collect_and_partition_mono_items(LOCAL_CRATE)
129+
.1
130+
.iter()
131+
.map(|cgu| format!("{}", cgu.name()))
132+
.collect::<Vec<String>>()
133+
.join(", ");
134+
135+
self.tcx.sess.span_err(attr.span,
136+
&format!("no module named `{}` (mangled: {}).\nAvailable modules: {}",
137+
user_path,
138+
cgu_name,
139+
available_cgus));
103140
}
104141
}
105142

‎src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 84 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@
105105
use monomorphize::collector::InliningMap;
106106
use rustc::dep_graph::WorkProductId;
107107
use rustc::hir::CodegenFnAttrFlags;
108-
use rustc::hir::def_id::DefId;
108+
use rustc::hir::def_id::{DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
109109
use rustc::hir::map::DefPathData;
110-
use rustc::mir::mono::{Linkage, Visibility};
110+
use rustc::mir::mono::{Linkage, Visibility, CodegenUnitNameBuilder};
111111
use rustc::middle::exported_symbols::SymbolExportLevel;
112112
use rustc::ty::{self, TyCtxt, InstanceDef};
113113
use rustc::ty::item_path::characteristic_def_id_of_type;
114114
use rustc::util::nodemap::{FxHashMap, FxHashSet};
115115
use std::collections::hash_map::Entry;
116116
use std::cmp;
117117
use syntax::ast::NodeId;
118-
use syntax::symbol::{Symbol, InternedString};
118+
use syntax::symbol::InternedString;
119119
use rustc::mir::mono::MonoItem;
120120
use monomorphize::item::{MonoItemExt, InstantiationMode};
121121

@@ -203,17 +203,10 @@ impl<'tcx> CodegenUnitExt<'tcx> for CodegenUnit<'tcx> {
203203
}
204204

205205
// Anything we can't find a proper codegen unit for goes into this.
206-
fn fallback_cgu_name(tcx: TyCtxt) -> InternedString {
207-
const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
208-
209-
if tcx.sess.opts.debugging_opts.human_readable_cgu_names {
210-
Symbol::intern(FALLBACK_CODEGEN_UNIT).as_interned_str()
211-
} else {
212-
Symbol::intern(&CodegenUnit::mangle_name(FALLBACK_CODEGEN_UNIT)).as_interned_str()
213-
}
206+
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder) -> InternedString {
207+
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))
214208
}
215209

216-
217210
pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
218211
mono_items: I,
219212
strategy: PartitioningStrategy,
@@ -224,8 +217,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
224217
// In the first step, we place all regular monomorphizations into their
225218
// respective 'home' codegen unit. Regular monomorphizations are all
226219
// functions and statics defined in the local crate.
227-
let mut initial_partitioning = place_root_mono_items(tcx,
228-
mono_items);
220+
let mut initial_partitioning = place_root_mono_items(tcx, mono_items);
229221

230222
initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(&tcx));
231223

@@ -234,7 +226,7 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
234226
// If the partitioning should produce a fixed count of codegen units, merge
235227
// until that count is reached.
236228
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
237-
merge_codegen_units(&mut initial_partitioning, count, &tcx.crate_name.as_str());
229+
merge_codegen_units(tcx, &mut initial_partitioning, count);
238230

239231
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
240232
}
@@ -308,6 +300,9 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
308300
let export_generics = tcx.sess.opts.share_generics() &&
309301
tcx.local_crate_exports_generics();
310302

303+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
304+
let cgu_name_cache = &mut FxHashMap();
305+
311306
for mono_item in mono_items {
312307
match mono_item.instantiation_mode(tcx) {
313308
InstantiationMode::GloballyShared { .. } => {}
@@ -319,8 +314,12 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
319314
mono_item.is_generic_fn();
320315

321316
let codegen_unit_name = match characteristic_def_id {
322-
Some(def_id) => compute_codegen_unit_name(tcx, def_id, is_volatile),
323-
None => fallback_cgu_name(tcx),
317+
Some(def_id) => compute_codegen_unit_name(tcx,
318+
cgu_name_builder,
319+
def_id,
320+
is_volatile,
321+
cgu_name_cache),
322+
None => fallback_cgu_name(cgu_name_builder),
324323
};
325324

326325
let codegen_unit = codegen_units.entry(codegen_unit_name.clone())
@@ -344,7 +343,7 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
344343
// always ensure we have at least one CGU; otherwise, if we have a
345344
// crate with just types (for example), we could wind up with no CGU
346345
if codegen_units.is_empty() {
347-
let codegen_unit_name = fallback_cgu_name(tcx);
346+
let codegen_unit_name = fallback_cgu_name(cgu_name_builder);
348347
codegen_units.insert(codegen_unit_name.clone(),
349348
CodegenUnit::new(codegen_unit_name.clone()));
350349
}
@@ -552,9 +551,9 @@ fn default_visibility(tcx: TyCtxt, id: DefId, is_generic: bool) -> Visibility {
552551
}
553552
}
554553

555-
fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<'tcx>,
556-
target_cgu_count: usize,
557-
crate_name: &str) {
554+
fn merge_codegen_units<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>,
555+
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
556+
target_cgu_count: usize) {
558557
assert!(target_cgu_count >= 1);
559558
let codegen_units = &mut initial_partitioning.codegen_units;
560559

@@ -582,14 +581,15 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
582581
}
583582
}
584583

584+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
585585
for (index, cgu) in codegen_units.iter_mut().enumerate() {
586-
cgu.set_name(numbered_codegen_unit_name(crate_name, index));
586+
cgu.set_name(numbered_codegen_unit_name(cgu_name_builder, index));
587587
}
588588
}
589589

590590
fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<'tcx>,
591-
inlining_map: &InliningMap<'tcx>)
592-
-> PostInliningPartitioning<'tcx> {
591+
inlining_map: &InliningMap<'tcx>)
592+
-> PostInliningPartitioning<'tcx> {
593593
let mut new_partitioning = Vec::new();
594594
let mut mono_item_placements = FxHashMap();
595595

@@ -783,46 +783,72 @@ fn characteristic_def_id_of_mono_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
783783
}
784784
}
785785

786-
fn compute_codegen_unit_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
787-
def_id: DefId,
788-
volatile: bool)
789-
-> InternedString {
790-
// Unfortunately we cannot just use the `ty::item_path` infrastructure here
791-
// because we need paths to modules and the DefIds of those are not
792-
// available anymore for external items.
793-
let mut cgu_name = String::with_capacity(64);
794-
795-
let def_path = tcx.def_path(def_id);
796-
cgu_name.push_str(&tcx.crate_name(def_path.krate).as_str());
797-
798-
for part in tcx.def_path(def_id)
799-
.data
800-
.iter()
801-
.take_while(|part| {
802-
match part.data {
803-
DefPathData::Module(..) => true,
804-
_ => false,
805-
}
806-
}) {
807-
cgu_name.push_str("-");
808-
cgu_name.push_str(&part.data.as_interned_str().as_str());
809-
}
786+
type CguNameCache = FxHashMap<(DefId, bool), InternedString>;
787+
788+
fn compute_codegen_unit_name(tcx: TyCtxt,
789+
name_builder: &mut CodegenUnitNameBuilder,
790+
def_id: DefId,
791+
volatile: bool,
792+
cache: &mut CguNameCache)
793+
-> InternedString {
794+
// Find the innermost module that is not nested within a function
795+
let mut current_def_id = def_id;
796+
let mut cgu_def_id = None;
797+
// Walk backwards from the item we want to find the module for:
798+
loop {
799+
let def_key = tcx.def_key(current_def_id);
800+
801+
match def_key.disambiguated_data.data {
802+
DefPathData::Module(..) => {
803+
if cgu_def_id.is_none() {
804+
cgu_def_id = Some(current_def_id);
805+
}
806+
}
807+
DefPathData::CrateRoot { .. } => {
808+
if cgu_def_id.is_none() {
809+
// If we have not found a module yet, take the crate root.
810+
cgu_def_id = Some(DefId {
811+
krate: def_id.krate,
812+
index: CRATE_DEF_INDEX,
813+
});
814+
}
815+
break
816+
}
817+
_ => {
818+
// If we encounter something that is not a module, throw away
819+
// any module that we've found so far because we now know that
820+
// it is nested within something else.
821+
cgu_def_id = None;
822+
}
823+
}
810824

811-
if volatile {
812-
cgu_name.push_str(".volatile");
825+
current_def_id.index = def_key.parent.unwrap();
813826
}
814827

815-
let cgu_name = if tcx.sess.opts.debugging_opts.human_readable_cgu_names {
816-
cgu_name
817-
} else {
818-
CodegenUnit::mangle_name(&cgu_name)
819-
};
828+
let cgu_def_id = cgu_def_id.unwrap();
829+
830+
cache.entry((cgu_def_id, volatile)).or_insert_with(|| {
831+
let def_path = tcx.def_path(cgu_def_id);
832+
833+
let components = def_path
834+
.data
835+
.iter()
836+
.map(|part| part.data.as_interned_str());
837+
838+
let volatile_suffix = if volatile {
839+
Some("volatile")
840+
} else {
841+
None
842+
};
820843

821-
Symbol::intern(&cgu_name[..]).as_interned_str()
844+
name_builder.build_cgu_name(def_path.krate, components, volatile_suffix)
845+
}).clone()
822846
}
823847

824-
fn numbered_codegen_unit_name(crate_name: &str, index: usize) -> InternedString {
825-
Symbol::intern(&format!("{}{}", crate_name, index)).as_interned_str()
848+
fn numbered_codegen_unit_name(name_builder: &mut CodegenUnitNameBuilder,
849+
index: usize)
850+
-> InternedString {
851+
name_builder.build_cgu_name_no_mangle(LOCAL_CRATE, &["cgu"], Some(index))
826852
}
827853

828854
fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

‎src/test/codegen-units/item-collection/drop_in_place_intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#![feature(start)]
1616

17-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<drop_in_place_intrinsic::StructWithDtor[0]> @@ drop_in_place_intrinsic0[Internal]
17+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<drop_in_place_intrinsic::StructWithDtor[0]> @@ drop_in_place_intrinsic-cgu.0[Internal]
1818
struct StructWithDtor(u32);
1919

2020
impl Drop for StructWithDtor {
@@ -26,7 +26,7 @@ impl Drop for StructWithDtor {
2626
#[start]
2727
fn start(_: isize, _: *const *const u8) -> isize {
2828

29-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]; 2]> @@ drop_in_place_intrinsic0[Internal]
29+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]; 2]> @@ drop_in_place_intrinsic-cgu.0[Internal]
3030
let x = [StructWithDtor(0), StructWithDtor(1)];
3131

3232
drop_slice_in_place(&x);
@@ -40,7 +40,7 @@ fn drop_slice_in_place(x: &[StructWithDtor]) {
4040
// This is the interesting thing in this test case: Normally we would
4141
// not have drop-glue for the unsized [StructWithDtor]. This has to be
4242
// generated though when the drop_in_place() intrinsic is used.
43-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]]> @@ drop_in_place_intrinsic0[Internal]
43+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<[drop_in_place_intrinsic::StructWithDtor[0]]> @@ drop_in_place_intrinsic-cgu.0[Internal]
4444
::std::ptr::drop_in_place(x as *const _ as *mut [StructWithDtor]);
4545
}
4646
}

‎src/test/codegen-units/item-collection/generic-drop-glue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ enum EnumNoDrop<T1, T2> {
4747
struct NonGenericNoDrop(i32);
4848

4949
struct NonGenericWithDrop(i32);
50-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue0[Internal]
50+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::NonGenericWithDrop[0]> @@ generic_drop_glue-cgu.0[Internal]
5151

5252
impl Drop for NonGenericWithDrop {
5353
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[2]::drop[0]
@@ -57,11 +57,11 @@ impl Drop for NonGenericWithDrop {
5757
//~ MONO_ITEM fn generic_drop_glue::start[0]
5858
#[start]
5959
fn start(_: isize, _: *const *const u8) -> isize {
60-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue0[Internal]
60+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<i8, char>> @@ generic_drop_glue-cgu.0[Internal]
6161
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<i8, char>
6262
let _ = StructWithDrop { x: 0i8, y: 'a' }.x;
6363

64-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue0[Internal]
64+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructWithDrop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>> @@ generic_drop_glue-cgu.0[Internal]
6565
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[0]::drop[0]<&str, generic_drop_glue::NonGenericNoDrop[0]>
6666
let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y;
6767

@@ -70,17 +70,17 @@ fn start(_: isize, _: *const *const u8) -> isize {
7070

7171
// This is supposed to generate drop-glue because it contains a field that
7272
// needs to be dropped.
73-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue0[Internal]
73+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::StructNoDrop[0]<generic_drop_glue::NonGenericWithDrop[0], f64>> @@ generic_drop_glue-cgu.0[Internal]
7474
let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y;
7575

76-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue0[Internal]
76+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<i32, i64>> @@ generic_drop_glue-cgu.0[Internal]
7777
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<i32, i64>
7878
let _ = match EnumWithDrop::A::<i32, i64>(0) {
7979
EnumWithDrop::A(x) => x,
8080
EnumWithDrop::B(x) => x as i32
8181
};
8282

83-
//~MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue0[Internal]
83+
//~MONO_ITEM fn core::ptr[0]::drop_in_place[0]<generic_drop_glue::EnumWithDrop[0]<f64, f32>> @@ generic_drop_glue-cgu.0[Internal]
8484
//~ MONO_ITEM fn generic_drop_glue::{{impl}}[1]::drop[0]<f64, f32>
8585
let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
8686
EnumWithDrop::A(x) => x,

‎src/test/codegen-units/item-collection/instantiation-through-vtable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ impl<T> Trait for Struct<T> {
3434
fn start(_: isize, _: *const *const u8) -> isize {
3535
let s1 = Struct { _a: 0u32 };
3636

37-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u32>> @@ instantiation_through_vtable0[Internal]
37+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u32>> @@ instantiation_through_vtable-cgu.0[Internal]
3838
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::foo[0]<u32>
3939
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u32>
4040
let _ = &s1 as &Trait;
4141

4242
let s1 = Struct { _a: 0u64 };
43-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u64>> @@ instantiation_through_vtable0[Internal]
43+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<instantiation_through_vtable::Struct[0]<u64>> @@ instantiation_through_vtable-cgu.0[Internal]
4444
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::foo[0]<u64>
4545
//~ MONO_ITEM fn instantiation_through_vtable::{{impl}}[0]::bar[0]<u64>
4646
let _ = &s1 as &Trait;

‎src/test/codegen-units/item-collection/non-generic-drop-glue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![deny(dead_code)]
1616
#![feature(start)]
1717

18-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::StructWithDrop[0]> @@ non_generic_drop_glue0[Internal]
18+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::StructWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
1919
struct StructWithDrop {
2020
x: i32
2121
}
@@ -29,7 +29,7 @@ struct StructNoDrop {
2929
x: i32
3030
}
3131

32-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::EnumWithDrop[0]> @@ non_generic_drop_glue0[Internal]
32+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<non_generic_drop_glue::EnumWithDrop[0]> @@ non_generic_drop_glue-cgu.0[Internal]
3333
enum EnumWithDrop {
3434
A(i32)
3535
}

‎src/test/codegen-units/item-collection/transitive-drop-glue.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#![deny(dead_code)]
1616
#![feature(start)]
1717

18-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Root[0]> @@ transitive_drop_glue0[Internal]
18+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Root[0]> @@ transitive_drop_glue-cgu.0[Internal]
1919
struct Root(Intermediate);
20-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Intermediate[0]> @@ transitive_drop_glue0[Internal]
20+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Intermediate[0]> @@ transitive_drop_glue-cgu.0[Internal]
2121
struct Intermediate(Leaf);
22-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Leaf[0]> @@ transitive_drop_glue0[Internal]
22+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::Leaf[0]> @@ transitive_drop_glue-cgu.0[Internal]
2323
struct Leaf;
2424

2525
impl Drop for Leaf {
@@ -40,15 +40,15 @@ impl<T> Drop for LeafGen<T> {
4040
fn start(_: isize, _: *const *const u8) -> isize {
4141
let _ = Root(Intermediate(Leaf));
4242

43-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<u32>> @@ transitive_drop_glue0[Internal]
44-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<u32>> @@ transitive_drop_glue0[Internal]
45-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<u32>> @@ transitive_drop_glue0[Internal]
43+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
44+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
45+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<u32>> @@ transitive_drop_glue-cgu.0[Internal]
4646
//~ MONO_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<u32>
4747
let _ = RootGen(IntermediateGen(LeafGen(0u32)));
4848

49-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<i16>> @@ transitive_drop_glue0[Internal]
50-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<i16>> @@ transitive_drop_glue0[Internal]
51-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<i16>> @@ transitive_drop_glue0[Internal]
49+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::RootGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
50+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::IntermediateGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
51+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<transitive_drop_glue::LeafGen[0]<i16>> @@ transitive_drop_glue-cgu.0[Internal]
5252
//~ MONO_ITEM fn transitive_drop_glue::{{impl}}[1]::drop[0]<i16>
5353
let _ = RootGen(IntermediateGen(LeafGen(0i16)));
5454

‎src/test/codegen-units/item-collection/tuple-drop-glue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![deny(dead_code)]
1616
#![feature(start)]
1717

18-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<tuple_drop_glue::Dropped[0]> @@ tuple_drop_glue0[Internal]
18+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<tuple_drop_glue::Dropped[0]> @@ tuple_drop_glue-cgu.0[Internal]
1919
struct Dropped;
2020

2121
impl Drop for Dropped {
@@ -26,11 +26,11 @@ impl Drop for Dropped {
2626
//~ MONO_ITEM fn tuple_drop_glue::start[0]
2727
#[start]
2828
fn start(_: isize, _: *const *const u8) -> isize {
29-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(u32, tuple_drop_glue::Dropped[0])> @@ tuple_drop_glue0[Internal]
29+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(u32, tuple_drop_glue::Dropped[0])> @@ tuple_drop_glue-cgu.0[Internal]
3030
let x = (0u32, Dropped);
3131

32-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(i16, (tuple_drop_glue::Dropped[0], bool))> @@ tuple_drop_glue0[Internal]
33-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(tuple_drop_glue::Dropped[0], bool)> @@ tuple_drop_glue0[Internal]
32+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(i16, (tuple_drop_glue::Dropped[0], bool))> @@ tuple_drop_glue-cgu.0[Internal]
33+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<(tuple_drop_glue::Dropped[0], bool)> @@ tuple_drop_glue-cgu.0[Internal]
3434
let x = (0i16, (Dropped, true));
3535

3636
0

‎src/test/codegen-units/item-collection/unsizing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Wrapper<U>> for Wrapper<T>
5959
fn start(_: isize, _: *const *const u8) -> isize {
6060
// simple case
6161
let bool_sized = &true;
62-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<bool> @@ unsizing0[Internal]
62+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<bool> @@ unsizing-cgu.0[Internal]
6363
//~ MONO_ITEM fn unsizing::{{impl}}[0]::foo[0]
6464
let _bool_unsized = bool_sized as &Trait;
6565

6666
let char_sized = &'a';
6767

68-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<char> @@ unsizing0[Internal]
68+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<char> @@ unsizing-cgu.0[Internal]
6969
//~ MONO_ITEM fn unsizing::{{impl}}[1]::foo[0]
7070
let _char_unsized = char_sized as &Trait;
7171

@@ -75,13 +75,13 @@ fn start(_: isize, _: *const *const u8) -> isize {
7575
_b: 2,
7676
_c: 3.0f64
7777
};
78-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<f64> @@ unsizing0[Internal]
78+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<f64> @@ unsizing-cgu.0[Internal]
7979
//~ MONO_ITEM fn unsizing::{{impl}}[2]::foo[0]
8080
let _struct_unsized = struct_sized as &Struct<Trait>;
8181

8282
// custom coercion
8383
let wrapper_sized = Wrapper(&0u32);
84-
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<u32> @@ unsizing0[Internal]
84+
//~ MONO_ITEM fn core::ptr[0]::drop_in_place[0]<u32> @@ unsizing-cgu.0[Internal]
8585
//~ MONO_ITEM fn unsizing::{{impl}}[3]::foo[0]
8686
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;
8787

‎src/test/incremental/issue-39828/auxiliary/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// revisions:rpass1 rpass2
1212
// compile-flags: -Z query-dep-graph
1313

14-
#![rustc_partition_reused(module="__rustc_fallback_codegen_unit", cfg="rpass2")]
14+
#![rustc_partition_reused(module="generic-fallback.cgu", cfg="rpass2")]
1515
#![feature(rustc_attrs)]
1616

1717
#![crate_type="rlib"]

‎src/test/run-make-fulldeps/cross-lang-lto/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib
1616
staticlib: lib.rs
1717
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib.a
1818
$(call EXTRACT_OBJS, liblib.a)
19-
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
19+
for file in $(TMPDIR)/liblib.*.rcgu.o; do $(ASSERT_IS_BITCODE_OBJ) $$file; done
2020

2121
staticlib-fat-lto: lib.rs
2222
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat
2323
$(call EXTRACT_OBJS, liblib-fat-lto.a)
24-
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-fat-lto.lib0.rcgu.o
24+
for file in $(TMPDIR)/liblib-fat-lto.*.rcgu.o; do $(ASSERT_IS_BITCODE_OBJ) $$file; done
2525

2626
staticlib-thin-lto: lib.rs
2727
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin
2828
$(call EXTRACT_OBJS, liblib-thin-lto.a)
29-
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-thin-lto.lib0.rcgu.o
29+
for file in $(TMPDIR)/liblib-thin-lto.*.rcgu.o; do $(ASSERT_IS_BITCODE_OBJ) $$file; done
3030

3131
rlib: lib.rs
3232
$(BUILD_LIB) --crate-type=rlib -o $(TMPDIR)/liblib.rlib
3333
$(call EXTRACT_OBJS, liblib.rlib)
34-
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
34+
for file in $(TMPDIR)/liblib.*.rcgu.o; do $(ASSERT_IS_BITCODE_OBJ) $$file; done
3535

3636
cdylib: lib.rs
3737
$(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o

‎src/test/run-make-fulldeps/extra-filename-with-temp-outputs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
all:
44
$(RUSTC) -C extra-filename=bar foo.rs -C save-temps
5-
rm $(TMPDIR)/foobar.foo0.rcgu.o
5+
rm $(TMPDIR)/foobar.foo*0.rcgu.o
66
rm $(TMPDIR)/$(call BIN,foobar)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
warning: Linking globals named 'foo': symbol multiply defined!
22

3-
error: failed to load bc of "lto_duplicate_symbols10-8787f43e282added376259c1adb08b80.rs":
3+
error: failed to load bc of "lto_duplicate_symbols1.3a1fbbbh-cgu.0":
44

55
error: aborting due to previous error
66

‎src/tools/compiletest/src/runtest.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,12 +2209,12 @@ impl<'test> TestCx<'test> {
22092209
.stdout
22102210
.lines()
22112211
.filter(|line| line.starts_with(PREFIX))
2212-
.map(str_to_mono_item)
2212+
.map(|line| str_to_mono_item(line, true))
22132213
.collect();
22142214

22152215
let expected: Vec<MonoItem> = errors::load_errors(&self.testpaths.file, None)
22162216
.iter()
2217-
.map(|e| str_to_mono_item(&e.msg[..]))
2217+
.map(|e| str_to_mono_item(&e.msg[..], false))
22182218
.collect();
22192219

22202220
let mut missing = Vec::new();
@@ -2299,14 +2299,14 @@ impl<'test> TestCx<'test> {
22992299
}
23002300

23012301
// [MONO_ITEM] name [@@ (cgu)+]
2302-
fn str_to_mono_item(s: &str) -> MonoItem {
2302+
fn str_to_mono_item(s: &str, cgu_has_crate_disambiguator: bool) -> MonoItem {
23032303
let s = if s.starts_with(PREFIX) {
23042304
(&s[PREFIX.len()..]).trim()
23052305
} else {
23062306
s.trim()
23072307
};
23082308

2309-
let full_string = format!("{}{}", PREFIX, s.trim().to_owned());
2309+
let full_string = format!("{}{}", PREFIX, s);
23102310

23112311
let parts: Vec<&str> = s
23122312
.split(CGU_MARKER)
@@ -2323,7 +2323,13 @@ impl<'test> TestCx<'test> {
23232323
.split(' ')
23242324
.map(str::trim)
23252325
.filter(|s| !s.is_empty())
2326-
.map(str::to_owned)
2326+
.map(|s| {
2327+
if cgu_has_crate_disambiguator {
2328+
remove_crate_disambiguator_from_cgu(s)
2329+
} else {
2330+
s.to_string()
2331+
}
2332+
})
23272333
.collect()
23282334
} else {
23292335
HashSet::new()
@@ -2348,6 +2354,23 @@ impl<'test> TestCx<'test> {
23482354

23492355
string
23502356
}
2357+
2358+
fn remove_crate_disambiguator_from_cgu(cgu: &str) -> String {
2359+
// The first '.' is the start of the crate disambiguator
2360+
let disambiguator_start = cgu.find('.')
2361+
.expect("Could not find start of crate disambiguator in CGU spec");
2362+
2363+
// The first non-alphanumeric character is the end of the disambiguator
2364+
let disambiguator_end = cgu[disambiguator_start + 1 ..]
2365+
.find(|c| !char::is_alphanumeric(c))
2366+
.expect("Could not find end of crate disambiguator in CGU spec")
2367+
+ disambiguator_start + 1;
2368+
2369+
let mut result = cgu[0 .. disambiguator_start].to_string();
2370+
result.push_str(&cgu[disambiguator_end ..]);
2371+
2372+
result
2373+
}
23512374
}
23522375

23532376
fn init_incremental_test(&self) {

0 commit comments

Comments
 (0)
Please sign in to comment.