Skip to content

Commit adee551

Browse files
committed
trans: save metadata even with -Z no-trans.
1 parent 749494e commit adee551

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11031103
let no_analysis = debugging_opts.no_analysis;
11041104

11051105
let mut output_types = HashMap::new();
1106-
if !debugging_opts.parse_only && !no_trans {
1106+
if !debugging_opts.parse_only {
11071107
for list in matches.opt_strs("emit") {
11081108
for output_type in list.split(',') {
11091109
let mut parts = output_type.splitn(2, '=');

src/librustc_driver/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
504504
control.after_write_deps.stop = Compilation::Stop;
505505
}
506506

507-
if sess.opts.no_trans {
508-
control.after_analysis.stop = Compilation::Stop;
509-
}
510-
511507
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
512508
control.after_llvm.stop = Compilation::Stop;
513509
}

src/librustc_trans/base.rs

+32-22
Original file line numberDiff line numberDiff line change
@@ -2424,11 +2424,7 @@ fn contains_null(s: &str) -> bool {
24242424
s.bytes().any(|b| b == 0)
24252425
}
24262426

2427-
pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
2428-
krate: &hir::Crate,
2429-
reachable: &NodeSet,
2430-
mir_map: &MirMap<'tcx>)
2431-
-> Vec<u8> {
2427+
pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>) -> Vec<u8> {
24322428
use flate;
24332429

24342430
let any_library = cx.sess()
@@ -2444,9 +2440,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
24442440
let metadata = cstore.encode_metadata(cx.tcx(),
24452441
cx.export_map(),
24462442
cx.link_meta(),
2447-
reachable,
2448-
mir_map,
2449-
krate);
2443+
cx.reachable(),
2444+
cx.mir_map(),
2445+
cx.tcx().map.krate());
24502446
let mut compressed = cstore.metadata_encoding_version().to_vec();
24512447
compressed.extend_from_slice(&flate::deflate_bytes(&metadata));
24522448

@@ -2679,6 +2675,16 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26792675
reachable,
26802676
check_overflow,
26812677
check_dropflag);
2678+
// Translate the metadata.
2679+
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
2680+
write_metadata(&shared_ccx)
2681+
});
2682+
2683+
let metadata_module = ModuleTranslation {
2684+
llcx: shared_ccx.metadata_llcx(),
2685+
llmod: shared_ccx.metadata_llmod(),
2686+
};
2687+
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
26822688

26832689
let codegen_units = collect_and_partition_translation_items(&shared_ccx);
26842690
let codegen_unit_count = codegen_units.len();
@@ -2687,6 +2693,24 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26872693

26882694
let crate_context_list = CrateContextList::new(&shared_ccx, codegen_units);
26892695

2696+
let modules = crate_context_list.iter()
2697+
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
2698+
.collect();
2699+
2700+
// Skip crate items and just output metadata in -Z no-trans mode.
2701+
if tcx.sess.opts.no_trans {
2702+
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
2703+
return CrateTranslation {
2704+
modules: modules,
2705+
metadata_module: metadata_module,
2706+
link: link_meta,
2707+
metadata: metadata,
2708+
reachable: vec![],
2709+
no_builtins: no_builtins,
2710+
linker_info: linker_info
2711+
};
2712+
}
2713+
26902714
{
26912715
let ccx = crate_context_list.get_ccx(0);
26922716

@@ -2718,10 +2742,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27182742

27192743
let reachable_symbol_ids = filter_reachable_ids(&shared_ccx);
27202744

2721-
// Translate the metadata.
2722-
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
2723-
write_metadata(&shared_ccx, krate, &reachable_symbol_ids, mir_map)
2724-
});
27252745

27262746
if shared_ccx.sess().trans_stats() {
27272747
let stats = shared_ccx.stats();
@@ -2752,10 +2772,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27522772
}
27532773
}
27542774

2755-
let modules = crate_context_list.iter()
2756-
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
2757-
.collect();
2758-
27592775
let sess = shared_ccx.sess();
27602776
let mut reachable_symbols = reachable_symbol_ids.iter().map(|&id| {
27612777
let def_id = shared_ccx.tcx().map.local_def_id(id);
@@ -2789,12 +2805,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27892805
create_imps(&crate_context_list);
27902806
}
27912807

2792-
let metadata_module = ModuleTranslation {
2793-
llcx: shared_ccx.metadata_llcx(),
2794-
llmod: shared_ccx.metadata_llmod(),
2795-
};
2796-
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
2797-
27982808
let linker_info = LinkerInfo::new(&shared_ccx, &reachable_symbols);
27992809
CrateTranslation {
28002810
modules: modules,

src/librustc_trans/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
485485
pub fn symbol_hasher(&self) -> &RefCell<Sha256> {
486486
&self.symbol_hasher
487487
}
488+
489+
pub fn mir_map(&self) -> &MirMap<'tcx> {
490+
&self.mir_map
491+
}
488492
}
489493

490494
impl<'tcx> LocalCrateContext<'tcx> {

0 commit comments

Comments
 (0)