Skip to content

Commit 17716be

Browse files
compiler: die immediately instead of handling unknown target codegen
We cannot produce anything useful if asked to compile unknown targets. We should handle the error immediately at the point of discovery instead of propagating it upward, and preferably in the simplest way: Die. This allows cleaning up our "error-handling" spread across 5 crates.
1 parent 8c04e39 commit 17716be

File tree

7 files changed

+7
-63
lines changed

7 files changed

+7
-63
lines changed

compiler/rustc_const_eval/src/errors.rs

-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_middle::mir::interpret::{
1616
};
1717
use rustc_middle::ty::{self, Mutability, Ty};
1818
use rustc_span::{Span, Symbol};
19-
use rustc_target::callconv::AdjustForForeignAbiError;
2019

2120
use crate::interpret::InternKind;
2221

@@ -936,9 +935,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
936935
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
937936
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
938937
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
939-
InvalidProgramInfo::FnAbiAdjustForForeignAbi(_) => {
940-
rustc_middle::error::middle_adjust_for_foreign_abi_error
941-
}
942938
}
943939
}
944940
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
@@ -953,12 +949,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
953949
}
954950
dummy_diag.cancel();
955951
}
956-
InvalidProgramInfo::FnAbiAdjustForForeignAbi(
957-
AdjustForForeignAbiError::Unsupported { arch, abi },
958-
) => {
959-
diag.arg("arch", arch);
960-
diag.arg("abi", abi.name());
961-
}
962952
}
963953
}
964954
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
106106
) -> InterpErrorKind<'tcx> {
107107
match err {
108108
FnAbiError::Layout(err) => err_inval!(Layout(err)),
109-
FnAbiError::AdjustForForeignAbi(err) => {
110-
err_inval!(FnAbiAdjustForForeignAbi(err))
111-
}
112109
}
113110
}
114111
}

compiler/rustc_middle/src/mir/interpret/error.rs

-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ pub enum InvalidProgramInfo<'tcx> {
216216
AlreadyReported(ReportedErrorInfo),
217217
/// An error occurred during layout computation.
218218
Layout(layout::LayoutError<'tcx>),
219-
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
220-
/// (which unfortunately typeck does not reject).
221-
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
222-
FnAbiAdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
223219
}
224220

225221
/// Details of why a pointer had to be in-bounds.

compiler/rustc_middle/src/ty/layout.rs

-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_target::spec::{
2424
use tracing::debug;
2525
use {rustc_abi as abi, rustc_hir as hir};
2626

27-
use crate::error::UnsupportedFnAbi;
2827
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
2928
use crate::query::TyCtxtAt;
3029
use crate::ty::normalize_erasing_regions::NormalizationError;
@@ -1275,18 +1274,12 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
12751274
pub enum FnAbiError<'tcx> {
12761275
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
12771276
Layout(LayoutError<'tcx>),
1278-
1279-
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
1280-
AdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
12811277
}
12821278

12831279
impl<'a, 'b, G: EmissionGuarantee> Diagnostic<'a, G> for FnAbiError<'b> {
12841280
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
12851281
match self {
12861282
Self::Layout(e) => e.into_diagnostic().into_diag(dcx, level),
1287-
Self::AdjustForForeignAbi(
1288-
rustc_target::callconv::AdjustForForeignAbiError::Unsupported { arch, abi },
1289-
) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
12901283
}
12911284
}
12921285
}

compiler/rustc_passes/src/abi_test.rs

-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ fn unwrap_fn_abi<'tcx>(
4646
span: tcx.def_span(item_def_id),
4747
});
4848
}
49-
Err(FnAbiError::AdjustForForeignAbi(e)) => {
50-
// Sadly there seems to be no `into_diagnostic` for this case... and I am not sure if
51-
// this can even be reached. Anyway this is a perma-unstable debug attribute, an ICE
52-
// isn't the worst thing. Also this matches what codegen does.
53-
span_bug!(
54-
tcx.def_span(item_def_id),
55-
"error computing fn_abi_of_instance, cannot adjust for foreign ABI: {e:?}",
56-
)
57-
}
5849
}
5950
}
6051

compiler/rustc_target/src/callconv/mod.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_abi::{
66
Size, TyAbiInterface, TyAndLayout,
77
};
88
use rustc_macros::HashStable_Generic;
9-
use rustc_span::Symbol;
109

1110
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
1211

@@ -623,19 +622,8 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
623622
}
624623
}
625624

626-
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
627-
#[derive(Copy, Clone, Debug, HashStable_Generic)]
628-
pub enum AdjustForForeignAbiError {
629-
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
630-
Unsupported { arch: Symbol, abi: ExternAbi },
631-
}
632-
633625
impl<'a, Ty> FnAbi<'a, Ty> {
634-
pub fn adjust_for_foreign_abi<C>(
635-
&mut self,
636-
cx: &C,
637-
abi: ExternAbi,
638-
) -> Result<(), AdjustForForeignAbiError>
626+
pub fn adjust_for_foreign_abi<C>(&mut self, cx: &C, abi: ExternAbi)
639627
where
640628
Ty: TyAbiInterface<'a, C> + Copy,
641629
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
@@ -644,7 +632,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
644632
if let Some(arg) = self.args.first_mut() {
645633
arg.pass_by_stack_offset(None);
646634
}
647-
return Ok(());
635+
return;
648636
}
649637

650638
let spec = cx.target_spec();
@@ -719,15 +707,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
719707
}
720708
"wasm64" => wasm::compute_c_abi_info(cx, self),
721709
"bpf" => bpf::compute_abi_info(self),
722-
arch => {
723-
return Err(AdjustForForeignAbiError::Unsupported {
724-
arch: Symbol::intern(arch),
725-
abi,
726-
});
727-
}
710+
arch => panic!("no lowering implemented for {arch}"),
728711
}
729-
730-
Ok(())
731712
}
732713

733714
pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: ExternAbi)

compiler/rustc_ty_utils/src/abi.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ fn fn_abi_new_uncached<'tcx>(
650650
conv,
651651
can_unwind: fn_can_unwind(cx.tcx(), fn_def_id, sig.abi),
652652
};
653-
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id)?;
653+
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id);
654654
debug!("fn_abi_new_uncached = {:?}", fn_abi);
655655
fn_abi_sanity_check(cx, &fn_abi, sig.abi);
656656
Ok(tcx.arena.alloc(fn_abi))
@@ -662,7 +662,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
662662
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
663663
abi: ExternAbi,
664664
fn_def_id: Option<DefId>,
665-
) -> Result<(), &'tcx FnAbiError<'tcx>> {
665+
) {
666666
if abi == ExternAbi::Unadjusted {
667667
// The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for
668668
// some LLVM intrinsics.
@@ -682,7 +682,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
682682
for arg in fn_abi.args.iter_mut() {
683683
unadjust(arg);
684684
}
685-
return Ok(());
685+
return;
686686
}
687687

688688
let tcx = cx.tcx();
@@ -723,12 +723,8 @@ fn fn_abi_adjust_for_abi<'tcx>(
723723
}
724724
}
725725
} else {
726-
fn_abi
727-
.adjust_for_foreign_abi(cx, abi)
728-
.map_err(|err| &*tcx.arena.alloc(FnAbiError::AdjustForForeignAbi(err)))?;
726+
fn_abi.adjust_for_foreign_abi(cx, abi);
729727
}
730-
731-
Ok(())
732728
}
733729

734730
#[tracing::instrument(level = "debug", skip(cx))]

0 commit comments

Comments
 (0)