trans: save metadata even with -Z no-trans.

This commit is contained in:
Eduard Burtescu 2016-05-25 08:46:36 +03:00
parent 04464db954
commit a619901e3d
6 changed files with 58 additions and 33 deletions

View File

@ -1104,7 +1104,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let no_analysis = debugging_opts.no_analysis;
let mut output_types = HashMap::new();
if !debugging_opts.parse_only && !no_trans {
if !debugging_opts.parse_only {
for list in matches.opt_strs("emit") {
for output_type in list.split(',') {
let mut parts = output_type.splitn(2, '=');

View File

@ -511,10 +511,6 @@ fn build_controller(&mut self,
control.after_write_deps.stop = Compilation::Stop;
}
if sess.opts.no_trans {
control.after_analysis.stop = Compilation::Stop;
}
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
control.after_llvm.stop = Compilation::Stop;
}

View File

@ -188,6 +188,11 @@ pub fn link_binary(sess: &Session,
let mut out_filenames = Vec::new();
for &crate_type in sess.crate_types.borrow().iter() {
// Ignore executable crates if we have -Z no-trans, as they will error.
if sess.opts.no_trans && crate_type == config::CrateTypeExecutable {
continue;
}
if invalid_output_for_target(sess, crate_type) {
bug!("invalid output type `{:?}` for target os `{}`",
crate_type, sess.opts.target_triple);

View File

@ -2432,11 +2432,8 @@ fn contains_null(s: &str) -> bool {
s.bytes().any(|b| b == 0)
}
pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
krate: &hir::Crate,
reachable: &NodeSet,
mir_map: &MirMap<'tcx>)
-> Vec<u8> {
fn write_metadata(cx: &SharedCrateContext,
reachable_ids: &NodeSet) -> Vec<u8> {
use flate;
let any_library = cx.sess()
@ -2452,9 +2449,9 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
let metadata = cstore.encode_metadata(cx.tcx(),
cx.export_map(),
cx.link_meta(),
reachable,
mir_map,
krate);
reachable_ids,
cx.mir_map(),
cx.tcx().map.krate());
let mut compressed = cstore.metadata_encoding_version().to_vec();
compressed.extend_from_slice(&flate::deflate_bytes(&metadata));
@ -2639,10 +2636,12 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
node: hir::ItemStatic(..), .. }) |
hir_map::NodeItem(&hir::Item {
node: hir::ItemFn(..), .. }) |
hir_map::NodeTraitItem(&hir::TraitItem {
node: hir::MethodTraitItem(_, Some(_)), .. }) |
hir_map::NodeImplItem(&hir::ImplItem {
node: hir::ImplItemKind::Method(..), .. }) => true,
node: hir::ImplItemKind::Method(..), .. }) => {
let def_id = scx.tcx().map.local_def_id(id);
let scheme = scx.tcx().lookup_item_type(def_id);
scheme.generics.types.is_empty()
}
_ => false
}
@ -2686,6 +2685,19 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
check_overflow,
check_dropflag);
let reachable_symbol_ids = filter_reachable_ids(&shared_ccx);
// Translate the metadata.
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
write_metadata(&shared_ccx, &reachable_symbol_ids)
});
let metadata_module = ModuleTranslation {
llcx: shared_ccx.metadata_llcx(),
llmod: shared_ccx.metadata_llmod(),
};
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
let codegen_units = collect_and_partition_translation_items(&shared_ccx);
let codegen_unit_count = codegen_units.len();
assert!(tcx.sess.opts.cg.codegen_units == codegen_unit_count ||
@ -2693,6 +2705,24 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let crate_context_list = CrateContextList::new(&shared_ccx, codegen_units);
let modules = crate_context_list.iter()
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
.collect();
// Skip crate items and just output metadata in -Z no-trans mode.
if tcx.sess.opts.no_trans {
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
return CrateTranslation {
modules: modules,
metadata_module: metadata_module,
link: link_meta,
metadata: metadata,
reachable: vec![],
no_builtins: no_builtins,
linker_info: linker_info
};
}
{
let ccx = crate_context_list.get_ccx(0);
@ -2722,13 +2752,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}
let reachable_symbol_ids = filter_reachable_ids(&shared_ccx);
// Translate the metadata.
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
write_metadata(&shared_ccx, krate, &reachable_symbol_ids, mir_map)
});
if shared_ccx.sess().trans_stats() {
let stats = shared_ccx.stats();
println!("--- trans stats ---");
@ -2758,10 +2781,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}
let modules = crate_context_list.iter()
.map(|ccx| ModuleTranslation { llcx: ccx.llcx(), llmod: ccx.llmod() })
.collect();
let sess = shared_ccx.sess();
let mut reachable_symbols = reachable_symbol_ids.iter().map(|&id| {
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>,
create_imps(&crate_context_list);
}
let metadata_module = ModuleTranslation {
llcx: shared_ccx.metadata_llcx(),
llmod: shared_ccx.metadata_llmod(),
};
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
let linker_info = LinkerInfo::new(&shared_ccx, &reachable_symbols);
CrateTranslation {
modules: modules,

View File

@ -502,6 +502,10 @@ pub fn symbol_hasher(&self) -> &RefCell<Sha256> {
&self.symbol_hasher
}
pub fn mir_map(&self) -> &MirMap<'tcx> {
&self.mir_map
}
pub fn metadata_symbol_name(&self) -> String {
format!("rust_metadata_{}_{}",
self.link_meta().crate_name,

View File

@ -371,9 +371,16 @@ fn make_typecheck_args(&self) -> ProcArgs {
} else {
&*self.config.target
};
let out_dir = self.output_base_name().with_extension("pretty-out");
let _ = fs::remove_dir_all(&out_dir);
self.create_dir_racy(&out_dir);
// FIXME (#9639): This needs to handle non-utf8 paths
let mut args = vec!("-".to_owned(),
"-Zno-trans".to_owned(),
"--out-dir".to_owned(),
out_dir.to_str().unwrap().to_owned(),
format!("--target={}", target),
"-L".to_owned(),
self.config.build_base.to_str().unwrap().to_owned(),