Skip to content

Commit

Permalink
Rename TyLayout to TyAndLayout.
Browse files Browse the repository at this point in the history
  • Loading branch information
anyska committed Mar 27, 2020
1 parent 0a2df62 commit 50d2c3a
Show file tree
Hide file tree
Showing 41 changed files with 298 additions and 285 deletions.
76 changes: 43 additions & 33 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Layout, LayoutError<'tcx>> {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
) => {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1573,15 +1577,15 @@ 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 {
self.record_layout_for_printing_outlined(layout)
}
}

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.
Expand Down Expand Up @@ -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<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()
Expand Down Expand Up @@ -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<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`.
Expand All @@ -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<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`.
Expand All @@ -1950,7 +1956,7 @@ impl TyCtxt<'tcx> {
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)
}
Expand All @@ -1963,19 +1969,23 @@ impl ty::query::TyCtxtAt<'tcx> {
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.
Expand Down Expand Up @@ -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),
}))
Expand All @@ -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, .. }) => {
Expand Down Expand Up @@ -2080,7 +2090,7 @@ where
])
*/
}
_ => bug!("TyLayout::field_type({:?}): not applicable", this),
_ => bug!("TyAndLayout::field_type({:?}): not applicable", this),
}
}

Expand Down Expand Up @@ -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<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 {
Expand Down Expand Up @@ -2337,7 +2347,7 @@ impl<'tcx> ty::Instance<'tcx> {

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>
Expand Down Expand Up @@ -2368,7 +2378,7 @@ where

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>
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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> {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1203,7 +1203,7 @@ fn prepare_tuple_metadata(
//=-----------------------------------------------------------------------------

struct UnionMemberDescriptionFactory<'tcx> {
layout: TyLayout<'tcx>,
layout: TyAndLayout<'tcx>,
variant: &'tcx ty::VariantDef,
span: Span,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
) {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_codegen_llvm/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 50d2c3a

Please sign in to comment.