found another place where we can eval() a const, and go through valtrees
This commit is contained in:
parent
292d5bba86
commit
19fb2c7ccd
3 changed files with 14 additions and 39 deletions
|
@ -2297,7 +2297,11 @@ pub struct Constant<'tcx> {
|
|||
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||
#[derive(Lift, TypeFoldable, TypeVisitable)]
|
||||
pub enum ConstantKind<'tcx> {
|
||||
/// This constant came from the type system
|
||||
/// This constant came from the type system.
|
||||
///
|
||||
/// Any way of turning `ty::Const` into `ConstValue` should go through `valtree_to_const_val`;
|
||||
/// this ensures that we consistently produce "clean" values without data in the padding or
|
||||
/// anything like that.
|
||||
Ty(ty::Const<'tcx>),
|
||||
|
||||
/// An unevaluated mir constant which is not part of the type system.
|
||||
|
|
|
@ -22,11 +22,6 @@ impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> {
|
|||
}
|
||||
|
||||
impl<'tcx> UnevaluatedConst<'tcx> {
|
||||
#[inline]
|
||||
pub fn expand(self) -> mir::UnevaluatedConst<'tcx> {
|
||||
mir::UnevaluatedConst { def: self.def, args: self.args, promoted: None }
|
||||
}
|
||||
|
||||
/// FIXME(RalfJung): I cannot explain what this does or why it makes sense, but not doing this
|
||||
/// hurts performance.
|
||||
#[inline]
|
||||
|
|
|
@ -749,39 +749,15 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
|||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) {
|
||||
let literal = self.monomorphize(constant.literal);
|
||||
let val = match literal {
|
||||
mir::ConstantKind::Val(val, _) => val,
|
||||
mir::ConstantKind::Ty(ct) => match ct.kind() {
|
||||
ty::ConstKind::Value(val) => self.tcx.valtree_to_const_val((ct.ty(), val)),
|
||||
ty::ConstKind::Unevaluated(ct) => {
|
||||
debug!(?ct);
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
match self.tcx.const_eval_resolve(param_env, ct.expand(), None) {
|
||||
// The `monomorphize` call should have evaluated that constant already.
|
||||
Ok(val) => val,
|
||||
let val = match literal.eval(self.tcx, param_env, None) {
|
||||
Ok(v) => v,
|
||||
Err(ErrorHandled::Reported(_)) => return,
|
||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered polymorphic constant: {:?}",
|
||||
literal
|
||||
),
|
||||
}
|
||||
}
|
||||
_ => return,
|
||||
},
|
||||
mir::ConstantKind::Unevaluated(uv, _) => {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
match self.tcx.const_eval_resolve(param_env, uv, None) {
|
||||
// The `monomorphize` call should have evaluated that constant already.
|
||||
Ok(val) => val,
|
||||
Err(ErrorHandled::Reported(_)) => return,
|
||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered polymorphic constant: {:?}",
|
||||
literal
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
collect_const_value(self.tcx, val, self.output);
|
||||
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue