Auto merge of #63820 - oli-obk:eager_const_eval, r=nikomatsakis
Simplify eager normalization of constants r? @nikomatsakis
This commit is contained in:
commit
ac21131f78
@ -15,7 +15,6 @@ use super::util;
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
|
||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::mir::interpret::{GlobalId, ConstValue};
|
||||
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
|
||||
use rustc_macros::HashStable;
|
||||
use syntax::ast::Ident;
|
||||
@ -397,40 +396,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
|
||||
let tcx = self.selcx.tcx().global_tcx();
|
||||
let param_env = self.param_env;
|
||||
if !param_env.has_local_value() {
|
||||
if substs.needs_infer() || substs.has_placeholders() {
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
|
||||
if let Some(instance) = instance {
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None
|
||||
};
|
||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||
let evaluated = evaluated.subst(tcx, substs);
|
||||
return evaluated;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !substs.has_local_value() {
|
||||
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs);
|
||||
if let Some(instance) = instance {
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None
|
||||
};
|
||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||
return evaluated;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
constant
|
||||
constant.eval(self.selcx.tcx(), self.param_env)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,10 @@
|
||||
use crate::infer::at::At;
|
||||
use crate::infer::canonical::OriginalQueryValues;
|
||||
use crate::infer::{InferCtxt, InferOk};
|
||||
use crate::mir::interpret::{GlobalId, ConstValue};
|
||||
use crate::traits::project::Normalized;
|
||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use crate::ty::subst::{Subst, InternalSubsts};
|
||||
use crate::ty::subst::Subst;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
|
||||
use super::NoSolution;
|
||||
@ -191,40 +190,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
|
||||
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
|
||||
let tcx = self.infcx.tcx.global_tcx();
|
||||
let param_env = self.param_env;
|
||||
if !param_env.has_local_value() {
|
||||
if substs.needs_infer() || substs.has_placeholders() {
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs);
|
||||
if let Some(instance) = instance {
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
};
|
||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||
let evaluated = evaluated.subst(tcx, substs);
|
||||
return evaluated;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !substs.has_local_value() {
|
||||
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs);
|
||||
if let Some(instance) = instance {
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
};
|
||||
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
|
||||
return evaluated;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
constant
|
||||
constant.eval(self.infcx.tcx, self.param_env)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,11 @@ error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{con
|
||||
LL | bytes: [u8; std::mem::size_of::<Foo>()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}#0`...
|
||||
--> $DIR/const-size_of-cycle.rs:6:17
|
||||
|
|
||||
LL | bytes: [u8; std::mem::size_of::<Foo>()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires const-evaluating `Foo::bytes::{{constant}}#0`...
|
||||
--> $SRC_DIR/libcore/mem/mod.rs:LL:COL
|
||||
|
|
||||
@ -11,11 +16,6 @@ LL | intrinsics::size_of::<T>()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which requires computing layout of `Foo`...
|
||||
= note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
|
||||
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}#0`...
|
||||
--> $DIR/const-size_of-cycle.rs:6:17
|
||||
|
|
||||
LL | bytes: [u8; std::mem::size_of::<Foo>()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}#0`, completing the cycle
|
||||
note: cycle used when processing `Foo`
|
||||
--> $DIR/const-size_of-cycle.rs:5:1
|
||||
|
@ -4,6 +4,11 @@ error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{{con
|
||||
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
|
||||
| ^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}#0`...
|
||||
--> $DIR/issue-44415.rs:6:17
|
||||
|
|
||||
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
|
||||
| ^^^^^^
|
||||
note: ...which requires const-evaluating `Foo::bytes::{{constant}}#0`...
|
||||
--> $DIR/issue-44415.rs:6:26
|
||||
|
|
||||
@ -11,11 +16,6 @@ LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which requires computing layout of `Foo`...
|
||||
= note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
|
||||
note: ...which requires const-evaluating + checking `Foo::bytes::{{constant}}#0`...
|
||||
--> $DIR/issue-44415.rs:6:17
|
||||
|
|
||||
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
|
||||
| ^^^^^^
|
||||
= note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}#0`, completing the cycle
|
||||
note: cycle used when processing `Foo`
|
||||
--> $DIR/issue-44415.rs:5:1
|
||||
|
Loading…
Reference in New Issue
Block a user