Skip to content

Commit 460abea

Browse files
Do not unnecessarily eval consts in codegen
1 parent 37204ee commit 460abea

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/base.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,10 @@ fn codegen_stmt<'tcx>(
785785
}
786786
Rvalue::Repeat(ref operand, times) => {
787787
let operand = codegen_operand(fx, operand);
788-
let times =
789-
fx.monomorphize(times).eval_target_usize(fx.tcx, ParamEnv::reveal_all());
788+
let times = fx
789+
.monomorphize(times)
790+
.try_to_target_usize(fx.tcx)
791+
.expect("expected monomorphic const in codegen");
790792
if operand.layout().size.bytes() == 0 {
791793
// Do nothing for ZST's
792794
} else if fx.clif_type(operand.layout().ty) == Some(types::I8) {
@@ -944,7 +946,10 @@ fn codegen_stmt<'tcx>(
944946
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
945947
match *place.layout().ty.kind() {
946948
ty::Array(_elem_ty, len) => {
947-
let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
949+
let len = fx
950+
.monomorphize(len)
951+
.try_to_target_usize(fx.tcx)
952+
.expect("expected monomorphic const in codegen") as i64;
948953
fx.bcx.ins().iconst(fx.pointer_type, len)
949954
}
950955
ty::Slice(_elem_ty) => place.to_ptr_unsized().1,

src/debuginfo/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl DebugContext {
4444
type_dbg,
4545
ty,
4646
*elem_ty,
47-
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
47+
len.try_to_target_usize(tcx).expect("expected monomorphic const in codegen"),
4848
),
4949
// ty::Slice(_) | ty::Str
5050
// ty::Dynamic

src/intrinsics/simd.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
131131

132132
let idx = generic_args[2]
133133
.expect_const()
134-
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
135-
.unwrap()
136-
.1
134+
.try_to_valtree()
135+
.expect("expected monomorphic const in codegen")
137136
.unwrap_branch();
138137

139138
assert_eq!(x.layout(), y.layout());

src/unsize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub(crate) fn unsized_info<'tcx>(
2424
let (source, target) =
2525
fx.tcx.struct_lockstep_tails_for_codegen(source, target, ParamEnv::reveal_all());
2626
match (&source.kind(), &target.kind()) {
27-
(&ty::Array(_, len), &ty::Slice(_)) => fx
28-
.bcx
29-
.ins()
30-
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
27+
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
28+
fx.pointer_type,
29+
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
30+
),
3131
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
3232
if src_dyn_kind == target_dyn_kind =>
3333
{

0 commit comments

Comments
 (0)