Skip to content

Commit b2ea54d

Browse files
trans: Split LocalCrateContext ownership out of SharedCrateContext.
1 parent faca79f commit b2ea54d

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
@@ -68,7 +68,7 @@ use common::{node_id_type, fulfill_obligation};
6868
use common::{type_is_immediate, type_is_zero_size, val_ty};
6969
use common;
7070
use consts;
71-
use context::SharedCrateContext;
71+
use context::{SharedCrateContext, CrateContextList};
7272
use controlflow;
7373
use datum;
7474
use debuginfo::{self, DebugLoc, ToDebugLoc};
@@ -2522,7 +2522,7 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
25222522

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

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

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

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

2726+
let codegen_units = tcx.sess.opts.cg.codegen_units;
2727+
let crate_context_list = CrateContextList::new(&shared_ccx, codegen_units);
2728+
27292729
{
2730-
let ccx = shared_ccx.get_ccx(0);
2730+
let ccx = crate_context_list.get_ccx(0);
27312731
collect_translation_items(&ccx);
27322732

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

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

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

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

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

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

28312831
let metadata_module = ModuleTranslation {

0 commit comments

Comments
 (0)