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 Oct 1, 2023
1 parent 0a6d794 commit a5637e5
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
use rustc_session::lint;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{FieldIdx, Integer, Primitive, Size, VariantIdx, FIRST_VARIANT};
use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT};

use self::Constructor::*;
use self::SliceKind::*;
Expand Down 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 a5637e5

Please sign in to comment.