Skip to content

Commit a2a949b

Browse files
committed
Auto merge of rust-lang#124113 - RalfJung:interpret-scalar-ops, r=oli-obk
interpret: use ScalarInt for bin-ops; avoid PartialOrd for ScalarInt Best reviewed commit-by-commit r? `@oli-obk`
2 parents fbac8ef + f532309 commit a2a949b

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/constant.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub(crate) fn codegen_const_value<'tcx>(
110110
if fx.clif_type(layout.ty).is_some() {
111111
return CValue::const_val(fx, layout, int);
112112
} else {
113-
let raw_val = int.size().truncate(int.to_bits(int.size()).unwrap());
113+
let raw_val = int.size().truncate(int.assert_bits(int.size()));
114114
let val = match int.size().bytes() {
115115
1 => fx.bcx.ins().iconst(types::I8, raw_val as i64),
116116
2 => fx.bcx.ins().iconst(types::I16, raw_val as i64),
@@ -491,27 +491,24 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
491491
return None;
492492
}
493493
let scalar_int = mir_operand_get_const_val(fx, operand)?;
494-
let scalar_int = match fx
495-
.layout_of(*ty)
496-
.size
497-
.cmp(&scalar_int.size())
498-
{
499-
Ordering::Equal => scalar_int,
500-
Ordering::Less => match ty.kind() {
501-
ty::Uint(_) => ScalarInt::try_from_uint(
502-
scalar_int.try_to_uint(scalar_int.size()).unwrap(),
503-
fx.layout_of(*ty).size,
504-
)
505-
.unwrap(),
506-
ty::Int(_) => ScalarInt::try_from_int(
507-
scalar_int.try_to_int(scalar_int.size()).unwrap(),
508-
fx.layout_of(*ty).size,
509-
)
510-
.unwrap(),
511-
_ => unreachable!(),
512-
},
513-
Ordering::Greater => return None,
514-
};
494+
let scalar_int =
495+
match fx.layout_of(*ty).size.cmp(&scalar_int.size()) {
496+
Ordering::Equal => scalar_int,
497+
Ordering::Less => match ty.kind() {
498+
ty::Uint(_) => ScalarInt::try_from_uint(
499+
scalar_int.assert_uint(scalar_int.size()),
500+
fx.layout_of(*ty).size,
501+
)
502+
.unwrap(),
503+
ty::Int(_) => ScalarInt::try_from_int(
504+
scalar_int.assert_int(scalar_int.size()),
505+
fx.layout_of(*ty).size,
506+
)
507+
.unwrap(),
508+
_ => unreachable!(),
509+
},
510+
Ordering::Greater => return None,
511+
};
515512
computed_scalar_int = Some(scalar_int);
516513
}
517514
Rvalue::Use(operand) => {

src/value_and_place.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'tcx> CValue<'tcx> {
326326

327327
let val = match layout.ty.kind() {
328328
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
329-
let const_val = const_val.to_bits(layout.size).unwrap();
329+
let const_val = const_val.assert_bits(layout.size);
330330
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
331331
let msb = fx.bcx.ins().iconst(types::I64, (const_val >> 64) as u64 as i64);
332332
fx.bcx.ins().iconcat(lsb, msb)
@@ -338,7 +338,7 @@ impl<'tcx> CValue<'tcx> {
338338
| ty::Ref(..)
339339
| ty::RawPtr(..)
340340
| ty::FnPtr(..) => {
341-
let raw_val = const_val.size().truncate(const_val.to_bits(layout.size).unwrap());
341+
let raw_val = const_val.size().truncate(const_val.assert_bits(layout.size));
342342
fx.bcx.ins().iconst(clif_ty, raw_val as i64)
343343
}
344344
ty::Float(FloatTy::F32) => {

0 commit comments

Comments
 (0)