make LayoutCx
not generic
This commit is contained in:
parent
13b5a4e43b
commit
16be6666d4
9 changed files with 42 additions and 71 deletions
|
@ -358,7 +358,7 @@ fn fn_abi_of_instance<'tcx>(
|
|||
|
||||
// Handle safe Rust thin and fat pointers.
|
||||
fn adjust_for_rust_scalar<'tcx>(
|
||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: LayoutCx<'tcx>,
|
||||
attrs: &mut ArgAttributes,
|
||||
scalar: Scalar,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
|
@ -448,12 +448,12 @@ fn adjust_for_rust_scalar<'tcx>(
|
|||
|
||||
/// Ensure that the ABI makes basic sense.
|
||||
fn fn_abi_sanity_check<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
||||
spec_abi: SpecAbi,
|
||||
) {
|
||||
fn fn_arg_sanity_check<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
||||
spec_abi: SpecAbi,
|
||||
arg: &ArgAbi<'tcx, Ty<'tcx>>,
|
||||
|
@ -538,7 +538,7 @@ fn fn_abi_sanity_check<'tcx>(
|
|||
// arguments of this method, into a separate `struct`.
|
||||
#[tracing::instrument(level = "debug", skip(cx, caller_location, fn_def_id, force_thin_self_ptr))]
|
||||
fn fn_abi_new_uncached<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
sig: ty::PolyFnSig<'tcx>,
|
||||
extra_args: &[Ty<'tcx>],
|
||||
caller_location: Option<Ty<'tcx>>,
|
||||
|
@ -643,7 +643,7 @@ fn fn_abi_new_uncached<'tcx>(
|
|||
|
||||
#[tracing::instrument(level = "trace", skip(cx))]
|
||||
fn fn_abi_adjust_for_abi<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
||||
abi: SpecAbi,
|
||||
fn_def_id: Option<DefId>,
|
||||
|
|
|
@ -79,15 +79,12 @@ fn layout_of<'tcx>(
|
|||
Ok(layout)
|
||||
}
|
||||
|
||||
fn error<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
err: LayoutError<'tcx>,
|
||||
) -> &'tcx LayoutError<'tcx> {
|
||||
fn error<'tcx>(cx: &LayoutCx<'tcx>, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> {
|
||||
cx.tcx.arena.alloc(err)
|
||||
}
|
||||
|
||||
fn univariant_uninterned<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
fields: &IndexSlice<FieldIdx, Layout<'_>>,
|
||||
repr: &ReprOptions,
|
||||
|
@ -103,7 +100,7 @@ fn univariant_uninterned<'tcx>(
|
|||
}
|
||||
|
||||
fn layout_of_uncached<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
||||
// Types that reference `ty::Error` pessimistically don't have a meaningful layout.
|
||||
|
@ -809,7 +806,7 @@ fn coroutine_saved_local_eligibility(
|
|||
|
||||
/// Compute the full coroutine layout.
|
||||
fn coroutine_layout<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
def_id: hir::def_id::DefId,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
|
@ -1017,7 +1014,7 @@ fn coroutine_layout<'tcx>(
|
|||
Ok(layout)
|
||||
}
|
||||
|
||||
fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: TyAndLayout<'tcx>) {
|
||||
fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx>, 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.
|
||||
|
@ -1068,7 +1065,7 @@ fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: T
|
|||
}
|
||||
|
||||
fn variant_info_for_adt<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
adt_def: AdtDef<'tcx>,
|
||||
) -> (Vec<VariantInfo>, Option<Size>) {
|
||||
|
@ -1140,7 +1137,7 @@ fn variant_info_for_adt<'tcx>(
|
|||
}
|
||||
|
||||
fn variant_info_for_coroutine<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
cx: &LayoutCx<'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
def_id: DefId,
|
||||
args: ty::GenericArgsRef<'tcx>,
|
||||
|
|
|
@ -2,14 +2,10 @@ use std::assert_matches::assert_matches;
|
|||
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::layout::{LayoutCx, TyAndLayout};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_target::abi::*;
|
||||
|
||||
/// Enforce some basic invariants on layouts.
|
||||
pub(super) fn sanity_check_layout<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
layout: &TyAndLayout<'tcx>,
|
||||
) {
|
||||
pub(super) fn sanity_check_layout<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
|
||||
// Type-level uninhabitedness should always imply ABI uninhabitedness.
|
||||
if layout.ty.is_privately_uninhabited(cx.tcx, cx.param_env) {
|
||||
assert!(layout.abi.is_uninhabited());
|
||||
|
@ -28,8 +24,8 @@ pub(super) fn sanity_check_layout<'tcx>(
|
|||
}
|
||||
|
||||
/// Yields non-ZST fields of the type
|
||||
fn non_zst_fields<'a, 'tcx>(
|
||||
cx: &'a LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
fn non_zst_fields<'tcx, 'a>(
|
||||
cx: &'a LayoutCx<'tcx>,
|
||||
layout: &'a TyAndLayout<'tcx>,
|
||||
) -> impl Iterator<Item = (Size, TyAndLayout<'tcx>)> + 'a {
|
||||
(0..layout.layout.fields().count()).filter_map(|i| {
|
||||
|
@ -43,10 +39,7 @@ pub(super) fn sanity_check_layout<'tcx>(
|
|||
})
|
||||
}
|
||||
|
||||
fn skip_newtypes<'tcx>(
|
||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
layout: &TyAndLayout<'tcx>,
|
||||
) -> TyAndLayout<'tcx> {
|
||||
fn skip_newtypes<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) -> TyAndLayout<'tcx> {
|
||||
if matches!(layout.layout.variants(), Variants::Multiple { .. }) {
|
||||
// Definitely not a newtype of anything.
|
||||
return *layout;
|
||||
|
@ -69,7 +62,7 @@ pub(super) fn sanity_check_layout<'tcx>(
|
|||
*layout
|
||||
}
|
||||
|
||||
fn check_layout_abi<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: &TyAndLayout<'tcx>) {
|
||||
fn check_layout_abi<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
|
||||
// Verify the ABI mandated alignment and size.
|
||||
let align = layout.abi.inherent_align(cx).map(|align| align.abi);
|
||||
let size = layout.abi.inherent_size(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue