about summary refs log tree commit diff
path: root/src/base.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-09-20 20:38:11 -0400
committerMichael Goulet <michael@errs.io>2024-09-20 20:38:11 -0400
commit460abead209f253a2b0de993de242d0778756d58 (patch)
tree1448381ac8959901a25deefadc54dbf05f4d3743 /src/base.rs
parent37204ee5637c5bd28e464c78c48bcf5f5b429245 (diff)
Do not unnecessarily eval consts in codegen
Diffstat (limited to 'src/base.rs')
-rw-r--r--src/base.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/base.rs b/src/base.rs
index 4af4b39cc5b..8839829e2f5 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -785,8 +785,10 @@ fn codegen_stmt<'tcx>(
                 }
                 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 codegen_stmt<'tcx>(
 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,