1
Fork 0

rustc_target: remove LayoutOf bound from TyAbiInterface.

This commit is contained in:
Eduard-Mihai Burtescu 2021-08-25 18:15:09 +03:00
parent 8e6d126b7d
commit 78778fc6aa
14 changed files with 81 additions and 85 deletions

View file

@ -2090,7 +2090,7 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx> impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
where where
C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
{ {
fn ty_and_layout_for_variant( fn ty_and_layout_for_variant(
this: TyAndLayout<'tcx>, this: TyAndLayout<'tcx>,
@ -2109,8 +2109,11 @@ where
} }
Variants::Single { index } => { Variants::Single { index } => {
let tcx = cx.tcx();
let param_env = cx.param_env();
// Deny calling for_variant more than once for non-Single enums. // Deny calling for_variant more than once for non-Single enums.
if let Ok(original_layout) = cx.layout_of(this.ty).to_result() { if let Ok(original_layout) = tcx.layout_of(param_env.and(this.ty)) {
assert_eq!(original_layout.variants, Variants::Single { index }); assert_eq!(original_layout.variants, Variants::Single { index });
} }
@ -2120,7 +2123,6 @@ where
ty::Adt(def, _) => def.variants[variant_index].fields.len(), ty::Adt(def, _) => def.variants[variant_index].fields.len(),
_ => bug!(), _ => bug!(),
}; };
let tcx = cx.tcx();
tcx.intern_layout(Layout { tcx.intern_layout(Layout {
variants: Variants::Single { index: variant_index }, variants: Variants::Single { index: variant_index },
fields: match NonZeroUsize::new(fields) { fields: match NonZeroUsize::new(fields) {
@ -2300,13 +2302,16 @@ where
cx: &C, cx: &C,
offset: Size, offset: Size,
) -> Option<PointeeInfo> { ) -> Option<PointeeInfo> {
let tcx = cx.tcx();
let param_env = cx.param_env();
let addr_space_of_ty = |ty: Ty<'tcx>| { let addr_space_of_ty = |ty: Ty<'tcx>| {
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA } if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA }
}; };
let pointee_info = match *this.ty.kind() { let pointee_info = match *this.ty.kind() {
ty::RawPtr(mt) if offset.bytes() == 0 => { ty::RawPtr(mt) if offset.bytes() == 0 => {
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo { tcx.layout_of(param_env.and(mt.ty)).ok().map(|layout| PointeeInfo {
size: layout.size, size: layout.size,
align: layout.align.abi, align: layout.align.abi,
safe: None, safe: None,
@ -2314,18 +2319,15 @@ where
}) })
} }
ty::FnPtr(fn_sig) if offset.bytes() == 0 => { ty::FnPtr(fn_sig) if offset.bytes() == 0 => {
cx.layout_of(cx.tcx().mk_fn_ptr(fn_sig)).to_result().ok().map(|layout| { tcx.layout_of(param_env.and(tcx.mk_fn_ptr(fn_sig))).ok().map(|layout| PointeeInfo {
PointeeInfo { size: layout.size,
size: layout.size, align: layout.align.abi,
align: layout.align.abi, safe: None,
safe: None, address_space: cx.data_layout().instruction_address_space,
address_space: cx.data_layout().instruction_address_space,
}
}) })
} }
ty::Ref(_, ty, mt) if offset.bytes() == 0 => { ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
let address_space = addr_space_of_ty(ty); let address_space = addr_space_of_ty(ty);
let tcx = cx.tcx();
let kind = if tcx.sess.opts.optimize == OptLevel::No { let kind = if tcx.sess.opts.optimize == OptLevel::No {
// Use conservative pointer kind if not optimizing. This saves us the // Use conservative pointer kind if not optimizing. This saves us the
// Freeze/Unpin queries, and can save time in the codegen backend (noalias // Freeze/Unpin queries, and can save time in the codegen backend (noalias
@ -2354,7 +2356,7 @@ where
} }
}; };
cx.layout_of(ty).to_result().ok().map(|layout| PointeeInfo { tcx.layout_of(param_env.and(ty)).ok().map(|layout| PointeeInfo {
size: layout.size, size: layout.size,
align: layout.align.abi, align: layout.align.abi,
safe: Some(kind), safe: Some(kind),
@ -3023,16 +3025,15 @@ where
} }
} }
fn make_thin_self_ptr<'tcx, C>(cx: &C, mut layout: TyAndLayout<'tcx>) -> TyAndLayout<'tcx> fn make_thin_self_ptr<'tcx>(
where cx: &(impl HasTyCtxt<'tcx> + HasParamEnv<'tcx>),
C: LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> layout: TyAndLayout<'tcx>,
+ HasTyCtxt<'tcx> ) -> TyAndLayout<'tcx> {
+ HasParamEnv<'tcx>, let tcx = cx.tcx();
{
let fat_pointer_ty = if layout.is_unsized() { let fat_pointer_ty = if layout.is_unsized() {
// unsized `self` is passed as a pointer to `self` // unsized `self` is passed as a pointer to `self`
// FIXME (mikeyhew) change this to use &own if it is ever added to the language // FIXME (mikeyhew) change this to use &own if it is ever added to the language
cx.tcx().mk_mut_ptr(layout.ty) tcx.mk_mut_ptr(layout.ty)
} else { } else {
match layout.abi { match layout.abi {
Abi::ScalarPair(..) => (), Abi::ScalarPair(..) => (),
@ -3066,8 +3067,13 @@ where
// we now have a type like `*mut RcBox<dyn Trait>` // we now have a type like `*mut RcBox<dyn Trait>`
// change its layout to that of `*mut ()`, a thin pointer, but keep the same type // change its layout to that of `*mut ()`, a thin pointer, but keep the same type
// this is understood as a special case elsewhere in the compiler // this is understood as a special case elsewhere in the compiler
let unit_pointer_ty = cx.tcx().mk_mut_ptr(cx.tcx().mk_unit()); let unit_ptr_ty = tcx.mk_mut_ptr(tcx.mk_unit());
layout = cx.layout_of(unit_pointer_ty);
layout.ty = fat_pointer_ty; TyAndLayout {
layout ty: fat_pointer_ty,
// NOTE(eddyb) using an empty `ParamEnv`, and `unwrap`-ing the `Result`
// should always work because the type is always `*mut ()`.
..tcx.layout_of(ty::ParamEnv::reveal_all().and(unit_ptr_ty)).unwrap()
}
} }

View file

@ -1,10 +1,10 @@
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface};
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform> fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
let size = arg.layout.size; let size = arg.layout.size;
@ -27,7 +27,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !ret.layout.is_aggregate() { if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(32); ret.extend_integer_width_to(32);
@ -49,7 +49,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() { if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(32); arg.extend_integer_width_to(32);
@ -71,7 +71,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret); classify_ret(cx, &mut fn_abi.ret);

View file

@ -1,10 +1,10 @@
use crate::abi::call::{ArgAbi, FnAbi}; use crate::abi::call::{ArgAbi, FnAbi};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface};
fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
ret.extend_integer_width_to(32); ret.extend_integer_width_to(32);
} }
@ -12,7 +12,7 @@ where
fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.extend_integer_width_to(32); arg.extend_integer_width_to(32);
} }
@ -20,7 +20,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret); classify_ret(cx, &mut fn_abi.ret);

View file

@ -1,11 +1,11 @@
use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface};
use crate::spec::HasTargetSpec; use crate::spec::HasTargetSpec;
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform> fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
let size = arg.layout.size; let size = arg.layout.size;
@ -28,7 +28,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !ret.layout.is_aggregate() { if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(32); ret.extend_integer_width_to(32);
@ -54,7 +54,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() { if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(32); arg.extend_integer_width_to(32);
@ -76,7 +76,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, C: HasDataLayout + HasTargetSpec,
{ {
// If this is a target with a hard-float ABI, and the function is not explicitly // If this is a target with a hard-float ABI, and the function is not explicitly
// `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates. // `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.

View file

@ -1,5 +1,5 @@
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; use crate::abi::{self, HasDataLayout, Size, TyAbiInterface};
fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) { fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
// Always sign extend u32 values on 64-bit mips // 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) {
fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option<Reg> fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option<Reg>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
match ret.layout.field(cx, i).abi { match ret.layout.field(cx, i).abi {
abi::Abi::Scalar(ref scalar) => match scalar.value { abi::Abi::Scalar(ref scalar) => match scalar.value {
@ -35,7 +35,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !ret.layout.is_aggregate() { if !ret.layout.is_aggregate() {
extend_integer_width_mips(ret, 64); extend_integer_width_mips(ret, 64);
@ -75,7 +75,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() { if !arg.layout.is_aggregate() {
extend_integer_width_mips(arg, 64); extend_integer_width_mips(arg, 64);
@ -145,7 +145,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret); classify_ret(cx, &mut fn_abi.ret);

View file

@ -1,5 +1,5 @@
use crate::abi::{self, Abi, Align, FieldsShape, Size}; use crate::abi::{self, Abi, Align, FieldsShape, Size};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::spec::{self, HasTargetSpec}; use crate::spec::{self, HasTargetSpec};
mod aarch64; mod aarch64;
@ -317,7 +317,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, Heterogeneous> pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, Heterogeneous>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = Self>,
{ {
match self.abi { match self.abi {
Abi::Uninhabited => Err(Heterogeneous), Abi::Uninhabited => Err(Heterogeneous),
@ -604,7 +603,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
pub fn adjust_for_cabi<C>(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String> pub fn adjust_for_cabi<C>(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, C: HasDataLayout + HasTargetSpec,
{ {
if abi == spec::abi::Abi::X86Interrupt { if abi == spec::abi::Abi::X86Interrupt {
if let Some(arg) = self.args.first_mut() { if let Some(arg) = self.args.first_mut() {

View file

@ -3,7 +3,7 @@
// need to be fixed when PowerPC vector support is added. // need to be fixed when PowerPC vector support is added.
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{Endian, HasDataLayout, TyAbiInterface};
use crate::spec::HasTargetSpec; use crate::spec::HasTargetSpec;
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
@ -20,7 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(
) -> Option<Uniform> ) -> Option<Uniform>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
// ELFv1 only passes one-member aggregates transparently. // ELFv1 only passes one-member aggregates transparently.
@ -44,7 +44,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !ret.layout.is_aggregate() { if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64); ret.extend_integer_width_to(64);
@ -87,7 +87,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() { if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64); arg.extend_integer_width_to(64);
@ -117,7 +117,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, C: HasDataLayout + HasTargetSpec,
{ {
let abi = if cx.target_spec().env == "musl" { let abi = if cx.target_spec().env == "musl" {
ELFv2 ELFv2

View file

@ -5,9 +5,7 @@
// https://github.com/llvm/llvm-project/blob/8e780252a7284be45cf1ba224cabd884847e8e92/clang/lib/CodeGen/TargetInfo.cpp#L9311-L9773 // https://github.com/llvm/llvm-project/blob/8e780252a7284be45cf1ba224cabd884847e8e92/clang/lib/CodeGen/TargetInfo.cpp#L9311-L9773
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
use crate::abi::{ use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout,
};
use crate::spec::HasTargetSpec; use crate::spec::HasTargetSpec;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -44,7 +42,6 @@ fn should_use_fp_conv_helper<'a, Ty, C>(
) -> Result<(), CannotUseFpConv> ) -> Result<(), CannotUseFpConv>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{ {
match arg_layout.abi { match arg_layout.abi {
Abi::Scalar(ref scalar) => match scalar.value { Abi::Scalar(ref scalar) => match scalar.value {
@ -131,7 +128,6 @@ fn should_use_fp_conv<'a, Ty, C>(
) -> Option<FloatConv> ) -> Option<FloatConv>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{ {
let mut field1_kind = RegPassKind::Unknown; let mut field1_kind = RegPassKind::Unknown;
let mut field2_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown;
@ -150,7 +146,6 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{ {
if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) { if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) {
match conv { match conv {
@ -213,7 +208,6 @@ fn classify_arg<'a, Ty, C>(
avail_fprs: &mut u64, avail_fprs: &mut u64,
) where ) where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{ {
if !is_vararg { if !is_vararg {
match should_use_fp_conv(cx, &arg.layout, xlen, flen) { 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) {
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, C: HasDataLayout + HasTargetSpec,
{ {
let flen = match &cx.target_spec().llvm_abiname[..] { let flen = match &cx.target_spec().llvm_abiname[..] {
"ilp32f" | "lp64f" => 32, "ilp32f" | "lp64f" => 32,

View file

@ -2,7 +2,7 @@
// for a pre-z13 machine or using -mno-vx. // for a pre-z13 machine or using -mno-vx.
use crate::abi::call::{ArgAbi, FnAbi, Reg}; use crate::abi::call::{ArgAbi, FnAbi, Reg};
use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) { fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 { if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
@ -15,7 +15,7 @@ fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where where
Ty: TyAbiInterface<'a, C>, Ty: TyAbiInterface<'a, C>,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
match layout.abi { match layout.abi {
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
@ -33,7 +33,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 { if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
arg.extend_integer_width_to(64); arg.extend_integer_width_to(64);
@ -60,7 +60,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(&mut fn_abi.ret); classify_ret(&mut fn_abi.ret);

View file

@ -1,12 +1,12 @@
// FIXME: This needs an audit for correctness and completeness. // FIXME: This needs an audit for correctness and completeness.
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface};
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform> fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
// Ensure we have at most eight uniquely addressable members. // Ensure we have at most eight uniquely addressable members.
@ -27,7 +27,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !ret.layout.is_aggregate() { if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64); ret.extend_integer_width_to(64);
@ -53,7 +53,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !arg.layout.is_aggregate() { if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64); arg.extend_integer_width_to(64);
@ -77,7 +77,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret); classify_ret(cx, &mut fn_abi.ret);

View file

@ -1,10 +1,10 @@
use crate::abi::call::{ArgAbi, FnAbi, Uniform}; use crate::abi::call::{ArgAbi, FnAbi, Uniform};
use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{HasDataLayout, TyAbiInterface};
fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if val.layout.is_aggregate() { if val.layout.is_aggregate() {
if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) { if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) {
@ -21,7 +21,7 @@ where
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
ret.extend_integer_width_to(32); ret.extend_integer_width_to(32);
if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) { if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) {
@ -32,7 +32,7 @@ where
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
arg.extend_integer_width_to(32); arg.extend_integer_width_to(32);
if arg.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, arg) { if arg.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, arg) {
@ -44,7 +44,7 @@ where
pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret); classify_ret(cx, &mut fn_abi.ret);

View file

@ -1,5 +1,5 @@
use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind}; use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind};
use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::spec::HasTargetSpec; use crate::spec::HasTargetSpec;
#[derive(PartialEq)] #[derive(PartialEq)]
@ -11,7 +11,7 @@ pub enum Flavor {
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
match layout.abi { match layout.abi {
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
@ -29,7 +29,7 @@ where
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, C: HasDataLayout + HasTargetSpec,
{ {
if !fn_abi.ret.is_ignore() { if !fn_abi.ret.is_ignore() {
if fn_abi.ret.layout.is_aggregate() { if fn_abi.ret.layout.is_aggregate() {

View file

@ -2,7 +2,7 @@
// https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp // https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp
use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind}; use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind};
use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; use crate::abi::{self, Abi, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
/// Classification of "eightbyte" components. /// Classification of "eightbyte" components.
// N.B., the order of the variants is from general to specific, // N.B., the order of the variants is from general to specific,
@ -27,7 +27,7 @@ fn classify_arg<'a, Ty, C>(
) -> Result<[Option<Class>; MAX_EIGHTBYTES], Memory> ) -> Result<[Option<Class>; MAX_EIGHTBYTES], Memory>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
fn classify<'a, Ty, C>( fn classify<'a, Ty, C>(
cx: &C, cx: &C,
@ -37,7 +37,7 @@ where
) -> Result<(), Memory> ) -> Result<(), Memory>
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
if !off.is_aligned(layout.align.abi) { if !off.is_aligned(layout.align.abi) {
if !layout.is_zst() { if !layout.is_zst() {
@ -173,7 +173,7 @@ const MAX_SSE_REGS: usize = 8; // XMM0-7
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,
C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, C: HasDataLayout,
{ {
let mut int_regs = MAX_INT_REGS; let mut int_regs = MAX_INT_REGS;
let mut sse_regs = MAX_SSE_REGS; let mut sse_regs = MAX_SSE_REGS;

View file

@ -1238,7 +1238,7 @@ pub struct PointeeInfo {
/// Trait that needs to be implemented by the higher-level type representation /// Trait that needs to be implemented by the higher-level type representation
/// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality. /// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality.
pub trait TyAbiInterface<'a, C: LayoutOf<'a, Ty = Self>>: Sized { pub trait TyAbiInterface<'a, C>: Sized {
fn ty_and_layout_for_variant( fn ty_and_layout_for_variant(
this: TyAndLayout<'a, Self>, this: TyAndLayout<'a, Self>,
cx: &C, cx: &C,
@ -1256,7 +1256,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
pub fn for_variant<C>(self, cx: &C, variant_index: VariantIdx) -> Self pub fn for_variant<C>(self, cx: &C, variant_index: VariantIdx) -> Self
where where
Ty: TyAbiInterface<'a, C>, Ty: TyAbiInterface<'a, C>,
C: LayoutOf<'a, Ty = Ty>,
{ {
Ty::ty_and_layout_for_variant(self, cx, variant_index) Ty::ty_and_layout_for_variant(self, cx, variant_index)
} }
@ -1264,7 +1263,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
pub fn field<C>(self, cx: &C, i: usize) -> Self pub fn field<C>(self, cx: &C, i: usize) -> Self
where where
Ty: TyAbiInterface<'a, C>, Ty: TyAbiInterface<'a, C>,
C: LayoutOf<'a, Ty = Ty>,
{ {
Ty::ty_and_layout_field(self, cx, i) Ty::ty_and_layout_field(self, cx, i)
} }
@ -1272,7 +1270,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
pub fn pointee_info_at<C>(self, cx: &C, offset: Size) -> Option<PointeeInfo> pub fn pointee_info_at<C>(self, cx: &C, offset: Size) -> Option<PointeeInfo>
where where
Ty: TyAbiInterface<'a, C>, Ty: TyAbiInterface<'a, C>,
C: LayoutOf<'a, Ty = Ty>,
{ {
Ty::ty_and_layout_pointee_info_at(self, cx, offset) Ty::ty_and_layout_pointee_info_at(self, cx, offset)
} }
@ -1306,7 +1303,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
where where
Self: Copy, Self: Copy,
Ty: TyAbiInterface<'a, C>, Ty: TyAbiInterface<'a, C>,
C: LayoutOf<'a, Ty = Ty> + HasDataLayout, C: HasDataLayout,
{ {
let scalar_allows_raw_init = move |s: &Scalar| -> bool { let scalar_allows_raw_init = move |s: &Scalar| -> bool {
if zero { if zero {