Skip to content

Commit 5f98943

Browse files
committed
Merge HasCodegen into BuilderMethods.
It has `Backend` and `Deref` boudns, plus an associated type `CodegenCx`, and it has a single use. This commit "inlines" it into `BuilderMethods`, which makes the complicated backend trait situation a little simpler.
1 parent 47830ed commit 5f98943

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_codegen_ssa::common::{
1414
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1515
use rustc_codegen_ssa::mir::place::PlaceRef;
1616
use rustc_codegen_ssa::traits::{
17-
BackendTypes, BaseTypeMethods, BuilderMethods, ConstMethods, HasCodegen, LayoutTypeMethods,
18-
OverflowOp, StaticBuilderMethods,
17+
BackendTypes, BaseTypeMethods, BuilderMethods, ConstMethods, LayoutTypeMethods, OverflowOp,
18+
StaticBuilderMethods,
1919
};
2020
use rustc_codegen_ssa::MemFlags;
2121
use rustc_data_structures::fx::FxHashSet;
@@ -460,10 +460,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
460460
}
461461
}
462462

463-
impl<'gcc, 'tcx> HasCodegen<'tcx> for Builder<'_, 'gcc, 'tcx> {
464-
type CodegenCx = CodegenCx<'gcc, 'tcx>;
465-
}
466-
467463
impl<'tcx> HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
468464
fn tcx(&self) -> TyCtxt<'tcx> {
469465
self.cx.tcx()
@@ -531,6 +527,8 @@ fn set_rvalue_location<'a, 'gcc, 'tcx>(
531527
}
532528

533529
impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
530+
type CodegenCx = CodegenCx<'gcc, 'tcx>;
531+
534532
fn build(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Builder<'a, 'gcc, 'tcx> {
535533
Builder::with_cx(cx, block)
536534
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ impl<'ll, 'tcx> Deref for Builder<'_, 'll, 'tcx> {
124124
}
125125
}
126126

127-
impl<'ll, 'tcx> HasCodegen<'tcx> for Builder<'_, 'll, 'tcx> {
128-
type CodegenCx = CodegenCx<'ll, 'tcx>;
129-
}
130-
131127
macro_rules! builder_methods_for_value_instructions {
132128
($($name:ident($($arg:ident),*) => $llvm_capi:ident),+ $(,)?) => {
133129
$(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value {
@@ -139,6 +135,8 @@ macro_rules! builder_methods_for_value_instructions {
139135
}
140136

141137
impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
138+
type CodegenCx = CodegenCx<'ll, 'tcx>;
139+
142140
fn build(cx: &'a CodegenCx<'ll, 'tcx>, llbb: &'ll BasicBlock) -> Self {
143141
let bx = Builder::with_cx(cx);
144142
unsafe {

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::assert_matches::assert_matches;
2+
use std::ops::Deref;
23

34
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
45
use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
@@ -17,7 +18,7 @@ use super::debuginfo::DebugInfoBuilderMethods;
1718
use super::intrinsic::IntrinsicCallMethods;
1819
use super::misc::MiscMethods;
1920
use super::type_::{ArgAbiMethods, BaseTypeMethods, LayoutTypeMethods};
20-
use super::{HasCodegen, StaticBuilderMethods};
21+
use super::{Backend, BackendTypes, CodegenMethods, StaticBuilderMethods};
2122
use crate::common::{
2223
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
2324
};
@@ -33,7 +34,8 @@ pub enum OverflowOp {
3334
}
3435

3536
pub trait BuilderMethods<'a, 'tcx>:
36-
HasCodegen<'tcx>
37+
Backend<'tcx>
38+
+ Deref<Target = Self::CodegenCx>
3739
+ CoverageInfoBuilderMethods<'tcx>
3840
+ DebugInfoBuilderMethods
3941
+ ArgAbiMethods<'tcx>
@@ -44,6 +46,18 @@ pub trait BuilderMethods<'a, 'tcx>:
4446
+ HasParamEnv<'tcx>
4547
+ HasTargetSpec
4648
{
49+
type CodegenCx: CodegenMethods<'tcx>
50+
+ BackendTypes<
51+
Value = Self::Value,
52+
Function = Self::Function,
53+
BasicBlock = Self::BasicBlock,
54+
Type = Self::Type,
55+
Funclet = Self::Funclet,
56+
DIScope = Self::DIScope,
57+
DILocation = Self::DILocation,
58+
DIVariable = Self::DIVariable,
59+
>;
60+
4761
fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self;
4862

4963
fn cx(&self) -> &Self::CodegenCx;

compiler/rustc_codegen_ssa/src/traits/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,3 @@ pub trait CodegenMethods<'tcx> = Backend<'tcx>
6363
+ HasParamEnv<'tcx>
6464
+ HasTyCtxt<'tcx>
6565
+ HasTargetSpec;
66-
67-
pub trait HasCodegen<'tcx>:
68-
Backend<'tcx> + std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
69-
{
70-
type CodegenCx: CodegenMethods<'tcx>
71-
+ BackendTypes<
72-
Value = Self::Value,
73-
Function = Self::Function,
74-
BasicBlock = Self::BasicBlock,
75-
Type = Self::Type,
76-
Funclet = Self::Funclet,
77-
DIScope = Self::DIScope,
78-
DILocation = Self::DILocation,
79-
DIVariable = Self::DIVariable,
80-
>;
81-
}

0 commit comments

Comments
 (0)