Skip to content

Commit 57200c2

Browse files
Remove eval
1 parent e5d8e94 commit 57200c2

File tree

5 files changed

+26
-40
lines changed

5 files changed

+26
-40
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1240,12 +1240,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
12401240
}
12411241

12421242
if name == sym::simd_shuffle_generic {
1243-
let idx = fn_args[2]
1244-
.expect_const()
1245-
.eval(tcx, ty::ParamEnv::reveal_all(), span)
1246-
.unwrap()
1247-
.1
1248-
.unwrap_branch();
1243+
let idx = fn_args[2].expect_const().try_to_valtree().unwrap().0.unwrap_branch();
12491244
let n = idx.len() as u64;
12501245

12511246
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
2323
use rustc_middle::ty::{
2424
self, ExistentialProjection, GenericArgKind, GenericArgsRef, ParamEnv, Ty, TyCtxt,
2525
};
26-
use rustc_span::DUMMY_SP;
2726
use rustc_target::abi::Integer;
2827
use smallvec::SmallVec;
2928

@@ -685,7 +684,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
685684
ty::ConstKind::Param(param) => {
686685
write!(output, "{}", param.name)
687686
}
688-
ty::ConstKind::Value(ty, _) => {
687+
ty::ConstKind::Value(ty, valtree) => {
689688
match ty.kind() {
690689
ty::Int(ity) => {
691690
// FIXME: directly extract the bits from a valtree instead of evaluating an
@@ -715,8 +714,9 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
715714
// avoiding collisions and will make the emitted type names shorter.
716715
let hash_short = tcx.with_stable_hashing_context(|mut hcx| {
717716
let mut hasher = StableHasher::new();
718-
let ct = ct.eval(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP).unwrap();
719-
hcx.while_hashing_spans(false, |hcx| ct.hash_stable(hcx, &mut hasher));
717+
hcx.while_hashing_spans(false, |hcx| {
718+
(ty, valtree).hash_stable(hcx, &mut hasher)
719+
});
720720
hasher.finish::<Hash64>()
721721
});
722722

compiler/rustc_middle/src/mir/consts.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_session::RemapFileNameExt;
66
use rustc_session::config::RemapPathScopeComponents;
77
use rustc_span::{DUMMY_SP, Span};
88
use rustc_target::abi::{HasDataLayout, Size};
9+
use either::Either;
910

1011
use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range};
1112
use crate::mir::{Promoted, pretty_print_const_value};
@@ -318,8 +319,14 @@ impl<'tcx> Const<'tcx> {
318319
Const::Ty(_, c) => {
319320
// We want to consistently have a "clean" value for type system constants (i.e., no
320321
// data hidden in the padding), so we always go through a valtree here.
321-
let (ty, val) = c.eval(tcx, param_env, span)?;
322-
Ok(tcx.valtree_to_const_val((ty, val)))
322+
match c.eval_valtree(tcx, param_env, span) {
323+
Ok((ty, val)) => Ok(tcx.valtree_to_const_val((ty, val))),
324+
Err(Either::Left(_bad_ty)) => Err(tcx
325+
.dcx()
326+
.delayed_bug("`mir::Const::eval` called on a non-valtree-compatible type")
327+
.into()),
328+
Err(Either::Right(e)) => Err(e),
329+
}
323330
}
324331
Const::Unevaluated(uneval, _) => {
325332
// FIXME: We might want to have a `try_eval`-like function on `Unevaluated`

compiler/rustc_middle/src/ty/consts.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -398,36 +398,21 @@ impl<'tcx> Const<'tcx> {
398398
}
399399
}
400400

401-
/// Returns the evaluated constant
402-
#[inline]
403-
pub fn eval(
404-
self,
405-
tcx: TyCtxt<'tcx>,
406-
param_env: ParamEnv<'tcx>,
407-
span: Span,
408-
) -> Result<(Ty<'tcx>, ValTree<'tcx>), ErrorHandled> {
409-
self.eval_valtree(tcx, param_env, span).map_err(|err| {
410-
match err {
411-
Either::Right(err) => err,
412-
Either::Left(_bad_ty) => {
413-
// This can happen when we run on ill-typed code.
414-
let e = tcx.dcx().span_delayed_bug(
415-
span,
416-
"`ty::Const::eval` called on a non-valtree-compatible type",
417-
);
418-
e.into()
419-
}
420-
}
421-
})
422-
}
423-
424401
/// Normalizes the constant to a value or an error if possible.
425402
#[inline]
426403
pub fn normalize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Self {
427-
match self.eval(tcx, param_env, DUMMY_SP) {
404+
match self.eval_valtree(tcx, param_env, DUMMY_SP) {
428405
Ok((ty, val)) => Self::new_value(tcx, val, ty),
429-
Err(ErrorHandled::Reported(r, _span)) => Self::new_error(tcx, r.into()),
430-
Err(ErrorHandled::TooGeneric(_span)) => self,
406+
Err(Either::Left(_bad_ty)) => {
407+
// This can happen when we run on ill-typed code.
408+
Self::new_error(
409+
tcx,
410+
tcx.dcx()
411+
.delayed_bug("`ty::Const::eval` called on a non-valtree-compatible type"),
412+
)
413+
}
414+
Err(Either::Right(ErrorHandled::Reported(r, _span))) => Self::new_error(tcx, r.into()),
415+
Err(Either::Right(ErrorHandled::TooGeneric(_span))) => self,
431416
}
432417
}
433418

compiler/rustc_transmute/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ mod rustc {
8585
use rustc_macros::TypeVisitable;
8686
use rustc_middle::traits::ObligationCause;
8787
use rustc_middle::ty::{Const, ParamEnv, Ty, TyCtxt, ValTree};
88-
use rustc_span::DUMMY_SP;
8988

9089
use super::*;
9190

@@ -134,7 +133,7 @@ mod rustc {
134133
use rustc_middle::ty::ScalarInt;
135134
use rustc_span::symbol::sym;
136135

137-
let Ok((ty, cv)) = c.eval(tcx, param_env, DUMMY_SP) else {
136+
let Some((cv, ty)) = c.try_to_valtree() else {
138137
return Some(Self {
139138
alignment: true,
140139
lifetimes: true,

0 commit comments

Comments
 (0)