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.
This commit is contained in:
parent
8c04e39595
commit
17716be86e
7 changed files with 7 additions and 63 deletions
|
@ -16,7 +16,6 @@ use rustc_middle::mir::interpret::{
|
|||
};
|
||||
use rustc_middle::ty::{self, Mutability, Ty};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::callconv::AdjustForForeignAbiError;
|
||||
|
||||
use crate::interpret::InternKind;
|
||||
|
||||
|
@ -936,9 +935,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
|
|||
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
|
||||
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
|
||||
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
|
||||
InvalidProgramInfo::FnAbiAdjustForForeignAbi(_) => {
|
||||
rustc_middle::error::middle_adjust_for_foreign_abi_error
|
||||
}
|
||||
}
|
||||
}
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
|
@ -953,12 +949,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
|
|||
}
|
||||
dummy_diag.cancel();
|
||||
}
|
||||
InvalidProgramInfo::FnAbiAdjustForForeignAbi(
|
||||
AdjustForForeignAbiError::Unsupported { arch, abi },
|
||||
) => {
|
||||
diag.arg("arch", arch);
|
||||
diag.arg("abi", abi.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,9 +106,6 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
|
|||
) -> InterpErrorKind<'tcx> {
|
||||
match err {
|
||||
FnAbiError::Layout(err) => err_inval!(Layout(err)),
|
||||
FnAbiError::AdjustForForeignAbi(err) => {
|
||||
err_inval!(FnAbiAdjustForForeignAbi(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,10 +216,6 @@ pub enum InvalidProgramInfo<'tcx> {
|
|||
AlreadyReported(ReportedErrorInfo),
|
||||
/// An error occurred during layout computation.
|
||||
Layout(layout::LayoutError<'tcx>),
|
||||
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
|
||||
/// (which unfortunately typeck does not reject).
|
||||
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
|
||||
FnAbiAdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
|
||||
}
|
||||
|
||||
/// Details of why a pointer had to be in-bounds.
|
||||
|
|
|
@ -24,7 +24,6 @@ use rustc_target::spec::{
|
|||
use tracing::debug;
|
||||
use {rustc_abi as abi, rustc_hir as hir};
|
||||
|
||||
use crate::error::UnsupportedFnAbi;
|
||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use crate::query::TyCtxtAt;
|
||||
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)
|
|||
pub enum FnAbiError<'tcx> {
|
||||
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
|
||||
Layout(LayoutError<'tcx>),
|
||||
|
||||
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
||||
AdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
|
||||
}
|
||||
|
||||
impl<'a, 'b, G: EmissionGuarantee> Diagnostic<'a, G> for FnAbiError<'b> {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
match self {
|
||||
Self::Layout(e) => e.into_diagnostic().into_diag(dcx, level),
|
||||
Self::AdjustForForeignAbi(
|
||||
rustc_target::callconv::AdjustForForeignAbiError::Unsupported { arch, abi },
|
||||
) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,15 +46,6 @@ fn unwrap_fn_abi<'tcx>(
|
|||
span: tcx.def_span(item_def_id),
|
||||
});
|
||||
}
|
||||
Err(FnAbiError::AdjustForForeignAbi(e)) => {
|
||||
// Sadly there seems to be no `into_diagnostic` for this case... and I am not sure if
|
||||
// this can even be reached. Anyway this is a perma-unstable debug attribute, an ICE
|
||||
// isn't the worst thing. Also this matches what codegen does.
|
||||
span_bug!(
|
||||
tcx.def_span(item_def_id),
|
||||
"error computing fn_abi_of_instance, cannot adjust for foreign ABI: {e:?}",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ use rustc_abi::{
|
|||
Size, TyAbiInterface, TyAndLayout,
|
||||
};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
|
||||
|
||||
|
@ -623,19 +622,8 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||
pub enum AdjustForForeignAbiError {
|
||||
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
|
||||
Unsupported { arch: Symbol, abi: ExternAbi },
|
||||
}
|
||||
|
||||
impl<'a, Ty> FnAbi<'a, Ty> {
|
||||
pub fn adjust_for_foreign_abi<C>(
|
||||
&mut self,
|
||||
cx: &C,
|
||||
abi: ExternAbi,
|
||||
) -> Result<(), AdjustForForeignAbiError>
|
||||
pub fn adjust_for_foreign_abi<C>(&mut self, cx: &C, abi: ExternAbi)
|
||||
where
|
||||
Ty: TyAbiInterface<'a, C> + Copy,
|
||||
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
|
||||
|
@ -644,7 +632,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
|
|||
if let Some(arg) = self.args.first_mut() {
|
||||
arg.pass_by_stack_offset(None);
|
||||
}
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
let spec = cx.target_spec();
|
||||
|
@ -719,15 +707,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
|
|||
}
|
||||
"wasm64" => wasm::compute_c_abi_info(cx, self),
|
||||
"bpf" => bpf::compute_abi_info(self),
|
||||
arch => {
|
||||
return Err(AdjustForForeignAbiError::Unsupported {
|
||||
arch: Symbol::intern(arch),
|
||||
abi,
|
||||
});
|
||||
}
|
||||
arch => panic!("no lowering implemented for {arch}"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: ExternAbi)
|
||||
|
|
|
@ -650,7 +650,7 @@ fn fn_abi_new_uncached<'tcx>(
|
|||
conv,
|
||||
can_unwind: fn_can_unwind(cx.tcx(), fn_def_id, sig.abi),
|
||||
};
|
||||
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id)?;
|
||||
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id);
|
||||
debug!("fn_abi_new_uncached = {:?}", fn_abi);
|
||||
fn_abi_sanity_check(cx, &fn_abi, sig.abi);
|
||||
Ok(tcx.arena.alloc(fn_abi))
|
||||
|
@ -662,7 +662,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
|
|||
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
||||
abi: ExternAbi,
|
||||
fn_def_id: Option<DefId>,
|
||||
) -> Result<(), &'tcx FnAbiError<'tcx>> {
|
||||
) {
|
||||
if abi == ExternAbi::Unadjusted {
|
||||
// The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for
|
||||
// some LLVM intrinsics.
|
||||
|
@ -682,7 +682,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
|
|||
for arg in fn_abi.args.iter_mut() {
|
||||
unadjust(arg);
|
||||
}
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
let tcx = cx.tcx();
|
||||
|
@ -723,12 +723,8 @@ fn fn_abi_adjust_for_abi<'tcx>(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
fn_abi
|
||||
.adjust_for_foreign_abi(cx, abi)
|
||||
.map_err(|err| &*tcx.arena.alloc(FnAbiError::AdjustForForeignAbi(err)))?;
|
||||
fn_abi.adjust_for_foreign_abi(cx, abi);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(cx))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue