Skip to content

Commit 21313d7

Browse files
authored
Rollup merge of #130457 - nnethercote:cleanup-codegen-traits, r=bjorn3
Cleanup codegen traits The traits governing codegen are quite complicated and hard to follow. This PR cleans them up a bit. r? `@bjorn3`
2 parents aaed38b + acb832d commit 21313d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+154
-226
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,13 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
309309
}
310310

311311
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
312-
type LayoutOfResult = TyAndLayout<'tcx>;
313-
314312
#[inline]
315313
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
316314
RevealAllLayoutCx(self.tcx).handle_layout_err(err, span, ty)
317315
}
318316
}
319317

320318
impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
321-
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
322-
323319
#[inline]
324320
fn handle_fn_abi_err(
325321
&self,
@@ -450,8 +446,6 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
450446
pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
451447

452448
impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
453-
type LayoutOfResult = TyAndLayout<'tcx>;
454-
455449
#[inline]
456450
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
457451
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
@@ -466,8 +460,6 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
466460
}
467461

468462
impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
469-
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
470-
471463
#[inline]
472464
fn handle_fn_abi_err(
473465
&self,

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
33
use gccjit::{ToLValue, ToRValue, Type};
4-
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods};
4+
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods};
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_middle::bug;
77
use rustc_middle::ty::layout::LayoutOf;

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
55
use rustc_codegen_ssa::mir::operand::OperandValue;
66
use rustc_codegen_ssa::mir::place::PlaceRef;
77
use rustc_codegen_ssa::traits::{
8-
AsmBuilderMethods, AsmMethods, BaseTypeMethods, BuilderMethods, GlobalAsmOperandRef,
9-
InlineAsmOperandRef,
8+
AsmBuilderMethods, AsmCodegenMethods, BaseTypeCodegenMethods, BuilderMethods,
9+
GlobalAsmOperandRef, InlineAsmOperandRef,
1010
};
1111
use rustc_middle::bug;
1212
use rustc_middle::ty::Instance;
@@ -770,7 +770,7 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
770770
}
771771
}
772772

773-
impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
773+
impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
774774
fn codegen_global_asm(
775775
&self,
776776
template: &[InlineAsmTemplatePiece],

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Instant;
66
use gccjit::{CType, FunctionType, GlobalKind};
77
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
88
use rustc_codegen_ssa::mono_item::MonoItemExt;
9-
use rustc_codegen_ssa::traits::DebugInfoMethods;
9+
use rustc_codegen_ssa::traits::DebugInfoCodegenMethods;
1010
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
1111
use rustc_middle::dep_graph;
1212
use rustc_middle::mir::mono::Linkage;

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ 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, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
18+
LayoutTypeCodegenMethods, OverflowOp, StaticBuilderMethods,
1919
};
2020
use rustc_codegen_ssa::MemFlags;
2121
use rustc_data_structures::fx::FxHashSet;
2222
use rustc_middle::bug;
2323
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2424
use rustc_middle::ty::layout::{
2525
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
26-
TyAndLayout,
2726
};
2827
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
2928
use rustc_span::def_id::DefId;
@@ -460,10 +459,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
460459
}
461460
}
462461

463-
impl<'gcc, 'tcx> HasCodegen<'tcx> for Builder<'_, 'gcc, 'tcx> {
464-
type CodegenCx = CodegenCx<'gcc, 'tcx>;
465-
}
466-
467462
impl<'tcx> HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
468463
fn tcx(&self) -> TyCtxt<'tcx> {
469464
self.cx.tcx()
@@ -477,17 +472,13 @@ impl HasDataLayout for Builder<'_, '_, '_> {
477472
}
478473

479474
impl<'tcx> LayoutOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
480-
type LayoutOfResult = TyAndLayout<'tcx>;
481-
482475
#[inline]
483476
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
484477
self.cx.handle_layout_err(err, span, ty)
485478
}
486479
}
487480

488481
impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
489-
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
490-
491482
#[inline]
492483
fn handle_fn_abi_err(
493484
&self,
@@ -531,6 +522,8 @@ fn set_rvalue_location<'a, 'gcc, 'tcx>(
531522
}
532523

533524
impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
525+
type CodegenCx = CodegenCx<'gcc, 'tcx>;
526+
534527
fn build(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Builder<'a, 'gcc, 'tcx> {
535528
Builder::with_cx(cx, block)
536529
}

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use gccjit::{LValue, RValue, ToRValue, Type};
2-
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, MiscMethods, StaticMethods};
2+
use rustc_codegen_ssa::traits::{
3+
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods,
4+
};
35
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
46
use rustc_middle::mir::Mutability;
57
use rustc_middle::ty::layout::LayoutOf;
@@ -55,7 +57,7 @@ pub fn type_is_pointer(typ: Type<'_>) -> bool {
5557
typ.get_pointee().is_some()
5658
}
5759

58-
impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
60+
impl<'gcc, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
5961
fn const_null(&self, typ: Type<'gcc>) -> RValue<'gcc> {
6062
if type_is_pointer(typ) { self.context.new_null(typ) } else { self.const_int(typ, 0) }
6163
}

compiler/rustc_codegen_gcc/src/consts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#[cfg(feature = "master")]
22
use gccjit::{FnAttribute, VarAttribute, Visibility};
33
use gccjit::{Function, GlobalKind, LValue, RValue, ToRValue, Type};
4-
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, StaticMethods};
4+
use rustc_codegen_ssa::traits::{
5+
BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods,
6+
};
57
use rustc_hir::def::DefKind;
68
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
79
use rustc_middle::mir::interpret::{
@@ -37,7 +39,7 @@ fn set_global_alignment<'gcc, 'tcx>(
3739
gv.set_alignment(align.bytes() as i32);
3840
}
3941

40-
impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
42+
impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
4143
fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
4244
// TODO(antoyo): implement a proper rvalue comparison in libgccjit instead of doing the
4345
// following:

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ use gccjit::{
55
};
66
use rustc_codegen_ssa::base::wants_msvc_seh;
77
use rustc_codegen_ssa::errors as ssa_errors;
8-
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeMethods, MiscMethods};
8+
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods};
99
use rustc_data_structures::base_n::{ToBaseN, ALPHANUMERIC_ONLY};
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_middle::mir::mono::CodegenUnit;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::layout::{
1414
FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError,
15-
LayoutOfHelpers, TyAndLayout,
15+
LayoutOfHelpers,
1616
};
1717
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1818
use rustc_session::Session;
1919
use rustc_span::source_map::respan;
2020
use rustc_span::{Span, DUMMY_SP};
21-
use rustc_target::abi::call::FnAbi;
2221
use rustc_target::abi::{HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2322
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, Target, TlsModel, WasmCAbi};
2423

@@ -426,7 +425,7 @@ impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
426425
type DIVariable = (); // TODO(antoyo)
427426
}
428427

429-
impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
428+
impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
430429
fn vtables(
431430
&self,
432431
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<PolyExistentialTraitRef<'tcx>>), RValue<'gcc>>> {
@@ -572,8 +571,6 @@ impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
572571
}
573572

574573
impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
575-
type LayoutOfResult = TyAndLayout<'tcx>;
576-
577574
#[inline]
578575
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
579576
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
@@ -585,8 +582,6 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
585582
}
586583

587584
impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
588-
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
589-
590585
#[inline]
591586
fn handle_fn_abi_err(
592587
&self,

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::Range;
22

33
use gccjit::{Location, RValue};
44
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
5-
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoMethods};
5+
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
66
use rustc_data_structures::sync::Lrc;
77
use rustc_index::bit_set::BitSet;
88
use rustc_index::{Idx, IndexVec};
@@ -206,7 +206,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
206206
}
207207
}
208208

209-
impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
209+
impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
210210
fn create_vtable_debuginfo(
211211
&self,
212212
_ty: Ty<'tcx>,

compiler/rustc_codegen_gcc/src/declare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "master")]
22
use gccjit::{FnAttribute, ToRValue};
33
use gccjit::{Function, FunctionType, GlobalKind, LValue, RValue, Type};
4-
use rustc_codegen_ssa::traits::BaseTypeMethods;
4+
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods;
55
use rustc_middle::ty::Ty;
66
use rustc_span::Symbol;
77
use rustc_target::abi::call::FnAbi;

0 commit comments

Comments
 (0)