trans: save metadata even with -Z no-trans.
This commit is contained in:
parent
04464db954
commit
a619901e3d
6 changed files with 58 additions and 33 deletions
|
@ -1104,7 +1104,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||||
let no_analysis = debugging_opts.no_analysis;
|
let no_analysis = debugging_opts.no_analysis;
|
||||||
|
|
||||||
let mut output_types = HashMap::new();
|
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 list in matches.opt_strs("emit") {
|
||||||
for output_type in list.split(',') {
|
for output_type in list.split(',') {
|
||||||
let mut parts = output_type.splitn(2, '=');
|
let mut parts = output_type.splitn(2, '=');
|
||||||
|
|
|
@ -511,10 +511,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
||||||
control.after_write_deps.stop = Compilation::Stop;
|
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) {
|
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {
|
||||||
control.after_llvm.stop = Compilation::Stop;
|
control.after_llvm.stop = Compilation::Stop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,6 +188,11 @@ pub fn link_binary(sess: &Session,
|
||||||
|
|
||||||
let mut out_filenames = Vec::new();
|
let mut out_filenames = Vec::new();
|
||||||
for &crate_type in sess.crate_types.borrow().iter() {
|
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) {
|
if invalid_output_for_target(sess, crate_type) {
|
||||||
bug!("invalid output type `{:?}` for target os `{}`",
|
bug!("invalid output type `{:?}` for target os `{}`",
|
||||||
crate_type, sess.opts.target_triple);
|
crate_type, sess.opts.target_triple);
|
||||||
|
|
|
@ -2432,11 +2432,8 @@ fn contains_null(s: &str) -> bool {
|
||||||
s.bytes().any(|b| b == 0)
|
s.bytes().any(|b| b == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
|
fn write_metadata(cx: &SharedCrateContext,
|
||||||
krate: &hir::Crate,
|
reachable_ids: &NodeSet) -> Vec<u8> {
|
||||||
reachable: &NodeSet,
|
|
||||||
mir_map: &MirMap<'tcx>)
|
|
||||||
-> Vec<u8> {
|
|
||||||
use flate;
|
use flate;
|
||||||
|
|
||||||
let any_library = cx.sess()
|
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(),
|
let metadata = cstore.encode_metadata(cx.tcx(),
|
||||||
cx.export_map(),
|
cx.export_map(),
|
||||||
cx.link_meta(),
|
cx.link_meta(),
|
||||||
reachable,
|
reachable_ids,
|
||||||
mir_map,
|
cx.mir_map(),
|
||||||
krate);
|
cx.tcx().map.krate());
|
||||||
let mut compressed = cstore.metadata_encoding_version().to_vec();
|
let mut compressed = cstore.metadata_encoding_version().to_vec();
|
||||||
compressed.extend_from_slice(&flate::deflate_bytes(&metadata));
|
compressed.extend_from_slice(&flate::deflate_bytes(&metadata));
|
||||||
|
|
||||||
|
@ -2639,10 +2636,12 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
|
||||||
node: hir::ItemStatic(..), .. }) |
|
node: hir::ItemStatic(..), .. }) |
|
||||||
hir_map::NodeItem(&hir::Item {
|
hir_map::NodeItem(&hir::Item {
|
||||||
node: hir::ItemFn(..), .. }) |
|
node: hir::ItemFn(..), .. }) |
|
||||||
hir_map::NodeTraitItem(&hir::TraitItem {
|
|
||||||
node: hir::MethodTraitItem(_, Some(_)), .. }) |
|
|
||||||
hir_map::NodeImplItem(&hir::ImplItem {
|
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
|
_ => false
|
||||||
}
|
}
|
||||||
|
@ -2686,6 +2685,19 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
check_overflow,
|
check_overflow,
|
||||||
check_dropflag);
|
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_units = collect_and_partition_translation_items(&shared_ccx);
|
||||||
let codegen_unit_count = codegen_units.len();
|
let codegen_unit_count = codegen_units.len();
|
||||||
assert!(tcx.sess.opts.cg.codegen_units == codegen_unit_count ||
|
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 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);
|
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() {
|
if shared_ccx.sess().trans_stats() {
|
||||||
let stats = shared_ccx.stats();
|
let stats = shared_ccx.stats();
|
||||||
println!("--- trans 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 sess = shared_ccx.sess();
|
||||||
let mut reachable_symbols = reachable_symbol_ids.iter().map(|&id| {
|
let mut reachable_symbols = reachable_symbol_ids.iter().map(|&id| {
|
||||||
let def_id = shared_ccx.tcx().map.local_def_id(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);
|
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);
|
let linker_info = LinkerInfo::new(&shared_ccx, &reachable_symbols);
|
||||||
CrateTranslation {
|
CrateTranslation {
|
||||||
modules: modules,
|
modules: modules,
|
||||||
|
|
|
@ -502,6 +502,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||||
&self.symbol_hasher
|
&self.symbol_hasher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mir_map(&self) -> &MirMap<'tcx> {
|
||||||
|
&self.mir_map
|
||||||
|
}
|
||||||
|
|
||||||
pub fn metadata_symbol_name(&self) -> String {
|
pub fn metadata_symbol_name(&self) -> String {
|
||||||
format!("rust_metadata_{}_{}",
|
format!("rust_metadata_{}_{}",
|
||||||
self.link_meta().crate_name,
|
self.link_meta().crate_name,
|
||||||
|
|
|
@ -371,9 +371,16 @@ actual:\n\
|
||||||
} else {
|
} else {
|
||||||
&*self.config.target
|
&*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
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||||
let mut args = vec!("-".to_owned(),
|
let mut args = vec!("-".to_owned(),
|
||||||
"-Zno-trans".to_owned(),
|
"-Zno-trans".to_owned(),
|
||||||
|
"--out-dir".to_owned(),
|
||||||
|
out_dir.to_str().unwrap().to_owned(),
|
||||||
format!("--target={}", target),
|
format!("--target={}", target),
|
||||||
"-L".to_owned(),
|
"-L".to_owned(),
|
||||||
self.config.build_base.to_str().unwrap().to_owned(),
|
self.config.build_base.to_str().unwrap().to_owned(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue