Skip to content

Commit

Permalink
test: is try_eval_bits fast enough actually?
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Sep 30, 2023
1 parent 2471179 commit bf87f3e
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,27 @@ fn fast_try_eval_bits<'tcx>(
param_env: ty::ParamEnv<'tcx>,
value: &mir::Const<'tcx>,
) -> Option<u128> {
let int = match value {
// If the constant is already evaluated, we shortcut here.
mir::Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
valtree.unwrap_leaf()
},
// This is a more general form of the previous case.
_ => {
value.try_eval_scalar_int(tcx, param_env)?
},
};
let size = match value.ty().kind() {
ty::Bool => Size::from_bytes(1),
ty::Char => Size::from_bytes(4),
ty::Int(ity) => Integer::from_int_ty(&tcx, *ity).size(),
ty::Uint(uty) => Integer::from_uint_ty(&tcx, *uty).size(),
ty::Float(ty::FloatTy::F32) => Primitive::F32.size(&tcx),
ty::Float(ty::FloatTy::F64) => Primitive::F64.size(&tcx),
_ => return None,
};
int.to_bits(size).ok()
value.try_eval_bits(tcx, param_env)
// let int = match value {
// // If the constant is already evaluated, we shortcut here.
// mir::Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
// valtree.unwrap_leaf()
// },
// // This is a more general form of the previous case.
// _ => {
// value.try_eval_scalar_int(tcx, param_env)?
// },
// };
// let size = match value.ty().kind() {
// ty::Bool => Size::from_bytes(1),
// ty::Char => Size::from_bytes(4),
// ty::Int(ity) => Integer::from_int_ty(&tcx, *ity).size(),
// ty::Uint(uty) => Integer::from_uint_ty(&tcx, *uty).size(),
// ty::Float(ty::FloatTy::F32) => Primitive::F32.size(&tcx),
// ty::Float(ty::FloatTy::F64) => Primitive::F64.size(&tcx),
// _ => return None,
// };
// int.to_bits(size).ok()
}

/// An inclusive interval, used for precise integer exhaustiveness checking.
Expand Down

0 comments on commit bf87f3e

Please sign in to comment.