Skip to content

Commit 699f83f

Browse files
committedMar 29, 2020
Auto merge of #70544 - Dylan-DPC:rollup-pj86j17, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #69702 (Rename TyLayout to TyAndLayout.) - #70539 (add test for 62220) - #70540 (#[link]: mention wasm_import_module instead of cfg) - #70541 (prohibit_generics: update has_err for consts) Failed merges: r? @ghost
2 parents 285519d + 800ed0c commit 699f83f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+324
-288
lines changed
 

‎src/librustc/ty/layout.rs

+43-33
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
270270
fn univariant_uninterned(
271271
&self,
272272
ty: Ty<'tcx>,
273-
fields: &[TyLayout<'_>],
273+
fields: &[TyAndLayout<'_>],
274274
repr: &ReprOptions,
275275
kind: StructKind,
276276
) -> Result<Layout, LayoutError<'tcx>> {
@@ -293,7 +293,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
293293
let end =
294294
if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
295295
let optimizing = &mut inverse_memory_index[..end];
296-
let field_align = |f: &TyLayout<'_>| {
296+
let field_align = |f: &TyAndLayout<'_>| {
297297
if let Some(pack) = pack { f.align.abi.min(pack) } else { f.align.abi }
298298
};
299299
match kind {
@@ -422,11 +422,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
422422
(
423423
Some((
424424
i,
425-
&TyLayout { layout: &Layout { abi: Abi::Scalar(ref a), .. }, .. },
425+
&TyAndLayout {
426+
layout: &Layout { abi: Abi::Scalar(ref a), .. }, ..
427+
},
426428
)),
427429
Some((
428430
j,
429-
&TyLayout { layout: &Layout { abi: Abi::Scalar(ref b), .. }, .. },
431+
&TyAndLayout {
432+
layout: &Layout { abi: Abi::Scalar(ref b), .. }, ..
433+
},
430434
)),
431435
None,
432436
) => {
@@ -485,7 +489,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
485489
};
486490
let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value)));
487491

488-
let univariant = |fields: &[TyLayout<'_>], repr: &ReprOptions, kind| {
492+
let univariant = |fields: &[TyAndLayout<'_>], repr: &ReprOptions, kind| {
489493
Ok(tcx.intern_layout(self.univariant_uninterned(ty, fields, repr, kind)?))
490494
};
491495
debug_assert!(!ty.has_infer_types_or_consts());
@@ -754,7 +758,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
754758
// but *not* an encoding of the discriminant (e.g., a tag value).
755759
// See issue #49298 for more details on the need to leave space
756760
// for non-ZST uninhabited data (mostly partial initialization).
757-
let absent = |fields: &[TyLayout<'_>]| {
761+
let absent = |fields: &[TyAndLayout<'_>]| {
758762
let uninhabited = fields.iter().any(|f| f.abi.is_uninhabited());
759763
let is_zst = fields.iter().all(|f| f.is_zst());
760764
uninhabited && is_zst
@@ -1404,7 +1408,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14041408
let discr_int_ty = discr_int.to_ty(tcx, false);
14051409
let discr = Scalar { value: Primitive::Int(discr_int, false), valid_range: 0..=max_discr };
14061410
let discr_layout = self.tcx.intern_layout(Layout::scalar(self, discr.clone()));
1407-
let discr_layout = TyLayout { ty: discr_int_ty, layout: discr_layout };
1411+
let discr_layout = TyAndLayout { ty: discr_int_ty, layout: discr_layout };
14081412

14091413
let promoted_layouts = ineligible_locals
14101414
.iter()
@@ -1573,15 +1577,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
15731577
/// This is invoked by the `layout_raw` query to record the final
15741578
/// layout of each type.
15751579
#[inline(always)]
1576-
fn record_layout_for_printing(&self, layout: TyLayout<'tcx>) {
1580+
fn record_layout_for_printing(&self, layout: TyAndLayout<'tcx>) {
15771581
// If we are running with `-Zprint-type-sizes`, maybe record layouts
15781582
// for dumping later.
15791583
if self.tcx.sess.opts.debugging_opts.print_type_sizes {
15801584
self.record_layout_for_printing_outlined(layout)
15811585
}
15821586
}
15831587

1584-
fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) {
1588+
fn record_layout_for_printing_outlined(&self, layout: TyAndLayout<'tcx>) {
15851589
// Ignore layouts that are done with non-empty environments or
15861590
// non-monomorphic layouts, as the user only wants to see the stuff
15871591
// resulting from the final codegen session.
@@ -1624,7 +1628,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
16241628
let adt_kind = adt_def.adt_kind();
16251629
let adt_packed = adt_def.repr.pack.is_some();
16261630

1627-
let build_variant_info = |n: Option<Ident>, flds: &[ast::Name], layout: TyLayout<'tcx>| {
1631+
let build_variant_info = |n: Option<Ident>,
1632+
flds: &[ast::Name],
1633+
layout: TyAndLayout<'tcx>| {
16281634
let mut min_size = Size::ZERO;
16291635
let field_info: Vec<_> = flds
16301636
.iter()
@@ -1891,19 +1897,19 @@ impl<'tcx, T: HasTyCtxt<'tcx>> HasTyCtxt<'tcx> for LayoutCx<'tcx, T> {
18911897
}
18921898
}
18931899

1894-
pub type TyLayout<'tcx> = ::rustc_target::abi::TyLayout<'tcx, Ty<'tcx>>;
1900+
pub type TyAndLayout<'tcx> = ::rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>;
18951901

18961902
impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
18971903
type Ty = Ty<'tcx>;
1898-
type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
1904+
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
18991905

19001906
/// Computes the layout of a type. Note that this implicitly
19011907
/// executes in "reveal all" mode.
1902-
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
1908+
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
19031909
let param_env = self.param_env.with_reveal_all();
19041910
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
19051911
let layout = self.tcx.layout_raw(param_env.and(ty))?;
1906-
let layout = TyLayout { ty, layout };
1912+
let layout = TyAndLayout { ty, layout };
19071913

19081914
// N.B., this recording is normally disabled; when enabled, it
19091915
// can however trigger recursive invocations of `layout_of`.
@@ -1919,15 +1925,15 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
19191925

19201926
impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
19211927
type Ty = Ty<'tcx>;
1922-
type TyLayout = Result<TyLayout<'tcx>, LayoutError<'tcx>>;
1928+
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
19231929

19241930
/// Computes the layout of a type. Note that this implicitly
19251931
/// executes in "reveal all" mode.
1926-
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
1932+
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
19271933
let param_env = self.param_env.with_reveal_all();
19281934
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
19291935
let layout = self.tcx.layout_raw(param_env.and(ty))?;
1930-
let layout = TyLayout { ty, layout };
1936+
let layout = TyAndLayout { ty, layout };
19311937

19321938
// N.B., this recording is normally disabled; when enabled, it
19331939
// can however trigger recursive invocations of `layout_of`.
@@ -1950,7 +1956,7 @@ impl TyCtxt<'tcx> {
19501956
pub fn layout_of(
19511957
self,
19521958
param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
1953-
) -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
1959+
) -> Result<TyAndLayout<'tcx>, LayoutError<'tcx>> {
19541960
let cx = LayoutCx { tcx: self, param_env: param_env_and_ty.param_env };
19551961
cx.layout_of(param_env_and_ty.value)
19561962
}
@@ -1963,19 +1969,23 @@ impl ty::query::TyCtxtAt<'tcx> {
19631969
pub fn layout_of(
19641970
self,
19651971
param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
1966-
) -> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
1972+
) -> Result<TyAndLayout<'tcx>, LayoutError<'tcx>> {
19671973
let cx = LayoutCx { tcx: self.at(self.span), param_env: param_env_and_ty.param_env };
19681974
cx.layout_of(param_env_and_ty.value)
19691975
}
19701976
}
19711977

1972-
impl<'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1978+
impl<'tcx, C> TyAndLayoutMethods<'tcx, C> for Ty<'tcx>
19731979
where
1974-
C: LayoutOf<Ty = Ty<'tcx>, TyLayout: MaybeResult<TyLayout<'tcx>>>
1980+
C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout: MaybeResult<TyAndLayout<'tcx>>>
19751981
+ HasTyCtxt<'tcx>
19761982
+ HasParamEnv<'tcx>,
19771983
{
1978-
fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: VariantIdx) -> TyLayout<'tcx> {
1984+
fn for_variant(
1985+
this: TyAndLayout<'tcx>,
1986+
cx: &C,
1987+
variant_index: VariantIdx,
1988+
) -> TyAndLayout<'tcx> {
19791989
let layout = match this.variants {
19801990
Variants::Single { index }
19811991
// If all variants but one are uninhabited, the variant layout is the enum layout.
@@ -2013,14 +2023,14 @@ where
20132023

20142024
assert_eq!(layout.variants, Variants::Single { index: variant_index });
20152025

2016-
TyLayout { ty: this.ty, layout }
2026+
TyAndLayout { ty: this.ty, layout }
20172027
}
20182028

2019-
fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout {
2029+
fn field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout {
20202030
let tcx = cx.tcx();
2021-
let discr_layout = |discr: &Scalar| -> C::TyLayout {
2031+
let discr_layout = |discr: &Scalar| -> C::TyAndLayout {
20222032
let layout = Layout::scalar(cx, discr.clone());
2023-
MaybeResult::from(Ok(TyLayout {
2033+
MaybeResult::from(Ok(TyAndLayout {
20242034
layout: tcx.intern_layout(layout),
20252035
ty: discr.value.to_ty(tcx),
20262036
}))
@@ -2037,7 +2047,7 @@ where
20372047
| ty::FnDef(..)
20382048
| ty::GeneratorWitness(..)
20392049
| ty::Foreign(..)
2040-
| ty::Dynamic(..) => bug!("TyLayout::field_type({:?}): not applicable", this),
2050+
| ty::Dynamic(..) => bug!("TyAndLayout::field_type({:?}): not applicable", this),
20412051

20422052
// Potentially-fat pointers.
20432053
ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
@@ -2080,7 +2090,7 @@ where
20802090
])
20812091
*/
20822092
}
2083-
_ => bug!("TyLayout::field_type({:?}): not applicable", this),
2093+
_ => bug!("TyAndLayout::field_type({:?}): not applicable", this),
20842094
}
20852095
}
20862096

@@ -2132,11 +2142,11 @@ where
21322142
| ty::Opaque(..)
21332143
| ty::Param(_)
21342144
| ty::Infer(_)
2135-
| ty::Error => bug!("TyLayout::field_type: unexpected type `{}`", this.ty),
2145+
| ty::Error => bug!("TyAndLayout::field_type: unexpected type `{}`", this.ty),
21362146
})
21372147
}
21382148

2139-
fn pointee_info_at(this: TyLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> {
2149+
fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> {
21402150
match this.ty.kind {
21412151
ty::RawPtr(mt) if offset.bytes() == 0 => {
21422152
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo {
@@ -2337,7 +2347,7 @@ impl<'tcx> ty::Instance<'tcx> {
23372347

23382348
pub trait FnAbiExt<'tcx, C>
23392349
where
2340-
C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
2350+
C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
23412351
+ HasDataLayout
23422352
+ HasTargetSpec
23432353
+ HasTyCtxt<'tcx>
@@ -2368,7 +2378,7 @@ where
23682378

23692379
impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>>
23702380
where
2371-
C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
2381+
C: LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>>
23722382
+ HasDataLayout
23732383
+ HasTargetSpec
23742384
+ HasTyCtxt<'tcx>
@@ -2518,7 +2528,7 @@ where
25182528
// Handle safe Rust thin and fat pointers.
25192529
let adjust_for_rust_scalar = |attrs: &mut ArgAttributes,
25202530
scalar: &Scalar,
2521-
layout: TyLayout<'tcx>,
2531+
layout: TyAndLayout<'tcx>,
25222532
offset: Size,
25232533
is_return: bool| {
25242534
// Booleans are always an i1 that needs to be zero-extended.

‎src/librustc_codegen_llvm/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::type_of::LayoutLlvmExt;
77
use crate::value::Value;
88
use libc::{c_char, c_uint};
99
use log::debug;
10-
use rustc::ty::layout::{self, Align, Size, TyLayout};
10+
use rustc::ty::layout::{self, Align, Size, TyAndLayout};
1111
use rustc::ty::{self, Ty, TyCtxt};
1212
use rustc_codegen_ssa::base::to_immediate;
1313
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind};
@@ -86,9 +86,9 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> {
8686

8787
impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
8888
type Ty = Ty<'tcx>;
89-
type TyLayout = TyLayout<'tcx>;
89+
type TyAndLayout = TyAndLayout<'tcx>;
9090

91-
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
91+
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
9292
self.cx.layout_of(ty)
9393
}
9494
}

0 commit comments

Comments
 (0)
Please sign in to comment.