Introduce FunctionSignature associated type for BackendTypes

In Cranelift the regular Type enum can't represent function signatures.
Function pointers are represented as plain pointer sized integer.
This commit is contained in:
bjorn3
2026-02-24 11:27:44 +00:00
parent e94aaf136d
commit f03581a12b
8 changed files with 12 additions and 6 deletions
@@ -491,6 +491,7 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
type Value = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Value;
type Type = <CodegenCx<'gcc, 'tcx> as BackendTypes>::Type;
type FunctionSignature = <CodegenCx<'gcc, 'tcx> as BackendTypes>::FunctionSignature;
type DIScope = <CodegenCx<'gcc, 'tcx> as BackendTypes>::DIScope;
type DILocation = <CodegenCx<'gcc, 'tcx> as BackendTypes>::DILocation;
@@ -386,6 +386,7 @@ impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
type Value = RValue<'gcc>;
type Type = Type<'gcc>;
type FunctionSignature = Type<'gcc>;
type DIScope = (); // TODO(antoyo)
type DILocation = Location<'gcc>;
@@ -202,6 +202,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericBuilder<'_, 'll, CX> {
type Value = <GenericCx<'ll, CX> as BackendTypes>::Value;
type Type = <GenericCx<'ll, CX> as BackendTypes>::Type;
type FunctionSignature = <GenericCx<'ll, CX> as BackendTypes>::FunctionSignature;
type DIScope = <GenericCx<'ll, CX> as BackendTypes>::DIScope;
type DILocation = <GenericCx<'ll, CX> as BackendTypes>::DILocation;
@@ -89,6 +89,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericCx<'ll, CX> {
type Value = &'ll Value;
type Type = &'ll Type;
type FunctionSignature = &'ll Type;
type DIScope = &'ll llvm::debuginfo::DIScope;
type DILocation = &'ll llvm::debuginfo::DILocation;
@@ -27,6 +27,7 @@ pub trait BackendTypes {
type Value: CodegenObject + PartialEq;
type Type: CodegenObject + PartialEq;
type FunctionSignature: CodegenObject + PartialEq;
// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
@@ -53,6 +53,7 @@ pub trait BuilderMethods<'a, 'tcx>:
Function = Self::Function,
BasicBlock = Self::BasicBlock,
Type = Self::Type,
FunctionSignature = Self::FunctionSignature,
Funclet = Self::Funclet,
DIScope = Self::DIScope,
DILocation = Self::DILocation,
@@ -124,7 +125,7 @@ fn switch_with_weights(
fn invoke(
&mut self,
llty: Self::Type,
llty: Self::FunctionSignature,
fn_attrs: Option<&CodegenFnAttrs>,
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
llfn: Self::Value,
@@ -621,7 +622,7 @@ fn atomic_rmw(
/// assuming the function does not explicitly pass the destination as a pointer in `args`.
fn call(
&mut self,
llty: Self::Type,
llty: Self::FunctionSignature,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
fn_val: Self::Value,
@@ -632,7 +633,7 @@ fn call(
fn tail_call(
&mut self,
llty: Self::Type,
llty: Self::FunctionSignature,
caller_attrs: Option<&CodegenFnAttrs>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
llfn: Self::Value,
@@ -25,5 +25,5 @@ fn apply_vcall_visibility_metadata(
fn apply_target_cpu_attr(&self, llfn: Self::Function);
/// Declares the extern "C" main function for the entry point. Returns None if the symbol
/// already exists.
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function>;
fn declare_c_main(&self, fn_type: Self::FunctionSignature) -> Option<Self::Function>;
}
@@ -23,7 +23,7 @@ pub trait BaseTypeCodegenMethods: BackendTypes {
fn type_f128(&self) -> Self::Type;
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::FunctionSignature;
fn type_kind(&self, ty: Self::Type) -> TypeKind;
fn type_ptr(&self) -> Self::Type;
fn type_ptr_ext(&self, address_space: AddressSpace) -> Self::Type;
@@ -114,7 +114,7 @@ pub trait LayoutTypeCodegenMethods<'tcx>: BackendTypes {
/// such as when it's stack-allocated or when it's being loaded or stored.
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::FunctionSignature;
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
/// The backend type used for a rust type when it's in an SSA register.