Skip to content

Commit 7bd4fde

Browse files
committed
Compute dominators on demand for borrowck.
1 parent ae318e3 commit 7bd4fde

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23822382
let mut back_edge_stack = Vec::new();
23832383

23842384
predecessor_locations(self.body, location).for_each(|predecessor| {
2385-
if location.dominates(predecessor, self.dominators) {
2385+
if location.dominates(predecessor, self.dominators()) {
23862386
back_edge_stack.push(predecessor)
23872387
} else {
23882388
stack.push(predecessor);
@@ -2494,7 +2494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24942494

24952495
let mut has_predecessor = false;
24962496
predecessor_locations(self.body, location).for_each(|predecessor| {
2497-
if location.dominates(predecessor, self.dominators) {
2497+
if location.dominates(predecessor, self.dominators()) {
24982498
back_edge_stack.push(predecessor)
24992499
} else {
25002500
stack.push(predecessor);

compiler/rustc_borrowck/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ fn do_mir_borrowck<'tcx>(
330330
used_mut: Default::default(),
331331
used_mut_upvars: SmallVec::new(),
332332
borrow_set: Rc::clone(&borrow_set),
333-
dominators: promoted_body.basic_blocks.dominators(),
334333
upvars: Vec::new(),
335334
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
336335
region_names: RefCell::default(),
@@ -359,7 +358,6 @@ fn do_mir_borrowck<'tcx>(
359358
used_mut: Default::default(),
360359
used_mut_upvars: SmallVec::new(),
361360
borrow_set: Rc::clone(&borrow_set),
362-
dominators: body.basic_blocks.dominators(),
363361
upvars,
364362
local_names,
365363
region_names: RefCell::default(),
@@ -590,9 +588,6 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
590588
/// The set of borrows extracted from the MIR
591589
borrow_set: Rc<BorrowSet<'tcx>>,
592590

593-
/// Dominators for MIR
594-
dominators: &'cx Dominators<BasicBlock>,
595-
596591
/// Information about upvars not necessarily preserved in types or MIR
597592
upvars: Vec<Upvar<'tcx>>,
598593

@@ -1102,7 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11021097

11031098
(Read(kind), BorrowKind::Unique | BorrowKind::Mut { .. }) => {
11041099
// Reading from mere reservations of mutable-borrows is OK.
1105-
if !is_active(this.dominators, borrow, location) {
1100+
if !is_active(this.dominators(), borrow, location) {
11061101
assert!(allow_two_phase_borrow(borrow.kind));
11071102
return Control::Continue;
11081103
}
@@ -2266,6 +2261,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22662261
fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<FieldIdx> {
22672262
path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
22682263
}
2264+
2265+
fn dominators(&self) -> &Dominators<BasicBlock> {
2266+
// `BasicBlocks` computes dominators on-demand and caches them.
2267+
self.body.basic_blocks.dominators()
2268+
}
22692269
}
22702270

22712271
mod error {

0 commit comments

Comments
 (0)