Skip to content

Commit 78778fc

Browse files
committed
rustc_target: remove LayoutOf bound from TyAbiInterface.
1 parent 8e6d126 commit 78778fc

File tree

14 files changed

+81
-85
lines changed

14 files changed

+81
-85
lines changed

compiler/rustc_middle/src/ty/layout.rs

+30-24
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
20902090

20912091
impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
20922092
where
2093-
C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
2093+
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
20942094
{
20952095
fn ty_and_layout_for_variant(
20962096
this: TyAndLayout<'tcx>,
@@ -2109,8 +2109,11 @@ where
21092109
}
21102110

21112111
Variants::Single { index } => {
2112+
let tcx = cx.tcx();
2113+
let param_env = cx.param_env();
2114+
21122115
// Deny calling for_variant more than once for non-Single enums.
2113-
if let Ok(original_layout) = cx.layout_of(this.ty).to_result() {
2116+
if let Ok(original_layout) = tcx.layout_of(param_env.and(this.ty)) {
21142117
assert_eq!(original_layout.variants, Variants::Single { index });
21152118
}
21162119

@@ -2120,7 +2123,6 @@ where
21202123
ty::Adt(def, _) => def.variants[variant_index].fields.len(),
21212124
_ => bug!(),
21222125
};
2123-
let tcx = cx.tcx();
21242126
tcx.intern_layout(Layout {
21252127
variants: Variants::Single { index: variant_index },
21262128
fields: match NonZeroUsize::new(fields) {
@@ -2300,32 +2302,32 @@ where
23002302
cx: &C,
23012303
offset: Size,
23022304
) -> Option<PointeeInfo> {
2305+
let tcx = cx.tcx();
2306+
let param_env = cx.param_env();
2307+
23032308
let addr_space_of_ty = |ty: Ty<'tcx>| {
23042309
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA }
23052310
};
23062311

23072312
let pointee_info = match *this.ty.kind() {
23082313
ty::RawPtr(mt) if offset.bytes() == 0 => {
2309-
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo {
2314+
tcx.layout_of(param_env.and(mt.ty)).ok().map(|layout| PointeeInfo {
23102315
size: layout.size,
23112316
align: layout.align.abi,
23122317
safe: None,
23132318
address_space: addr_space_of_ty(mt.ty),
23142319
})
23152320
}
23162321
ty::FnPtr(fn_sig) if offset.bytes() == 0 => {
2317-
cx.layout_of(cx.tcx().mk_fn_ptr(fn_sig)).to_result().ok().map(|layout| {
2318-
PointeeInfo {
2319-
size: layout.size,
2320-
align: layout.align.abi,
2321-
safe: None,
2322-
address_space: cx.data_layout().instruction_address_space,
2323-
}
2322+
tcx.layout_of(param_env.and(tcx.mk_fn_ptr(fn_sig))).ok().map(|layout| PointeeInfo {
2323+
size: layout.size,
2324+
align: layout.align.abi,
2325+
safe: None,
2326+
address_space: cx.data_layout().instruction_address_space,
23242327
})
23252328
}
23262329
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
23272330
let address_space = addr_space_of_ty(ty);
2328-
let tcx = cx.tcx();
23292331
let kind = if tcx.sess.opts.optimize == OptLevel::No {
23302332
// Use conservative pointer kind if not optimizing. This saves us the
23312333
// Freeze/Unpin queries, and can save time in the codegen backend (noalias
@@ -2354,7 +2356,7 @@ where
23542356
}
23552357
};
23562358

2357-
cx.layout_of(ty).to_result().ok().map(|layout| PointeeInfo {
2359+
tcx.layout_of(param_env.and(ty)).ok().map(|layout| PointeeInfo {
23582360
size: layout.size,
23592361
align: layout.align.abi,
23602362
safe: Some(kind),
@@ -3023,16 +3025,15 @@ where
30233025
}
30243026
}
30253027

3026-
fn make_thin_self_ptr<'tcx, C>(cx: &C, mut layout: TyAndLayout<'tcx>) -> TyAndLayout<'tcx>
3027-
where
3028-
C: LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
3029-
+ HasTyCtxt<'tcx>
3030-
+ HasParamEnv<'tcx>,
3031-
{
3028+
fn make_thin_self_ptr<'tcx>(
3029+
cx: &(impl HasTyCtxt<'tcx> + HasParamEnv<'tcx>),
3030+
layout: TyAndLayout<'tcx>,
3031+
) -> TyAndLayout<'tcx> {
3032+
let tcx = cx.tcx();
30323033
let fat_pointer_ty = if layout.is_unsized() {
30333034
// unsized `self` is passed as a pointer to `self`
30343035
// FIXME (mikeyhew) change this to use &own if it is ever added to the language
3035-
cx.tcx().mk_mut_ptr(layout.ty)
3036+
tcx.mk_mut_ptr(layout.ty)
30363037
} else {
30373038
match layout.abi {
30383039
Abi::ScalarPair(..) => (),
@@ -3066,8 +3067,13 @@ where
30663067
// we now have a type like `*mut RcBox<dyn Trait>`
30673068
// change its layout to that of `*mut ()`, a thin pointer, but keep the same type
30683069
// this is understood as a special case elsewhere in the compiler
3069-
let unit_pointer_ty = cx.tcx().mk_mut_ptr(cx.tcx().mk_unit());
3070-
layout = cx.layout_of(unit_pointer_ty);
3071-
layout.ty = fat_pointer_ty;
3072-
layout
3070+
let unit_ptr_ty = tcx.mk_mut_ptr(tcx.mk_unit());
3071+
3072+
TyAndLayout {
3073+
ty: fat_pointer_ty,
3074+
3075+
// NOTE(eddyb) using an empty `ParamEnv`, and `unwrap`-ing the `Result`
3076+
// should always work because the type is always `*mut ()`.
3077+
..tcx.layout_of(ty::ParamEnv::reveal_all().and(unit_ptr_ty)).unwrap()
3078+
}
30733079
}

compiler/rustc_target/src/abi/call/aarch64.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
2-
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{HasDataLayout, TyAbiInterface};
33

44
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
55
where
66
Ty: TyAbiInterface<'a, C> + Copy,
7-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
7+
C: HasDataLayout,
88
{
99
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
1010
let size = arg.layout.size;
@@ -27,7 +27,7 @@ where
2727
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
2828
where
2929
Ty: TyAbiInterface<'a, C> + Copy,
30-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
30+
C: HasDataLayout,
3131
{
3232
if !ret.layout.is_aggregate() {
3333
ret.extend_integer_width_to(32);
@@ -49,7 +49,7 @@ where
4949
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
5050
where
5151
Ty: TyAbiInterface<'a, C> + Copy,
52-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
52+
C: HasDataLayout,
5353
{
5454
if !arg.layout.is_aggregate() {
5555
arg.extend_integer_width_to(32);
@@ -71,7 +71,7 @@ where
7171
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
7272
where
7373
Ty: TyAbiInterface<'a, C> + Copy,
74-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
74+
C: HasDataLayout,
7575
{
7676
if !fn_abi.ret.is_ignore() {
7777
classify_ret(cx, &mut fn_abi.ret);

compiler/rustc_target/src/abi/call/amdgpu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
use crate::abi::call::{ArgAbi, FnAbi};
2-
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{HasDataLayout, TyAbiInterface};
33

44
fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
55
where
66
Ty: TyAbiInterface<'a, C> + Copy,
7-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
7+
C: HasDataLayout,
88
{
99
ret.extend_integer_width_to(32);
1010
}
1111

1212
fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>)
1313
where
1414
Ty: TyAbiInterface<'a, C> + Copy,
15-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
15+
C: HasDataLayout,
1616
{
1717
arg.extend_integer_width_to(32);
1818
}
1919

2020
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
2121
where
2222
Ty: TyAbiInterface<'a, C> + Copy,
23-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
23+
C: HasDataLayout,
2424
{
2525
if !fn_abi.ret.is_ignore() {
2626
classify_ret(cx, &mut fn_abi.ret);

compiler/rustc_target/src/abi/call/arm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform};
2-
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{HasDataLayout, TyAbiInterface};
33
use crate::spec::HasTargetSpec;
44

55
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
66
where
77
Ty: TyAbiInterface<'a, C> + Copy,
8-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
8+
C: HasDataLayout,
99
{
1010
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
1111
let size = arg.layout.size;
@@ -28,7 +28,7 @@ where
2828
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool)
2929
where
3030
Ty: TyAbiInterface<'a, C> + Copy,
31-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
31+
C: HasDataLayout,
3232
{
3333
if !ret.layout.is_aggregate() {
3434
ret.extend_integer_width_to(32);
@@ -54,7 +54,7 @@ where
5454
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool)
5555
where
5656
Ty: TyAbiInterface<'a, C> + Copy,
57-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
57+
C: HasDataLayout,
5858
{
5959
if !arg.layout.is_aggregate() {
6060
arg.extend_integer_width_to(32);
@@ -76,7 +76,7 @@ where
7676
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
7777
where
7878
Ty: TyAbiInterface<'a, C> + Copy,
79-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
79+
C: HasDataLayout + HasTargetSpec,
8080
{
8181
// If this is a target with a hard-float ABI, and the function is not explicitly
8282
// `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.

compiler/rustc_target/src/abi/call/mips64.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
2-
use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{self, HasDataLayout, Size, TyAbiInterface};
33

44
fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
55
// Always sign extend u32 values on 64-bit mips
@@ -20,7 +20,7 @@ fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
2020
fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option<Reg>
2121
where
2222
Ty: TyAbiInterface<'a, C> + Copy,
23-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
23+
C: HasDataLayout,
2424
{
2525
match ret.layout.field(cx, i).abi {
2626
abi::Abi::Scalar(ref scalar) => match scalar.value {
@@ -35,7 +35,7 @@ where
3535
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
3636
where
3737
Ty: TyAbiInterface<'a, C> + Copy,
38-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
38+
C: HasDataLayout,
3939
{
4040
if !ret.layout.is_aggregate() {
4141
extend_integer_width_mips(ret, 64);
@@ -75,7 +75,7 @@ where
7575
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
7676
where
7777
Ty: TyAbiInterface<'a, C> + Copy,
78-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
78+
C: HasDataLayout,
7979
{
8080
if !arg.layout.is_aggregate() {
8181
extend_integer_width_mips(arg, 64);
@@ -145,7 +145,7 @@ where
145145
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
146146
where
147147
Ty: TyAbiInterface<'a, C> + Copy,
148-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
148+
C: HasDataLayout,
149149
{
150150
if !fn_abi.ret.is_ignore() {
151151
classify_ret(cx, &mut fn_abi.ret);

compiler/rustc_target/src/abi/call/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::{self, Abi, Align, FieldsShape, Size};
2-
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
33
use crate::spec::{self, HasTargetSpec};
44

55
mod aarch64;
@@ -317,7 +317,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
317317
pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, Heterogeneous>
318318
where
319319
Ty: TyAbiInterface<'a, C> + Copy,
320-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = Self>,
321320
{
322321
match self.abi {
323322
Abi::Uninhabited => Err(Heterogeneous),
@@ -604,7 +603,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
604603
pub fn adjust_for_cabi<C>(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String>
605604
where
606605
Ty: TyAbiInterface<'a, C> + Copy,
607-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
606+
C: HasDataLayout + HasTargetSpec,
608607
{
609608
if abi == spec::abi::Abi::X86Interrupt {
610609
if let Some(arg) = self.args.first_mut() {

compiler/rustc_target/src/abi/call/powerpc64.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// need to be fixed when PowerPC vector support is added.
44

55
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
6-
use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout};
6+
use crate::abi::{Endian, HasDataLayout, TyAbiInterface};
77
use crate::spec::HasTargetSpec;
88

99
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -20,7 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(
2020
) -> Option<Uniform>
2121
where
2222
Ty: TyAbiInterface<'a, C> + Copy,
23-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
23+
C: HasDataLayout,
2424
{
2525
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
2626
// ELFv1 only passes one-member aggregates transparently.
@@ -44,7 +44,7 @@ where
4444
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI)
4545
where
4646
Ty: TyAbiInterface<'a, C> + Copy,
47-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
47+
C: HasDataLayout,
4848
{
4949
if !ret.layout.is_aggregate() {
5050
ret.extend_integer_width_to(64);
@@ -87,7 +87,7 @@ where
8787
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI)
8888
where
8989
Ty: TyAbiInterface<'a, C> + Copy,
90-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
90+
C: HasDataLayout,
9191
{
9292
if !arg.layout.is_aggregate() {
9393
arg.extend_integer_width_to(64);
@@ -117,7 +117,7 @@ where
117117
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
118118
where
119119
Ty: TyAbiInterface<'a, C> + Copy,
120-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
120+
C: HasDataLayout + HasTargetSpec,
121121
{
122122
let abi = if cx.target_spec().env == "musl" {
123123
ELFv2

compiler/rustc_target/src/abi/call/riscv.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// https://github.com/llvm/llvm-project/blob/8e780252a7284be45cf1ba224cabd884847e8e92/clang/lib/CodeGen/TargetInfo.cpp#L9311-L9773
66

77
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
8-
use crate::abi::{
9-
self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout,
10-
};
8+
use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
119
use crate::spec::HasTargetSpec;
1210

1311
#[derive(Copy, Clone)]
@@ -44,7 +42,6 @@ fn should_use_fp_conv_helper<'a, Ty, C>(
4442
) -> Result<(), CannotUseFpConv>
4543
where
4644
Ty: TyAbiInterface<'a, C> + Copy,
47-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
4845
{
4946
match arg_layout.abi {
5047
Abi::Scalar(ref scalar) => match scalar.value {
@@ -131,7 +128,6 @@ fn should_use_fp_conv<'a, Ty, C>(
131128
) -> Option<FloatConv>
132129
where
133130
Ty: TyAbiInterface<'a, C> + Copy,
134-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
135131
{
136132
let mut field1_kind = RegPassKind::Unknown;
137133
let mut field2_kind = RegPassKind::Unknown;
@@ -150,7 +146,6 @@ where
150146
fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool
151147
where
152148
Ty: TyAbiInterface<'a, C> + Copy,
153-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
154149
{
155150
if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) {
156151
match conv {
@@ -213,7 +208,6 @@ fn classify_arg<'a, Ty, C>(
213208
avail_fprs: &mut u64,
214209
) where
215210
Ty: TyAbiInterface<'a, C> + Copy,
216-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
217211
{
218212
if !is_vararg {
219213
match should_use_fp_conv(cx, &arg.layout, xlen, flen) {
@@ -321,7 +315,7 @@ fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) {
321315
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
322316
where
323317
Ty: TyAbiInterface<'a, C> + Copy,
324-
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
318+
C: HasDataLayout + HasTargetSpec,
325319
{
326320
let flen = match &cx.target_spec().llvm_abiname[..] {
327321
"ilp32f" | "lp64f" => 32,

0 commit comments

Comments
 (0)