Skip to content

Commit a849da6

Browse files
committed
remove ReserveOrActivateIndex
1 parent d32e5aa commit a849da6

File tree

4 files changed

+28
-80
lines changed

4 files changed

+28
-80
lines changed

src/librustc_mir/borrow_check/flows.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
8888
s.push_str(", ");
8989
};
9090
saw_one = true;
91-
let borrow_data = &self.borrows.operator().borrows()[borrow.borrow_index()];
92-
s.push_str(&format!("{}{}", borrow_data,
93-
if borrow.is_activation() { "@active" } else { "" }));
91+
let borrow_data = &self.borrows.operator().borrows()[borrow];
92+
s.push_str(&format!("{}", borrow_data));
9493
});
9594
s.push_str("] ");
9695

@@ -101,7 +100,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
101100
s.push_str(", ");
102101
};
103102
saw_one = true;
104-
let borrow_data = &self.borrows.operator().borrows()[borrow.borrow_index()];
103+
let borrow_data = &self.borrows.operator().borrows()[borrow];
105104
s.push_str(&format!("{}", borrow_data));
106105
});
107106
s.push_str("] ");

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
220220
&attributes,
221221
&dead_unwinds,
222222
Borrows::new(tcx, mir, opt_regioncx.clone(), def_id, body_id, borrow_set),
223-
|rs, i| {
224-
DebugFormatted::new(&(i.kind(), rs.location(i.borrow_index())))
225-
}
223+
|rs, i| DebugFormatted::new(&rs.location(i)),
226224
));
227225

228226
let movable_generator = !match tcx.hir.get(id) {
@@ -549,7 +547,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
549547
let data = domain.borrows();
550548
flow_state.borrows.with_iter_outgoing(|borrows| {
551549
for i in borrows {
552-
let borrow = &data[i.borrow_index()];
550+
let borrow = &data[i];
553551
self.check_for_local_borrow(borrow, span);
554552
}
555553
});
@@ -565,7 +563,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
565563
let data = domain.borrows();
566564
flow_state.borrows.with_iter_outgoing(|borrows| {
567565
for i in borrows {
568-
let borrow = &data[i.borrow_index()];
566+
let borrow = &data[i];
569567
let context = ContextKind::StorageDead.new(loc);
570568
self.check_for_invalidation_at_exit(context, borrow, span, flow_state);
571569
}
@@ -2245,21 +2243,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22452243
// borrows of P, P.a.b, etc.
22462244
let mut iter_incoming = flow_state.borrows.iter_incoming();
22472245
while let Some(i) = iter_incoming.next() {
2248-
// TODO -- for now, just skip activations, since
2249-
// everywhere that activation is set, reservation should
2250-
// be set
2251-
if i.is_activation() {
2252-
continue;
2253-
}
2254-
2255-
let borrowed = &data[i.borrow_index()];
2246+
let borrowed = &data[i];
22562247

22572248
if self.places_conflict(&borrowed.borrowed_place, place, access) {
22582249
debug!(
22592250
"each_borrow_involving_path: {:?} @ {:?} vs. {:?}/{:?}",
22602251
i, borrowed, place, access
22612252
);
2262-
let ctrl = op(self, i.borrow_index(), borrowed);
2253+
let ctrl = op(self, i, borrowed);
22632254
if ctrl == Control::Break {
22642255
return;
22652256
}

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ use rustc::ty::{Region, TyCtxt};
2020
use rustc::ty::RegionKind;
2121
use rustc::ty::RegionKind::ReScope;
2222

23-
use rustc_data_structures::bitslice::{BitwiseOperator};
24-
use rustc_data_structures::indexed_set::{IdxSet};
25-
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
23+
use rustc_data_structures::bitslice::BitwiseOperator;
24+
use rustc_data_structures::indexed_set::IdxSet;
25+
use rustc_data_structures::indexed_vec::IndexVec;
2626
use rustc_data_structures::sync::Lrc;
2727

2828
use dataflow::{BitDenotation, BlockSets, InitialFlow};
29-
pub use dataflow::indexes::{BorrowIndex, ReserveOrActivateIndex};
29+
pub use dataflow::indexes::BorrowIndex;
3030
use borrow_check::nll::region_infer::RegionInferenceContext;
3131
use borrow_check::nll::ToRegionVid;
3232

@@ -53,21 +53,6 @@ pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
5353
nonlexical_regioncx: Option<Rc<RegionInferenceContext<'tcx>>>,
5454
}
5555

56-
impl ReserveOrActivateIndex {
57-
fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new(i.index() * 2) }
58-
fn active(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2) + 1) }
59-
60-
pub(crate) fn is_reservation(self) -> bool { self.index() % 2 == 0 }
61-
pub(crate) fn is_activation(self) -> bool { self.index() % 2 == 1}
62-
63-
pub(crate) fn kind(self) -> &'static str {
64-
if self.is_reservation() { "reserved" } else { "active" }
65-
}
66-
pub(crate) fn borrow_index(self) -> BorrowIndex {
67-
BorrowIndex::new(self.index() / 2)
68-
}
69-
}
70-
7156
impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
7257
crate fn new(
7358
tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -120,7 +105,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
120105
/// That means either they went out of either a nonlexical scope, if we care about those
121106
/// at the moment, or the location represents a lexical EndRegion
122107
fn kill_loans_out_of_scope_at_location(&self,
123-
sets: &mut BlockSets<ReserveOrActivateIndex>,
108+
sets: &mut BlockSets<BorrowIndex>,
124109
location: Location) {
125110
if let Some(ref regioncx) = self.nonlexical_regioncx {
126111
// NOTE: The state associated with a given `location`
@@ -137,22 +122,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
137122
for (borrow_index, borrow_data) in self.borrow_set.borrows.iter_enumerated() {
138123
let borrow_region = borrow_data.region.to_region_vid();
139124
if !regioncx.region_contains_point(borrow_region, location) {
140-
sets.kill(&ReserveOrActivateIndex::reserved(borrow_index));
141-
sets.kill(&ReserveOrActivateIndex::active(borrow_index));
125+
sets.kill(&borrow_index);
142126
}
143127
}
144128
}
145129
}
146130

147131
fn kill_borrows_on_local(&self,
148-
sets: &mut BlockSets<ReserveOrActivateIndex>,
132+
sets: &mut BlockSets<BorrowIndex>,
149133
local: &rustc::mir::Local)
150134
{
151135
if let Some(borrow_indexes) = self.borrow_set.local_map.get(local) {
152-
sets.kill_all(borrow_indexes.iter()
153-
.map(|b| ReserveOrActivateIndex::reserved(*b)));
154-
sets.kill_all(borrow_indexes.iter()
155-
.map(|b| ReserveOrActivateIndex::active(*b)));
136+
sets.kill_all(borrow_indexes);
156137
}
157138
}
158139

@@ -162,45 +143,29 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
162143
.map(|activations| &activations[..])
163144
.unwrap_or(&[])
164145
}
165-
166-
/// Performs the activations for a given location
167-
fn perform_activations_at_location(&self,
168-
sets: &mut BlockSets<ReserveOrActivateIndex>,
169-
location: Location) {
170-
// Handle activations
171-
match self.borrow_set.activation_map.get(&location) {
172-
Some(activations) => {
173-
for activated in activations {
174-
debug!("activating borrow {:?}", activated);
175-
sets.gen(&ReserveOrActivateIndex::active(*activated))
176-
}
177-
}
178-
None => {}
179-
}
180-
}
181146
}
182147

183148
impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
184-
type Idx = ReserveOrActivateIndex;
149+
type Idx = BorrowIndex;
185150
fn name() -> &'static str { "borrows" }
186151
fn bits_per_block(&self) -> usize {
187152
self.borrow_set.borrows.len() * 2
188153
}
189154

190-
fn start_block_effect(&self, _entry_set: &mut IdxSet<ReserveOrActivateIndex>) {
155+
fn start_block_effect(&self, _entry_set: &mut IdxSet<BorrowIndex>) {
191156
// no borrows of code region_scopes have been taken prior to
192157
// function execution, so this method has no effect on
193158
// `_sets`.
194159
}
195160

196161
fn before_statement_effect(&self,
197-
sets: &mut BlockSets<ReserveOrActivateIndex>,
162+
sets: &mut BlockSets<BorrowIndex>,
198163
location: Location) {
199164
debug!("Borrows::before_statement_effect sets: {:?} location: {:?}", sets, location);
200165
self.kill_loans_out_of_scope_at_location(sets, location);
201166
}
202167

203-
fn statement_effect(&self, sets: &mut BlockSets<ReserveOrActivateIndex>, location: Location) {
168+
fn statement_effect(&self, sets: &mut BlockSets<BorrowIndex>, location: Location) {
204169
debug!("Borrows::statement_effect sets: {:?} location: {:?}", sets, location);
205170

206171
let block = &self.mir.basic_blocks().get(location.block).unwrap_or_else(|| {
@@ -210,7 +175,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
210175
panic!("could not find statement at location {:?}");
211176
});
212177

213-
self.perform_activations_at_location(sets, location);
214178
self.kill_loans_out_of_scope_at_location(sets, location);
215179

216180
match stmt.kind {
@@ -221,8 +185,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
221185
{
222186
assert!(self.nonlexical_regioncx.is_none());
223187
for idx in borrow_indexes {
224-
sets.kill(&ReserveOrActivateIndex::reserved(*idx));
225-
sets.kill(&ReserveOrActivateIndex::active(*idx));
188+
sets.kill(idx);
226189
}
227190
} else {
228191
// (if there is no entry, then there are no borrows to be tracked)
@@ -252,14 +215,14 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
252215
if let RegionKind::ReEmpty = region {
253216
// If the borrowed value dies before the borrow is used, the region for
254217
// the borrow can be empty. Don't track the borrow in that case.
255-
sets.kill(&ReserveOrActivateIndex::active(*index));
218+
sets.kill(&index);
256219
return
257220
}
258221

259222
assert!(self.borrow_set.region_map.get(region).unwrap_or_else(|| {
260223
panic!("could not find BorrowIndexs for region {:?}", region);
261224
}).contains(&index));
262-
sets.gen(&ReserveOrActivateIndex::reserved(*index));
225+
sets.gen(&index);
263226

264227
// Issue #46746: Two-phase borrows handles
265228
// stmts of form `Tmp = &mut Borrow` ...
@@ -270,7 +233,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
270233
// e.g. `box (&mut _)`. Current
271234
// conservative solution: force
272235
// immediate activation here.
273-
sets.gen(&ReserveOrActivateIndex::active(*index));
236+
sets.gen(&index);
274237
}
275238
}
276239
}
@@ -306,21 +269,20 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
306269
}
307270

308271
fn before_terminator_effect(&self,
309-
sets: &mut BlockSets<ReserveOrActivateIndex>,
272+
sets: &mut BlockSets<BorrowIndex>,
310273
location: Location) {
311274
debug!("Borrows::before_terminator_effect sets: {:?} location: {:?}", sets, location);
312275
self.kill_loans_out_of_scope_at_location(sets, location);
313276
}
314277

315-
fn terminator_effect(&self, sets: &mut BlockSets<ReserveOrActivateIndex>, location: Location) {
278+
fn terminator_effect(&self, sets: &mut BlockSets<BorrowIndex>, location: Location) {
316279
debug!("Borrows::terminator_effect sets: {:?} location: {:?}", sets, location);
317280

318281
let block = &self.mir.basic_blocks().get(location.block).unwrap_or_else(|| {
319282
panic!("could not find block at location {:?}", location);
320283
});
321284

322285
let term = block.terminator();
323-
self.perform_activations_at_location(sets, location);
324286
self.kill_loans_out_of_scope_at_location(sets, location);
325287

326288

@@ -343,8 +305,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
343305
if *scope != root_scope &&
344306
self.scope_tree.is_subscope_of(*scope, root_scope)
345307
{
346-
sets.kill(&ReserveOrActivateIndex::reserved(borrow_index));
347-
sets.kill(&ReserveOrActivateIndex::active(borrow_index));
308+
sets.kill(&borrow_index);
348309
}
349310
}
350311
}
@@ -365,7 +326,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
365326
}
366327

367328
fn propagate_call_return(&self,
368-
_in_out: &mut IdxSet<ReserveOrActivateIndex>,
329+
_in_out: &mut IdxSet<BorrowIndex>,
369330
_call_bb: mir::BasicBlock,
370331
_dest_bb: mir::BasicBlock,
371332
_dest_place: &mir::Place) {

src/librustc_mir/dataflow/move_paths/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ pub(crate) mod indexes {
6565

6666
/// Index into Borrows.locations
6767
new_index!(BorrowIndex, "bw");
68-
69-
/// Index into Reservations/Activations bitvector
70-
new_index!(ReserveOrActivateIndex, "ra");
7168
}
7269

7370
pub use self::indexes::MovePathIndex;

0 commit comments

Comments
 (0)