Avoid collect_and_partition_mono_items call when not doing codegen

Fixes #1401
This commit is contained in:
bjorn3 2023-10-23 09:32:55 +00:00
parent 7c4fcd4165
commit ed8c515cc4

View File

@ -361,12 +361,26 @@ pub(crate) fn run_aot(
metadata: EncodedMetadata, metadata: EncodedMetadata,
need_metadata_module: bool, need_metadata_module: bool,
) -> Box<OngoingCodegen> { ) -> Box<OngoingCodegen> {
// FIXME handle `-Ctarget-cpu=native`
let target_cpu = match tcx.sess.opts.cg.target_cpu {
Some(ref name) => name,
None => tcx.sess.target.cpu.as_ref(),
}
.to_owned();
let cgus = if tcx.sess.opts.output_types.should_codegen() { let cgus = if tcx.sess.opts.output_types.should_codegen() {
tcx.collect_and_partition_mono_items(()).1 tcx.collect_and_partition_mono_items(()).1
} else { } else {
// If only `--emit metadata` is used, we shouldn't perform any codegen. // If only `--emit metadata` is used, we shouldn't perform any codegen.
// Also `tcx.collect_and_partition_mono_items` may panic in that case. // Also `tcx.collect_and_partition_mono_items` may panic in that case.
&[] return Box::new(OngoingCodegen {
modules: vec![],
allocator_module: None,
metadata_module: None,
metadata,
crate_info: CrateInfo::new(tcx, target_cpu),
concurrency_limiter: ConcurrencyLimiter::new(tcx.sess, 0),
});
}; };
if tcx.dep_graph.is_fully_enabled() { if tcx.dep_graph.is_fully_enabled() {
@ -481,13 +495,6 @@ pub(crate) fn run_aot(
None None
}; };
// FIXME handle `-Ctarget-cpu=native`
let target_cpu = match tcx.sess.opts.cg.target_cpu {
Some(ref name) => name,
None => tcx.sess.target.cpu.as_ref(),
}
.to_owned();
Box::new(OngoingCodegen { Box::new(OngoingCodegen {
modules, modules,
allocator_module, allocator_module,