Unify the names of const eval queries and their return types
This commit is contained in:
parent
69a6be73e6
commit
888afd50d9
12 changed files with 38 additions and 36 deletions
|
@ -200,21 +200,21 @@ fn turn_into_const<'tcx>(
|
|||
);
|
||||
assert!(
|
||||
!is_static || cid.promoted.is_some(),
|
||||
"the `const_eval_for_ty` query should not be used for statics, use `const_eval` instead"
|
||||
"the `eval_to_const_value` query should not be used for statics, use `eval_to_allocation` instead"
|
||||
);
|
||||
// Turn this into a proper constant.
|
||||
op_to_const(&ecx, mplace.into())
|
||||
}
|
||||
|
||||
pub fn const_eval_for_ty_provider<'tcx>(
|
||||
pub fn eval_to_const_value_provider<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
||||
) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
|
||||
// see comment in const_eval_provider for what we're doing here
|
||||
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
|
||||
// see comment in const_eval_raw_provider for what we're doing here
|
||||
if key.param_env.reveal() == Reveal::All {
|
||||
let mut key = key;
|
||||
key.param_env = key.param_env.with_user_facing();
|
||||
match tcx.const_eval_for_ty(key) {
|
||||
match tcx.eval_to_const_value(key) {
|
||||
// try again with reveal all as requested
|
||||
Err(ErrorHandled::TooGeneric) => {}
|
||||
// deduplicate calls
|
||||
|
@ -237,13 +237,13 @@ pub fn const_eval_for_ty_provider<'tcx>(
|
|||
});
|
||||
}
|
||||
|
||||
tcx.const_eval(key).map(|val| turn_into_const(tcx, val, key))
|
||||
tcx.eval_to_allocation_raw(key).map(|val| turn_into_const(tcx, val, key))
|
||||
}
|
||||
|
||||
pub fn const_eval_provider<'tcx>(
|
||||
pub fn eval_to_allocation_raw_provider<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
|
||||
) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
|
||||
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
|
||||
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
|
||||
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
|
||||
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was
|
||||
|
@ -255,7 +255,7 @@ pub fn const_eval_provider<'tcx>(
|
|||
if key.param_env.reveal() == Reveal::All {
|
||||
let mut key = key;
|
||||
key.param_env = key.param_env.with_user_facing();
|
||||
match tcx.const_eval(key) {
|
||||
match tcx.eval_to_allocation_raw(key) {
|
||||
// try again with reveal all as requested
|
||||
Err(ErrorHandled::TooGeneric) => {}
|
||||
// deduplicate calls
|
||||
|
|
|
@ -51,7 +51,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
|
|||
|
||||
let gid = GlobalId { instance, promoted: None };
|
||||
|
||||
let place = self.const_eval(gid)?;
|
||||
let place = self.eval_to_allocation(gid)?;
|
||||
|
||||
self.copy_op(place.into(), dest)?;
|
||||
|
||||
|
|
|
@ -875,7 +875,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn const_eval(
|
||||
pub fn eval_to_allocation(
|
||||
&self,
|
||||
gid: GlobalId<'tcx>,
|
||||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
|
||||
|
@ -889,7 +889,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
} else {
|
||||
self.param_env
|
||||
};
|
||||
let val = self.tcx.const_eval(param_env.and(gid))?;
|
||||
let val = self.tcx.eval_to_allocation_raw(param_env.and(gid))?;
|
||||
self.raw_const_to_mplace(val)
|
||||
}
|
||||
|
||||
|
|
|
@ -553,7 +553,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => {
|
||||
let instance = self.resolve(def.did, substs)?;
|
||||
return Ok(self.const_eval(GlobalId { instance, promoted })?.into());
|
||||
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
|
||||
}
|
||||
ty::ConstKind::Infer(..)
|
||||
| ty::ConstKind::Bound(..)
|
||||
|
|
|
@ -52,8 +52,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
transform::provide(providers);
|
||||
monomorphize::partitioning::provide(providers);
|
||||
monomorphize::polymorphize::provide(providers);
|
||||
providers.const_eval_for_ty = const_eval::const_eval_for_ty_provider;
|
||||
providers.const_eval = const_eval::const_eval_provider;
|
||||
providers.eval_to_const_value = const_eval::eval_to_const_value_provider;
|
||||
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
||||
providers.const_caller_location = const_eval::const_caller_location;
|
||||
providers.destructure_const = |tcx, param_env_and_value| {
|
||||
let (param_env, value) = param_env_and_value.into_parts();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue