update const_eval_resolve
This commit is contained in:
parent
43ebac119b
commit
7c9b5b4ce0
@ -45,9 +45,9 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
|
||||
};
|
||||
match const_.val {
|
||||
ConstKind::Value(_) => {}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
ConstKind::Unevaluated(unevaluated) => {
|
||||
if let Err(err) =
|
||||
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None)
|
||||
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None)
|
||||
{
|
||||
all_constants_ok = false;
|
||||
match err {
|
||||
@ -122,14 +122,14 @@ pub(crate) fn codegen_constant<'tcx>(
|
||||
};
|
||||
let const_val = match const_.val {
|
||||
ConstKind::Value(const_val) => const_val,
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
|
||||
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => {
|
||||
assert!(substs.is_empty());
|
||||
assert!(promoted.is_none());
|
||||
|
||||
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
|
||||
}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||
ConstKind::Unevaluated(unevaluated) => {
|
||||
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
|
||||
Ok(const_val) => const_val,
|
||||
Err(_) => {
|
||||
span_bug!(constant.span, "erroneous constant not captured by required_consts");
|
||||
|
@ -30,10 +30,10 @@ pub fn eval_mir_constant(
|
||||
mir::ConstantKind::Val(val, _) => return Ok(val),
|
||||
};
|
||||
match ct.val {
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => self
|
||||
ty::ConstKind::Unevaluated(ct) => self
|
||||
.cx
|
||||
.tcx()
|
||||
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
|
||||
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None)
|
||||
.map_err(|err| {
|
||||
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
|
||||
err
|
||||
|
@ -18,7 +18,6 @@
|
||||
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
||||
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::EvalToConstValueResult;
|
||||
use rustc_middle::traits::select;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
|
||||
@ -1499,9 +1498,7 @@ pub fn create_next_universe(&self) -> ty::UniverseIndex {
|
||||
pub fn const_eval_resolve(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
def: ty::WithOptConstParam<DefId>,
|
||||
substs: SubstsRef<'tcx>,
|
||||
promoted: Option<mir::Promoted>,
|
||||
ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>,
|
||||
span: Option<Span>,
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
let mut original_values = OriginalQueryValues::default();
|
||||
@ -1510,7 +1507,7 @@ pub fn const_eval_resolve(
|
||||
let (param_env, substs) = canonical.value;
|
||||
// The return value is the evaluated value which doesn't contain any reference to inference
|
||||
// variables, thus we don't need to substitute back the original values.
|
||||
self.tcx.const_eval_resolve(param_env, def, substs, promoted, span)
|
||||
self.tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, span)
|
||||
}
|
||||
|
||||
/// If `typ` is a type variable of some kind, resolve it one level
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::{ErrorHandled, EvalToConstValueResult, GlobalId};
|
||||
|
||||
use crate::mir;
|
||||
use crate::ty::subst::{InternalSubsts, SubstsRef};
|
||||
use crate::ty::subst::InternalSubsts;
|
||||
use crate::ty::{self, TyCtxt};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_span::Span;
|
||||
@ -35,14 +35,12 @@ pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
|
||||
pub fn const_eval_resolve(
|
||||
self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
def: ty::WithOptConstParam<DefId>,
|
||||
substs: SubstsRef<'tcx>,
|
||||
promoted: Option<mir::Promoted>,
|
||||
ct: ty::Unevaluated<'tcx>,
|
||||
span: Option<Span>,
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
|
||||
match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs) {
|
||||
Ok(Some(instance)) => {
|
||||
let cid = GlobalId { instance, promoted };
|
||||
let cid = GlobalId { instance, promoted: ct.promoted };
|
||||
self.const_eval_global_id(param_env, cid, span)
|
||||
}
|
||||
Ok(None) => Err(ErrorHandled::TooGeneric),
|
||||
|
@ -140,7 +140,8 @@ pub(super) fn try_eval(
|
||||
let (param_env, substs) = param_env_and_substs.into_parts();
|
||||
// try to resolve e.g. associated constants to their definition on an impl, and then
|
||||
// evaluate the const.
|
||||
match tcx.const_eval_resolve(param_env, def, substs, promoted, None) {
|
||||
match tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, None)
|
||||
{
|
||||
// NOTE(eddyb) `val` contains no lifetimes/types/consts,
|
||||
// and we use the original type, so nothing from `substs`
|
||||
// (which may be identity substs, see above),
|
||||
|
@ -646,8 +646,8 @@ fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, location: Location)
|
||||
|
||||
match substituted_constant.val {
|
||||
ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output),
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => {
|
||||
match self.tcx.const_eval_resolve(param_env, def, substs, promoted, None) {
|
||||
ty::ConstKind::Unevaluated(unevaluated) => {
|
||||
match self.tcx.const_eval_resolve(param_env, unevaluated, None) {
|
||||
Ok(val) => collect_const_value(self.tcx, val, self.output),
|
||||
Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted) => {}
|
||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||
|
@ -803,17 +803,10 @@ fn evaluate_nested_obligations(
|
||||
}
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
}) = c.val
|
||||
{
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
|
||||
match select.infcx().const_eval_resolve(
|
||||
obligation.param_env,
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
unevaluated,
|
||||
Some(obligation.cause.span),
|
||||
) {
|
||||
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty)),
|
||||
|
@ -163,7 +163,11 @@ enum FailureKind {
|
||||
// and hopefully soon change this to an error.
|
||||
//
|
||||
// See #74595 for more details about this.
|
||||
let concrete = infcx.const_eval_resolve(param_env, def, substs, None, Some(span));
|
||||
let concrete = infcx.const_eval_resolve(
|
||||
param_env,
|
||||
ty::Unevaluated { def, substs, promoted: None },
|
||||
Some(span),
|
||||
);
|
||||
|
||||
if concrete.is_ok() && substs.has_param_types_or_consts() {
|
||||
match infcx.tcx.def_kind(def.did) {
|
||||
|
@ -532,23 +532,17 @@ fn progress_changed_obligations(
|
||||
let stalled_on = &mut pending_obligation.stalled_on;
|
||||
|
||||
let mut evaluate = |c: &'tcx Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
}) = c.val
|
||||
{
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
|
||||
match self.selcx.infcx().const_eval_resolve(
|
||||
obligation.param_env,
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
unevaluated,
|
||||
Some(obligation.cause.span),
|
||||
) {
|
||||
Ok(val) => Ok(Const::from_value(self.selcx.tcx(), val, c.ty)),
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
stalled_on.extend(
|
||||
substs
|
||||
unevaluated
|
||||
.substs
|
||||
.iter()
|
||||
.filter_map(TyOrConstInferVar::maybe_from_generic_arg),
|
||||
);
|
||||
|
@ -556,18 +556,11 @@ fn evaluate_predicate_recursively<'o>(
|
||||
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");
|
||||
|
||||
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(ty::Unevaluated {
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
}) = c.val
|
||||
{
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
|
||||
self.infcx
|
||||
.const_eval_resolve(
|
||||
obligation.param_env,
|
||||
def,
|
||||
substs,
|
||||
promoted,
|
||||
unevaluated,
|
||||
Some(obligation.cause.span),
|
||||
)
|
||||
.map(|val| ty::Const::from_value(self.tcx(), val, c.ty))
|
||||
|
@ -296,7 +296,7 @@ fn to_src(&self, cx: &DocContext<'_>) -> String {
|
||||
|
||||
crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
|
||||
match n.val {
|
||||
ty::ConstKind::Unevaluated(def, _, promoted) => {
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
|
||||
let mut s = if let Some(def) = def.as_local() {
|
||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
|
||||
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(hir_id))
|
||||
|
@ -181,7 +181,15 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D
|
||||
|
||||
let result = cx
|
||||
.tcx
|
||||
.const_eval_resolve(cx.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None);
|
||||
.const_eval_resolve(
|
||||
cx.param_env,
|
||||
ty::Unevaluated {
|
||||
def: ty::WithOptConstParam::unknown(def_id),
|
||||
substs,
|
||||
promoted: None
|
||||
},
|
||||
None
|
||||
);
|
||||
is_value_unfrozen_raw(cx, result, ty)
|
||||
}
|
||||
|
||||
|
@ -341,9 +341,11 @@ fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<C
|
||||
.tcx
|
||||
.const_eval_resolve(
|
||||
self.param_env,
|
||||
ty::WithOptConstParam::unknown(def_id),
|
||||
substs,
|
||||
None,
|
||||
ty::Unevaluated {
|
||||
def: ty::WithOptConstParam::unknown(def_id),
|
||||
substs,
|
||||
promoted: None,
|
||||
},
|
||||
None,
|
||||
)
|
||||
.ok()
|
||||
|
Loading…
Reference in New Issue
Block a user