From 50d2c3abd59af8cbed7e001b5b4e2f6a9a011112 Mon Sep 17 00:00:00 2001 From: Ana-Maria Mihalache Date: Wed, 4 Mar 2020 14:50:21 +0000 Subject: [PATCH 1/4] Rename TyLayout to TyAndLayout. --- src/librustc/ty/layout.rs | 76 +++++++++++-------- src/librustc_codegen_llvm/builder.rs | 6 +- src/librustc_codegen_llvm/common.rs | 4 +- src/librustc_codegen_llvm/context.rs | 8 +- .../debuginfo/metadata.rs | 10 +-- src/librustc_codegen_llvm/type_.rs | 14 ++-- src/librustc_codegen_llvm/type_of.rs | 18 ++--- src/librustc_codegen_ssa/base.rs | 6 +- src/librustc_codegen_ssa/mir/mod.rs | 4 +- src/librustc_codegen_ssa/mir/operand.rs | 8 +- src/librustc_codegen_ssa/mir/place.rs | 16 ++-- src/librustc_codegen_ssa/traits/backend.rs | 6 +- src/librustc_codegen_ssa/traits/consts.rs | 2 +- src/librustc_codegen_ssa/traits/type_.rs | 14 ++-- src/librustc_lint/context.rs | 6 +- src/librustc_mir/interpret/cast.rs | 8 +- src/librustc_mir/interpret/eval_context.rs | 18 ++--- src/librustc_mir/interpret/operand.rs | 30 ++++---- src/librustc_mir/interpret/operator.rs | 6 +- src/librustc_mir/interpret/place.rs | 18 ++--- src/librustc_mir/interpret/terminator.rs | 6 +- src/librustc_mir/interpret/validity.rs | 6 +- src/librustc_mir/interpret/visitor.rs | 8 +- src/librustc_mir/transform/const_prop.rs | 8 +- .../transform/uninhabited_enum_branching.rs | 4 +- src/librustc_passes/layout_test.rs | 6 +- src/librustc_target/abi/call/aarch64.rs | 18 ++--- src/librustc_target/abi/call/amdgpu.rs | 14 ++-- src/librustc_target/abi/call/arm.rs | 18 ++--- src/librustc_target/abi/call/mips.rs | 8 +- src/librustc_target/abi/call/mips64.rs | 18 ++--- src/librustc_target/abi/call/mod.rs | 16 ++-- src/librustc_target/abi/call/powerpc64.rs | 18 ++--- src/librustc_target/abi/call/riscv.rs | 26 +++---- src/librustc_target/abi/call/s390x.rs | 18 ++--- src/librustc_target/abi/call/sparc.rs | 8 +- src/librustc_target/abi/call/sparc64.rs | 18 ++--- src/librustc_target/abi/call/wasm32.rs | 18 ++--- src/librustc_target/abi/call/x86.rs | 12 +-- src/librustc_target/abi/call/x86_64.rs | 16 ++-- src/librustc_target/abi/mod.rs | 41 +++++----- 41 files changed, 298 insertions(+), 285 deletions(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index ad4352c010572..bfe9ed200a154 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -270,7 +270,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { fn univariant_uninterned( &self, ty: Ty<'tcx>, - fields: &[TyLayout<'_>], + fields: &[TyAndLayout<'_>], repr: &ReprOptions, kind: StructKind, ) -> Result> { @@ -293,7 +293,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() }; let optimizing = &mut inverse_memory_index[..end]; - let field_align = |f: &TyLayout<'_>| { + let field_align = |f: &TyAndLayout<'_>| { if let Some(pack) = pack { f.align.abi.min(pack) } else { f.align.abi } }; match kind { @@ -422,11 +422,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ( Some(( i, - &TyLayout { layout: &Layout { abi: Abi::Scalar(ref a), .. }, .. }, + &TyAndLayout { + layout: &Layout { abi: Abi::Scalar(ref a), .. }, .. + }, )), Some(( j, - &TyLayout { layout: &Layout { abi: Abi::Scalar(ref b), .. }, .. }, + &TyAndLayout { + layout: &Layout { abi: Abi::Scalar(ref b), .. }, .. + }, )), None, ) => { @@ -485,7 +489,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }; let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value))); - let univariant = |fields: &[TyLayout<'_>], repr: &ReprOptions, kind| { + let univariant = |fields: &[TyAndLayout<'_>], repr: &ReprOptions, kind| { Ok(tcx.intern_layout(self.univariant_uninterned(ty, fields, repr, kind)?)) }; debug_assert!(!ty.has_infer_types_or_consts()); @@ -754,7 +758,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // but *not* an encoding of the discriminant (e.g., a tag value). // See issue #49298 for more details on the need to leave space // for non-ZST uninhabited data (mostly partial initialization). - let absent = |fields: &[TyLayout<'_>]| { + let absent = |fields: &[TyAndLayout<'_>]| { let uninhabited = fields.iter().any(|f| f.abi.is_uninhabited()); let is_zst = fields.iter().all(|f| f.is_zst()); uninhabited && is_zst @@ -1404,7 +1408,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let discr_int_ty = discr_int.to_ty(tcx, false); let discr = Scalar { value: Primitive::Int(discr_int, false), valid_range: 0..=max_discr }; let discr_layout = self.tcx.intern_layout(Layout::scalar(self, discr.clone())); - let discr_layout = TyLayout { ty: discr_int_ty, layout: discr_layout }; + let discr_layout = TyAndLayout { ty: discr_int_ty, layout: discr_layout }; let promoted_layouts = ineligible_locals .iter() @@ -1573,7 +1577,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { /// This is invoked by the `layout_raw` query to record the final /// layout of each type. #[inline(always)] - fn record_layout_for_printing(&self, layout: TyLayout<'tcx>) { + fn record_layout_for_printing(&self, layout: TyAndLayout<'tcx>) { // If we are running with `-Zprint-type-sizes`, maybe record layouts // for dumping later. if self.tcx.sess.opts.debugging_opts.print_type_sizes { @@ -1581,7 +1585,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } } - fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) { + fn record_layout_for_printing_outlined(&self, layout: TyAndLayout<'tcx>) { // Ignore layouts that are done with non-empty environments or // non-monomorphic layouts, as the user only wants to see the stuff // resulting from the final codegen session. @@ -1624,7 +1628,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let adt_kind = adt_def.adt_kind(); let adt_packed = adt_def.repr.pack.is_some(); - let build_variant_info = |n: Option, flds: &[ast::Name], layout: TyLayout<'tcx>| { + let build_variant_info = |n: Option, + flds: &[ast::Name], + layout: TyAndLayout<'tcx>| { let mut min_size = Size::ZERO; let field_info: Vec<_> = flds .iter() @@ -1891,19 +1897,19 @@ impl<'tcx, T: HasTyCtxt<'tcx>> HasTyCtxt<'tcx> for LayoutCx<'tcx, T> { } } -pub type TyLayout<'tcx> = ::rustc_target::abi::TyLayout<'tcx, Ty<'tcx>>; +pub type TyAndLayout<'tcx> = ::rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>; impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { type Ty = Ty<'tcx>; - type TyLayout = Result, LayoutError<'tcx>>; + type TyAndLayout = Result, LayoutError<'tcx>>; /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { let param_env = self.param_env.with_reveal_all(); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let layout = self.tcx.layout_raw(param_env.and(ty))?; - let layout = TyLayout { ty, layout }; + let layout = TyAndLayout { ty, layout }; // N.B., this recording is normally disabled; when enabled, it // can however trigger recursive invocations of `layout_of`. @@ -1919,15 +1925,15 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { type Ty = Ty<'tcx>; - type TyLayout = Result, LayoutError<'tcx>>; + type TyAndLayout = Result, LayoutError<'tcx>>; /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { let param_env = self.param_env.with_reveal_all(); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let layout = self.tcx.layout_raw(param_env.and(ty))?; - let layout = TyLayout { ty, layout }; + let layout = TyAndLayout { ty, layout }; // N.B., this recording is normally disabled; when enabled, it // can however trigger recursive invocations of `layout_of`. @@ -1950,7 +1956,7 @@ impl TyCtxt<'tcx> { pub fn layout_of( self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Result, LayoutError<'tcx>> { + ) -> Result, LayoutError<'tcx>> { let cx = LayoutCx { tcx: self, param_env: param_env_and_ty.param_env }; cx.layout_of(param_env_and_ty.value) } @@ -1963,19 +1969,23 @@ impl ty::query::TyCtxtAt<'tcx> { pub fn layout_of( self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Result, LayoutError<'tcx>> { + ) -> Result, LayoutError<'tcx>> { let cx = LayoutCx { tcx: self.at(self.span), param_env: param_env_and_ty.param_env }; cx.layout_of(param_env_and_ty.value) } } -impl<'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> +impl<'tcx, C> TyAndLayoutMethods<'tcx, C> for Ty<'tcx> where - C: LayoutOf, TyLayout: MaybeResult>> + C: LayoutOf, TyAndLayout: MaybeResult>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, { - fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: VariantIdx) -> TyLayout<'tcx> { + fn for_variant( + this: TyAndLayout<'tcx>, + cx: &C, + variant_index: VariantIdx, + ) -> TyAndLayout<'tcx> { let layout = match this.variants { Variants::Single { index } // If all variants but one are uninhabited, the variant layout is the enum layout. @@ -2013,14 +2023,14 @@ where assert_eq!(layout.variants, Variants::Single { index: variant_index }); - TyLayout { ty: this.ty, layout } + TyAndLayout { ty: this.ty, layout } } - fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout { + fn field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { let tcx = cx.tcx(); - let discr_layout = |discr: &Scalar| -> C::TyLayout { + let discr_layout = |discr: &Scalar| -> C::TyAndLayout { let layout = Layout::scalar(cx, discr.clone()); - MaybeResult::from(Ok(TyLayout { + MaybeResult::from(Ok(TyAndLayout { layout: tcx.intern_layout(layout), ty: discr.value.to_ty(tcx), })) @@ -2037,7 +2047,7 @@ where | ty::FnDef(..) | ty::GeneratorWitness(..) | ty::Foreign(..) - | ty::Dynamic(..) => bug!("TyLayout::field_type({:?}): not applicable", this), + | ty::Dynamic(..) => bug!("TyAndLayout::field_type({:?}): not applicable", this), // Potentially-fat pointers. ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { @@ -2080,7 +2090,7 @@ where ]) */ } - _ => bug!("TyLayout::field_type({:?}): not applicable", this), + _ => bug!("TyAndLayout::field_type({:?}): not applicable", this), } } @@ -2132,11 +2142,11 @@ where | ty::Opaque(..) | ty::Param(_) | ty::Infer(_) - | ty::Error => bug!("TyLayout::field_type: unexpected type `{}`", this.ty), + | ty::Error => bug!("TyAndLayout::field_type: unexpected type `{}`", this.ty), }) } - fn pointee_info_at(this: TyLayout<'tcx>, cx: &C, offset: Size) -> Option { + fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option { match this.ty.kind { ty::RawPtr(mt) if offset.bytes() == 0 => { cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo { @@ -2337,7 +2347,7 @@ impl<'tcx> ty::Instance<'tcx> { pub trait FnAbiExt<'tcx, C> where - C: LayoutOf, TyLayout = TyLayout<'tcx>> + C: LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + HasDataLayout + HasTargetSpec + HasTyCtxt<'tcx> @@ -2368,7 +2378,7 @@ where impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>> where - C: LayoutOf, TyLayout = TyLayout<'tcx>> + C: LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + HasDataLayout + HasTargetSpec + HasTyCtxt<'tcx> @@ -2518,7 +2528,7 @@ where // Handle safe Rust thin and fat pointers. let adjust_for_rust_scalar = |attrs: &mut ArgAttributes, scalar: &Scalar, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, offset: Size, is_return: bool| { // Booleans are always an i1 that needs to be zero-extended. diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index b37d63fce6592..c743a08954927 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -7,7 +7,7 @@ use crate::type_of::LayoutLlvmExt; use crate::value::Value; use libc::{c_char, c_uint}; use log::debug; -use rustc::ty::layout::{self, Align, Size, TyLayout}; +use rustc::ty::layout::{self, Align, Size, TyAndLayout}; use rustc::ty::{self, Ty, TyCtxt}; use rustc_codegen_ssa::base::to_immediate; use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind}; @@ -86,9 +86,9 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> { impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> { type Ty = Ty<'tcx>; - type TyLayout = TyLayout<'tcx>; + type TyAndLayout = TyAndLayout<'tcx>; - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.cx.layout_of(ty) } } diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index f72060868128c..c28958e0b4b4f 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -13,7 +13,7 @@ use rustc_codegen_ssa::traits::*; use crate::consts::const_alloc_to_llvm; use rustc::mir::interpret::{Allocation, GlobalAlloc, Scalar}; -use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size, TyLayout}; +use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size, TyAndLayout}; use rustc_codegen_ssa::mir::place::PlaceRef; use libc::{c_char, c_uint}; @@ -289,7 +289,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn from_const_alloc( &self, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, alloc: &Allocation, offset: Size, ) -> PlaceRef<'tcx, &'ll Value> { diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 92f59feef90fe..4ed69c30a4a50 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -10,7 +10,7 @@ use rustc::bug; use rustc::dep_graph::DepGraphSafe; use rustc::mir::mono::CodegenUnit; use rustc::ty::layout::{ - HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx, + HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyAndLayout, VariantIdx, }; use rustc::ty::{self, Instance, Ty, TyCtxt}; use rustc_codegen_ssa::base::wants_msvc_seh; @@ -840,13 +840,13 @@ impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> { impl LayoutOf for CodegenCx<'ll, 'tcx> { type Ty = Ty<'tcx>; - type TyLayout = TyLayout<'tcx>; + type TyAndLayout = TyAndLayout<'tcx>; - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.spanned_layout_of(ty, DUMMY_SP) } - fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout { + fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyAndLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap_or_else(|e| { if let LayoutError::SizeOverflow(_) = e { self.sess().span_fatal(span, &e.to_string()) diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index d7a0acb133956..6d4309c9660ea 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -25,7 +25,7 @@ use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::mir::interpret::truncate; use rustc::mir::{self, Field, GeneratorLayout}; use rustc::ty::layout::{ - self, Align, Integer, IntegerExt, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx, + self, Align, Integer, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, }; use rustc::ty::subst::{GenericArgKind, SubstsRef}; use rustc::ty::Instance; @@ -1203,7 +1203,7 @@ fn prepare_tuple_metadata( //=----------------------------------------------------------------------------- struct UnionMemberDescriptionFactory<'tcx> { - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, variant: &'tcx ty::VariantDef, span: Span, } @@ -1325,7 +1325,7 @@ fn generator_layout_and_saved_local_names( /// offset of zero bytes). struct EnumMemberDescriptionFactory<'ll, 'tcx> { enum_type: Ty<'tcx>, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, discriminant_type_metadata: Option<&'ll DIType>, containing_scope: &'ll DIScope, span: Span, @@ -1494,7 +1494,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { fn compute_field_path<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, name: &mut String, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, offset: Size, size: Size, ) { @@ -1695,7 +1695,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> { /// `RecursiveTypeDescription`. fn describe_enum_variant( cx: &CodegenCx<'ll, 'tcx>, - layout: layout::TyLayout<'tcx>, + layout: layout::TyAndLayout<'tcx>, variant: VariantInfo<'_, 'tcx>, discriminant_info: EnumDiscriminantInfo<'ll>, containing_scope: &'ll DIScope, diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index 5bc1475df23a7..85e0f284e26c0 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -10,7 +10,7 @@ use rustc_codegen_ssa::traits::*; use crate::abi::{FnAbiLlvmExt, LlvmType}; use crate::common; use crate::type_of::LayoutLlvmExt; -use rustc::ty::layout::{self, Align, Size, TyLayout}; +use rustc::ty::layout::{self, Align, Size, TyAndLayout}; use rustc::ty::Ty; use rustc_ast::ast; use rustc_codegen_ssa::common::TypeKind; @@ -250,24 +250,24 @@ impl Type { } impl LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> { - fn backend_type(&self, layout: TyLayout<'tcx>) -> &'ll Type { + fn backend_type(&self, layout: TyAndLayout<'tcx>) -> &'ll Type { layout.llvm_type(self) } - fn immediate_backend_type(&self, layout: TyLayout<'tcx>) -> &'ll Type { + fn immediate_backend_type(&self, layout: TyAndLayout<'tcx>) -> &'ll Type { layout.immediate_llvm_type(self) } - fn is_backend_immediate(&self, layout: TyLayout<'tcx>) -> bool { + fn is_backend_immediate(&self, layout: TyAndLayout<'tcx>) -> bool { layout.is_llvm_immediate() } - fn is_backend_scalar_pair(&self, layout: TyLayout<'tcx>) -> bool { + fn is_backend_scalar_pair(&self, layout: TyAndLayout<'tcx>) -> bool { layout.is_llvm_scalar_pair() } - fn backend_field_index(&self, layout: TyLayout<'tcx>, index: usize) -> u64 { + fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64 { layout.llvm_field_index(index) } fn scalar_pair_element_backend_type( &self, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, index: usize, immediate: bool, ) -> &'ll Type { diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 3e6c75e4d6f82..9d909e83d175a 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -3,18 +3,18 @@ use crate::common::*; use crate::type_::Type; use log::debug; use rustc::bug; -use rustc::ty::layout::{self, Align, FnAbiExt, LayoutOf, PointeeInfo, Size, TyLayout}; +use rustc::ty::layout::{self, Align, FnAbiExt, LayoutOf, PointeeInfo, Size, TyAndLayout}; use rustc::ty::print::obsolete::DefPathBasedNames; use rustc::ty::{self, Ty, TypeFoldable}; use rustc_codegen_ssa::traits::*; -use rustc_target::abi::TyLayoutMethods; +use rustc_target::abi::TyAndLayoutMethods; use std::fmt::Write; fn uncached_llvm_type<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, - layout: TyLayout<'tcx>, - defer: &mut Option<(&'a Type, TyLayout<'tcx>)>, + layout: TyAndLayout<'tcx>, + defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>, ) -> &'a Type { match layout.abi { layout::Abi::Scalar(_) => bug!("handled elsewhere"), @@ -110,7 +110,7 @@ fn uncached_llvm_type<'a, 'tcx>( fn struct_llfields<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> (Vec<&'a Type>, bool) { debug!("struct_llfields: {:#?}", layout); let field_count = layout.fields.count(); @@ -202,7 +202,7 @@ pub trait LayoutLlvmExt<'tcx> { fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option; } -impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> { +impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { fn is_llvm_immediate(&self) -> bool { match self.abi { layout::Abi::Scalar(_) | layout::Abi::Vector { .. } => true, @@ -344,7 +344,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> { let (a, b) = match self.abi { layout::Abi::ScalarPair(ref a, ref b) => (a, b), - _ => bug!("TyLayout::scalar_pair_element_llty({:?}): not applicable", self), + _ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self), }; let scalar = [a, b][index]; @@ -366,13 +366,13 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> { fn llvm_field_index(&self, index: usize) -> u64 { match self.abi { layout::Abi::Scalar(_) | layout::Abi::ScalarPair(..) => { - bug!("TyLayout::llvm_field_index({:?}): not applicable", self) + bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self) } _ => {} } match self.fields { layout::FieldPlacement::Union(_) => { - bug!("TyLayout::llvm_field_index({:?}): not applicable", self) + bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self) } layout::FieldPlacement::Array { .. } => index as u64, diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 834702a30099c..3f5a5e4e5312a 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -31,7 +31,7 @@ use rustc::middle::cstore::{self, LinkagePreference}; use rustc::middle::lang_items; use rustc::middle::lang_items::StartFnLangItem; use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; -use rustc::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyLayout, VariantIdx}; +use rustc::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyAndLayout, VariantIdx}; use rustc::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; use rustc::ty::query::Providers; use rustc::ty::{self, Instance, Ty, TyCtxt}; @@ -341,7 +341,7 @@ pub fn from_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn to_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, val: Bx::Value, - layout: layout::TyLayout<'_>, + layout: layout::TyAndLayout<'_>, ) -> Bx::Value { if let layout::Abi::Scalar(ref scalar) = layout.abi { return to_immediate_scalar(bx, val, scalar); @@ -366,7 +366,7 @@ pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( dst_align: Align, src: Bx::Value, src_align: Align, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, flags: MemFlags, ) { let size = layout.size.bytes(); diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 000db0155ada3..b94a87a8e43e2 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -1,7 +1,7 @@ use crate::base; use crate::traits::*; use rustc::mir; -use rustc::ty::layout::{FnAbiExt, HasTyCtxt, TyLayout}; +use rustc::ty::layout::{FnAbiExt, HasTyCtxt, TyAndLayout}; use rustc::ty::{self, Instance, Ty, TypeFoldable}; use rustc_target::abi::call::{FnAbi, PassMode}; @@ -114,7 +114,7 @@ enum LocalRef<'tcx, V> { impl<'a, 'tcx, V: CodegenObject> LocalRef<'tcx, V> { fn new_operand>( bx: &mut Bx, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> LocalRef<'tcx, V> { if layout.is_zst() { // Zero-size temporaries aren't always initialized, which diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs index 5bb30d03d9f8d..3e6bdb3b80b81 100644 --- a/src/librustc_codegen_ssa/mir/operand.rs +++ b/src/librustc_codegen_ssa/mir/operand.rs @@ -8,7 +8,7 @@ use crate::MemFlags; use rustc::mir; use rustc::mir::interpret::{ConstValue, ErrorHandled, Pointer, Scalar}; -use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout}; +use rustc::ty::layout::{self, Align, LayoutOf, Size, TyAndLayout}; use rustc::ty::Ty; use std::fmt; @@ -43,7 +43,7 @@ pub struct OperandRef<'tcx, V> { pub val: OperandValue, // The layout of value, based on its Rust type. - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, } impl fmt::Debug for OperandRef<'tcx, V> { @@ -55,7 +55,7 @@ impl fmt::Debug for OperandRef<'tcx, V> { impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { pub fn new_zst>( bx: &mut Bx, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> OperandRef<'tcx, V> { assert!(layout.is_zst()); OperandRef { @@ -159,7 +159,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { pub fn from_immediate_or_packed_pair>( bx: &mut Bx, llval: V, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> Self { let val = if let layout::Abi::ScalarPair(ref a, ref b) = layout.abi { debug!("Operand::from_immediate_or_packed_pair: unpacking {:?} @ {:?}", llval, layout); diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 2eba88c6b5f31..5607250fe4b41 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -8,7 +8,7 @@ use crate::MemFlags; use rustc::mir; use rustc::mir::tcx::PlaceTy; -use rustc::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyLayout, VariantIdx}; +use rustc::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyAndLayout, VariantIdx}; use rustc::ty::{self, Ty}; #[derive(Copy, Clone, Debug)] @@ -20,19 +20,23 @@ pub struct PlaceRef<'tcx, V> { pub llextra: Option, /// The monomorphized type of this place, including variant information. - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, /// The alignment we know for this place. pub align: Align, } impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { - pub fn new_sized(llval: V, layout: TyLayout<'tcx>) -> PlaceRef<'tcx, V> { + pub fn new_sized(llval: V, layout: TyAndLayout<'tcx>) -> PlaceRef<'tcx, V> { assert!(!layout.is_unsized()); PlaceRef { llval, llextra: None, layout, align: layout.align.abi } } - pub fn new_sized_aligned(llval: V, layout: TyLayout<'tcx>, align: Align) -> PlaceRef<'tcx, V> { + pub fn new_sized_aligned( + llval: V, + layout: TyAndLayout<'tcx>, + align: Align, + ) -> PlaceRef<'tcx, V> { assert!(!layout.is_unsized()); PlaceRef { llval, llextra: None, layout, align } } @@ -41,7 +45,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`). pub fn alloca>( bx: &mut Bx, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> Self { assert!(!layout.is_unsized(), "tried to statically allocate unsized place"); let tmp = bx.alloca(bx.cx().backend_type(layout), layout.align.abi); @@ -53,7 +57,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`). pub fn alloca_unsized_indirect>( bx: &mut Bx, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> Self { assert!(layout.is_unsized(), "tried to allocate indirect place for sized values"); let ptr_ty = bx.cx().tcx().mk_mut_ptr(layout.ty); diff --git a/src/librustc_codegen_ssa/traits/backend.rs b/src/librustc_codegen_ssa/traits/backend.rs index 4e861f45ff7a5..755f988cc0717 100644 --- a/src/librustc_codegen_ssa/traits/backend.rs +++ b/src/librustc_codegen_ssa/traits/backend.rs @@ -4,7 +4,7 @@ use crate::ModuleCodegen; use rustc::dep_graph::DepGraph; use rustc::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; -use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout}; +use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; use rustc::ty::query::Providers; use rustc::ty::{Ty, TyCtxt}; use rustc::util::common::ErrorReported; @@ -35,12 +35,12 @@ pub trait BackendTypes { } pub trait Backend<'tcx>: - Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyLayout = TyLayout<'tcx>> + Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyAndLayout = TyAndLayout<'tcx>> { } impl<'tcx, T> Backend<'tcx> for T where - Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyLayout = TyLayout<'tcx>> + Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyAndLayout = TyAndLayout<'tcx>> { } diff --git a/src/librustc_codegen_ssa/traits/consts.rs b/src/librustc_codegen_ssa/traits/consts.rs index 608fa5ef71e03..7fbcb8874de78 100644 --- a/src/librustc_codegen_ssa/traits/consts.rs +++ b/src/librustc_codegen_ssa/traits/consts.rs @@ -34,7 +34,7 @@ pub trait ConstMethods<'tcx>: BackendTypes { ) -> Self::Value; fn from_const_alloc( &self, - layout: layout::TyLayout<'tcx>, + layout: layout::TyAndLayout<'tcx>, alloc: &Allocation, offset: layout::Size, ) -> PlaceRef<'tcx, Self::Value>; diff --git a/src/librustc_codegen_ssa/traits/type_.rs b/src/librustc_codegen_ssa/traits/type_.rs index 0d644e6dd30b3..39274921ed2d9 100644 --- a/src/librustc_codegen_ssa/traits/type_.rs +++ b/src/librustc_codegen_ssa/traits/type_.rs @@ -3,7 +3,7 @@ use super::Backend; use super::HasCodegen; use crate::common::TypeKind; use crate::mir::place::PlaceRef; -use rustc::ty::layout::{self, TyLayout}; +use rustc::ty::layout::{self, TyAndLayout}; use rustc::ty::{self, Ty}; use rustc_span::DUMMY_SP; use rustc_target::abi::call::{ArgAbi, CastTarget, FnAbi, Reg}; @@ -94,17 +94,17 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> { impl DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {} pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> { - fn backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type; + fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type; fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type; fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type; fn reg_backend_type(&self, ty: &Reg) -> Self::Type; - fn immediate_backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type; - fn is_backend_immediate(&self, layout: TyLayout<'tcx>) -> bool; - fn is_backend_scalar_pair(&self, layout: TyLayout<'tcx>) -> bool; - fn backend_field_index(&self, layout: TyLayout<'tcx>, index: usize) -> u64; + fn immediate_backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type; + fn is_backend_immediate(&self, layout: TyAndLayout<'tcx>) -> bool; + fn is_backend_scalar_pair(&self, layout: TyAndLayout<'tcx>) -> bool; + fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64; fn scalar_pair_element_backend_type( &self, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, index: usize, immediate: bool, ) -> Self::Type; diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index 257b179d6ba6d..f519c41c71a8c 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -21,7 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc::lint::LintDiagnosticBuilder; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; -use rustc::ty::layout::{LayoutError, LayoutOf, TyLayout}; +use rustc::ty::layout::{LayoutError, LayoutOf, TyAndLayout}; use rustc::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use rustc_ast::ast; use rustc_ast::util::lev_distance::find_best_match_for_name; @@ -811,9 +811,9 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> { impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> { type Ty = Ty<'tcx>; - type TyLayout = Result, LayoutError<'tcx>>; + type TyAndLayout = Result, LayoutError<'tcx>>; - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx.layout_of(self.param_env.and(ty)) } } diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 24176427ba526..01cad77b2c3c8 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -1,7 +1,7 @@ use std::convert::TryFrom; use rustc::ty::adjustment::PointerCast; -use rustc::ty::layout::{self, Size, TyLayout}; +use rustc::ty::layout::{self, Size, TyAndLayout}; use rustc::ty::{self, Ty, TypeAndMut, TypeFoldable}; use rustc_ast::ast::FloatTy; use rustc_span::symbol::sym; @@ -102,7 +102,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { fn cast_immediate( &self, src: ImmTy<'tcx, M::PointerTag>, - dest_layout: TyLayout<'tcx>, + dest_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, Immediate> { use rustc::ty::TyKind::*; trace!("Casting {:?}: {:?} to {:?}", *src, src.layout.ty, dest_layout.ty); @@ -183,8 +183,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { fn cast_from_int_like( &self, v: u128, // raw bits - src_layout: TyLayout<'tcx>, - dest_layout: TyLayout<'tcx>, + src_layout: TyAndLayout<'tcx>, + dest_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, Scalar> { // Let's make sure v is sign-extended *if* it has a signed type. let signed = src_layout.abi.is_signed(); diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index c2baabf4233ce..57431b18ef293 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -7,7 +7,7 @@ use rustc::mir; use rustc::mir::interpret::{ sign_extend, truncate, AllocId, FrameInfo, GlobalId, InterpResult, Pointer, Scalar, }; -use rustc::ty::layout::{self, Align, HasDataLayout, LayoutOf, Size, TyLayout}; +use rustc::ty::layout::{self, Align, HasDataLayout, LayoutOf, Size, TyAndLayout}; use rustc::ty::query::TyCtxtAt; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; @@ -114,7 +114,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> { pub value: LocalValue, /// Don't modify if `Some`, this is only used to prevent computing the layout twice #[stable_hasher(ignore)] - pub layout: Cell>>, + pub layout: Cell>>, } /// Current value of a local variable @@ -202,10 +202,10 @@ where impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> { type Ty = Ty<'tcx>; - type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>; + type TyAndLayout = InterpResult<'tcx, TyAndLayout<'tcx>>; #[inline] - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx .layout_of(self.param_env.and(ty)) .map_err(|layout| err_inval!(Layout(layout)).into()) @@ -284,13 +284,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } #[inline(always)] - pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 { + pub fn sign_extend(&self, value: u128, ty: TyAndLayout<'_>) -> u128 { assert!(ty.abi.is_signed()); sign_extend(value, ty.size) } #[inline(always)] - pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 { + pub fn truncate(&self, value: u128, ty: TyAndLayout<'_>) -> u128 { truncate(value, ty.size) } @@ -373,8 +373,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &self, frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, local: mir::Local, - layout: Option>, - ) -> InterpResult<'tcx, TyLayout<'tcx>> { + layout: Option>, + ) -> InterpResult<'tcx, TyAndLayout<'tcx>> { // `const_prop` runs into this with an invalid (empty) frame, so we // have to support that case (mostly by skipping all caching). match frame.locals.get(local).and_then(|state| state.layout.get()) { @@ -401,7 +401,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub(super) fn size_and_align_of( &self, metadata: MemPlaceMeta, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, Option<(Size, Align)>> { if !layout.is_unsized() { return Ok(Some((layout.size, layout.align.abi))); diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 8e2a0ca9b0214..7f9efa9c69572 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -9,7 +9,7 @@ use rustc::mir::interpret::{ sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpResult, Pointer, Scalar, }; use rustc::ty::layout::{ - self, HasDataLayout, IntegerExt, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx, + self, HasDataLayout, IntegerExt, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, }; use rustc::ty::print::{FmtPrinter, PrettyPrinter, Printer}; use rustc::ty::Ty; @@ -91,7 +91,7 @@ impl<'tcx, Tag> Immediate { #[derive(Copy, Clone, Debug)] pub struct ImmTy<'tcx, Tag = ()> { pub(crate) imm: Immediate, - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, } impl std::fmt::Display for ImmTy<'tcx, Tag> { @@ -155,7 +155,7 @@ pub enum Operand { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct OpTy<'tcx, Tag = ()> { op: Operand, // Keep this private; it helps enforce invariants. - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, } impl<'tcx, Tag> ::std::ops::Deref for OpTy<'tcx, Tag> { @@ -182,26 +182,26 @@ impl<'tcx, Tag> From> for OpTy<'tcx, Tag> { impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { #[inline] - pub fn from_scalar(val: Scalar, layout: TyLayout<'tcx>) -> Self { + pub fn from_scalar(val: Scalar, layout: TyAndLayout<'tcx>) -> Self { ImmTy { imm: val.into(), layout } } #[inline] - pub fn try_from_uint(i: impl Into, layout: TyLayout<'tcx>) -> Option { + pub fn try_from_uint(i: impl Into, layout: TyAndLayout<'tcx>) -> Option { Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout)) } #[inline] - pub fn from_uint(i: impl Into, layout: TyLayout<'tcx>) -> Self { + pub fn from_uint(i: impl Into, layout: TyAndLayout<'tcx>) -> Self { Self::from_scalar(Scalar::from_uint(i, layout.size), layout) } #[inline] - pub fn try_from_int(i: impl Into, layout: TyLayout<'tcx>) -> Option { + pub fn try_from_int(i: impl Into, layout: TyAndLayout<'tcx>) -> Option { Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout)) } #[inline] - pub fn from_int(i: impl Into, layout: TyLayout<'tcx>) -> Self { + pub fn from_int(i: impl Into, layout: TyAndLayout<'tcx>) -> Self { Self::from_scalar(Scalar::from_int(i, layout.size), layout) } } @@ -210,9 +210,9 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> { // or compute the layout. #[inline(always)] pub(super) fn from_known_layout<'tcx>( - layout: Option>, - compute: impl FnOnce() -> InterpResult<'tcx, TyLayout<'tcx>>, -) -> InterpResult<'tcx, TyLayout<'tcx>> { + layout: Option>, + compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>, +) -> InterpResult<'tcx, TyAndLayout<'tcx>> { match layout { None => compute(), Some(layout) => { @@ -437,7 +437,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &self, frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, local: mir::Local, - layout: Option>, + layout: Option>, ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { assert_ne!(local, mir::RETURN_PLACE); let layout = self.layout_of_local(frame, local, layout)?; @@ -468,7 +468,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn eval_place_to_op( &self, place: &mir::Place<'tcx>, - layout: Option>, + layout: Option>, ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { let base_op = match place.local { mir::RETURN_PLACE => throw_ub!(ReadFromReturnPlace), @@ -496,7 +496,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn eval_operand( &self, mir_op: &mir::Operand<'tcx>, - layout: Option>, + layout: Option>, ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { use rustc::mir::Operand::*; let op = match *mir_op { @@ -528,7 +528,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { crate fn eval_const_to_op( &self, val: &ty::Const<'tcx>, - layout: Option>, + layout: Option>, ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { let tag_scalar = |scalar| match scalar { Scalar::Ptr(ptr) => Scalar::Ptr(self.tag_global_base_pointer(ptr)), diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index cb0aaa4d40d3e..10fa66c49d7bf 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -4,7 +4,7 @@ use rustc::mir; use rustc::mir::interpret::{InterpResult, Scalar}; use rustc::ty::{ self, - layout::{LayoutOf, TyLayout}, + layout::{LayoutOf, TyAndLayout}, Ty, }; use rustc_apfloat::Float; @@ -123,9 +123,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { bin_op: mir::BinOp, // passing in raw bits l: u128, - left_layout: TyLayout<'tcx>, + left_layout: TyAndLayout<'tcx>, r: u128, - right_layout: TyLayout<'tcx>, + right_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> { use rustc::mir::BinOp::*; diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 94c9a8b2a6d59..d2f60c89cb25b 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -8,7 +8,7 @@ use std::hash::Hash; use rustc::mir; use rustc::mir::interpret::truncate; use rustc::ty::layout::{ - self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx, + self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyAndLayout, VariantIdx, }; use rustc::ty::{self, Ty}; use rustc_macros::HashStable; @@ -86,7 +86,7 @@ pub enum Place { #[derive(Copy, Clone, Debug)] pub struct PlaceTy<'tcx, Tag = ()> { place: Place, // Keep this private; it helps enforce invariants. - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, } impl<'tcx, Tag> ::std::ops::Deref for PlaceTy<'tcx, Tag> { @@ -101,7 +101,7 @@ impl<'tcx, Tag> ::std::ops::Deref for PlaceTy<'tcx, Tag> { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub struct MPlaceTy<'tcx, Tag = ()> { mplace: MemPlace, - pub layout: TyLayout<'tcx>, + pub layout: TyAndLayout<'tcx>, } impl<'tcx, Tag> ::std::ops::Deref for MPlaceTy<'tcx, Tag> { @@ -178,7 +178,7 @@ impl MemPlace { impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { /// Produces a MemPlace that works for ZST but nothing else #[inline] - pub fn dangling(layout: TyLayout<'tcx>, cx: &impl HasDataLayout) -> Self { + pub fn dangling(layout: TyAndLayout<'tcx>, cx: &impl HasDataLayout) -> Self { let align = layout.align.abi; let ptr = Scalar::from_uint(align.bytes(), cx.pointer_size()); // `Poison` this to make sure that the pointer value `ptr` is never observable by the program. @@ -196,14 +196,14 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { self, offset: Size, meta: MemPlaceMeta, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, cx: &impl HasDataLayout, ) -> InterpResult<'tcx, Self> { Ok(MPlaceTy { mplace: self.mplace.offset(offset, meta, cx)?, layout }) } #[inline] - fn from_aligned_ptr(ptr: Pointer, layout: TyLayout<'tcx>) -> Self { + fn from_aligned_ptr(ptr: Pointer, layout: TyAndLayout<'tcx>) -> Self { MPlaceTy { mplace: MemPlace::from_ptr(ptr, layout.align.abi), layout } } @@ -1030,7 +1030,7 @@ where pub fn allocate( &mut self, - layout: TyLayout<'tcx>, + layout: TyAndLayout<'tcx>, kind: MemoryKind, ) -> MPlaceTy<'tcx, M::PointerTag> { let ptr = self.memory.allocate(layout.size, layout.align.abi, kind); @@ -1077,7 +1077,7 @@ where .. } => { // No need to validate that the discriminant here because the - // `TyLayout::for_variant()` call earlier already checks the variant is valid. + // `TyAndLayout::for_variant()` call earlier already checks the variant is valid. let discr_val = dest.layout.ty.discriminant_for_variant(*self.tcx, variant_index).unwrap().val; @@ -1099,7 +1099,7 @@ where .. } => { // No need to validate that the discriminant here because the - // `TyLayout::for_variant()` call earlier already checks the variant is valid. + // `TyAndLayout::for_variant()` call earlier already checks the variant is valid. if variant_index != dataful_variant { let variants_start = niche_variants.start().as_u32(); diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 5ce5ba31a0987..edae6ef066d3e 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::convert::TryFrom; -use rustc::ty::layout::{self, LayoutOf, TyLayout}; +use rustc::ty::layout::{self, LayoutOf, TyAndLayout}; use rustc::ty::Instance; use rustc::{mir, ty}; use rustc_span::source_map::Span; @@ -134,8 +134,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { fn check_argument_compat( rust_abi: bool, - caller: TyLayout<'tcx>, - callee: TyLayout<'tcx>, + caller: TyAndLayout<'tcx>, + callee: TyAndLayout<'tcx>, ) -> bool { if caller.ty == callee.ty { // No question diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index a355a22748010..7b580fa12ebaa 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -9,7 +9,7 @@ use std::fmt::Write; use std::ops::RangeInclusive; use rustc::ty; -use rustc::ty::layout::{self, LayoutOf, TyLayout, VariantIdx}; +use rustc::ty::layout::{self, LayoutOf, TyAndLayout, VariantIdx}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_span::symbol::{sym, Symbol}; @@ -177,7 +177,7 @@ struct ValidityVisitor<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> { } impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M> { - fn aggregate_field_path_elem(&mut self, layout: TyLayout<'tcx>, field: usize) -> PathElem { + fn aggregate_field_path_elem(&mut self, layout: TyAndLayout<'tcx>, field: usize) -> PathElem { // First, check if we are projecting to a variant. match layout.variants { layout::Variants::Multiple { discr_index, .. } => { @@ -266,7 +266,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M fn check_wide_ptr_meta( &mut self, meta: MemPlaceMeta, - pointee: TyLayout<'tcx>, + pointee: TyAndLayout<'tcx>, ) -> InterpResult<'tcx> { let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(pointee.ty, self.ecx.param_env); match tail.kind { diff --git a/src/librustc_mir/interpret/visitor.rs b/src/librustc_mir/interpret/visitor.rs index e8a7626406413..54dec393e71b6 100644 --- a/src/librustc_mir/interpret/visitor.rs +++ b/src/librustc_mir/interpret/visitor.rs @@ -3,7 +3,7 @@ use rustc::mir::interpret::InterpResult; use rustc::ty; -use rustc::ty::layout::{self, TyLayout, VariantIdx}; +use rustc::ty::layout::{self, TyAndLayout, VariantIdx}; use super::{InterpCx, MPlaceTy, Machine, OpTy}; @@ -12,7 +12,7 @@ use super::{InterpCx, MPlaceTy, Machine, OpTy}; // that's just more convenient to work with (avoids repeating all the `Machine` bounds). pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy { /// Gets this value's layout. - fn layout(&self) -> TyLayout<'tcx>; + fn layout(&self) -> TyAndLayout<'tcx>; /// Makes this into an `OpTy`. fn to_op(self, ecx: &InterpCx<'mir, 'tcx, M>) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>>; @@ -36,7 +36,7 @@ pub trait Value<'mir, 'tcx, M: Machine<'mir, 'tcx>>: Copy { // Places in general are not due to `place_field` having to do `force_allocation`. impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M::PointerTag> { #[inline(always)] - fn layout(&self) -> TyLayout<'tcx> { + fn layout(&self) -> TyAndLayout<'tcx> { self.layout } @@ -74,7 +74,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for OpTy<'tcx, M:: impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M> for MPlaceTy<'tcx, M::PointerTag> { #[inline(always)] - fn layout(&self) -> TyLayout<'tcx> { + fn layout(&self) -> TyAndLayout<'tcx> { self.layout } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 5fe8f9f3771b3..927deebb17578 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -15,7 +15,7 @@ use rustc::mir::{ UnOp, RETURN_PLACE, }; use rustc::ty::layout::{ - HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout, + HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyAndLayout, }; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; @@ -316,9 +316,9 @@ struct ConstPropagator<'mir, 'tcx> { impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> { type Ty = Ty<'tcx>; - type TyLayout = Result, LayoutError<'tcx>>; + type TyAndLayout = Result, LayoutError<'tcx>>; - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx.layout_of(self.param_env.and(ty)) } } @@ -573,7 +573,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn const_prop( &mut self, rvalue: &Rvalue<'tcx>, - place_layout: TyLayout<'tcx>, + place_layout: TyAndLayout<'tcx>, source_info: SourceInfo, place: &Place<'tcx>, ) -> Option<()> { diff --git a/src/librustc_mir/transform/uninhabited_enum_branching.rs b/src/librustc_mir/transform/uninhabited_enum_branching.rs index 7178e614f0a97..d33f9b6a28627 100644 --- a/src/librustc_mir/transform/uninhabited_enum_branching.rs +++ b/src/librustc_mir/transform/uninhabited_enum_branching.rs @@ -5,7 +5,7 @@ use rustc::mir::{ BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Operand, Rvalue, StatementKind, TerminatorKind, }; -use rustc::ty::layout::{Abi, TyLayout, Variants}; +use rustc::ty::layout::{Abi, TyAndLayout, Variants}; use rustc::ty::{Ty, TyCtxt}; pub struct UninhabitedEnumBranching; @@ -49,7 +49,7 @@ fn get_switched_on_type<'tcx>( } fn variant_discriminants<'tcx>( - layout: &TyLayout<'tcx>, + layout: &TyAndLayout<'tcx>, ty: Ty<'tcx>, tcx: TyCtxt<'tcx>, ) -> Vec { diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 9d8b1422bdf24..a3bbfd8b4c0ae 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -3,7 +3,7 @@ use rustc::ty::layout::HasParamEnv; use rustc::ty::layout::HasTyCtxt; use rustc::ty::layout::LayoutOf; use rustc::ty::layout::TargetDataLayout; -use rustc::ty::layout::TyLayout; +use rustc::ty::layout::TyAndLayout; use rustc::ty::ParamEnv; use rustc::ty::Ty; use rustc::ty::TyCtxt; @@ -118,9 +118,9 @@ struct UnwrapLayoutCx<'tcx> { impl LayoutOf for UnwrapLayoutCx<'tcx> { type Ty = Ty<'tcx>; - type TyLayout = TyLayout<'tcx>; + type TyAndLayout = TyAndLayout<'tcx>; - fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx.layout_of(self.param_env.and(ty)).unwrap() } } diff --git a/src/librustc_target/abi/call/aarch64.rs b/src/librustc_target/abi/call/aarch64.rs index c8bac5aebc634..1ab7722edab98 100644 --- a/src/librustc_target/abi/call/aarch64.rs +++ b/src/librustc_target/abi/call/aarch64.rs @@ -1,10 +1,10 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; @@ -26,8 +26,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -58,8 +58,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(32); @@ -90,8 +90,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/amdgpu.rs b/src/librustc_target/abi/call/amdgpu.rs index 704e8b8ffa895..0b4f279fece40 100644 --- a/src/librustc_target/abi/call/amdgpu.rs +++ b/src/librustc_target/abi/call/amdgpu.rs @@ -1,26 +1,26 @@ use crate::abi::call::{ArgAbi, FnAbi}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { ret.extend_integer_width_to(32); } fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.extend_integer_width_to(32); } pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/arm.rs b/src/librustc_target/abi/call/arm.rs index 59ec87e3c9e09..26fed3bae4e48 100644 --- a/src/librustc_target/abi/call/arm.rs +++ b/src/librustc_target/abi/call/arm.rs @@ -1,11 +1,11 @@ use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; use crate::spec::HasTargetSpec; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; @@ -27,8 +27,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -60,8 +60,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(32); @@ -82,8 +82,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout + HasTargetSpec, { // 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. diff --git a/src/librustc_target/abi/call/mips.rs b/src/librustc_target/abi/call/mips.rs index b332b9afe7f18..733a7328bd3a0 100644 --- a/src/librustc_target/abi/call/mips.rs +++ b/src/librustc_target/abi/call/mips.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, Size, TyAndLayoutMethods}; fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -16,7 +16,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { let dl = cx.data_layout(); @@ -37,7 +37,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { let mut offset = Size::ZERO; diff --git a/src/librustc_target/abi/call/mips64.rs b/src/librustc_target/abi/call/mips64.rs index 6f8910a011a32..285cb5ff6433f 100644 --- a/src/librustc_target/abi/call/mips64.rs +++ b/src/librustc_target/abi/call/mips64.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAbi, ArgAttribute, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; -use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyLayout, TyLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips @@ -19,8 +19,8 @@ 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: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { match ret.layout.field(cx, i).abi { abi::Abi::Scalar(ref scalar) => match scalar.value { @@ -34,8 +34,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !ret.layout.is_aggregate() { extend_integer_width_mips(ret, 64); @@ -74,8 +74,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() { extend_integer_width_mips(arg, 64); @@ -143,8 +143,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index 77e7ff1e2a738..ffc85c153c9cd 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -1,5 +1,5 @@ use crate::abi::{self, Abi, Align, FieldPlacement, Size}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; use crate::spec::{self, HasTargetSpec}; mod aarch64; @@ -264,7 +264,7 @@ impl HomogeneousAggregate { } } -impl<'a, Ty> TyLayout<'a, Ty> { +impl<'a, Ty> TyAndLayout<'a, Ty> { fn is_aggregate(&self) -> bool { match self.abi { Abi::Uninhabited | Abi::Scalar(_) | Abi::Vector { .. } => false, @@ -284,8 +284,8 @@ impl<'a, Ty> TyLayout<'a, Ty> { /// specific targets. pub fn homogeneous_aggregate(&self, cx: &C) -> Result where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf, { match self.abi { Abi::Uninhabited => Err(Heterogeneous), @@ -404,7 +404,7 @@ impl<'a, Ty> TyLayout<'a, Ty> { /// or return a value from, a function, under some ABI. #[derive(Debug)] pub struct ArgAbi<'a, Ty> { - pub layout: TyLayout<'a, Ty>, + pub layout: TyAndLayout<'a, Ty>, /// Dummy argument, which is emitted before the real argument. pub pad: Option, @@ -413,7 +413,7 @@ pub struct ArgAbi<'a, Ty> { } impl<'a, Ty> ArgAbi<'a, Ty> { - pub fn new(layout: TyLayout<'a, Ty>) -> Self { + pub fn new(layout: TyAndLayout<'a, Ty>) -> Self { ArgAbi { layout, pad: None, mode: PassMode::Direct(ArgAttributes::new()) } } @@ -551,8 +551,8 @@ 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: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout + HasTargetSpec, { match &cx.target_spec().arch[..] { "x86" => { diff --git a/src/librustc_target/abi/call/powerpc64.rs b/src/librustc_target/abi/call/powerpc64.rs index 93c4e97de10b9..b740707320f60 100644 --- a/src/librustc_target/abi/call/powerpc64.rs +++ b/src/librustc_target/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, TyLayout, TyLayoutMethods}; +use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; use crate::spec::HasTargetSpec; #[derive(Debug, Clone, Copy, PartialEq)] @@ -19,8 +19,8 @@ fn is_homogeneous_aggregate<'a, Ty, C>( abi: ABI, ) -> Option where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { // ELFv1 only passes one-member aggregates transparently. @@ -43,8 +43,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(64); @@ -86,8 +86,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(64); @@ -116,8 +116,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout + HasTargetSpec, { let abi = if cx.target_spec().target_env == "musl" { ELFv2 diff --git a/src/librustc_target/abi/call/riscv.rs b/src/librustc_target/abi/call/riscv.rs index 11d6c4d819107..7cd3a0900941d 100644 --- a/src/librustc_target/abi/call/riscv.rs +++ b/src/librustc_target/abi/call/riscv.rs @@ -6,7 +6,7 @@ use crate::abi::call::{ArgAbi, ArgAttribute, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; use crate::abi::{ - self, Abi, FieldPlacement, HasDataLayout, LayoutOf, Size, TyLayout, TyLayoutMethods, + self, Abi, FieldPlacement, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods, }; use crate::spec::HasTargetSpec; @@ -36,15 +36,15 @@ fn is_riscv_aggregate<'a, Ty>(arg: &ArgAbi<'a, Ty>) -> bool { fn should_use_fp_conv_helper<'a, Ty, C>( cx: &C, - arg_layout: &TyLayout<'a, Ty>, + arg_layout: &TyAndLayout<'a, Ty>, xlen: u64, flen: u64, field1_kind: &mut RegPassKind, field2_kind: &mut RegPassKind, ) -> Result<(), CannotUseFpConv> where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf>, { match arg_layout.abi { Abi::Scalar(ref scalar) => match scalar.value { @@ -122,13 +122,13 @@ where fn should_use_fp_conv<'a, Ty, C>( cx: &C, - arg: &TyLayout<'a, Ty>, + arg: &TyAndLayout<'a, Ty>, xlen: u64, flen: u64, ) -> Option where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf>, { let mut field1_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown; @@ -146,8 +146,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf>, { if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) { match conv { @@ -209,8 +209,8 @@ fn classify_arg<'a, Ty, C>( avail_gprs: &mut u64, avail_fprs: &mut u64, ) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf>, { if !is_vararg { match should_use_fp_conv(cx, &arg.layout, xlen, flen) { @@ -322,8 +322,8 @@ 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: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout + HasTargetSpec, { let flen = match &cx.target_spec().options.llvm_abiname[..] { "ilp32f" | "lp64f" => 32, diff --git a/src/librustc_target/abi/call/s390x.rs b/src/librustc_target/abi/call/s390x.rs index d4e9511d08775..005dcc62dfdc1 100644 --- a/src/librustc_target/abi/call/s390x.rs +++ b/src/librustc_target/abi/call/s390x.rs @@ -2,11 +2,11 @@ // for a pre-z13 machine or using -mno-vx. use crate::abi::call::{ArgAbi, FnAbi, Reg}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn classify_ret<'a, Ty, C>(ret: &mut ArgAbi<'_, Ty>) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 { @@ -16,10 +16,10 @@ where } } -fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool +fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyLayoutMethods<'a, C>, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C>, + C: LayoutOf> + HasDataLayout, { match layout.abi { abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), @@ -36,8 +36,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 { arg.extend_integer_width_to(64); @@ -63,8 +63,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/sparc.rs b/src/librustc_target/abi/call/sparc.rs index b332b9afe7f18..733a7328bd3a0 100644 --- a/src/librustc_target/abi/call/sparc.rs +++ b/src/librustc_target/abi/call/sparc.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, Size, TyAndLayoutMethods}; fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -16,7 +16,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { let dl = cx.data_layout(); @@ -37,7 +37,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout, { let mut offset = Size::ZERO; diff --git a/src/librustc_target/abi/call/sparc64.rs b/src/librustc_target/abi/call/sparc64.rs index c80f8316feb72..a647675e0735b 100644 --- a/src/librustc_target/abi/call/sparc64.rs +++ b/src/librustc_target/abi/call/sparc64.rs @@ -1,12 +1,12 @@ // FIXME: This needs an audit for correctness and completeness. use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { // Ensure we have at most eight uniquely addressable members. @@ -26,8 +26,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(64); @@ -52,8 +52,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(64); @@ -76,8 +76,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/wasm32.rs b/src/librustc_target/abi/call/wasm32.rs index 9aab64ef272b2..510f671a501e1 100644 --- a/src/librustc_target/abi/call/wasm32.rs +++ b/src/librustc_target/abi/call/wasm32.rs @@ -1,10 +1,10 @@ use crate::abi::call::{ArgAbi, FnAbi, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if val.layout.is_aggregate() { if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) { @@ -20,8 +20,8 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { ret.extend_integer_width_to(32); if ret.layout.is_aggregate() { @@ -33,8 +33,8 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { arg.extend_integer_width_to(32); if arg.layout.is_aggregate() { @@ -46,8 +46,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/src/librustc_target/abi/call/x86.rs b/src/librustc_target/abi/call/x86.rs index e776a8b3fe4a9..df3dd5d9208d3 100644 --- a/src/librustc_target/abi/call/x86.rs +++ b/src/librustc_target/abi/call/x86.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; use crate::spec::HasTargetSpec; #[derive(PartialEq)] @@ -8,10 +8,10 @@ pub enum Flavor { Fastcall, } -fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool +fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { match layout.abi { abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), @@ -28,8 +28,8 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { if fn_abi.ret.layout.is_aggregate() { diff --git a/src/librustc_target/abi/call/x86_64.rs b/src/librustc_target/abi/call/x86_64.rs index 4c192c46786be..5f154dc1bc9f8 100644 --- a/src/librustc_target/abi/call/x86_64.rs +++ b/src/librustc_target/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, TyLayout, TyLayoutMethods}; +use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; /// Classification of "eightbyte" components. // N.B., the order of the variants is from general to specific, @@ -26,18 +26,18 @@ fn classify_arg<'a, Ty, C>( arg: &ArgAbi<'a, Ty>, ) -> Result<[Option; MAX_EIGHTBYTES], Memory> where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { fn classify<'a, Ty, C>( cx: &C, - layout: TyLayout<'a, Ty>, + layout: TyAndLayout<'a, Ty>, cls: &mut [Option], off: Size, ) -> Result<(), Memory> where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { if !off.is_aligned(layout.align.abi) { if !layout.is_zst() { @@ -172,8 +172,8 @@ const MAX_SSE_REGS: usize = 8; // XMM0-7 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C> + Copy, + C: LayoutOf> + HasDataLayout, { let mut int_regs = MAX_INT_REGS; let mut sse_regs = MAX_SSE_REGS; diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 6976ac9f0d73d..3cc7292bbdfd5 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -939,14 +939,13 @@ impl Layout { /// to that obtained from `layout_of(ty)`, as we need to produce /// layouts for which Rust types do not exist, such as enum variants /// or synthetic fields of enums (i.e., discriminants) and fat pointers. -// FIXME: rename to TyAndLayout. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub struct TyLayout<'a, Ty> { +pub struct TyAndLayout<'a, Ty> { pub ty: Ty, pub layout: &'a Layout, } -impl<'a, Ty> Deref for TyLayout<'a, Ty> { +impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { type Target = &'a Layout; fn deref(&self) -> &&'a Layout { &self.layout @@ -956,15 +955,15 @@ impl<'a, Ty> Deref for TyLayout<'a, Ty> { /// Trait for context types that can compute layouts of things. pub trait LayoutOf { type Ty; - type TyLayout; + type TyAndLayout; - fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; - fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyLayout { + fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout; + fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyAndLayout { self.layout_of(ty) } } -/// The `TyLayout` above will always be a `MaybeResult>`. +/// The `TyAndLayout` above will always be a `MaybeResult>`. /// We can't add the bound due to the lifetime, but this trait is still useful when /// writing code that's generic over the `LayoutOf` impl. pub trait MaybeResult { @@ -1018,30 +1017,30 @@ pub struct PointeeInfo { pub safe: Option, } -pub trait TyLayoutMethods<'a, C: LayoutOf>: Sized { +pub trait TyAndLayoutMethods<'a, C: LayoutOf>: Sized { fn for_variant( - this: TyLayout<'a, Self>, + this: TyAndLayout<'a, Self>, cx: &C, variant_index: VariantIdx, - ) -> TyLayout<'a, Self>; - fn field(this: TyLayout<'a, Self>, cx: &C, i: usize) -> C::TyLayout; - fn pointee_info_at(this: TyLayout<'a, Self>, cx: &C, offset: Size) -> Option; + ) -> 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; } -impl<'a, Ty> TyLayout<'a, Ty> { +impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn for_variant(self, cx: &C, variant_index: VariantIdx) -> Self where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf, { Ty::for_variant(self, cx, variant_index) } - /// Callers might want to use `C: LayoutOf>` + /// Callers might want to use `C: LayoutOf>` /// to allow recursion (see `might_permit_zero_init` below for an example). - pub fn field(self, cx: &C, i: usize) -> C::TyLayout + pub fn field(self, cx: &C, i: usize) -> C::TyAndLayout where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf, { Ty::field(self, cx, i) @@ -1049,14 +1048,14 @@ impl<'a, Ty> TyLayout<'a, Ty> { pub fn pointee_info_at(self, cx: &C, offset: Size) -> Option where - Ty: TyLayoutMethods<'a, C>, + Ty: TyAndLayoutMethods<'a, C>, C: LayoutOf, { Ty::pointee_info_at(self, cx, offset) } } -impl<'a, Ty> TyLayout<'a, Ty> { +impl<'a, Ty> TyAndLayout<'a, Ty> { /// Returns `true` if the layout corresponds to an unsized type. pub fn is_unsized(&self) -> bool { self.abi.is_unsized() @@ -1083,8 +1082,8 @@ impl<'a, Ty> TyLayout<'a, Ty> { pub fn might_permit_raw_init(self, cx: &C, zero: bool) -> Result where Self: Copy, - Ty: TyLayoutMethods<'a, C>, - C: LayoutOf> + HasDataLayout, + Ty: TyAndLayoutMethods<'a, C>, + C: LayoutOf> + HasDataLayout, { let scalar_allows_raw_init = move |s: &Scalar| -> bool { if zero { From 042f4941e78876d95f3106d34c34e9bc3494e446 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 29 Mar 2020 17:40:04 +0200 Subject: [PATCH 2/4] #[link]: mention wasm_import_module instead of cfg --- src/librustc_feature/builtin_attrs.rs | 2 +- src/test/ui/malformed/malformed-regressions.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_feature/builtin_attrs.rs b/src/librustc_feature/builtin_attrs.rs index 2e89f36fea2ab..e4975aae6b983 100644 --- a/src/librustc_feature/builtin_attrs.rs +++ b/src/librustc_feature/builtin_attrs.rs @@ -220,7 +220,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ABI, linking, symbols, and FFI ungated!( link, Whitelisted, - template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...""#), + template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#), ), ungated!(link_name, Whitelisted, template!(NameValueStr: "name")), ungated!(no_link, Normal, template!(Word)), diff --git a/src/test/ui/malformed/malformed-regressions.stderr b/src/test/ui/malformed/malformed-regressions.stderr index b14f99be50c2d..13c12ff721360 100644 --- a/src/test/ui/malformed/malformed-regressions.stderr +++ b/src/test/ui/malformed/malformed-regressions.stderr @@ -26,7 +26,7 @@ LL | #[inline = ""] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` +error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...")]` --> $DIR/malformed-regressions.rs:7:1 | LL | #[link] @@ -35,7 +35,7 @@ LL | #[link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #57571 -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ cfg = "...")]` +error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...")]` --> $DIR/malformed-regressions.rs:9:1 | LL | #[link = ""] From 61d419314f3ea5c8e7d3380afc019db1070c4744 Mon Sep 17 00:00:00 2001 From: Dodo Date: Sun, 29 Mar 2020 18:27:54 +0200 Subject: [PATCH 3/4] add a build-pass test for issue 62220 --- .../ui/const-generics/issues/issue-62220.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/ui/const-generics/issues/issue-62220.rs diff --git a/src/test/ui/const-generics/issues/issue-62220.rs b/src/test/ui/const-generics/issues/issue-62220.rs new file mode 100644 index 0000000000000..c95b306320175 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-62220.rs @@ -0,0 +1,22 @@ +// build-pass +#![allow(incomplete_features)] + +#![feature(const_generics)] +pub struct Vector([T; N]); + +pub type TruncatedVector = Vector; + +impl Vector { + /// Drop the last component and return the vector with one fewer dimension. + pub fn trunc(self) -> (TruncatedVector, T) { + unimplemented!() + } +} + +fn vec4(a: T, b: T, c: T, d: T) -> Vector { + Vector([a, b, c, d]) +} + +fn main() { + let (_xyz, _w): (TruncatedVector, u32) = vec4(0u32, 1, 2, 3).trunc(); +} From 8b762c5537b3e7b223bec3a80ab45aa3c5fe7e40 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Sun, 29 Mar 2020 18:34:42 +0200 Subject: [PATCH 4/4] prohibit_generics: update has_err for consts --- src/librustc_typeck/astconv.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 07630d7969e81..5f444a5fd2dec 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2440,6 +2440,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { continue; } err_for_ct = true; + has_err = true; (ct.span, "const") } };