Skip to content

Commit 344681d

Browse files
trans: Split LocalCrateContext ownership out of SharedCrateContext.
1 parent 102bab3 commit 344681d

File tree

2 files changed

+151
-134
lines changed

2 files changed

+151
-134
lines changed

src/librustc_trans/base.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use common::{node_id_type, fulfill_obligation};
6969
use common::{type_is_immediate, type_is_zero_size, val_ty};
7070
use common;
7171
use consts;
72-
use context::SharedCrateContext;
72+
use context::{SharedCrateContext, CrateContextList};
7373
use controlflow;
7474
use datum;
7575
use debuginfo::{self, DebugLoc, ToDebugLoc};
@@ -2523,7 +2523,7 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
25232523

25242524
/// Find any symbols that are defined in one compilation unit, but not declared
25252525
/// in any other compilation unit. Give these symbols internal linkage.
2526-
fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet<&str>) {
2526+
fn internalize_symbols(cx: &CrateContextList, reachable: &HashSet<&str>) {
25272527
unsafe {
25282528
let mut declared = HashSet::new();
25292529

@@ -2578,12 +2578,12 @@ fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet<&str>) {
25782578
// when using MSVC linker. We do this only for data, as linker can fix up
25792579
// code references on its own.
25802580
// See #26591, #27438
2581-
fn create_imps(cx: &SharedCrateContext) {
2581+
fn create_imps(cx: &CrateContextList) {
25822582
// The x86 ABI seems to require that leading underscores are added to symbol
25832583
// names, so we need an extra underscore on 32-bit. There's also a leading
25842584
// '\x01' here which disables LLVM's symbol mangling (e.g. no extra
25852585
// underscores added in front).
2586-
let prefix = if cx.sess().target.target.target_pointer_width == "32" {
2586+
let prefix = if cx.shared().sess().target.target.target_pointer_width == "32" {
25872587
"\x01__imp__"
25882588
} else {
25892589
"\x01__imp_"
@@ -2715,10 +2715,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27152715

27162716
let link_meta = link::build_link_meta(&tcx, name);
27172717

2718-
let codegen_units = tcx.sess.opts.cg.codegen_units;
2719-
let shared_ccx = SharedCrateContext::new(&link_meta.crate_name,
2720-
codegen_units,
2721-
tcx,
2718+
let shared_ccx = SharedCrateContext::new(tcx,
27222719
&mir_map,
27232720
export_map,
27242721
Sha256::new(),
@@ -2727,8 +2724,11 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27272724
check_overflow,
27282725
check_dropflag);
27292726

2727+
let codegen_units = tcx.sess.opts.cg.codegen_units;
2728+
let crate_context_list = CrateContextList::new(&shared_ccx, codegen_units);
2729+
27302730
{
2731-
let ccx = shared_ccx.get_ccx(0);
2731+
let ccx = crate_context_list.get_ccx(0);
27322732
collect_translation_items(&ccx);
27332733

27342734
// Translate all items. See `TransModVisitor` for
@@ -2744,7 +2744,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27442744
symbol_names_test::report_symbol_names(&ccx);
27452745
}
27462746

2747-
for ccx in shared_ccx.iter() {
2747+
for ccx in crate_context_list.iter() {
27482748
if ccx.sess().opts.debuginfo != NoDebugInfo {
27492749
debuginfo::finalize(&ccx);
27502750
}
@@ -2793,7 +2793,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27932793
}
27942794
}
27952795

2796-
let modules = shared_ccx.iter()
2796+
let modules = crate_context_list.iter()
27972797
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
27982798
.collect();
27992799

@@ -2820,13 +2820,13 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
28202820
}
28212821

28222822
if codegen_units > 1 {
2823-
internalize_symbols(&shared_ccx,
2823+
internalize_symbols(&crate_context_list,
28242824
&reachable_symbols.iter().map(|x| &x[..]).collect());
28252825
}
28262826

28272827
if sess.target.target.options.is_like_msvc &&
28282828
sess.crate_types.borrow().iter().any(|ct| *ct == config::CrateTypeRlib) {
2829-
create_imps(&shared_ccx);
2829+
create_imps(&crate_context_list);
28302830
}
28312831

28322832
let metadata_module = ModuleTranslation {

0 commit comments

Comments
 (0)