Rename const eval queries to reflect the validation changes
This commit is contained in:
parent
40c2087eb5
commit
69a6be73e6
6 changed files with 20 additions and 27 deletions
|
@ -69,9 +69,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// improve caching of queries.
|
// improve caching of queries.
|
||||||
let inputs = self.erase_regions(¶m_env.and(cid));
|
let inputs = self.erase_regions(¶m_env.and(cid));
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
self.at(span).const_eval_validated(inputs)
|
self.at(span).const_eval_for_ty(inputs)
|
||||||
} else {
|
} else {
|
||||||
self.const_eval_validated(inputs)
|
self.const_eval_for_ty(inputs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> Result<&'tcx mir::Allocation, ErrorHandled> {
|
) -> Result<&'tcx mir::Allocation, ErrorHandled> {
|
||||||
trace!("eval_to_allocation: Need to compute {:?}", gid);
|
trace!("eval_to_allocation: Need to compute {:?}", gid);
|
||||||
let raw_const = self.const_eval_raw(param_env.and(gid))?;
|
let raw_const = self.const_eval(param_env.and(gid))?;
|
||||||
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
|
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -707,13 +707,8 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
|
|
||||||
Other {
|
Other {
|
||||||
/// Evaluates a constant without running sanity checks.
|
/// Evaluates a constant and returns the computed allocation.
|
||||||
///
|
query const_eval(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
|
||||||
/// **Do not use this** outside const eval. Const eval uses this to break query cycles
|
|
||||||
/// during validation. Please add a comment to every use site explaining why using
|
|
||||||
/// `const_eval_validated` isn't sufficient. The returned constant also isn't in a suitable
|
|
||||||
/// form to be used outside of const eval.
|
|
||||||
query const_eval_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
|
|
||||||
-> ConstEvalRawResult<'tcx> {
|
-> ConstEvalRawResult<'tcx> {
|
||||||
desc { |tcx|
|
desc { |tcx|
|
||||||
"const-evaluating `{}`",
|
"const-evaluating `{}`",
|
||||||
|
@ -721,15 +716,13 @@ rustc_queries! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Results of evaluating const items or constants embedded in
|
/// Evaluates const items or anonymous constants
|
||||||
/// other items (such as enum variant explicit discriminants).
|
/// (such as enum variant explicit discriminants or array lengths)
|
||||||
///
|
/// into a representation suitable for the type system and const generics.
|
||||||
/// In contrast to `const_eval_raw` this performs some validation on the constant, and
|
|
||||||
/// returns a proper constant that is usable by the rest of the compiler.
|
|
||||||
///
|
///
|
||||||
/// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
|
/// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
|
||||||
/// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
|
/// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
|
||||||
query const_eval_validated(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
|
query const_eval_for_ty(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
|
||||||
-> ConstEvalResult<'tcx> {
|
-> ConstEvalResult<'tcx> {
|
||||||
desc { |tcx|
|
desc { |tcx|
|
||||||
"const-evaluating + checking `{}`",
|
"const-evaluating + checking `{}`",
|
||||||
|
|
|
@ -200,21 +200,21 @@ fn turn_into_const<'tcx>(
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
!is_static || cid.promoted.is_some(),
|
!is_static || cid.promoted.is_some(),
|
||||||
"the const eval query should not be used for statics, use `const_eval_raw` instead"
|
"the `const_eval_for_ty` query should not be used for statics, use `const_eval` instead"
|
||||||
);
|
);
|
||||||
// Turn this into a proper constant.
|
// Turn this into a proper constant.
|
||||||
op_to_const(&ecx, mplace.into())
|
op_to_const(&ecx, mplace.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_eval_validated_provider<'tcx>(
|
pub fn const_eval_for_ty_provider<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
||||||
) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
|
) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
|
||||||
// see comment in const_eval_raw_provider for what we're doing here
|
// see comment in const_eval_provider for what we're doing here
|
||||||
if key.param_env.reveal() == Reveal::All {
|
if key.param_env.reveal() == Reveal::All {
|
||||||
let mut key = key;
|
let mut key = key;
|
||||||
key.param_env = key.param_env.with_user_facing();
|
key.param_env = key.param_env.with_user_facing();
|
||||||
match tcx.const_eval_validated(key) {
|
match tcx.const_eval_for_ty(key) {
|
||||||
// try again with reveal all as requested
|
// try again with reveal all as requested
|
||||||
Err(ErrorHandled::TooGeneric) => {}
|
Err(ErrorHandled::TooGeneric) => {}
|
||||||
// deduplicate calls
|
// deduplicate calls
|
||||||
|
@ -237,10 +237,10 @@ pub fn const_eval_validated_provider<'tcx>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
tcx.const_eval_raw(key).map(|val| turn_into_const(tcx, val, key))
|
tcx.const_eval(key).map(|val| turn_into_const(tcx, val, key))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_eval_raw_provider<'tcx>(
|
pub fn const_eval_provider<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
||||||
) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
|
) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
|
||||||
|
@ -255,7 +255,7 @@ pub fn const_eval_raw_provider<'tcx>(
|
||||||
if key.param_env.reveal() == Reveal::All {
|
if key.param_env.reveal() == Reveal::All {
|
||||||
let mut key = key;
|
let mut key = key;
|
||||||
key.param_env = key.param_env.with_user_facing();
|
key.param_env = key.param_env.with_user_facing();
|
||||||
match tcx.const_eval_raw(key) {
|
match tcx.const_eval(key) {
|
||||||
// try again with reveal all as requested
|
// try again with reveal all as requested
|
||||||
Err(ErrorHandled::TooGeneric) => {}
|
Err(ErrorHandled::TooGeneric) => {}
|
||||||
// deduplicate calls
|
// deduplicate calls
|
||||||
|
|
|
@ -889,7 +889,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
} else {
|
} else {
|
||||||
self.param_env
|
self.param_env
|
||||||
};
|
};
|
||||||
let val = self.tcx.const_eval_raw(param_env.and(gid))?;
|
let val = self.tcx.const_eval(param_env.and(gid))?;
|
||||||
self.raw_const_to_mplace(val)
|
self.raw_const_to_mplace(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -469,7 +469,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||||
// Notice that every static has two `AllocId` that will resolve to the same
|
// Notice that every static has two `AllocId` that will resolve to the same
|
||||||
// thing here: one maps to `GlobalAlloc::Static`, this is the "lazy" ID,
|
// thing here: one maps to `GlobalAlloc::Static`, this is the "lazy" ID,
|
||||||
// and the other one is maps to `GlobalAlloc::Memory`, this is returned by
|
// and the other one is maps to `GlobalAlloc::Memory`, this is returned by
|
||||||
// `const_eval_raw` and it is the "resolved" ID.
|
// `const_eval` and it is the "resolved" ID.
|
||||||
// The resolved ID is never used by the interpreted program, it is hidden.
|
// The resolved ID is never used by the interpreted program, it is hidden.
|
||||||
// This is relied upon for soundness of const-patterns; a pointer to the resolved
|
// This is relied upon for soundness of const-patterns; a pointer to the resolved
|
||||||
// ID would "sidestep" the checks that make sure consts do not point to statics!
|
// ID would "sidestep" the checks that make sure consts do not point to statics!
|
||||||
|
|
|
@ -52,8 +52,8 @@ pub fn provide(providers: &mut Providers) {
|
||||||
transform::provide(providers);
|
transform::provide(providers);
|
||||||
monomorphize::partitioning::provide(providers);
|
monomorphize::partitioning::provide(providers);
|
||||||
monomorphize::polymorphize::provide(providers);
|
monomorphize::polymorphize::provide(providers);
|
||||||
providers.const_eval_validated = const_eval::const_eval_validated_provider;
|
providers.const_eval_for_ty = const_eval::const_eval_for_ty_provider;
|
||||||
providers.const_eval_raw = const_eval::const_eval_raw_provider;
|
providers.const_eval = const_eval::const_eval_provider;
|
||||||
providers.const_caller_location = const_eval::const_caller_location;
|
providers.const_caller_location = const_eval::const_caller_location;
|
||||||
providers.destructure_const = |tcx, param_env_and_value| {
|
providers.destructure_const = |tcx, param_env_and_value| {
|
||||||
let (param_env, value) = param_env_and_value.into_parts();
|
let (param_env, value) = param_env_and_value.into_parts();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue