make LayoutCx
not generic
This commit is contained in:
parent
13b5a4e43b
commit
16be6666d4
9 changed files with 42 additions and 71 deletions
|
@ -21,7 +21,7 @@ use rustc_middle::mir::interpret::{
|
||||||
UnsupportedOpInfo, ValidationErrorInfo,
|
UnsupportedOpInfo, ValidationErrorInfo,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_target::abi::{
|
use rustc_target::abi::{
|
||||||
Abi, FieldIdx, FieldsShape, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
|
Abi, FieldIdx, FieldsShape, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
|
||||||
|
@ -949,7 +949,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
|
||||||
|
|
||||||
/// Helper for recursive traversal: add data ranges of the given type to `out`.
|
/// Helper for recursive traversal: add data ranges of the given type to `out`.
|
||||||
fn union_data_range_uncached<'tcx>(
|
fn union_data_range_uncached<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
base_offset: Size,
|
base_offset: Size,
|
||||||
out: &mut RangeSet,
|
out: &mut RangeSet,
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub fn check_validity_requirement<'tcx>(
|
||||||
/// for details.
|
/// for details.
|
||||||
fn check_validity_requirement_strict<'tcx>(
|
fn check_validity_requirement_strict<'tcx>(
|
||||||
ty: TyAndLayout<'tcx>,
|
ty: TyAndLayout<'tcx>,
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
kind: ValidityRequirement,
|
kind: ValidityRequirement,
|
||||||
) -> Result<bool, &'tcx LayoutError<'tcx>> {
|
) -> Result<bool, &'tcx LayoutError<'tcx>> {
|
||||||
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
|
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
|
||||||
|
@ -80,7 +80,7 @@ fn check_validity_requirement_strict<'tcx>(
|
||||||
/// function for details.
|
/// function for details.
|
||||||
fn check_validity_requirement_lax<'tcx>(
|
fn check_validity_requirement_lax<'tcx>(
|
||||||
this: TyAndLayout<'tcx>,
|
this: TyAndLayout<'tcx>,
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
init_kind: ValidityRequirement,
|
init_kind: ValidityRequirement,
|
||||||
) -> Result<bool, &'tcx LayoutError<'tcx>> {
|
) -> Result<bool, &'tcx LayoutError<'tcx>> {
|
||||||
let scalar_allows_raw_init = move |s: Scalar| -> bool {
|
let scalar_allows_raw_init = move |s: Scalar| -> bool {
|
||||||
|
|
|
@ -286,12 +286,12 @@ impl<'tcx> IntoDiagArg for LayoutError<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct LayoutCx<'tcx, C> {
|
pub struct LayoutCx<'tcx> {
|
||||||
pub tcx: C,
|
pub tcx: TyCtxt<'tcx>,
|
||||||
pub param_env: ty::ParamEnv<'tcx>,
|
pub param_env: ty::ParamEnv<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> {
|
impl<'tcx> LayoutCalculator for LayoutCx<'tcx> {
|
||||||
type TargetDataLayoutRef = &'tcx TargetDataLayout;
|
type TargetDataLayoutRef = &'tcx TargetDataLayout;
|
||||||
|
|
||||||
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
|
fn delayed_bug(&self, txt: impl Into<Cow<'static, str>>) {
|
||||||
|
@ -568,31 +568,31 @@ impl<'tcx> HasTyCtxt<'tcx> for TyCtxtAt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> {
|
impl<'tcx> HasParamEnv<'tcx> for LayoutCx<'tcx> {
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.param_env
|
self.param_env
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: HasDataLayout> HasDataLayout for LayoutCx<'tcx, T> {
|
impl<'tcx> HasDataLayout for LayoutCx<'tcx> {
|
||||||
fn data_layout(&self) -> &TargetDataLayout {
|
fn data_layout(&self) -> &TargetDataLayout {
|
||||||
self.tcx.data_layout()
|
self.tcx.data_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: HasTargetSpec> HasTargetSpec for LayoutCx<'tcx, T> {
|
impl<'tcx> HasTargetSpec for LayoutCx<'tcx> {
|
||||||
fn target_spec(&self) -> &Target {
|
fn target_spec(&self) -> &Target {
|
||||||
self.tcx.target_spec()
|
self.tcx.target_spec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: HasWasmCAbiOpt> HasWasmCAbiOpt for LayoutCx<'tcx, T> {
|
impl<'tcx> HasWasmCAbiOpt for LayoutCx<'tcx> {
|
||||||
fn wasm_c_abi_opt(&self) -> WasmCAbi {
|
fn wasm_c_abi_opt(&self) -> WasmCAbi {
|
||||||
self.tcx.wasm_c_abi_opt()
|
self.tcx.wasm_c_abi_opt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: HasTyCtxt<'tcx>> HasTyCtxt<'tcx> for LayoutCx<'tcx, T> {
|
impl<'tcx> HasTyCtxt<'tcx> for LayoutCx<'tcx> {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.tcx.tcx()
|
self.tcx.tcx()
|
||||||
}
|
}
|
||||||
|
@ -685,7 +685,7 @@ pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
|
||||||
|
|
||||||
impl<'tcx, C: LayoutOfHelpers<'tcx>> LayoutOf<'tcx> for C {}
|
impl<'tcx, C: LayoutOfHelpers<'tcx>> LayoutOf<'tcx> for C {}
|
||||||
|
|
||||||
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
|
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx> {
|
||||||
type LayoutOfResult = Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>>;
|
type LayoutOfResult = Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -699,25 +699,6 @@ impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxtAt<'tcx>> {
|
|
||||||
type LayoutOfResult = Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn layout_tcx_at_span(&self) -> Span {
|
|
||||||
self.tcx.span
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn handle_layout_err(
|
|
||||||
&self,
|
|
||||||
err: LayoutError<'tcx>,
|
|
||||||
_: Span,
|
|
||||||
_: Ty<'tcx>,
|
|
||||||
) -> &'tcx LayoutError<'tcx> {
|
|
||||||
self.tcx.arena.alloc(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
|
impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx>
|
||||||
where
|
where
|
||||||
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
|
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
|
||||||
|
|
|
@ -64,7 +64,7 @@ pub mod rustc {
|
||||||
|
|
||||||
use rustc_middle::mir::Mutability;
|
use rustc_middle::mir::Mutability;
|
||||||
use rustc_middle::ty::layout::{LayoutCx, LayoutError};
|
use rustc_middle::ty::layout::{LayoutCx, LayoutError};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_target::abi::Layout;
|
use rustc_target::abi::Layout;
|
||||||
|
|
||||||
/// A reference in the layout.
|
/// A reference in the layout.
|
||||||
|
@ -124,7 +124,7 @@ pub mod rustc {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn layout_of<'tcx>(
|
pub(crate) fn layout_of<'tcx>(
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
|
|
|
@ -204,7 +204,7 @@ pub(crate) mod rustc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Tree<Def<'tcx>, Ref<'tcx>> {
|
impl<'tcx> Tree<Def<'tcx>, Ref<'tcx>> {
|
||||||
pub(crate) fn from_ty(ty: Ty<'tcx>, cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, Err> {
|
pub(crate) fn from_ty(ty: Ty<'tcx>, cx: LayoutCx<'tcx>) -> Result<Self, Err> {
|
||||||
use rustc_target::abi::HasDataLayout;
|
use rustc_target::abi::HasDataLayout;
|
||||||
let layout = layout_of(cx, ty)?;
|
let layout = layout_of(cx, ty)?;
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ pub(crate) mod rustc {
|
||||||
fn from_tuple(
|
fn from_tuple(
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
members: &'tcx List<Ty<'tcx>>,
|
members: &'tcx List<Ty<'tcx>>,
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
) -> Result<Self, Err> {
|
) -> Result<Self, Err> {
|
||||||
match &layout.fields {
|
match &layout.fields {
|
||||||
FieldsShape::Primitive => {
|
FieldsShape::Primitive => {
|
||||||
|
@ -299,7 +299,7 @@ pub(crate) mod rustc {
|
||||||
fn from_struct(
|
fn from_struct(
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
def: AdtDef<'tcx>,
|
def: AdtDef<'tcx>,
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
) -> Result<Self, Err> {
|
) -> Result<Self, Err> {
|
||||||
assert!(def.is_struct());
|
assert!(def.is_struct());
|
||||||
let def = Def::Adt(def);
|
let def = Def::Adt(def);
|
||||||
|
@ -314,7 +314,7 @@ pub(crate) mod rustc {
|
||||||
fn from_enum(
|
fn from_enum(
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
def: AdtDef<'tcx>,
|
def: AdtDef<'tcx>,
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
) -> Result<Self, Err> {
|
) -> Result<Self, Err> {
|
||||||
assert!(def.is_enum());
|
assert!(def.is_enum());
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ pub(crate) mod rustc {
|
||||||
tag: Option<(ScalarInt, VariantIdx, TagEncoding<VariantIdx>)>,
|
tag: Option<(ScalarInt, VariantIdx, TagEncoding<VariantIdx>)>,
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
total_size: Size,
|
total_size: Size,
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
) -> Result<Self, Err> {
|
) -> Result<Self, Err> {
|
||||||
// This constructor does not support non-`FieldsShape::Arbitrary`
|
// This constructor does not support non-`FieldsShape::Arbitrary`
|
||||||
// layouts.
|
// layouts.
|
||||||
|
@ -470,7 +470,7 @@ pub(crate) mod rustc {
|
||||||
fn from_union(
|
fn from_union(
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
def: AdtDef<'tcx>,
|
def: AdtDef<'tcx>,
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
) -> Result<Self, Err> {
|
) -> Result<Self, Err> {
|
||||||
assert!(def.is_union());
|
assert!(def.is_union());
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ pub(crate) mod rustc {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_field<'tcx>(
|
fn ty_field<'tcx>(
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
i: FieldIdx,
|
i: FieldIdx,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
|
@ -527,7 +527,7 @@ pub(crate) mod rustc {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_variant<'tcx>(
|
fn ty_variant<'tcx>(
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
|
||||||
i: VariantIdx,
|
i: VariantIdx,
|
||||||
) -> Layout<'tcx> {
|
) -> Layout<'tcx> {
|
||||||
|
|
|
@ -358,7 +358,7 @@ fn fn_abi_of_instance<'tcx>(
|
||||||
|
|
||||||
// Handle safe Rust thin and fat pointers.
|
// Handle safe Rust thin and fat pointers.
|
||||||
fn adjust_for_rust_scalar<'tcx>(
|
fn adjust_for_rust_scalar<'tcx>(
|
||||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: LayoutCx<'tcx>,
|
||||||
attrs: &mut ArgAttributes,
|
attrs: &mut ArgAttributes,
|
||||||
scalar: Scalar,
|
scalar: Scalar,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
|
@ -448,12 +448,12 @@ fn adjust_for_rust_scalar<'tcx>(
|
||||||
|
|
||||||
/// Ensure that the ABI makes basic sense.
|
/// Ensure that the ABI makes basic sense.
|
||||||
fn fn_abi_sanity_check<'tcx>(
|
fn fn_abi_sanity_check<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
||||||
spec_abi: SpecAbi,
|
spec_abi: SpecAbi,
|
||||||
) {
|
) {
|
||||||
fn fn_arg_sanity_check<'tcx>(
|
fn fn_arg_sanity_check<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
|
||||||
spec_abi: SpecAbi,
|
spec_abi: SpecAbi,
|
||||||
arg: &ArgAbi<'tcx, Ty<'tcx>>,
|
arg: &ArgAbi<'tcx, Ty<'tcx>>,
|
||||||
|
@ -538,7 +538,7 @@ fn fn_abi_sanity_check<'tcx>(
|
||||||
// arguments of this method, into a separate `struct`.
|
// arguments of this method, into a separate `struct`.
|
||||||
#[tracing::instrument(level = "debug", skip(cx, caller_location, fn_def_id, force_thin_self_ptr))]
|
#[tracing::instrument(level = "debug", skip(cx, caller_location, fn_def_id, force_thin_self_ptr))]
|
||||||
fn fn_abi_new_uncached<'tcx>(
|
fn fn_abi_new_uncached<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
sig: ty::PolyFnSig<'tcx>,
|
sig: ty::PolyFnSig<'tcx>,
|
||||||
extra_args: &[Ty<'tcx>],
|
extra_args: &[Ty<'tcx>],
|
||||||
caller_location: Option<Ty<'tcx>>,
|
caller_location: Option<Ty<'tcx>>,
|
||||||
|
@ -643,7 +643,7 @@ fn fn_abi_new_uncached<'tcx>(
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(cx))]
|
#[tracing::instrument(level = "trace", skip(cx))]
|
||||||
fn fn_abi_adjust_for_abi<'tcx>(
|
fn fn_abi_adjust_for_abi<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
||||||
abi: SpecAbi,
|
abi: SpecAbi,
|
||||||
fn_def_id: Option<DefId>,
|
fn_def_id: Option<DefId>,
|
||||||
|
|
|
@ -79,15 +79,12 @@ fn layout_of<'tcx>(
|
||||||
Ok(layout)
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error<'tcx>(
|
fn error<'tcx>(cx: &LayoutCx<'tcx>, err: LayoutError<'tcx>) -> &'tcx LayoutError<'tcx> {
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
|
||||||
err: LayoutError<'tcx>,
|
|
||||||
) -> &'tcx LayoutError<'tcx> {
|
|
||||||
cx.tcx.arena.alloc(err)
|
cx.tcx.arena.alloc(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn univariant_uninterned<'tcx>(
|
fn univariant_uninterned<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
fields: &IndexSlice<FieldIdx, Layout<'_>>,
|
fields: &IndexSlice<FieldIdx, Layout<'_>>,
|
||||||
repr: &ReprOptions,
|
repr: &ReprOptions,
|
||||||
|
@ -103,7 +100,7 @@ fn univariant_uninterned<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_of_uncached<'tcx>(
|
fn layout_of_uncached<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
||||||
// Types that reference `ty::Error` pessimistically don't have a meaningful layout.
|
// 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.
|
/// Compute the full coroutine layout.
|
||||||
fn coroutine_layout<'tcx>(
|
fn coroutine_layout<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
def_id: hir::def_id::DefId,
|
def_id: hir::def_id::DefId,
|
||||||
args: GenericArgsRef<'tcx>,
|
args: GenericArgsRef<'tcx>,
|
||||||
|
@ -1017,7 +1014,7 @@ fn coroutine_layout<'tcx>(
|
||||||
Ok(layout)
|
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
|
// Ignore layouts that are done with non-empty environments or
|
||||||
// non-monomorphic layouts, as the user only wants to see the stuff
|
// non-monomorphic layouts, as the user only wants to see the stuff
|
||||||
// resulting from the final codegen session.
|
// 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>(
|
fn variant_info_for_adt<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
adt_def: AdtDef<'tcx>,
|
adt_def: AdtDef<'tcx>,
|
||||||
) -> (Vec<VariantInfo>, Option<Size>) {
|
) -> (Vec<VariantInfo>, Option<Size>) {
|
||||||
|
@ -1140,7 +1137,7 @@ fn variant_info_for_adt<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variant_info_for_coroutine<'tcx>(
|
fn variant_info_for_coroutine<'tcx>(
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &LayoutCx<'tcx>,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
args: ty::GenericArgsRef<'tcx>,
|
args: ty::GenericArgsRef<'tcx>,
|
||||||
|
|
|
@ -2,14 +2,10 @@ use std::assert_matches::assert_matches;
|
||||||
|
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::ty::layout::{LayoutCx, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutCx, TyAndLayout};
|
||||||
use rustc_middle::ty::TyCtxt;
|
|
||||||
use rustc_target::abi::*;
|
use rustc_target::abi::*;
|
||||||
|
|
||||||
/// Enforce some basic invariants on layouts.
|
/// Enforce some basic invariants on layouts.
|
||||||
pub(super) fn sanity_check_layout<'tcx>(
|
pub(super) fn sanity_check_layout<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
|
||||||
layout: &TyAndLayout<'tcx>,
|
|
||||||
) {
|
|
||||||
// Type-level uninhabitedness should always imply ABI uninhabitedness.
|
// Type-level uninhabitedness should always imply ABI uninhabitedness.
|
||||||
if layout.ty.is_privately_uninhabited(cx.tcx, cx.param_env) {
|
if layout.ty.is_privately_uninhabited(cx.tcx, cx.param_env) {
|
||||||
assert!(layout.abi.is_uninhabited());
|
assert!(layout.abi.is_uninhabited());
|
||||||
|
@ -28,8 +24,8 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Yields non-ZST fields of the type
|
/// Yields non-ZST fields of the type
|
||||||
fn non_zst_fields<'a, 'tcx>(
|
fn non_zst_fields<'tcx, 'a>(
|
||||||
cx: &'a LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &'a LayoutCx<'tcx>,
|
||||||
layout: &'a TyAndLayout<'tcx>,
|
layout: &'a TyAndLayout<'tcx>,
|
||||||
) -> impl Iterator<Item = (Size, TyAndLayout<'tcx>)> + 'a {
|
) -> impl Iterator<Item = (Size, TyAndLayout<'tcx>)> + 'a {
|
||||||
(0..layout.layout.fields().count()).filter_map(|i| {
|
(0..layout.layout.fields().count()).filter_map(|i| {
|
||||||
|
@ -43,10 +39,7 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn skip_newtypes<'tcx>(
|
fn skip_newtypes<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) -> TyAndLayout<'tcx> {
|
||||||
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
|
|
||||||
layout: &TyAndLayout<'tcx>,
|
|
||||||
) -> TyAndLayout<'tcx> {
|
|
||||||
if matches!(layout.layout.variants(), Variants::Multiple { .. }) {
|
if matches!(layout.layout.variants(), Variants::Multiple { .. }) {
|
||||||
// Definitely not a newtype of anything.
|
// Definitely not a newtype of anything.
|
||||||
return *layout;
|
return *layout;
|
||||||
|
@ -69,7 +62,7 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
*layout
|
*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.
|
// Verify the ABI mandated alignment and size.
|
||||||
let align = layout.abi.inherent_align(cx).map(|align| align.abi);
|
let align = layout.abi.inherent_align(cx).map(|align| align.abi);
|
||||||
let size = layout.abi.inherent_size(cx);
|
let size = layout.abi.inherent_size(cx);
|
||||||
|
|
|
@ -381,7 +381,7 @@ pub struct PrimitiveLayouts<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> PrimitiveLayouts<'tcx> {
|
impl<'tcx> PrimitiveLayouts<'tcx> {
|
||||||
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
|
fn new(layout_cx: LayoutCx<'tcx>) -> Result<Self, &'tcx LayoutError<'tcx>> {
|
||||||
let tcx = layout_cx.tcx;
|
let tcx = layout_cx.tcx;
|
||||||
let mut_raw_ptr = Ty::new_mut_ptr(tcx, tcx.types.unit);
|
let mut_raw_ptr = Ty::new_mut_ptr(tcx, tcx.types.unit);
|
||||||
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
|
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
|
||||||
|
@ -596,7 +596,7 @@ pub struct MiriMachine<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MiriMachine<'tcx> {
|
impl<'tcx> MiriMachine<'tcx> {
|
||||||
pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Self {
|
pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx>) -> Self {
|
||||||
let tcx = layout_cx.tcx;
|
let tcx = layout_cx.tcx;
|
||||||
let local_crates = helpers::get_local_crates(tcx);
|
let local_crates = helpers::get_local_crates(tcx);
|
||||||
let layouts =
|
let layouts =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue