This commit is contained in:
bjorn3 2024-09-22 17:14:10 +00:00
commit 1d53572570
5 changed files with 15 additions and 19 deletions

View File

@ -785,8 +785,10 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
}
Rvalue::Repeat(ref operand, times) => {
let operand = codegen_operand(fx, operand);
let times =
fx.monomorphize(times).eval_target_usize(fx.tcx, ParamEnv::reveal_all());
let times = fx
.monomorphize(times)
.try_to_target_usize(fx.tcx)
.expect("expected monomorphic const in codegen");
if operand.layout().size.bytes() == 0 {
// Do nothing for ZST's
} else if fx.clif_type(operand.layout().ty) == Some(types::I8) {
@ -944,7 +946,10 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
match *place.layout().ty.kind() {
ty::Array(_elem_ty, len) => {
let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
let len = fx
.monomorphize(len)
.try_to_target_usize(fx.tcx)
.expect("expected monomorphic const in codegen") as i64;
fx.bcx.ins().iconst(fx.pointer_type, len)
}
ty::Slice(_elem_ty) => place.to_ptr_unsized().1,

View File

@ -309,8 +309,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
}
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
type LayoutOfResult = TyAndLayout<'tcx>;
#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
RevealAllLayoutCx(self.tcx).handle_layout_err(err, span, ty)
@ -318,8 +316,6 @@ fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) ->
}
impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
#[inline]
fn handle_fn_abi_err(
&self,
@ -450,8 +446,6 @@ pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value {
pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>);
impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
type LayoutOfResult = TyAndLayout<'tcx>;
#[inline]
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
@ -466,8 +460,6 @@ fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) ->
}
impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
#[inline]
fn handle_fn_abi_err(
&self,

View File

@ -44,7 +44,7 @@ pub(crate) fn debug_type<'tcx>(
type_dbg,
ty,
*elem_ty,
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
len.try_to_target_usize(tcx).expect("expected monomorphic const in codegen"),
),
// ty::Slice(_) | ty::Str
// ty::Dynamic

View File

@ -131,9 +131,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let idx = generic_args[2]
.expect_const()
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
.unwrap()
.1
.try_to_valtree()
.expect("expected monomorphic const in codegen")
.unwrap_branch();
assert_eq!(x.layout(), y.layout());

View File

@ -24,10 +24,10 @@ pub(crate) fn unsized_info<'tcx>(
let (source, target) =
fx.tcx.struct_lockstep_tails_for_codegen(source, target, ParamEnv::reveal_all());
match (&source.kind(), &target.kind()) {
(&ty::Array(_, len), &ty::Slice(_)) => fx
.bcx
.ins()
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
fx.pointer_type,
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
),
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{