Skip to content

Commit

Permalink
Rollup merge of rust-lang#121209 - nnethercote:infallible-join_codege…
Browse files Browse the repository at this point in the history
…n, r=bjorn3

Make `CodegenBackend::join_codegen` infallible.

Because they all are, in practice.

r? `@bjorn3`
  • Loading branch information
matthiaskrgr authored Feb 17, 2024
2 parents f4f2a75 + ede9923 commit b865d9b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ impl CodegenBackend for CraneliftCodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
_outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
Ok(ongoing_codegen
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
ongoing_codegen
.downcast::<driver::aot::OngoingCodegen>()
.unwrap()
.join(sess, self.config.borrow().as_ref().unwrap()))
.join(sess, self.config.borrow().as_ref().unwrap())
}

fn link(
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,11 @@ impl CodegenBackend for GccCodegenBackend {
Box::new(res)
}

fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
let (codegen_results, work_products) = ongoing_codegen
fn join_codegen(&self, ongoing_codegen: Box<dyn Any>, sess: &Session, _outputs: &OutputFilenames) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess);

Ok((codegen_results, work_products))
.join(sess)
}

fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorGuaranteed> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl CodegenBackend for LlvmCodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let (codegen_results, work_products) = ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
Expand All @@ -382,7 +382,7 @@ impl CodegenBackend for LlvmCodegenBackend {
});
}

Ok((codegen_results, work_products))
(codegen_results, work_products)
}

fn link(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub trait CodegenBackend {
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);

/// This is called on the returned `CodegenResults` from `join_codegen`
fn link(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub struct Linker {
impl Linker {
pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) -> Result<()> {
let (codegen_results, work_products) =
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames)?;
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames);

sess.compile_status()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ impl CodegenBackend for TheBackend {
ongoing_codegen: Box<dyn Any>,
_sess: &Session,
_outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let codegen_results = ongoing_codegen
.downcast::<CodegenResults>()
.expect("in join_codegen: ongoing_codegen is not a CodegenResults");
Ok((*codegen_results, FxIndexMap::default()))
(*codegen_results, FxIndexMap::default())
}

fn link(
Expand Down

0 comments on commit b865d9b

Please sign in to comment.