Skip to content

Commit 3fc0936

Browse files
committedApr 23, 2019
Don't generate unnecessary rmeta files.
1 parent 4eff852 commit 3fc0936

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed
 

‎src/librustc_codegen_ssa/back/link.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
8383
for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref()) {
8484
remove(sess, obj);
8585
}
86-
if let Some(ref obj) = codegen_results.metadata_module.object {
87-
remove(sess, obj);
88-
}
89-
if let Some(ref allocator) = codegen_results.allocator_module {
90-
if let Some(ref obj) = allocator.object {
86+
if let Some(ref metadata_module) = codegen_results.metadata_module {
87+
if let Some(ref obj) = metadata_module.object {
88+
remove(sess, obj);
89+
}
90+
}
91+
if let Some(ref allocator_module) = codegen_results.allocator_module {
92+
if let Some(ref obj) = allocator_module.object {
9193
remove(sess, obj);
9294
}
93-
if let Some(ref bc) = allocator.bytecode_compressed {
95+
if let Some(ref bc) = allocator_module.bytecode_compressed {
9496
remove(sess, bc);
9597
}
9698
}
@@ -1067,7 +1069,10 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
10671069
// object file, so we link that in here.
10681070
if crate_type == config::CrateType::Dylib ||
10691071
crate_type == config::CrateType::ProcMacro {
1070-
if let Some(obj) = codegen_results.metadata_module.object.as_ref() {
1072+
let obj = codegen_results.metadata_module
1073+
.as_ref()
1074+
.and_then(|m| m.object.as_ref());
1075+
if let Some(obj) = obj {
10711076
cmd.add_object(obj);
10721077
}
10731078
}

‎src/librustc_codegen_ssa/back/write.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
350350

351351
pub struct CompiledModules {
352352
pub modules: Vec<CompiledModule>,
353-
pub metadata_module: CompiledModule,
353+
pub metadata_module: Option<CompiledModule>,
354354
pub allocator_module: Option<CompiledModule>,
355355
}
356356

@@ -682,8 +682,10 @@ fn produce_final_output_artifacts(sess: &Session,
682682
}
683683

684684
if !user_wants_bitcode {
685-
if let Some(ref path) = compiled_modules.metadata_module.bytecode {
686-
remove(sess, &path);
685+
if let Some(ref metadata_module) = compiled_modules.metadata_module {
686+
if let Some(ref path) = metadata_module.bytecode {
687+
remove(sess, &path);
688+
}
687689
}
688690

689691
if let Some(ref allocator_module) = compiled_modules.allocator_module {
@@ -1564,9 +1566,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
15641566
// out deterministic results.
15651567
compiled_modules.sort_by(|a, b| a.name.cmp(&b.name));
15661568

1567-
let compiled_metadata_module = compiled_metadata_module
1568-
.expect("Metadata module not compiled?");
1569-
15701569
Ok(CompiledModules {
15711570
modules: compiled_modules,
15721571
metadata_module: compiled_metadata_module,

‎src/librustc_codegen_ssa/base.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
2525
use rustc::ty::query::Providers;
2626
use rustc::middle::cstore::{self, LinkagePreference};
2727
use rustc::util::common::{time, print_time_passes_entry};
28-
use rustc::session::config::{self, EntryFnType, Lto};
28+
use rustc::session::config::{self, CrateType, EntryFnType, Lto};
2929
use rustc::session::Session;
3030
use rustc_mir::monomorphize::item::DefPathBasedNames;
3131
use rustc_mir::monomorphize::Instance;
@@ -550,12 +550,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
550550
});
551551
tcx.sess.profiler(|p| p.end_activity("codegen crate metadata"));
552552

553-
let metadata_module = ModuleCodegen {
554-
name: metadata_cgu_name,
555-
module_llvm: metadata_llvm_module,
556-
kind: ModuleKind::Metadata,
557-
};
558-
559553
// Skip crate items and just output metadata in -Z no-codegen mode.
560554
if tcx.sess.opts.debugging_opts.no_codegen ||
561555
!tcx.sess.opts.output_types.should_codegen() {
@@ -566,7 +560,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
566560
rx,
567561
1);
568562

569-
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, metadata_module);
570563
ongoing_codegen.codegen_finished(tcx);
571564

572565
assert_and_save_dep_graph(tcx);
@@ -639,7 +632,24 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
639632
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, allocator_module);
640633
}
641634

642-
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, metadata_module);
635+
let needs_metadata_module = tcx.sess.crate_types.borrow().iter().any(|ct| {
636+
match *ct {
637+
CrateType::Dylib |
638+
CrateType::ProcMacro => true,
639+
CrateType::Executable |
640+
CrateType::Rlib |
641+
CrateType::Staticlib |
642+
CrateType::Cdylib => false,
643+
}
644+
});
645+
if needs_metadata_module {
646+
let metadata_module = ModuleCodegen {
647+
name: metadata_cgu_name,
648+
module_llvm: metadata_llvm_module,
649+
kind: ModuleKind::Metadata,
650+
};
651+
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, metadata_module);
652+
}
643653

644654
// We sort the codegen units by size. This way we can schedule work for LLVM
645655
// a bit more efficiently.

‎src/librustc_codegen_ssa/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub struct CodegenResults {
154154
pub crate_name: Symbol,
155155
pub modules: Vec<CompiledModule>,
156156
pub allocator_module: Option<CompiledModule>,
157-
pub metadata_module: CompiledModule,
157+
pub metadata_module: Option<CompiledModule>,
158158
pub crate_hash: Svh,
159159
pub metadata: rustc::middle::cstore::EncodedMetadata,
160160
pub windows_subsystem: Option<String>,

0 commit comments

Comments
 (0)
Please sign in to comment.