1
Fork 0

Rename supertraits of CodegenMethods.

Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`.
Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit
changes the latter to `XyzCodegenMethods`, for consistency.
This commit is contained in:
Nicholas Nethercote 2024-09-17 10:15:26 +10:00
parent 540fcc617a
commit a8d22eb39e
39 changed files with 98 additions and 88 deletions

View file

@ -27,32 +27,32 @@ pub enum OperandValue<V> {
/// which indicates that it refers to an unsized rvalue.
///
/// An `OperandValue` *must* be this variant for any type for which
/// [`LayoutTypeMethods::is_backend_ref`] returns `true`.
/// [`LayoutTypeCodegenMethods::is_backend_ref`] returns `true`.
/// (That basically amounts to "isn't one of the other variants".)
///
/// This holds a [`PlaceValue`] (like a [`PlaceRef`] does) with a pointer
/// to the location holding the value. The type behind that pointer is the
/// one returned by [`LayoutTypeMethods::backend_type`].
/// one returned by [`LayoutTypeCodegenMethods::backend_type`].
Ref(PlaceValue<V>),
/// A single LLVM immediate value.
///
/// An `OperandValue` *must* be this variant for any type for which
/// [`LayoutTypeMethods::is_backend_immediate`] returns `true`.
/// [`LayoutTypeCodegenMethods::is_backend_immediate`] returns `true`.
/// The backend value in this variant must be the *immediate* backend type,
/// as returned by [`LayoutTypeMethods::immediate_backend_type`].
/// as returned by [`LayoutTypeCodegenMethods::immediate_backend_type`].
Immediate(V),
/// A pair of immediate LLVM values. Used by fat pointers too.
///
/// An `OperandValue` *must* be this variant for any type for which
/// [`LayoutTypeMethods::is_backend_scalar_pair`] returns `true`.
/// [`LayoutTypeCodegenMethods::is_backend_scalar_pair`] returns `true`.
/// The backend values in this variant must be the *immediate* backend types,
/// as returned by [`LayoutTypeMethods::scalar_pair_element_backend_type`]
/// as returned by [`LayoutTypeCodegenMethods::scalar_pair_element_backend_type`]
/// with `immediate: true`.
Pair(V, V),
/// A value taking no bytes, and which therefore needs no LLVM value at all.
///
/// If you ever need a `V` to pass to something, get a fresh poison value
/// from [`ConstMethods::const_poison`].
/// from [`ConstCodegenMethods::const_poison`].
///
/// An `OperandValue` *must* be this variant for any type for which
/// `is_zst` on its `Layout` returns `true`. Note however that
@ -110,7 +110,7 @@ impl<V: CodegenObject> OperandValue<V> {
PlaceValue { llval, llextra, align }
}
pub(crate) fn is_expected_variant_for_type<'tcx, Cx: LayoutTypeMethods<'tcx>>(
pub(crate) fn is_expected_variant_for_type<'tcx, Cx: LayoutTypeCodegenMethods<'tcx>>(
&self,
cx: &Cx,
ty: TyAndLayout<'tcx>,

View file

@ -133,7 +133,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
Self::alloca(bx, ptr_layout)
}
pub fn len<Cx: ConstMethods<'tcx, Value = V>>(&self, cx: &Cx) -> V {
pub fn len<Cx: ConstCodegenMethods<'tcx, Value = V>>(&self, cx: &Cx) -> V {
if let FieldsShape::Array { count, .. } = self.layout.fields {
if self.layout.is_unsized() {
assert_eq!(count, 0);

View file

@ -60,7 +60,7 @@ pub trait AsmBuilderMethods<'tcx>: BackendTypes {
);
}
pub trait AsmMethods<'tcx> {
pub trait AsmCodegenMethods<'tcx> {
fn codegen_global_asm(
&self,
template: &[InlineAsmTemplatePiece],

View file

@ -11,12 +11,12 @@ use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
use super::abi::AbiBuilderMethods;
use super::asm::AsmBuilderMethods;
use super::consts::ConstMethods;
use super::consts::ConstCodegenMethods;
use super::coverageinfo::CoverageInfoBuilderMethods;
use super::debuginfo::DebugInfoBuilderMethods;
use super::intrinsic::IntrinsicCallBuilderMethods;
use super::misc::MiscMethods;
use super::type_::{ArgAbiBuilderMethods, BaseTypeMethods, LayoutTypeMethods};
use super::misc::MiscCodegenMethods;
use super::type_::{ArgAbiBuilderMethods, BaseTypeCodegenMethods, LayoutTypeCodegenMethods};
use super::{CodegenMethods, StaticBuilderMethods};
use crate::common::{
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,

View file

@ -3,7 +3,7 @@ use rustc_target::abi;
use super::BackendTypes;
pub trait ConstMethods<'tcx>: BackendTypes {
pub trait ConstCodegenMethods<'tcx>: BackendTypes {
// Constant constructors
fn const_null(&self, t: Self::Type) -> Self::Value;
/// Generate an uninitialized value (matching uninitialized memory in MIR).

View file

@ -9,7 +9,7 @@ use rustc_target::abi::Size;
use super::BackendTypes;
use crate::mir::debuginfo::{FunctionDebugContext, VariableKind};
pub trait DebugInfoMethods<'tcx>: BackendTypes {
pub trait DebugInfoCodegenMethods<'tcx>: BackendTypes {
fn create_vtable_debuginfo(
&self,
ty: Ty<'tcx>,

View file

@ -2,7 +2,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::mir::mono::{Linkage, Visibility};
use rustc_middle::ty::Instance;
pub trait PreDefineMethods<'tcx> {
pub trait PreDefineCodegenMethods<'tcx> {
fn predefine_static(
&self,
def_id: DefId,

View file

@ -7,7 +7,7 @@ use rustc_session::Session;
use super::BackendTypes;
pub trait MiscMethods<'tcx>: BackendTypes {
pub trait MiscCodegenMethods<'tcx>: BackendTypes {
fn vtables(
&self,
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Self::Value>>;

View file

@ -27,25 +27,26 @@ mod write;
use std::fmt;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
use rustc_middle::ty::Ty;
use rustc_target::abi::call::FnAbi;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
pub use self::abi::AbiBuilderMethods;
pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
pub use self::asm::{
AsmBuilderMethods, AsmCodegenMethods, GlobalAsmOperandRef, InlineAsmOperandRef,
};
pub use self::backend::{BackendTypes, CodegenBackend, ExtraBackendMethods};
pub use self::builder::{BuilderMethods, OverflowOp};
pub use self::consts::ConstMethods;
pub use self::consts::ConstCodegenMethods;
pub use self::coverageinfo::CoverageInfoBuilderMethods;
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
pub use self::declare::PreDefineMethods;
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
pub use self::declare::PreDefineCodegenMethods;
pub use self::intrinsic::IntrinsicCallBuilderMethods;
pub use self::misc::MiscMethods;
pub use self::statics::{StaticBuilderMethods, StaticMethods};
pub use self::misc::MiscCodegenMethods;
pub use self::statics::{StaticBuilderMethods, StaticCodegenMethods};
pub use self::type_::{
ArgAbiBuilderMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods,
TypeMembershipMethods, TypeMethods,
ArgAbiBuilderMethods, BaseTypeCodegenMethods, DerivedTypeCodegenMethods,
LayoutTypeCodegenMethods, TypeCodegenMethods, TypeMembershipCodegenMethods,
};
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
@ -53,9 +54,9 @@ pub trait CodegenObject = Copy + PartialEq + fmt::Debug;
pub trait CodegenMethods<'tcx> = LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
+ TypeMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>;
+ TypeCodegenMethods<'tcx>
+ ConstCodegenMethods<'tcx>
+ StaticCodegenMethods
+ DebugInfoCodegenMethods<'tcx>
+ AsmCodegenMethods<'tcx>
+ PreDefineCodegenMethods<'tcx>;

View file

@ -3,7 +3,7 @@ use rustc_target::abi::Align;
use super::BackendTypes;
pub trait StaticMethods: BackendTypes {
pub trait StaticCodegenMethods: BackendTypes {
fn static_addr_of(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value;
fn codegen_static(&self, def_id: DefId);

View file

@ -4,12 +4,12 @@ use rustc_middle::ty::{self, Ty};
use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg};
use rustc_target::abi::{AddressSpace, Float, Integer};
use super::misc::MiscMethods;
use super::misc::MiscCodegenMethods;
use super::BackendTypes;
use crate::common::TypeKind;
use crate::mir::place::PlaceRef;
pub trait BaseTypeMethods<'tcx>: BackendTypes {
pub trait BaseTypeCodegenMethods<'tcx>: BackendTypes {
fn type_i8(&self) -> Self::Type;
fn type_i16(&self) -> Self::Type;
fn type_i32(&self) -> Self::Type;
@ -40,8 +40,8 @@ pub trait BaseTypeMethods<'tcx>: BackendTypes {
fn val_ty(&self, v: Self::Value) -> Self::Type;
}
pub trait DerivedTypeMethods<'tcx>:
BaseTypeMethods<'tcx> + MiscMethods<'tcx> + HasTyCtxt<'tcx>
pub trait DerivedTypeCodegenMethods<'tcx>:
BaseTypeCodegenMethods<'tcx> + MiscCodegenMethods<'tcx> + HasTyCtxt<'tcx>
{
fn type_int(&self) -> Self::Type {
match &self.sess().target.c_int_width[..] {
@ -100,12 +100,12 @@ pub trait DerivedTypeMethods<'tcx>:
}
}
impl<'tcx, T> DerivedTypeMethods<'tcx> for T where
Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> + HasTyCtxt<'tcx>
impl<'tcx, T> DerivedTypeCodegenMethods<'tcx> for T where
Self: BaseTypeCodegenMethods<'tcx> + MiscCodegenMethods<'tcx> + HasTyCtxt<'tcx>
{
}
pub trait LayoutTypeMethods<'tcx>: BackendTypes {
pub trait LayoutTypeCodegenMethods<'tcx>: BackendTypes {
/// The backend type used for a rust type when it's in memory,
/// such as when it's stack-allocated or when it's being loaded or stored.
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
@ -117,7 +117,7 @@ pub trait LayoutTypeMethods<'tcx>: BackendTypes {
///
/// For nearly all types this is the same as the [`Self::backend_type`], however
/// `bool` (and other `0`-or-`1` values) are kept as `i1` in registers but as
/// [`BaseTypeMethods::type_i8`] in memory.
/// [`BaseTypeCodegenMethods::type_i8`] in memory.
///
/// Converting values between the two different backend types is done using
/// [`from_immediate`](super::BuilderMethods::from_immediate) and
@ -149,7 +149,7 @@ pub trait LayoutTypeMethods<'tcx>: BackendTypes {
// For backends that support CFI using type membership (i.e., testing whether a given pointer is
// associated with a type identifier).
pub trait TypeMembershipMethods<'tcx>: BackendTypes {
pub trait TypeMembershipCodegenMethods<'tcx>: BackendTypes {
fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {}
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {}
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Value> {
@ -175,5 +175,6 @@ pub trait ArgAbiBuilderMethods<'tcx>: BackendTypes {
fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> Self::Type;
}
pub trait TypeMethods<'tcx> =
DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx> + TypeMembershipMethods<'tcx>;
pub trait TypeCodegenMethods<'tcx> = DerivedTypeCodegenMethods<'tcx>
+ LayoutTypeCodegenMethods<'tcx>
+ TypeMembershipCodegenMethods<'tcx>;