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(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||||
#[derive(Lift, TypeFoldable, TypeVisitable)]
|
#[derive(Lift, TypeFoldable, TypeVisitable)]
|
||||||
pub enum ConstantKind<'tcx> {
|
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>),
|
Ty(ty::Const<'tcx>),
|
||||||
|
|
||||||
/// An unevaluated mir constant which is not part of the type system.
|
/// 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> {
|
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
|
/// FIXME(RalfJung): I cannot explain what this does or why it makes sense, but not doing this
|
||||||
/// hurts performance.
|
/// hurts performance.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -749,39 +749,15 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) {
|
fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location) {
|
||||||
let literal = self.monomorphize(constant.literal);
|
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();
|
let param_env = ty::ParamEnv::reveal_all();
|
||||||
match self.tcx.const_eval_resolve(param_env, ct.expand(), None) {
|
let val = match literal.eval(self.tcx, param_env, None) {
|
||||||
// The `monomorphize` call should have evaluated that constant already.
|
Ok(v) => v,
|
||||||
Ok(val) => val,
|
|
||||||
Err(ErrorHandled::Reported(_)) => return,
|
Err(ErrorHandled::Reported(_)) => return,
|
||||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||||
self.body.source_info(location).span,
|
self.body.source_info(location).span,
|
||||||
"collection encountered polymorphic constant: {:?}",
|
"collection encountered polymorphic constant: {:?}",
|
||||||
literal
|
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);
|
collect_const_value(self.tcx, val, self.output);
|
||||||
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue