mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
remove visit_const from mir visitors
This commit is contained in:
parent
0726265442
commit
372c4fd67f
@ -106,8 +106,4 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|||||||
|
|
||||||
debug!("constant: {:#?}", constant);
|
debug!("constant: {:#?}", constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_const(&mut self, _constant: &mut ty::Const<'tcx>, _location: Location) {
|
|
||||||
bug!("should never be called");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -706,13 +706,12 @@ pub fn write_allocations<'tcx>(
|
|||||||
struct CollectAllocIds(BTreeSet<AllocId>);
|
struct CollectAllocIds(BTreeSet<AllocId>);
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
|
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
|
||||||
fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) {
|
fn visit_constant(&mut self, c: &Constant<'tcx>, _: Location) {
|
||||||
match c.literal {
|
match c.literal {
|
||||||
ConstantKind::Ty(c) => self.visit_const(c, loc),
|
ConstantKind::Ty(_) | ConstantKind::Unevaluated(..) => {}
|
||||||
ConstantKind::Val(val, _) => {
|
ConstantKind::Val(val, _) => {
|
||||||
self.0.extend(alloc_ids_from_const_val(val));
|
self.0.extend(alloc_ids_from_const_val(val));
|
||||||
}
|
}
|
||||||
ConstantKind::Unevaluated(..) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,14 +237,6 @@ macro_rules! make_mir_visitor {
|
|||||||
self.super_region(region);
|
self.super_region(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_const(
|
|
||||||
&mut self,
|
|
||||||
constant: $(& $mutability)? ty::Const<'tcx>,
|
|
||||||
_: Location,
|
|
||||||
) {
|
|
||||||
self.super_const(constant);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_substs(
|
fn visit_substs(
|
||||||
&mut self,
|
&mut self,
|
||||||
substs: & $($mutability)? SubstsRef<'tcx>,
|
substs: & $($mutability)? SubstsRef<'tcx>,
|
||||||
@ -877,7 +869,7 @@ macro_rules! make_mir_visitor {
|
|||||||
self.visit_span($(& $mutability)? *span);
|
self.visit_span($(& $mutability)? *span);
|
||||||
drop(user_ty); // no visit method for this
|
drop(user_ty); // no visit method for this
|
||||||
match literal {
|
match literal {
|
||||||
ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location),
|
ConstantKind::Ty(_) => {}
|
||||||
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
||||||
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
||||||
}
|
}
|
||||||
@ -917,9 +909,6 @@ macro_rules! make_mir_visitor {
|
|||||||
fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {
|
fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_const(&mut self, _const: $(& $mutability)? ty::Const<'tcx>) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
|
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,12 +1077,20 @@ macro_rules! visit_place_fns {
|
|||||||
location,
|
location,
|
||||||
);
|
);
|
||||||
|
|
||||||
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
|
if new_local == local {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(PlaceElem::Index(new_local))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PlaceElem::Field(field, ty) => {
|
PlaceElem::Field(field, ty) => {
|
||||||
let mut new_ty = ty;
|
let mut new_ty = ty;
|
||||||
self.visit_ty(&mut new_ty, TyContext::Location(location));
|
self.visit_ty(&mut new_ty, TyContext::Location(location));
|
||||||
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
|
if ty != new_ty {
|
||||||
|
Some(PlaceElem::Field(field, new_ty))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PlaceElem::Deref
|
PlaceElem::Deref
|
||||||
| PlaceElem::ConstantIndex { .. }
|
| PlaceElem::ConstantIndex { .. }
|
||||||
|
@ -795,42 +795,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
collect_const_value(self.tcx, val, self.output);
|
collect_const_value(self.tcx, val, self.output);
|
||||||
self.visit_ty(literal.ty(), TyContext::Location(location));
|
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
|
||||||
fn visit_const(&mut self, constant: ty::Const<'tcx>, location: Location) {
|
|
||||||
debug!("visiting const {:?} @ {:?}", constant, location);
|
|
||||||
|
|
||||||
let substituted_constant = self.monomorphize(constant);
|
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
|
||||||
|
|
||||||
match substituted_constant.kind() {
|
|
||||||
ty::ConstKind::Value(val) => {
|
|
||||||
let const_val = self.tcx.valtree_to_const_val((constant.ty(), val));
|
|
||||||
collect_const_value(self.tcx, const_val, self.output)
|
|
||||||
}
|
|
||||||
ty::ConstKind::Unevaluated(unevaluated) => {
|
|
||||||
match self.tcx.const_eval_resolve(param_env, unevaluated.expand(), None) {
|
|
||||||
// The `monomorphize` call should have evaluated that constant already.
|
|
||||||
Ok(val) => span_bug!(
|
|
||||||
self.body.source_info(location).span,
|
|
||||||
"collection encountered the unevaluated constant {} which evaluated to {:?}",
|
|
||||||
substituted_constant,
|
|
||||||
val
|
|
||||||
),
|
|
||||||
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => {}
|
|
||||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
|
||||||
self.body.source_info(location).span,
|
|
||||||
"collection encountered polymorphic constant: {}",
|
|
||||||
substituted_constant
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.super_const(constant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
||||||
|
@ -9,7 +9,7 @@ use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
|
|||||||
use rustc_index::bit_set::FiniteBitSet;
|
use rustc_index::bit_set::FiniteBitSet;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
visit::{TyContext, Visitor},
|
visit::{TyContext, Visitor},
|
||||||
ConstantKind, Local, LocalDecl, Location,
|
Constant, ConstantKind, Local, LocalDecl, Location,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self,
|
self,
|
||||||
@ -270,8 +270,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||||||
self.super_local_decl(local, local_decl);
|
self.super_local_decl(local, local_decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_const(&mut self, c: Const<'tcx>, _: Location) {
|
fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
|
||||||
c.visit_with(self);
|
match ct.literal {
|
||||||
|
ConstantKind::Ty(c) => {
|
||||||
|
c.visit_with(self);
|
||||||
|
}
|
||||||
|
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
|
||||||
|
Visitor::visit_ty(self, ty, TyContext::Location(location))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {
|
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {
|
||||||
|
Loading…
Reference in New Issue
Block a user