Skip to content

Commit a03aeca

Browse files
committed
Allow workproducts without object files.
This pull request partially reverts changes from e16c3b4 Original motivation for this assert was described with "A WorkProduct without a saved file is useless" which was true at the time but now it is possible to have work products with other types of files (llvm-ir, asm, etc) and there are bugreports for this failure: For example: rust-lang#123695 Fixes rust-lang#123234 Now existing `assert` and `.unwrap_or_else` are unified into a single check that emits slightly more user friendly error message if an object files was meant to be produced but it's missing
1 parent 4e1f5d9 commit a03aeca

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,6 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
907907
module: CachedModuleCodegen,
908908
module_config: &ModuleConfig,
909909
) -> WorkItemResult<B> {
910-
assert!(module_config.emit_obj != EmitObj::None);
911-
912910
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
913911

914912
let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| {
@@ -928,12 +926,6 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
928926
}
929927
};
930928

931-
let object = load_from_incr_comp_dir(
932-
cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)),
933-
module.source.saved_files.get("o").unwrap_or_else(|| {
934-
cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name })
935-
}),
936-
);
937929
let dwarf_object =
938930
module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| {
939931
let dwarf_obj_out = cgcx
@@ -955,9 +947,14 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
955947
}
956948
};
957949

950+
let should_emit_obj = module_config.emit_obj != EmitObj::None;
958951
let assembly = load_from_incr_cache(module_config.emit_asm, OutputType::Assembly);
959952
let llvm_ir = load_from_incr_cache(module_config.emit_ir, OutputType::LlvmAssembly);
960953
let bytecode = load_from_incr_cache(module_config.emit_bc, OutputType::Bitcode);
954+
let object = load_from_incr_cache(should_emit_obj, OutputType::Object);
955+
if should_emit_obj && object.is_none() {
956+
cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name })
957+
}
961958

962959
WorkItemResult::Finished(CompiledModule {
963960
name: module.name,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_name = "foo"]
2+
3+
#[inline(never)]
4+
pub fn add(a: u32, b: u32) -> u32 {
5+
a + b
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// emitting an object file is not necessary if user didn't ask for one
2+
//
3+
// This test is similar to run-make/artifact-incr-cache but it doesn't
4+
// require to emit an object file
5+
//
6+
// Fixes: rust-lang/rust#123234
7+
8+
extern crate run_make_support;
9+
10+
use run_make_support::{rustc, tmp_dir};
11+
12+
fn main() {
13+
let inc_dir = tmp_dir();
14+
15+
for _ in 0..=1 {
16+
rustc()
17+
.input("lib.rs")
18+
.crate_type("lib")
19+
.emit("asm,dep-info,link,mir,llvm-ir,llvm-bc")
20+
.incremental(&inc_dir)
21+
.run();
22+
}
23+
}

0 commit comments

Comments
 (0)