fn univariant_uninterned(
&self,
ty: Ty<'tcx>,
- fields: &[TyLayout<'_>],
+ fields: &[TyAndLayout<'_>],
repr: &ReprOptions,
kind: StructKind,
) -> Result<Layout, LayoutError<'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 {
(
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,
) => {
};
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());
// 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
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()
/// 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 {
}
}
- 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.
let adt_kind = adt_def.adt_kind();
let adt_packed = adt_def.repr.pack.is_some();
- let build_variant_info = |n: Option<Ident>, flds: &[ast::Name], layout: TyLayout<'tcx>| {
+ let build_variant_info = |n: Option<Ident>,
+ flds: &[ast::Name],
+ layout: TyAndLayout<'tcx>| {
let mut min_size = Size::ZERO;
let field_info: Vec<_> = flds
.iter()
}
}
-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<TyLayout<'tcx>, LayoutError<'tcx>>;
+ type TyAndLayout = Result<TyAndLayout<'tcx>, 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`.
impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
type Ty = Ty<'tcx>;
- type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
+ type TyAndLayout = Result<TyAndLayout<'tcx>, 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`.
pub fn layout_of(
self,
param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
- ) -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
+ ) -> Result<TyAndLayout<'tcx>, LayoutError<'tcx>> {
let cx = LayoutCx { tcx: self, param_env: param_env_and_ty.param_env };
cx.layout_of(param_env_and_ty.value)
}
pub fn layout_of(
self,
param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
- ) -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
+ ) -> Result<TyAndLayout<'tcx>, 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<Ty = Ty<'tcx>, TyLayout: MaybeResult<TyLayout<'tcx>>>
+ C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout: MaybeResult<TyAndLayout<'tcx>>>
+ 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.
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),
}))
| 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, .. }) => {
])
*/
}
- _ => bug!("TyLayout::field_type({:?}): not applicable", this),
+ _ => bug!("TyAndLayout::field_type({:?}): not applicable", this),
}
}
| 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<PointeeInfo> {
+ fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> {
match this.ty.kind {
ty::RawPtr(mt) if offset.bytes() == 0 => {
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo {
pub trait FnAbiExt<'tcx, C>
where
- C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
+ C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
+ HasDataLayout
+ HasTargetSpec
+ HasTyCtxt<'tcx>
impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>>
where
- C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
+ C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
+ HasDataLayout
+ HasTargetSpec
+ HasTyCtxt<'tcx>
// 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.
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};
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)
}
}
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};
fn from_const_alloc(
&self,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
alloc: &Allocation,
offset: Size,
) -> PlaceRef<'tcx, &'ll Value> {
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;
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())
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;
//=-----------------------------------------------------------------------------
struct UnionMemberDescriptionFactory<'tcx> {
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
variant: &'tcx ty::VariantDef,
span: Span,
}
/// 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,
fn compute_field_path<'a, 'tcx>(
cx: &CodegenCx<'a, 'tcx>,
name: &mut String,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
offset: Size,
size: Size,
) {
/// `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,
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;
}
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 {
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"),
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();
fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option<PointeeInfo>;
}
-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,
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];
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,
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};
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);
dst_align: Align,
src: Bx::Value,
src_align: Align,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
flags: MemFlags,
) {
let size = layout.size.bytes();
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};
impl<'a, 'tcx, V: CodegenObject> LocalRef<'tcx, V> {
fn new_operand<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
bx: &mut Bx,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
) -> LocalRef<'tcx, V> {
if layout.is_zst() {
// Zero-size temporaries aren't always initialized, which
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;
pub val: OperandValue<V>,
// The layout of value, based on its Rust type.
- pub layout: TyLayout<'tcx>,
+ pub layout: TyAndLayout<'tcx>,
}
impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
pub fn new_zst<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
bx: &mut Bx,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
) -> OperandRef<'tcx, V> {
assert!(layout.is_zst());
OperandRef {
pub fn from_immediate_or_packed_pair<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
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);
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)]
pub llextra: Option<V>,
/// 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 }
}
// unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`).
pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
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);
// unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`).
pub fn alloca_unsized_indirect<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
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);
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;
}
pub trait Backend<'tcx>:
- Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
+ Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
{
}
impl<'tcx, T> Backend<'tcx> for T where
- Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
+ Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
{
}
) -> Self::Value;
fn from_const_alloc(
&self,
- layout: layout::TyLayout<'tcx>,
+ layout: layout::TyAndLayout<'tcx>,
alloc: &Allocation,
offset: layout::Size,
) -> PlaceRef<'tcx, Self::Value>;
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};
impl<T> 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;
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;
impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
type Ty = Ty<'tcx>;
- type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
+ type TyAndLayout = Result<TyAndLayout<'tcx>, 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))
}
}
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;
fn cast_immediate(
&self,
src: ImmTy<'tcx, M::PointerTag>,
- dest_layout: TyLayout<'tcx>,
+ dest_layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
use rustc::ty::TyKind::*;
trace!("Casting {:?}: {:?} to {:?}", *src, src.layout.ty, dest_layout.ty);
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<M::PointerTag>> {
// Let's make sure v is sign-extended *if* it has a signed type.
let signed = src_layout.abi.is_signed();
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};
pub value: LocalValue<Tag, Id>,
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
#[stable_hasher(ignore)]
- pub layout: Cell<Option<TyLayout<'tcx>>>,
+ pub layout: Cell<Option<TyAndLayout<'tcx>>>,
}
/// Current value of a local variable
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())
}
#[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)
}
&self,
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
local: mir::Local,
- layout: Option<TyLayout<'tcx>>,
- ) -> InterpResult<'tcx, TyLayout<'tcx>> {
+ layout: Option<TyAndLayout<'tcx>>,
+ ) -> 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()) {
pub(super) fn size_and_align_of(
&self,
metadata: MemPlaceMeta<M::PointerTag>,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, Option<(Size, Align)>> {
if !layout.is_unsized() {
return Ok(Some((layout.size, layout.align.abi)));
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;
#[derive(Copy, Clone, Debug)]
pub struct ImmTy<'tcx, Tag = ()> {
pub(crate) imm: Immediate<Tag>,
- pub layout: TyLayout<'tcx>,
+ pub layout: TyAndLayout<'tcx>,
}
impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OpTy<'tcx, Tag = ()> {
op: Operand<Tag>, // 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> {
impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
#[inline]
- pub fn from_scalar(val: Scalar<Tag>, layout: TyLayout<'tcx>) -> Self {
+ pub fn from_scalar(val: Scalar<Tag>, layout: TyAndLayout<'tcx>) -> Self {
ImmTy { imm: val.into(), layout }
}
#[inline]
- pub fn try_from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Option<Self> {
+ pub fn try_from_uint(i: impl Into<u128>, layout: TyAndLayout<'tcx>) -> Option<Self> {
Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout))
}
#[inline]
- pub fn from_uint(i: impl Into<u128>, layout: TyLayout<'tcx>) -> Self {
+ pub fn from_uint(i: impl Into<u128>, layout: TyAndLayout<'tcx>) -> Self {
Self::from_scalar(Scalar::from_uint(i, layout.size), layout)
}
#[inline]
- pub fn try_from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Option<Self> {
+ pub fn try_from_int(i: impl Into<i128>, layout: TyAndLayout<'tcx>) -> Option<Self> {
Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout))
}
#[inline]
- pub fn from_int(i: impl Into<i128>, layout: TyLayout<'tcx>) -> Self {
+ pub fn from_int(i: impl Into<i128>, layout: TyAndLayout<'tcx>) -> Self {
Self::from_scalar(Scalar::from_int(i, layout.size), layout)
}
}
// or compute the layout.
#[inline(always)]
pub(super) fn from_known_layout<'tcx>(
- layout: Option<TyLayout<'tcx>>,
- compute: impl FnOnce() -> InterpResult<'tcx, TyLayout<'tcx>>,
-) -> InterpResult<'tcx, TyLayout<'tcx>> {
+ layout: Option<TyAndLayout<'tcx>>,
+ compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
+) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
match layout {
None => compute(),
Some(layout) => {
&self,
frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
local: mir::Local,
- layout: Option<TyLayout<'tcx>>,
+ layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
assert_ne!(local, mir::RETURN_PLACE);
let layout = self.layout_of_local(frame, local, layout)?;
pub fn eval_place_to_op(
&self,
place: &mir::Place<'tcx>,
- layout: Option<TyLayout<'tcx>>,
+ layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let base_op = match place.local {
mir::RETURN_PLACE => throw_ub!(ReadFromReturnPlace),
pub fn eval_operand(
&self,
mir_op: &mir::Operand<'tcx>,
- layout: Option<TyLayout<'tcx>>,
+ layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Operand::*;
let op = match *mir_op {
crate fn eval_const_to_op(
&self,
val: &ty::Const<'tcx>,
- layout: Option<TyLayout<'tcx>>,
+ layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
let tag_scalar = |scalar| match scalar {
Scalar::Ptr(ptr) => Scalar::Ptr(self.tag_global_base_pointer(ptr)),
use rustc::mir::interpret::{InterpResult, Scalar};
use rustc::ty::{
self,
- layout::{LayoutOf, TyLayout},
+ layout::{LayoutOf, TyAndLayout},
Ty,
};
use rustc_apfloat::Float;
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<M::PointerTag>, bool, Ty<'tcx>)> {
use rustc::mir::BinOp::*;
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;
#[derive(Copy, Clone, Debug)]
pub struct PlaceTy<'tcx, Tag = ()> {
place: Place<Tag>, // 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> {
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct MPlaceTy<'tcx, Tag = ()> {
mplace: MemPlace<Tag>,
- pub layout: TyLayout<'tcx>,
+ pub layout: TyAndLayout<'tcx>,
}
impl<'tcx, Tag> ::std::ops::Deref for MPlaceTy<'tcx, Tag> {
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.
self,
offset: Size,
meta: MemPlaceMeta<Tag>,
- 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<Tag>, layout: TyLayout<'tcx>) -> Self {
+ fn from_aligned_ptr(ptr: Pointer<Tag>, layout: TyAndLayout<'tcx>) -> Self {
MPlaceTy { mplace: MemPlace::from_ptr(ptr, layout.align.abi), layout }
}
pub fn allocate(
&mut self,
- layout: TyLayout<'tcx>,
+ layout: TyAndLayout<'tcx>,
kind: MemoryKind<M::MemoryKind>,
) -> MPlaceTy<'tcx, M::PointerTag> {
let ptr = self.memory.allocate(layout.size, layout.align.abi, kind);
..
} => {
// 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;
..
} => {
// 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();
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;
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
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};
}
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, .. } => {
fn check_wide_ptr_meta(
&mut self,
meta: MemPlaceMeta<M::PointerTag>,
- 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 {
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};
// 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>>;
// 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
}
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
}
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};
impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> {
type Ty = Ty<'tcx>;
- type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
+ type TyAndLayout = Result<TyAndLayout<'tcx>, 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))
}
}
fn const_prop(
&mut self,
rvalue: &Rvalue<'tcx>,
- place_layout: TyLayout<'tcx>,
+ place_layout: TyAndLayout<'tcx>,
source_info: SourceInfo,
place: &Place<'tcx>,
) -> Option<()> {
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;
}
fn variant_discriminants<'tcx>(
- layout: &TyLayout<'tcx>,
+ layout: &TyAndLayout<'tcx>,
ty: Ty<'tcx>,
tcx: TyCtxt<'tcx>,
) -> Vec<u128> {
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;
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()
}
}
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<Uniform>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
let size = arg.layout.size;
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() {
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + 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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + 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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
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<Uniform>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
let size = arg.layout.size;
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(32);
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() {
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + 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.
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<Ty = Ty> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
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<Ty = Ty> + HasDataLayout,
{
let dl = cx.data_layout();
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<Ty = Ty> + HasDataLayout,
{
let mut offset = Size::ZERO;
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<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
// Always sign extend u32 values on 64-bit mips
fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option<Reg>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
match ret.layout.field(cx, i).abi {
abi::Abi::Scalar(ref scalar) => match scalar.value {
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
extend_integer_width_mips(ret, 64);
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() {
extend_integer_width_mips(arg, 64);
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
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;
}
}
-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,
/// specific targets.
pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, Heterogeneous>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = Self>,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = Self>,
{
match self.abi {
Abi::Uninhabited => Err(Heterogeneous),
/// 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<Reg>,
}
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()) }
}
impl<'a, Ty> FnAbi<'a, Ty> {
pub fn adjust_for_cabi<C>(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
{
match &cx.target_spec().arch[..] {
"x86" => {
// 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)]
abi: ABI,
) -> Option<Uniform>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
// ELFv1 only passes one-member aggregates transparently.
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64);
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64);
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
{
let abi = if cx.target_spec().target_env == "musl" {
ELFv2
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;
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 = Ty, TyLayout = TyLayout<'a, Ty>>,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{
match arg_layout.abi {
Abi::Scalar(ref scalar) => match scalar.value {
fn should_use_fp_conv<'a, Ty, C>(
cx: &C,
- arg: &TyLayout<'a, Ty>,
+ arg: &TyAndLayout<'a, Ty>,
xlen: u64,
flen: u64,
) -> Option<FloatConv>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>>,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{
let mut field1_kind = RegPassKind::Unknown;
let mut field2_kind = RegPassKind::Unknown;
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 = Ty, TyLayout = TyLayout<'a, Ty>>,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{
if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) {
match conv {
avail_gprs: &mut u64,
avail_fprs: &mut u64,
) where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>>,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>,
{
if !is_vararg {
match should_use_fp_conv(cx, &arg.layout, xlen, flen) {
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
{
let flen = match &cx.target_spec().options.llvm_abiname[..] {
"ilp32f" | "lp64f" => 32,
// 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<Ty = Ty> + HasDataLayout,
{
if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
}
}
-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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C>,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
match layout.abi {
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
arg.extend_integer_width_to(64);
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(&mut fn_abi.ret);
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<Ty = Ty> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
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<Ty = Ty> + HasDataLayout,
{
let dl = cx.data_layout();
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<Ty = Ty> + HasDataLayout,
{
let mut offset = Size::ZERO;
// 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<Uniform>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
// Ensure we have at most eight uniquely addressable members.
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !ret.layout.is_aggregate() {
ret.extend_integer_width_to(64);
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !arg.layout.is_aggregate() {
arg.extend_integer_width_to(64);
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if val.layout.is_aggregate() {
if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) {
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
ret.extend_integer_width_to(32);
if ret.layout.is_aggregate() {
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
arg.extend_integer_width_to(32);
if arg.layout.is_aggregate() {
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret);
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)]
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
match layout.abi {
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
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<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec,
{
if !fn_abi.ret.is_ignore() {
if fn_abi.ret.layout.is_aggregate() {
// 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,
arg: &ArgAbi<'a, Ty>,
) -> Result<[Option<Class>; MAX_EIGHTBYTES], Memory>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
fn classify<'a, Ty, C>(
cx: &C,
- layout: TyLayout<'a, Ty>,
+ layout: TyAndLayout<'a, Ty>,
cls: &mut [Option<Class>],
off: Size,
) -> Result<(), Memory>
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
if !off.is_aligned(layout.align.abi) {
if !layout.is_zst() {
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
- Ty: TyLayoutMethods<'a, C> + Copy,
- C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C> + Copy,
+ C: LayoutOf<Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout,
{
let mut int_regs = MAX_INT_REGS;
let mut sse_regs = MAX_SSE_REGS;
/// 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
/// 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<TyLayout<'_, Self>>`.
+/// The `TyAndLayout` above will always be a `MaybeResult<TyAndLayout<'_, Self>>`.
/// 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<T> {
pub safe: Option<PointerKind>,
}
-pub trait TyLayoutMethods<'a, C: LayoutOf<Ty = Self>>: Sized {
+pub trait TyAndLayoutMethods<'a, C: LayoutOf<Ty = Self>>: 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<PointeeInfo>;
+ ) -> 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<PointeeInfo>;
}
-impl<'a, Ty> TyLayout<'a, Ty> {
+impl<'a, Ty> TyAndLayout<'a, Ty> {
pub fn for_variant<C>(self, cx: &C, variant_index: VariantIdx) -> Self
where
- Ty: TyLayoutMethods<'a, C>,
+ Ty: TyAndLayoutMethods<'a, C>,
C: LayoutOf<Ty = Ty>,
{
Ty::for_variant(self, cx, variant_index)
}
- /// Callers might want to use `C: LayoutOf<Ty=Ty, TyLayout: MaybeResult<Self>>`
+ /// Callers might want to use `C: LayoutOf<Ty=Ty, TyAndLayout: MaybeResult<Self>>`
/// to allow recursion (see `might_permit_zero_init` below for an example).
- pub fn field<C>(self, cx: &C, i: usize) -> C::TyLayout
+ pub fn field<C>(self, cx: &C, i: usize) -> C::TyAndLayout
where
- Ty: TyLayoutMethods<'a, C>,
+ Ty: TyAndLayoutMethods<'a, C>,
C: LayoutOf<Ty = Ty>,
{
Ty::field(self, cx, i)
pub fn pointee_info_at<C>(self, cx: &C, offset: Size) -> Option<PointeeInfo>
where
- Ty: TyLayoutMethods<'a, C>,
+ Ty: TyAndLayoutMethods<'a, C>,
C: LayoutOf<Ty = Ty>,
{
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()
pub fn might_permit_raw_init<C, E>(self, cx: &C, zero: bool) -> Result<bool, E>
where
Self: Copy,
- Ty: TyLayoutMethods<'a, C>,
- C: LayoutOf<Ty = Ty, TyLayout: MaybeResult<Self, Error = E>> + HasDataLayout,
+ Ty: TyAndLayoutMethods<'a, C>,
+ C: LayoutOf<Ty = Ty, TyAndLayout: MaybeResult<Self, Error = E>> + HasDataLayout,
{
let scalar_allows_raw_init = move |s: &Scalar| -> bool {
if zero {