Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8e6f68b

Browse files
committed
make the eval() functions on our const types return the resulting value
1 parent c41e779 commit 8e6f68b

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

src/base.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,8 @@ fn codegen_stmt<'tcx>(
723723
}
724724
Rvalue::Repeat(ref operand, times) => {
725725
let operand = codegen_operand(fx, operand);
726-
let times = fx
727-
.monomorphize(times)
728-
.eval(fx.tcx, ParamEnv::reveal_all())
729-
.try_to_bits(fx.tcx.data_layout.pointer_size)
730-
.unwrap();
726+
let times =
727+
fx.monomorphize(times).eval_target_usize(fx.tcx, ParamEnv::reveal_all());
731728
if operand.layout().size.bytes() == 0 {
732729
// Do nothing for ZST's
733730
} else if fx.clif_type(operand.layout().ty) == Some(types::I8) {

src/constant.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,9 @@ pub(crate) fn eval_mir_constant<'tcx>(
7777
fx: &FunctionCx<'_, '_, 'tcx>,
7878
constant: &Constant<'tcx>,
7979
) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> {
80-
let constant_kind = fx.monomorphize(constant.literal);
81-
let uv = match constant_kind {
82-
ConstantKind::Ty(const_) => match const_.kind() {
83-
ty::ConstKind::Unevaluated(uv) => uv.expand(),
84-
ty::ConstKind::Value(val) => {
85-
return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()));
86-
}
87-
err => span_bug!(
88-
constant.span,
89-
"encountered bad ConstKind after monomorphizing: {:?}",
90-
err
91-
),
92-
},
93-
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, .. }, _)
94-
if fx.tcx.is_static(def) =>
95-
{
96-
span_bug!(constant.span, "MIR constant refers to static");
97-
}
98-
ConstantKind::Unevaluated(uv, _) => uv,
99-
ConstantKind::Val(val, _) => return Some((val, constant_kind.ty())),
100-
};
101-
102-
let val = fx
103-
.tcx
104-
.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None)
80+
let cv = fx.monomorphize(constant.literal);
81+
let val = cv
82+
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
10583
.map_err(|err| match err {
10684
ErrorHandled::Reported(_) => {
10785
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
@@ -111,7 +89,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
11189
}
11290
})
11391
.ok();
114-
val.map(|val| (val, constant_kind.ty()))
92+
val.map(|val| (val, cv.ty()))
11593
}
11694

11795
pub(crate) fn codegen_constant_operand<'tcx>(

0 commit comments

Comments
 (0)