1
Fork 0

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:
Jubilee Young 2025-02-10 10:30:41 -08:00
parent 8c04e39595
commit 17716be86e
7 changed files with 7 additions and 63 deletions

View file

@ -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)