Skip to content

Commit d32e5aa

Browse files
committed
use the activations_at_location map to check activations
Not gen bits
1 parent e1f82aa commit d32e5aa

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ crate struct BorrowSet<'tcx> {
3535
/// NOTE: A given location may activate more than one borrow in the future
3636
/// when more general two-phase borrow support is introduced, but for now we
3737
/// only need to store one borrow index
38-
crate activation_map: FxHashMap<Location, FxHashSet<BorrowIndex>>,
38+
crate activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
3939

4040
/// Every borrow has a region; this maps each such regions back to
4141
/// its borrow-indexes.
@@ -131,7 +131,7 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
131131
mir: &'a Mir<'tcx>,
132132
idx_vec: IndexVec<BorrowIndex, BorrowData<'tcx>>,
133133
location_map: FxHashMap<Location, BorrowIndex>,
134-
activation_map: FxHashMap<Location, FxHashSet<BorrowIndex>>,
134+
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
135135
region_map: FxHashMap<Region<'tcx>, FxHashSet<BorrowIndex>>,
136136
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,
137137
region_span_map: FxHashMap<RegionKind, Span>,
@@ -230,8 +230,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
230230
borrow_data.activation_location = Some(location);
231231
self.activation_map
232232
.entry(location)
233-
.or_insert(FxHashSet())
234-
.insert(borrow_index);
233+
.or_insert(Vec::new())
234+
.push(borrow_index);
235235
}
236236

237237
None => {}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,36 +1267,30 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12671267
// Two-phase borrow support: For each activation that is newly
12681268
// generated at this statement, check if it interferes with
12691269
// another borrow.
1270-
let domain = flow_state.borrows.operator();
1271-
let data = domain.borrows();
1272-
flow_state.borrows.each_gen_bit(|gen| {
1273-
if gen.is_activation() {
1274-
let borrow_index = gen.borrow_index();
1275-
let borrow = &data[borrow_index];
1276-
// currently the flow analysis registers
1277-
// activations for both mutable and immutable
1278-
// borrows. So make sure we are talking about a
1279-
// mutable borrow before we check it.
1280-
match borrow.kind {
1281-
BorrowKind::Shared => return,
1282-
BorrowKind::Unique | BorrowKind::Mut { .. } => {}
1283-
}
1284-
1285-
self.access_place(
1286-
ContextKind::Activation.new(location),
1287-
(&borrow.borrowed_place, span),
1288-
(
1289-
Deep,
1290-
Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index),
1291-
),
1292-
LocalMutationIsAllowed::No,
1293-
flow_state,
1294-
);
1295-
// We do not need to call `check_if_path_or_subpath_is_moved`
1296-
// again, as we already called it when we made the
1297-
// initial reservation.
1298-
}
1299-
});
1270+
let borrows = flow_state.borrows.operator();
1271+
for &borrow_index in borrows.activations_at_location(location) {
1272+
let borrow = &borrows.borrows()[borrow_index];
1273+
1274+
// only mutable borrows should be 2-phase
1275+
assert!(match borrow.kind {
1276+
BorrowKind::Shared => false,
1277+
BorrowKind::Unique | BorrowKind::Mut { .. } => true,
1278+
});
1279+
1280+
self.access_place(
1281+
ContextKind::Activation.new(location),
1282+
(&borrow.borrowed_place, span),
1283+
(
1284+
Deep,
1285+
Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index),
1286+
),
1287+
LocalMutationIsAllowed::No,
1288+
flow_state,
1289+
);
1290+
// We do not need to call `check_if_path_or_subpath_is_moved`
1291+
// again, as we already called it when we made the
1292+
// initial reservation.
1293+
}
13001294
}
13011295
}
13021296

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
156156
}
157157
}
158158

159+
crate fn activations_at_location(&self, location: Location) -> &[BorrowIndex] {
160+
self.borrow_set.activation_map
161+
.get(&location)
162+
.map(|activations| &activations[..])
163+
.unwrap_or(&[])
164+
}
165+
159166
/// Performs the activations for a given location
160167
fn perform_activations_at_location(&self,
161168
sets: &mut BlockSets<ReserveOrActivateIndex>,

0 commit comments

Comments
 (0)