Skip to content

Commit 69a6be7

Browse files
committed
Rename const eval queries to reflect the validation changes
1 parent 40c2087 commit 69a6be7

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ impl<'tcx> TyCtxt<'tcx> {
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_validated(inputs)
72+
self.at(span).const_eval_for_ty(inputs)
7373
} else {
74-
self.const_eval_validated(inputs)
74+
self.const_eval_for_ty(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_raw(param_env.and(gid))?;
97+
let raw_const = self.const_eval(param_env.and(gid))?;
9898
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
9999
}
100100
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -707,29 +707,22 @@ rustc_queries! {
707707
}
708708

709709
Other {
710-
/// Evaluates a constant without running sanity checks.
711-
///
712-
/// **Do not use this** outside const eval. Const eval uses this to break query cycles
713-
/// during validation. Please add a comment to every use site explaining why using
714-
/// `const_eval_validated` isn't sufficient. The returned constant also isn't in a suitable
715-
/// form to be used outside of const eval.
716-
query const_eval_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
710+
/// Evaluates a constant and returns the computed allocation.
711+
query const_eval(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
717712
-> ConstEvalRawResult<'tcx> {
718713
desc { |tcx|
719714
"const-evaluating `{}`",
720715
key.value.display(tcx)
721716
}
722717
}
723718

724-
/// Results of evaluating const items or constants embedded in
725-
/// other items (such as enum variant explicit discriminants).
726-
///
727-
/// In contrast to `const_eval_raw` this performs some validation on the constant, and
728-
/// returns a proper constant that is usable by the rest of the compiler.
719+
/// Evaluates const items or anonymous constants
720+
/// (such as enum variant explicit discriminants or array lengths)
721+
/// into a representation suitable for the type system and const generics.
729722
///
730723
/// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
731724
/// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
732-
query const_eval_validated(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
725+
query const_eval_for_ty(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
733726
-> ConstEvalResult<'tcx> {
734727
desc { |tcx|
735728
"const-evaluating + checking `{}`",

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 7 additions & 7 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 query should not be used for statics, use `const_eval_raw` instead"
203+
"the `const_eval_for_ty` query should not be used for statics, use `const_eval` instead"
204204
);
205205
// Turn this into a proper constant.
206206
op_to_const(&ecx, mplace.into())
207207
}
208208

209-
pub fn const_eval_validated_provider<'tcx>(
209+
pub fn const_eval_for_ty_provider<'tcx>(
210210
tcx: TyCtxt<'tcx>,
211211
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
212212
) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
213-
// see comment in const_eval_raw_provider for what we're doing here
213+
// see comment in const_eval_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_validated(key) {
217+
match tcx.const_eval_for_ty(key) {
218218
// try again with reveal all as requested
219219
Err(ErrorHandled::TooGeneric) => {}
220220
// deduplicate calls
@@ -237,10 +237,10 @@ pub fn const_eval_validated_provider<'tcx>(
237237
});
238238
}
239239

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

243-
pub fn const_eval_raw_provider<'tcx>(
243+
pub fn const_eval_provider<'tcx>(
244244
tcx: TyCtxt<'tcx>,
245245
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
246246
) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
@@ -255,7 +255,7 @@ pub fn const_eval_raw_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_raw(key) {
258+
match tcx.const_eval(key) {
259259
// try again with reveal all as requested
260260
Err(ErrorHandled::TooGeneric) => {}
261261
// deduplicate calls

compiler/rustc_mir/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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_raw(param_env.and(gid))?;
892+
let val = self.tcx.const_eval(param_env.and(gid))?;
893893
self.raw_const_to_mplace(val)
894894
}
895895

compiler/rustc_mir/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
469469
// Notice that every static has two `AllocId` that will resolve to the same
470470
// thing here: one maps to `GlobalAlloc::Static`, this is the "lazy" ID,
471471
// and the other one is maps to `GlobalAlloc::Memory`, this is returned by
472-
// `const_eval_raw` and it is the "resolved" ID.
472+
// `const_eval` and it is the "resolved" ID.
473473
// The resolved ID is never used by the interpreted program, it is hidden.
474474
// This is relied upon for soundness of const-patterns; a pointer to the resolved
475475
// ID would "sidestep" the checks that make sure consts do not point to statics!

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_validated = const_eval::const_eval_validated_provider;
56-
providers.const_eval_raw = const_eval::const_eval_raw_provider;
55+
providers.const_eval_for_ty = const_eval::const_eval_for_ty_provider;
56+
providers.const_eval = const_eval::const_eval_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)