Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Visitor::visit_body take a plain &Body #70449

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ use rustc_span::Span;
// variant argument) that does not require visiting, as in
// `is_cleanup` above.

macro_rules! body_cache_type {
(mut $a:lifetime, $tcx:lifetime) => {
macro_rules! body_type {
(mut $tcx:lifetime) => {
&mut BodyAndCache<$tcx>
};
($a:lifetime, $tcx:lifetime) => {
ReadOnlyBodyAndCache<$a, $tcx>
($tcx:lifetime) => {
&Body<$tcx>
};
}
Comment on lines +68 to 75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're having the read-only case not require the cache? I actually hadn't even considered that when I first wrote this. That should actually make this a lot easier to use!


Expand All @@ -82,7 +82,7 @@ macro_rules! make_mir_visitor {

fn visit_body(
&mut self,
body: body_cache_type!($($mutability)? '_, 'tcx)
body: body_type!($($mutability)? 'tcx)
) {
self.super_body(body);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ macro_rules! make_mir_visitor {

fn super_body(
&mut self,
$($mutability)? body: body_cache_type!($($mutability)? '_, 'tcx)
$($mutability)? body: body_type!($($mutability)? 'tcx)
) {
let span = body.span;
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
Expand Down Expand Up @@ -819,7 +819,7 @@ macro_rules! make_mir_visitor {

fn visit_location(
&mut self,
body: body_cache_type!($($mutability)? '_, 'tcx),
body: body_type!($($mutability)? 'tcx),
location: Location
) {
let basic_block = & $($mutability)? body[location.block];
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mir = fx.mir;
let mut analyzer = LocalAnalyzer::new(fx);

analyzer.visit_body(mir);
analyzer.visit_body(&mir);

for (local, decl) in mir.local_decls.iter_enumerated() {
let ty = fx.monomorphize(&decl.ty);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl LocalsStateAtExit {
LocalsStateAtExit::AllAreInvalidated
} else {
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
has_storage_dead.visit_body(body);
has_storage_dead.visit_body(&body);
let mut has_storage_dead_or_moved = has_storage_dead.0;
for move_out in &move_data.moves {
if let Some(index) = move_data.base_local(move_out.path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
let mut visitor = FakeReadCauseFinder { place, cause: None };
visitor.visit_body(self.body);
visitor.visit_body(&self.body);
match visitor.cause {
Some(FakeReadCause::ForMatchGuard) => Some("match guard"),
Some(FakeReadCause::ForIndex) => Some("indexing expression"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(super) fn generate_invalidates<'tcx>(
body: &body,
dominators,
};
ig.visit_body(body);
ig.visit_body(&body);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ fn do_mir_borrowck<'a, 'tcx>(
}

dataflow::visit_results(
&*body,
traversal::reverse_postorder(&*body).map(|(bb, _)| bb),
&body,
traversal::reverse_postorder(&body).map(|(bb, _)| bb),
&results,
&mut mbcx,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl LocalUseMap {
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);

LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
.visit_body(body);
.visit_body(&body);

local_use_map
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(super) fn populate_access_facts(
location_table,
move_data,
};
extractor.visit_body(body);
extractor.visit_body(&body);

facts.var_dropped_at.extend(
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn type_check_internal<'a, 'tcx, R>(
);
let errors_reported = {
let mut verifier = TypeVerifier::new(&mut checker, *body, promoted);
verifier.visit_body(body);
verifier.visit_body(&body);
verifier.errors_reported
};

Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
}
}

fn visit_body(&mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>) {
fn visit_body(&mut self, body: &Body<'tcx>) {
self.sanitize_type(&"return type", body.return_ty());
for local_decl in &body.local_decls {
self.sanitize_type(local_decl, local_decl.ty);
Expand Down Expand Up @@ -563,7 +563,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {

swap_constraints(self);

self.visit_body(promoted_body);
self.visit_body(&promoted_body);

if !self.errors_reported {
// if verifier failed, don't do further checks to avoid ICEs
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/used_muts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
never_initialized_mut_locals: &mut never_initialized_mut_locals,
mbcx: self,
};
visitor.visit_body(visitor.mbcx.body);
visitor.visit_body(&visitor.mbcx.body);
}

// Take the union of the existed `used_mut` set with those variables we've found were
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn const_eval_raw_provider<'tcx>(
);

let res = ecx.load_mir(cid.instance.def, cid.promoted);
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, *body))
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body))
.and_then(|place| {
Ok(RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
})
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/impls/storage_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
) -> Self {
MaybeRequiresStorage {
body,
borrowed_locals: RefCell::new(ResultsRefCursor::new(*body, borrowed_locals)),
borrowed_locals: RefCell::new(ResultsRefCursor::new(&body, borrowed_locals)),
}
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
/// Kill locals that are fully moved and have not been borrowed.
fn check_for_move(&self, trans: &mut impl GenKill<Local>, loc: Location) {
let mut visitor = MoveVisitor { trans, borrowed_locals: &self.borrowed_locals };
visitor.visit_location(self.body, loc);
visitor.visit_location(&self.body, loc);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ fn collect_neighbours<'tcx>(
debug!("collect_neighbours: {:?}", instance.def_id());
let body = tcx.instance_mir(instance.def);

MirNeighborCollector { tcx, body: &body, output, instance }.visit_body(body);
MirNeighborCollector { tcx, body: &body, output, instance }.visit_body(&body);
}

fn def_id_to_string(tcx: TyCtxt<'_>, def_id: DefId) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Validator<'a, 'mir, 'tcx> {
self.check_op_spanned(ops::Loop, body.span);
}

self.visit_body(body);
self.visit_body(&body);

// Ensure that the end result is `Sync` in a non-thread local `static`.
let should_check_for_sync =
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
// mir_built ensures that body has a computed cache, so we don't (and can't) attempt to
// recompute it here.
let body = body.unwrap_read_only();
checker.visit_body(body);
checker.visit_body(&body);

check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
UnsafetyCheckResult {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ impl CanConstProp {
trace!("local {:?} can't be const propagated because it's not a temporary", local);
}
}
cpv.visit_body(body);
cpv.visit_body(&body);
cpv.can_const_prop
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ fn locals_live_across_suspend_points(
// Find the MIR locals which do not use StorageLive/StorageDead statements.
// The storage of these locals are always live.
let mut ignored = StorageIgnored(BitSet::new_filled(body.local_decls.len()));
ignored.visit_body(body);
ignored.visit_body(&body);

// Calculate the MIR locals which have been previously
// borrowed (even if they are still active).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
let optimizations = {
let read_only_cache = read_only!(body);
let mut optimization_finder = OptimizationFinder::new(body, tcx);
optimization_finder.visit_body(read_only_cache);
optimization_finder.visit_body(&read_only_cache);
optimization_finder.optimizations
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyLocals {
let locals = {
let read_only_cache = read_only!(body);
let mut marker = DeclMarker { locals: BitSet::new_empty(body.local_decls.len()), body };
marker.visit_body(read_only_cache);
marker.visit_body(&read_only_cache);
// Return pointer and arguments are always live
marker.locals.insert(RETURN_PLACE);
for arg in body.args_iter() {
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_mir/util/collect_writes.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use rustc::mir::visit::PlaceContext;
use rustc::mir::visit::Visitor;
use rustc::mir::ReadOnlyBodyAndCache;
use rustc::mir::{Local, Location};
use rustc::mir::{Body, Local, Location};

crate trait FindAssignments {
// Finds all statements that assign directly to local (i.e., X = ...)
// and returns their locations.
fn find_assignments(&self, local: Local) -> Vec<Location>;
}

impl<'a, 'tcx> FindAssignments for ReadOnlyBodyAndCache<'a, 'tcx> {
impl<'tcx> FindAssignments for Body<'tcx> {
fn find_assignments(&self, local: Local) -> Vec<Location> {
let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![] };
visitor.visit_body(*self);
visitor.visit_body(self);
visitor.locations
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/def_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DefUseAnalysis {
var_debug_info_index: 0,
in_var_debug_info: false,
};
finder.visit_body(body);
finder.visit_body(&body);
self.info = finder.info
}

Expand Down