Skip to content

Commit 888afd5

Browse files
committed
Unify the names of const eval queries and their return types
1 parent 69a6be7 commit 888afd5

File tree

12 files changed

+38
-36
lines changed

12 files changed

+38
-36
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
2121
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
2222
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
2323
use rustc_middle::mir;
24-
use rustc_middle::mir::interpret::ConstEvalResult;
24+
use rustc_middle::mir::interpret::EvalToConstValueResult;
2525
use rustc_middle::traits::select;
2626
use rustc_middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
2727
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
@@ -1542,7 +1542,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15421542
substs: SubstsRef<'tcx>,
15431543
promoted: Option<mir::Promoted>,
15441544
span: Option<Span>,
1545-
) -> ConstEvalResult<'tcx> {
1545+
) -> EvalToConstValueResult<'tcx> {
15461546
let mut original_values = OriginalQueryValues::default();
15471547
let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values);
15481548

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ CloneTypeFoldableAndLiftImpls! {
2727
ErrorHandled,
2828
}
2929

30-
pub type ConstEvalRawResult<'tcx> = Result<RawConst<'tcx>, ErrorHandled>;
31-
pub type ConstEvalResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
30+
pub type EvalToAllocationRawResult<'tcx> = Result<RawConst<'tcx>, ErrorHandled>;
31+
pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
3232

3333
pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> {
3434
struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ use crate::ty::subst::GenericArgKind;
118118
use crate::ty::{self, Instance, Ty, TyCtxt};
119119

120120
pub use self::error::{
121-
struct_error, CheckInAllocMsg, ConstEvalRawResult, ConstEvalResult, ErrorHandled, InterpError,
122-
InterpErrorInfo, InterpResult, InvalidProgramInfo, MachineStopType, ResourceExhaustionInfo,
123-
UndefinedBehaviorInfo, UninitBytesAccess, UnsupportedOpInfo,
121+
struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
122+
InterpError, InterpErrorInfo, InterpResult, InvalidProgramInfo, MachineStopType,
123+
ResourceExhaustionInfo, UndefinedBehaviorInfo, UninitBytesAccess, UnsupportedOpInfo,
124124
};
125125

126126
pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUninit};

compiler/rustc_middle/src/mir/interpret/queries.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{ConstEvalResult, ErrorHandled, GlobalId};
1+
use super::{ErrorHandled, EvalToConstValueResult, GlobalId};
22

33
use crate::mir;
44
use crate::ty::subst::{InternalSubsts, SubstsRef};
@@ -10,7 +10,7 @@ impl<'tcx> TyCtxt<'tcx> {
1010
/// Evaluates a constant without providing any substitutions. This is useful to evaluate consts
1111
/// that can't take any generic arguments like statics, const items or enum discriminants. If a
1212
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
13-
pub fn const_eval_poly(self, def_id: DefId) -> ConstEvalResult<'tcx> {
13+
pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
1414
// In some situations def_id will have substitutions within scope, but they aren't allowed
1515
// to be used. So we can't use `Instance::mono`, instead we feed unresolved substitutions
1616
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
@@ -38,7 +38,7 @@ impl<'tcx> TyCtxt<'tcx> {
3838
substs: SubstsRef<'tcx>,
3939
promoted: Option<mir::Promoted>,
4040
span: Option<Span>,
41-
) -> ConstEvalResult<'tcx> {
41+
) -> EvalToConstValueResult<'tcx> {
4242
match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
4343
Ok(Some(instance)) => {
4444
let cid = GlobalId { instance, promoted };
@@ -54,7 +54,7 @@ impl<'tcx> TyCtxt<'tcx> {
5454
param_env: ty::ParamEnv<'tcx>,
5555
instance: ty::Instance<'tcx>,
5656
span: Option<Span>,
57-
) -> ConstEvalResult<'tcx> {
57+
) -> EvalToConstValueResult<'tcx> {
5858
self.const_eval_global_id(param_env, GlobalId { instance, promoted: None }, span)
5959
}
6060

@@ -64,14 +64,14 @@ impl<'tcx> TyCtxt<'tcx> {
6464
param_env: ty::ParamEnv<'tcx>,
6565
cid: GlobalId<'tcx>,
6666
span: Option<Span>,
67-
) -> ConstEvalResult<'tcx> {
67+
) -> EvalToConstValueResult<'tcx> {
6868
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
6969
// improve caching of queries.
7070
let inputs = self.erase_regions(&param_env.and(cid));
7171
if let Some(span) = span {
72-
self.at(span).const_eval_for_ty(inputs)
72+
self.at(span).eval_to_const_value(inputs)
7373
} else {
74-
self.const_eval_for_ty(inputs)
74+
self.eval_to_const_value(inputs)
7575
}
7676
}
7777

@@ -94,7 +94,7 @@ impl<'tcx> TyCtxt<'tcx> {
9494
param_env: ty::ParamEnv<'tcx>,
9595
) -> Result<&'tcx mir::Allocation, ErrorHandled> {
9696
trace!("eval_to_allocation: Need to compute {:?}", gid);
97-
let raw_const = self.const_eval(param_env.and(gid))?;
97+
let raw_const = self.eval_to_allocation_raw(param_env.and(gid))?;
9898
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
9999
}
100100
}

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ty::{ParamEnv, Ty, TyCtxt};
1212

1313
use super::{sign_extend, truncate, AllocId, Allocation, InterpResult, Pointer, PointerArithmetic};
1414

15-
/// Represents the result of a raw const operation, pre-validation.
15+
/// Represents the result of const evaluation via the `eval_to_allocation` query.
1616
#[derive(Clone, HashStable)]
1717
pub struct RawConst<'tcx> {
1818
// the value lives here, at offset 0, and that allocation definitely is a `AllocKind::Memory`

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,10 @@ rustc_queries! {
708708

709709
Other {
710710
/// Evaluates a constant and returns the computed allocation.
711-
query const_eval(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
712-
-> ConstEvalRawResult<'tcx> {
711+
///
712+
/// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
713+
query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
714+
-> EvalToAllocationRawResult<'tcx> {
713715
desc { |tcx|
714716
"const-evaluating `{}`",
715717
key.value.display(tcx)
@@ -722,8 +724,8 @@ rustc_queries! {
722724
///
723725
/// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
724726
/// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
725-
query const_eval_for_ty(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
726-
-> ConstEvalResult<'tcx> {
727+
query eval_to_const_value(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
728+
-> EvalToConstValueResult<'tcx> {
727729
desc { |tcx|
728730
"const-evaluating + checking `{}`",
729731
key.value.display(tcx)

compiler/rustc_middle/src/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLife
1414
use crate::middle::stability::{self, DeprecationEntry};
1515
use crate::mir;
1616
use crate::mir::interpret::GlobalId;
17-
use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult, ConstValue};
17+
use crate::mir::interpret::{ConstValue, EvalToAllocationRawResult, EvalToConstValueResult};
1818
use crate::mir::interpret::{LitToConstError, LitToConstInput};
1919
use crate::mir::mono::CodegenUnit;
2020
use crate::traits::query::{

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,21 @@ fn turn_into_const<'tcx>(
200200
);
201201
assert!(
202202
!is_static || cid.promoted.is_some(),
203-
"the `const_eval_for_ty` query should not be used for statics, use `const_eval` instead"
203+
"the `eval_to_const_value` query should not be used for statics, use `eval_to_allocation` instead"
204204
);
205205
// Turn this into a proper constant.
206206
op_to_const(&ecx, mplace.into())
207207
}
208208

209-
pub fn const_eval_for_ty_provider<'tcx>(
209+
pub fn eval_to_const_value_provider<'tcx>(
210210
tcx: TyCtxt<'tcx>,
211211
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
212-
) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
213-
// see comment in const_eval_provider for what we're doing here
212+
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
213+
// see comment in const_eval_raw_provider for what we're doing here
214214
if key.param_env.reveal() == Reveal::All {
215215
let mut key = key;
216216
key.param_env = key.param_env.with_user_facing();
217-
match tcx.const_eval_for_ty(key) {
217+
match tcx.eval_to_const_value(key) {
218218
// try again with reveal all as requested
219219
Err(ErrorHandled::TooGeneric) => {}
220220
// deduplicate calls
@@ -237,13 +237,13 @@ pub fn const_eval_for_ty_provider<'tcx>(
237237
});
238238
}
239239

240-
tcx.const_eval(key).map(|val| turn_into_const(tcx, val, key))
240+
tcx.eval_to_allocation_raw(key).map(|val| turn_into_const(tcx, val, key))
241241
}
242242

243-
pub fn const_eval_provider<'tcx>(
243+
pub fn eval_to_allocation_raw_provider<'tcx>(
244244
tcx: TyCtxt<'tcx>,
245245
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
246-
) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
246+
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
247247
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
248248
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
249249
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was
@@ -255,7 +255,7 @@ pub fn const_eval_provider<'tcx>(
255255
if key.param_env.reveal() == Reveal::All {
256256
let mut key = key;
257257
key.param_env = key.param_env.with_user_facing();
258-
match tcx.const_eval(key) {
258+
match tcx.eval_to_allocation_raw(key) {
259259
// try again with reveal all as requested
260260
Err(ErrorHandled::TooGeneric) => {}
261261
// deduplicate calls

compiler/rustc_mir/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
5151

5252
let gid = GlobalId { instance, promoted: None };
5353

54-
let place = self.const_eval(gid)?;
54+
let place = self.eval_to_allocation(gid)?;
5555

5656
self.copy_op(place.into(), dest)?;
5757

compiler/rustc_mir/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
875875
Ok(())
876876
}
877877

878-
pub fn const_eval(
878+
pub fn eval_to_allocation(
879879
&self,
880880
gid: GlobalId<'tcx>,
881881
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
@@ -889,7 +889,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
889889
} else {
890890
self.param_env
891891
};
892-
let val = self.tcx.const_eval(param_env.and(gid))?;
892+
let val = self.tcx.eval_to_allocation_raw(param_env.and(gid))?;
893893
self.raw_const_to_mplace(val)
894894
}
895895

compiler/rustc_mir/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
553553
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
554554
ty::ConstKind::Unevaluated(def, substs, promoted) => {
555555
let instance = self.resolve(def.did, substs)?;
556-
return Ok(self.const_eval(GlobalId { instance, promoted })?.into());
556+
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
557557
}
558558
ty::ConstKind::Infer(..)
559559
| ty::ConstKind::Bound(..)

compiler/rustc_mir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub fn provide(providers: &mut Providers) {
5252
transform::provide(providers);
5353
monomorphize::partitioning::provide(providers);
5454
monomorphize::polymorphize::provide(providers);
55-
providers.const_eval_for_ty = const_eval::const_eval_for_ty_provider;
56-
providers.const_eval = const_eval::const_eval_provider;
55+
providers.eval_to_const_value = const_eval::eval_to_const_value_provider;
56+
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
5757
providers.const_caller_location = const_eval::const_caller_location;
5858
providers.destructure_const = |tcx, param_env_and_value| {
5959
let (param_env, value) = param_env_and_value.into_parts();

0 commit comments

Comments
 (0)