Remove MirVisitable
.
The `MirVisitable` trait is just a complicated way to visit either a statement or a terminator. (And its impl for `Terminator` is unused.) It has a single use. This commit removes it, replacing it with an if/else, which is shorter and simpler.
This commit is contained in:
parent
cee430b2ce
commit
311e8d3e5d
3 changed files with 18 additions and 43 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
|
use rustc_middle::mir::visit::{PlaceContext, Visitor};
|
||||||
use rustc_middle::mir::{self, Body, Local, Location};
|
use rustc_middle::mir::{self, Body, Local, Location};
|
||||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||||
|
|
||||||
|
@ -45,7 +45,22 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
|
||||||
|
|
||||||
let block_data = &self.body[p.block];
|
let block_data = &self.body[p.block];
|
||||||
|
|
||||||
match self.def_use(p, block_data.visitable(p.statement_index)) {
|
let mut visitor = DefUseVisitor {
|
||||||
|
body: self.body,
|
||||||
|
tcx: self.tcx,
|
||||||
|
region_vid: self.region_vid,
|
||||||
|
def_use_result: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let is_statement = p.statement_index < block_data.statements.len();
|
||||||
|
|
||||||
|
if is_statement {
|
||||||
|
visitor.visit_statement(&block_data.statements[p.statement_index], p);
|
||||||
|
} else {
|
||||||
|
visitor.visit_terminator(block_data.terminator.as_ref().unwrap(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
match visitor.def_use_result {
|
||||||
Some(DefUseResult::Def) => {}
|
Some(DefUseResult::Def) => {}
|
||||||
|
|
||||||
Some(DefUseResult::UseLive { local }) => {
|
Some(DefUseResult::UseLive { local }) => {
|
||||||
|
@ -57,7 +72,7 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
if p.statement_index < block_data.statements.len() {
|
if is_statement {
|
||||||
queue.push_back(p.successor_within_block());
|
queue.push_back(p.successor_within_block());
|
||||||
} else {
|
} else {
|
||||||
queue.extend(
|
queue.extend(
|
||||||
|
@ -77,19 +92,6 @@ impl<'a, 'tcx> UseFinder<'a, 'tcx> {
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_use(&self, location: Location, thing: &dyn MirVisitable<'tcx>) -> Option<DefUseResult> {
|
|
||||||
let mut visitor = DefUseVisitor {
|
|
||||||
body: self.body,
|
|
||||||
tcx: self.tcx,
|
|
||||||
region_vid: self.region_vid,
|
|
||||||
def_use_result: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
thing.apply(location, &mut visitor);
|
|
||||||
|
|
||||||
visitor.def_use_result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DefUseVisitor<'a, 'tcx> {
|
struct DefUseVisitor<'a, 'tcx> {
|
||||||
|
|
|
@ -32,7 +32,6 @@ use tracing::{debug, trace};
|
||||||
pub use self::query::*;
|
pub use self::query::*;
|
||||||
use self::visit::TyContext;
|
use self::visit::TyContext;
|
||||||
use crate::mir::interpret::{AllocRange, Scalar};
|
use crate::mir::interpret::{AllocRange, Scalar};
|
||||||
use crate::mir::visit::MirVisitable;
|
|
||||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||||
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
|
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
|
||||||
use crate::ty::visit::TypeVisitableExt;
|
use crate::ty::visit::TypeVisitableExt;
|
||||||
|
@ -1364,10 +1363,6 @@ impl<'tcx> BasicBlockData<'tcx> {
|
||||||
self.terminator.as_mut().expect("invalid terminator state")
|
self.terminator.as_mut().expect("invalid terminator state")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visitable(&self, index: usize) -> &dyn MirVisitable<'tcx> {
|
|
||||||
if index < self.statements.len() { &self.statements[index] } else { &self.terminator }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Does the block have no statements and an unreachable terminator?
|
/// Does the block have no statements and an unreachable terminator?
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_empty_unreachable(&self) -> bool {
|
pub fn is_empty_unreachable(&self) -> bool {
|
||||||
|
|
|
@ -1265,28 +1265,6 @@ macro_rules! visit_place_fns {
|
||||||
make_mir_visitor!(Visitor,);
|
make_mir_visitor!(Visitor,);
|
||||||
make_mir_visitor!(MutVisitor, mut);
|
make_mir_visitor!(MutVisitor, mut);
|
||||||
|
|
||||||
pub trait MirVisitable<'tcx> {
|
|
||||||
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
|
|
||||||
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
|
|
||||||
visitor.visit_statement(self, location)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
|
|
||||||
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
|
|
||||||
visitor.visit_terminator(self, location)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
|
|
||||||
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>) {
|
|
||||||
visitor.visit_terminator(self.as_ref().unwrap(), location)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extra information passed to `visit_ty` and friends to give context
|
/// Extra information passed to `visit_ty` and friends to give context
|
||||||
/// about where the type etc appears.
|
/// about where the type etc appears.
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue