From 8486571a10ce57b02ae19bfb1b31736fb2a1b4fe Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 25 Aug 2021 16:45:24 +0300 Subject: [PATCH] rustc_target: rename `TyAndLayoutMethods` to `TyAbiInterface`. --- compiler/rustc_codegen_llvm/src/type_of.rs | 7 +++-- compiler/rustc_middle/src/ty/layout.rs | 12 +++++--- compiler/rustc_target/src/abi/call/aarch64.rs | 10 +++---- compiler/rustc_target/src/abi/call/amdgpu.rs | 8 +++--- compiler/rustc_target/src/abi/call/arm.rs | 10 +++---- compiler/rustc_target/src/abi/call/mips64.rs | 10 +++---- compiler/rustc_target/src/abi/call/mod.rs | 6 ++-- .../rustc_target/src/abi/call/powerpc64.rs | 10 +++---- compiler/rustc_target/src/abi/call/riscv.rs | 12 ++++---- compiler/rustc_target/src/abi/call/s390x.rs | 8 +++--- compiler/rustc_target/src/abi/call/sparc64.rs | 10 +++---- compiler/rustc_target/src/abi/call/wasm.rs | 10 +++---- compiler/rustc_target/src/abi/call/x86.rs | 6 ++-- compiler/rustc_target/src/abi/call/x86_64.rs | 8 +++--- compiler/rustc_target/src/abi/mod.rs | 28 +++++++++++-------- 15 files changed, 84 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 85efe3e6483..9818905464d 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TypeFoldable}; use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape}; use rustc_target::abi::{Int, Pointer, F32, F64}; -use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants}; +use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAbiInterface, Variants}; use smallvec::{smallvec, SmallVec}; use tracing::debug; @@ -393,12 +393,15 @@ fn llvm_field_index<'a>(&self, cx: &CodegenCx<'a, 'tcx>, index: usize) -> u64 { } } + // FIXME(eddyb) this having the same name as `TyAndLayout::pointee_info_at` + // (the inherent method, which is lacking this caching logic) can result in + // the uncached version being called - not wrong, but potentially inefficient. fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option { if let Some(&pointee) = cx.pointee_infos.borrow().get(&(self.ty, offset)) { return pointee; } - let result = Ty::pointee_info_at(*self, cx, offset); + let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset); cx.pointee_infos.borrow_mut().insert((self.ty, offset), result); result diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index b388f71d9f2..d8d1f4929ad 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2078,11 +2078,11 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { } } -impl<'tcx, C> TyAndLayoutMethods<'tcx, C> for Ty<'tcx> +impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx> where C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, { - fn for_variant( + fn ty_and_layout_for_variant( this: TyAndLayout<'tcx>, cx: &C, variant_index: VariantIdx, @@ -2132,7 +2132,7 @@ fn for_variant( TyAndLayout { ty: this.ty, layout } } - fn field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { + fn ty_and_layout_field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { enum TyMaybeWithLayout<'tcx, C: LayoutOf<'tcx>> { Ty(C::Ty), TyAndLayout(C::TyAndLayout), @@ -2276,7 +2276,11 @@ fn ty_and_layout_kind< }) } - fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option { + fn ty_and_layout_pointee_info_at( + this: TyAndLayout<'tcx>, + cx: &C, + offset: Size, + ) -> Option { let addr_space_of_ty = |ty: Ty<'tcx>| { if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA } }; diff --git a/compiler/rustc_target/src/abi/call/aarch64.rs b/compiler/rustc_target/src/abi/call/aarch64.rs index 02006e3fd69..3d5ca0daca6 100644 --- a/compiler/rustc_target/src/abi/call/aarch64.rs +++ b/compiler/rustc_target/src/abi/call/aarch64.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -26,7 +26,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Opti fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -48,7 +48,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -70,7 +70,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/amdgpu.rs b/compiler/rustc_target/src/abi/call/amdgpu.rs index 404702ae94b..289de140687 100644 --- a/compiler/rustc_target/src/abi/call/amdgpu.rs +++ b/compiler/rustc_target/src/abi/call/amdgpu.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); @@ -11,7 +11,7 @@ fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); @@ -19,7 +19,7 @@ fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/arm.rs b/compiler/rustc_target/src/abi/call/arm.rs index 55bcdba7aaa..4498beaa2dd 100644 --- a/compiler/rustc_target/src/abi/call/arm.rs +++ b/compiler/rustc_target/src/abi/call/arm.rs @@ -1,10 +1,10 @@ use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -27,7 +27,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Opti fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -53,7 +53,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -75,7 +75,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { // If this is a target with a hard-float ABI, and the function is not explicitly diff --git a/compiler/rustc_target/src/abi/call/mips64.rs b/compiler/rustc_target/src/abi/call/mips64.rs index 1b03024e329..99e70f216b2 100644 --- a/compiler/rustc_target/src/abi/call/mips64.rs +++ b/compiler/rustc_target/src/abi/call/mips64.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; -use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips @@ -19,7 +19,7 @@ fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match ret.layout.field(cx, i).abi { @@ -34,7 +34,7 @@ fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -74,7 +74,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -144,7 +144,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 452e700d5c2..3c030997390 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -1,5 +1,5 @@ use crate::abi::{self, Abi, Align, FieldsShape, Size}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::{self, HasTargetSpec}; mod aarch64; @@ -316,7 +316,7 @@ fn is_aggregate(&self) -> bool { /// specific targets. pub fn homogeneous_aggregate(&self, cx: &C) -> Result where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = Self>, { match self.abi { @@ -603,7 +603,7 @@ pub struct FnAbi<'a, Ty> { impl<'a, Ty> FnAbi<'a, Ty> { pub fn adjust_for_cabi(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if abi == spec::abi::Abi::X86Interrupt { diff --git a/compiler/rustc_target/src/abi/call/powerpc64.rs b/compiler/rustc_target/src/abi/call/powerpc64.rs index 662a0b44af5..62570a87f19 100644 --- a/compiler/rustc_target/src/abi/call/powerpc64.rs +++ b/compiler/rustc_target/src/abi/call/powerpc64.rs @@ -3,7 +3,7 @@ // need to be fixed when PowerPC vector support is added. use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; #[derive(Debug, Clone, Copy, PartialEq)] @@ -19,7 +19,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>( abi: ABI, ) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -43,7 +43,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>( fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -86,7 +86,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -116,7 +116,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let abi = if cx.target_spec().env == "musl" { diff --git a/compiler/rustc_target/src/abi/call/riscv.rs b/compiler/rustc_target/src/abi/call/riscv.rs index f1e7658aec6..c29fc7a08c0 100644 --- a/compiler/rustc_target/src/abi/call/riscv.rs +++ b/compiler/rustc_target/src/abi/call/riscv.rs @@ -6,7 +6,7 @@ use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; use crate::abi::{ - self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods, + self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout, }; use crate::spec::HasTargetSpec; @@ -43,7 +43,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( field2_kind: &mut RegPassKind, ) -> Result<(), CannotUseFpConv> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { match arg_layout.abi { @@ -130,7 +130,7 @@ fn should_use_fp_conv<'a, Ty, C>( flen: u64, ) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { let mut field1_kind = RegPassKind::Unknown; @@ -149,7 +149,7 @@ fn should_use_fp_conv<'a, Ty, C>( fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool where - Ty: TyAndLayoutMethods<'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) { @@ -212,7 +212,7 @@ fn classify_arg<'a, Ty, C>( avail_gprs: &mut u64, avail_fprs: &mut u64, ) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { if !is_vararg { @@ -320,7 +320,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>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let flen = match &cx.target_spec().llvm_abiname[..] { diff --git a/compiler/rustc_target/src/abi/call/s390x.rs b/compiler/rustc_target/src/abi/call/s390x.rs index dea5d4605d1..bd4eff5e321 100644 --- a/compiler/rustc_target/src/abi/call/s390x.rs +++ b/compiler/rustc_target/src/abi/call/s390x.rs @@ -2,7 +2,7 @@ // for a pre-z13 machine or using -mno-vx. use crate::abi::call::{ArgAbi, FnAbi, Reg}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 { @@ -14,7 +14,7 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { @@ -32,7 +32,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 { @@ -59,7 +59,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/sparc64.rs b/compiler/rustc_target/src/abi/call/sparc64.rs index bdbce38e86a..1fe7b74c2bc 100644 --- a/compiler/rustc_target/src/abi/call/sparc64.rs +++ b/compiler/rustc_target/src/abi/call/sparc64.rs @@ -1,11 +1,11 @@ // FIXME: This needs an audit for correctness and completeness. use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -26,7 +26,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Opti fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -52,7 +52,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -76,7 +76,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/wasm.rs b/compiler/rustc_target/src/abi/call/wasm.rs index c3187dff7af..7f607ebead1 100644 --- a/compiler/rustc_target/src/abi/call/wasm.rs +++ b/compiler/rustc_target/src/abi/call/wasm.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if val.layout.is_aggregate() { @@ -20,7 +20,7 @@ fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); @@ -31,7 +31,7 @@ fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); @@ -43,7 +43,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) /// The purpose of this ABI is to match the C ABI (aka clang) exactly. pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/x86.rs b/compiler/rustc_target/src/abi/call/x86.rs index d27f1996a61..41e9e842061 100644 --- a/compiler/rustc_target/src/abi/call/x86.rs +++ b/compiler/rustc_target/src/abi/call/x86.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; #[derive(PartialEq)] @@ -10,7 +10,7 @@ pub enum Flavor { fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { @@ -28,7 +28,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/x86_64.rs b/compiler/rustc_target/src/abi/call/x86_64.rs index da47396e2d1..9146839b086 100644 --- a/compiler/rustc_target/src/abi/call/x86_64.rs +++ b/compiler/rustc_target/src/abi/call/x86_64.rs @@ -2,7 +2,7 @@ // https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind}; -use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; /// Classification of "eightbyte" components. // N.B., the order of the variants is from general to specific, @@ -26,7 +26,7 @@ fn classify_arg<'a, Ty, C>( arg: &ArgAbi<'a, Ty>, ) -> Result<[Option; MAX_EIGHTBYTES], Memory> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { fn classify<'a, Ty, C>( @@ -36,7 +36,7 @@ fn classify<'a, Ty, C>( off: Size, ) -> Result<(), Memory> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !off.is_aligned(layout.align.abi) { @@ -172,7 +172,7 @@ fn cast_target(cls: &[Option], size: Size) -> CastTarget { pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { let mut int_regs = MAX_INT_REGS; diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 1d1a34dc248..250afbecd58 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1236,39 +1236,45 @@ pub struct PointeeInfo { pub address_space: AddressSpace, } -pub trait TyAndLayoutMethods<'a, C: LayoutOf<'a, Ty = Self>>: Sized { - fn for_variant( +/// Trait that needs to be implemented by the higher-level type representation +/// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality. +pub trait TyAbiInterface<'a, C: LayoutOf<'a, Ty = Self>>: Sized { + fn ty_and_layout_for_variant( this: TyAndLayout<'a, Self>, cx: &C, variant_index: VariantIdx, ) -> TyAndLayout<'a, Self>; - fn field(this: TyAndLayout<'a, Self>, cx: &C, i: usize) -> C::TyAndLayout; - fn pointee_info_at(this: TyAndLayout<'a, Self>, cx: &C, offset: Size) -> Option; + fn ty_and_layout_field(this: TyAndLayout<'a, Self>, cx: &C, i: usize) -> C::TyAndLayout; + fn ty_and_layout_pointee_info_at( + this: TyAndLayout<'a, Self>, + cx: &C, + offset: Size, + ) -> Option; } impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn for_variant(self, cx: &C, variant_index: VariantIdx) -> Self where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::for_variant(self, cx, variant_index) + Ty::ty_and_layout_for_variant(self, cx, variant_index) } pub fn field(self, cx: &C, i: usize) -> C::TyAndLayout where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::field(self, cx, i) + Ty::ty_and_layout_field(self, cx, i) } pub fn pointee_info_at(self, cx: &C, offset: Size) -> Option where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::pointee_info_at(self, cx, offset) + Ty::ty_and_layout_pointee_info_at(self, cx, offset) } } @@ -1299,7 +1305,7 @@ pub fn is_zst(&self) -> bool { pub fn might_permit_raw_init(self, cx: &C, zero: bool) -> Result where Self: Copy, - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty, TyAndLayout: MaybeResult> + HasDataLayout, { let scalar_allows_raw_init = move |s: &Scalar| -> bool { -- 2.44.0