Skip to content

Commit 928d8e6

Browse files
committed
Remove Backend.
It's a trait that aggregates five other traits. But consider the places that use it. - `BuilderMethods`: requires three of the five traits. - `CodegenMethods`: requires zero(!) of the five traits. - `BaseTypeMethods`: requires two of the five traits. - `LayoutTypeMethods`: requires three of the five traits. - `TypeMembershipMethods`: requires one of the five traits. This commit just removes it, which makes everything simpler.
1 parent 5f98943 commit 928d8e6

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use rustc_errors::ErrorGuaranteed;
88
use rustc_metadata::creader::MetadataLoaderDyn;
99
use rustc_metadata::EncodedMetadata;
1010
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
11-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
12-
use rustc_middle::ty::{Ty, TyCtxt};
11+
use rustc_middle::ty::TyCtxt;
1312
use rustc_middle::util::Providers;
1413
use rustc_session::config::{self, OutputFilenames, PrintRequest};
1514
use rustc_session::Session;
1615
use rustc_span::symbol::Symbol;
17-
use rustc_target::abi::call::FnAbi;
1816

1917
use super::write::WriteBackendMethods;
2018
use super::CodegenObject;
@@ -36,12 +34,6 @@ pub trait BackendTypes {
3634
type DIVariable: Copy;
3735
}
3836

39-
pub trait Backend<'tcx> = Sized
40-
+ BackendTypes
41-
+ HasTyCtxt<'tcx>
42-
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
43-
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>;
44-
4537
pub trait CodegenBackend {
4638
/// Locale resources for diagnostic messages - a string the content of the Fluent resource.
4739
/// Called before `init` so that all other functions are able to emit translatable diagnostics.

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::assert_matches::assert_matches;
22
use std::ops::Deref;
33

44
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
5-
use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
5+
use rustc_middle::ty::layout::{FnAbiOf, HasParamEnv, LayoutOf, TyAndLayout};
66
use rustc_middle::ty::{Instance, Ty};
77
use rustc_session::config::OptLevel;
88
use rustc_span::Span;
@@ -18,7 +18,7 @@ use super::debuginfo::DebugInfoBuilderMethods;
1818
use super::intrinsic::IntrinsicCallMethods;
1919
use super::misc::MiscMethods;
2020
use super::type_::{ArgAbiMethods, BaseTypeMethods, LayoutTypeMethods};
21-
use super::{Backend, BackendTypes, CodegenMethods, StaticBuilderMethods};
21+
use super::{BackendTypes, CodegenMethods, StaticBuilderMethods};
2222
use crate::common::{
2323
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
2424
};
@@ -34,7 +34,9 @@ pub enum OverflowOp {
3434
}
3535

3636
pub trait BuilderMethods<'a, 'tcx>:
37-
Backend<'tcx>
37+
Sized
38+
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
39+
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
3840
+ Deref<Target = Self::CodegenCx>
3941
+ CoverageInfoBuilderMethods<'tcx>
4042
+ DebugInfoBuilderMethods

compiler/rustc_codegen_ssa/src/traits/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
//! actual codegen, while the builder stores the information about the function during codegen and
99
//! is used to produce the instructions of the backend IR.
1010
//!
11-
//! Finally, a third `Backend` structure has to implement methods related to how codegen information
12-
//! is passed to the backend, especially for asynchronous compilation.
13-
//!
1411
//! The traits contain associated types that are backend-specific, such as the backend's value or
1512
//! basic blocks.
1613
@@ -35,7 +32,7 @@ use rustc_target::spec::HasTargetSpec;
3532

3633
pub use self::abi::AbiBuilderMethods;
3734
pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
38-
pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
35+
pub use self::backend::{BackendTypes, CodegenBackend, ExtraBackendMethods};
3936
pub use self::builder::{BuilderMethods, OverflowOp};
4037
pub use self::consts::ConstMethods;
4138
pub use self::coverageinfo::CoverageInfoBuilderMethods;
@@ -52,8 +49,7 @@ pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethod
5249

5350
pub trait CodegenObject = Copy + PartialEq + fmt::Debug;
5451

55-
pub trait CodegenMethods<'tcx> = Backend<'tcx>
56-
+ TypeMethods<'tcx>
52+
pub trait CodegenMethods<'tcx> = TypeMethods<'tcx>
5753
+ MiscMethods<'tcx>
5854
+ ConstMethods<'tcx>
5955
+ StaticMethods

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use rustc_middle::bug;
2-
use rustc_middle::ty::layout::TyAndLayout;
2+
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
33
use rustc_middle::ty::{self, Ty};
44
use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg};
55
use rustc_target::abi::{AddressSpace, Float, Integer};
66

77
use super::misc::MiscMethods;
8-
use super::{Backend, BackendTypes};
8+
use super::BackendTypes;
99
use crate::common::TypeKind;
1010
use crate::mir::place::PlaceRef;
1111

12-
// This depends on `Backend` and not `BackendTypes`, because consumers will probably want to use
13-
// `LayoutOf` or `HasTyCtxt`. This way, they don't have to add a constraint on it themselves.
14-
pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
12+
pub trait BaseTypeMethods<'tcx>: BackendTypes + HasTyCtxt<'tcx> {
1513
fn type_i8(&self) -> Self::Type;
1614
fn type_i16(&self) -> Self::Type;
1715
fn type_i32(&self) -> Self::Type;
@@ -102,7 +100,11 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
102100

103101
impl<'tcx, T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {}
104102

105-
pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
103+
pub trait LayoutTypeMethods<'tcx>:
104+
BackendTypes
105+
+ LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
106+
+ FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
107+
{
106108
/// The backend type used for a rust type when it's in memory,
107109
/// such as when it's stack-allocated or when it's being loaded or stored.
108110
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
@@ -146,7 +148,7 @@ pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
146148

147149
// For backends that support CFI using type membership (i.e., testing whether a given pointer is
148150
// associated with a type identifier).
149-
pub trait TypeMembershipMethods<'tcx>: Backend<'tcx> {
151+
pub trait TypeMembershipMethods<'tcx>: BackendTypes {
150152
fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {}
151153
fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {}
152154
fn typeid_metadata(&self, _typeid: String) -> Option<Self::Value> {

0 commit comments

Comments
 (0)