From a5637e59665015be09d7d3bcc14d24dfc2a0b414 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 30 Sep 2023 23:54:31 +0200 Subject: [PATCH] test: is try_eval_bits fast enough actually? --- .../src/thir/pattern/deconstruct_pat.rs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index 8344ddb2a6967..d0a18b01a8082 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -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::*; @@ -93,26 +93,27 @@ fn fast_try_eval_bits<'tcx>( param_env: ty::ParamEnv<'tcx>, value: &mir::Const<'tcx>, ) -> Option { - 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.