Skip to content

Commit a619901

Browse files
committed
trans: save metadata even with -Z no-trans.
1 parent 04464db commit a619901

File tree

6 files changed

+58
-33
lines changed

6 files changed

+58
-33
lines changed

src/librustc/session/config.rs

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

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

src/librustc_driver/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
511511
control.after_write_deps.stop = Compilation::Stop;
512512
}
513513

514-
if sess.opts.no_trans {
515-
control.after_analysis.stop = Compilation::Stop;
516-
}
517-
518514
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
519515
control.after_llvm.stop = Compilation::Stop;
520516
}

src/librustc_trans/back/link.rs

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ pub fn link_binary(sess: &Session,
188188

189189
let mut out_filenames = Vec::new();
190190
for &crate_type in sess.crate_types.borrow().iter() {
191+
// Ignore executable crates if we have -Z no-trans, as they will error.
192+
if sess.opts.no_trans && crate_type == config::CrateTypeExecutable {
193+
continue;
194+
}
195+
191196
if invalid_output_for_target(sess, crate_type) {
192197
bug!("invalid output type `{:?}` for target os `{}`",
193198
crate_type, sess.opts.target_triple);

src/librustc_trans/base.rs

+41-28
Original file line numberDiff line numberDiff line change
@@ -2432,11 +2432,8 @@ fn contains_null(s: &str) -> bool {
24322432
s.bytes().any(|b| b == 0)
24332433
}
24342434

2435-
pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
2436-
krate: &hir::Crate,
2437-
reachable: &NodeSet,
2438-
mir_map: &MirMap<'tcx>)
2439-
-> Vec<u8> {
2435+
fn write_metadata(cx: &SharedCrateContext,
2436+
reachable_ids: &NodeSet) -> Vec<u8> {
24402437
use flate;
24412438

24422439
let any_library = cx.sess()
@@ -2452,9 +2449,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
24522449
let metadata = cstore.encode_metadata(cx.tcx(),
24532450
cx.export_map(),
24542451
cx.link_meta(),
2455-
reachable,
2456-
mir_map,
2457-
krate);
2452+
reachable_ids,
2453+
cx.mir_map(),
2454+
cx.tcx().map.krate());
24582455
let mut compressed = cstore.metadata_encoding_version().to_vec();
24592456
compressed.extend_from_slice(&flate::deflate_bytes(&metadata));
24602457

@@ -2639,10 +2636,12 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
26392636
node: hir::ItemStatic(..), .. }) |
26402637
hir_map::NodeItem(&hir::Item {
26412638
node: hir::ItemFn(..), .. }) |
2642-
hir_map::NodeTraitItem(&hir::TraitItem {
2643-
node: hir::MethodTraitItem(_, Some(_)), .. }) |
26442639
hir_map::NodeImplItem(&hir::ImplItem {
2645-
node: hir::ImplItemKind::Method(..), .. }) => true,
2640+
node: hir::ImplItemKind::Method(..), .. }) => {
2641+
let def_id = scx.tcx().map.local_def_id(id);
2642+
let scheme = scx.tcx().lookup_item_type(def_id);
2643+
scheme.generics.types.is_empty()
2644+
}
26462645

26472646
_ => false
26482647
}
@@ -2686,13 +2685,44 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26862685
check_overflow,
26872686
check_dropflag);
26882687

2688+
let reachable_symbol_ids = filter_reachable_ids(&shared_ccx);
2689+
2690+
// Translate the metadata.
2691+
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
2692+
write_metadata(&shared_ccx, &reachable_symbol_ids)
2693+
});
2694+
2695+
let metadata_module = ModuleTranslation {
2696+
llcx: shared_ccx.metadata_llcx(),
2697+
llmod: shared_ccx.metadata_llmod(),
2698+
};
2699+
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
2700+
26892701
let codegen_units = collect_and_partition_translation_items(&shared_ccx);
26902702
let codegen_unit_count = codegen_units.len();
26912703
assert!(tcx.sess.opts.cg.codegen_units == codegen_unit_count ||
26922704
tcx.sess.opts.debugging_opts.incremental.is_some());
26932705

26942706
let crate_context_list = CrateContextList::new(&shared_ccx, codegen_units);
26952707

2708+
let modules = crate_context_list.iter()
2709+
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
2710+
.collect();
2711+
2712+
// Skip crate items and just output metadata in -Z no-trans mode.
2713+
if tcx.sess.opts.no_trans {
2714+
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
2715+
return CrateTranslation {
2716+
modules: modules,
2717+
metadata_module: metadata_module,
2718+
link: link_meta,
2719+
metadata: metadata,
2720+
reachable: vec![],
2721+
no_builtins: no_builtins,
2722+
linker_info: linker_info
2723+
};
2724+
}
2725+
26962726
{
26972727
let ccx = crate_context_list.get_ccx(0);
26982728

@@ -2722,13 +2752,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27222752
}
27232753
}
27242754

2725-
let reachable_symbol_ids = filter_reachable_ids(&shared_ccx);
2726-
2727-
// Translate the metadata.
2728-
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
2729-
write_metadata(&shared_ccx, krate, &reachable_symbol_ids, mir_map)
2730-
});
2731-
27322755
if shared_ccx.sess().trans_stats() {
27332756
let stats = shared_ccx.stats();
27342757
println!("--- trans stats ---");
@@ -2758,10 +2781,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27582781
}
27592782
}
27602783

2761-
let modules = crate_context_list.iter()
2762-
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
2763-
.collect();
2764-
27652784
let sess = shared_ccx.sess();
27662785
let mut reachable_symbols = reachable_symbol_ids.iter().map(|&id| {
27672786
let def_id = shared_ccx.tcx().map.local_def_id(id);
@@ -2802,12 +2821,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
28022821
create_imps(&crate_context_list);
28032822
}
28042823

2805-
let metadata_module = ModuleTranslation {
2806-
llcx: shared_ccx.metadata_llcx(),
2807-
llmod: shared_ccx.metadata_llmod(),
2808-
};
2809-
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
2810-
28112824
let linker_info = LinkerInfo::new(&shared_ccx, &reachable_symbols);
28122825
CrateTranslation {
28132826
modules: modules,

src/librustc_trans/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
502502
&self.symbol_hasher
503503
}
504504

505+
pub fn mir_map(&self) -> &MirMap<'tcx> {
506+
&self.mir_map
507+
}
508+
505509
pub fn metadata_symbol_name(&self) -> String {
506510
format!("rust_metadata_{}_{}",
507511
self.link_meta().crate_name,

src/tools/compiletest/src/runtest.rs

+7
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,16 @@ actual:\n\
371371
} else {
372372
&*self.config.target
373373
};
374+
375+
let out_dir = self.output_base_name().with_extension("pretty-out");
376+
let _ = fs::remove_dir_all(&out_dir);
377+
self.create_dir_racy(&out_dir);
378+
374379
// FIXME (#9639): This needs to handle non-utf8 paths
375380
let mut args = vec!("-".to_owned(),
376381
"-Zno-trans".to_owned(),
382+
"--out-dir".to_owned(),
383+
out_dir.to_str().unwrap().to_owned(),
377384
format!("--target={}", target),
378385
"-L".to_owned(),
379386
self.config.build_base.to_str().unwrap().to_owned(),

0 commit comments

Comments
 (0)