Skip to content

Commit e0d7ed1

Browse files
committed
Auto merge of #116281 - Nadrieril:eager-const-eval, r=cjgillot
Cleanup number handling in match exhaustiveness Doing a little bit of cleanup; handling number constants was somewhat messy. In particular, this: - evals float consts once instead of repetitively - reduces `Constructor` from 88 bytes to 56 (`mir::Const` is big!) The `fast_try_eval_bits` function was mostly constructed from inlining existing code but I don't fully understand it; I don't follow how consts work and are evaluated very well.
2 parents 51ddc74 + eac7bcd commit e0d7ed1

File tree

4 files changed

+206
-139
lines changed

4 files changed

+206
-139
lines changed

compiler/rustc_middle/src/mir/consts.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,16 @@ impl<'tcx> Const<'tcx> {
288288
tcx: TyCtxt<'tcx>,
289289
param_env: ty::ParamEnv<'tcx>,
290290
) -> Option<ScalarInt> {
291-
self.try_eval_scalar(tcx, param_env)?.try_to_int().ok()
291+
match self {
292+
// If the constant is already evaluated, we shortcut here.
293+
Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
294+
valtree.try_to_scalar_int()
295+
},
296+
// This is a more general form of the previous case.
297+
_ => {
298+
self.try_eval_scalar(tcx, param_env)?.try_to_int().ok()
299+
},
300+
}
292301
}
293302

294303
#[inline]

0 commit comments

Comments
 (0)