@@ -10,7 +10,8 @@ use crate::borrow_check::{
10
10
places_conflict, BorrowData, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext,
11
11
ToRegionVid,
12
12
};
13
- use crate::dataflow::{BitDenotation, BottomValue, GenKillSet};
13
+ use crate::dataflow::generic::{self, GenKill};
14
+ use crate::dataflow::BottomValue;
14
15
15
16
use std::rc::Rc;
16
17
@@ -172,7 +173,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
172
173
/// That means they went out of a nonlexical scope
173
174
fn kill_loans_out_of_scope_at_location(
174
175
&self,
175
- trans: &mut GenKillSet <BorrowIndex>,
176
+ trans: &mut impl GenKill <BorrowIndex>,
176
177
location: Location,
177
178
) {
178
179
// NOTE: The state associated with a given `location`
@@ -187,16 +188,21 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
187
188
// region, then setting that gen-bit will override any
188
189
// potential kill introduced here.
189
190
if let Some(indices) = self.borrows_out_of_scope_at_location.get(&location) {
190
- trans.kill_all(indices);
191
+ trans.kill_all(indices.iter().copied() );
191
192
}
192
193
}
193
194
194
195
/// Kill any borrows that conflict with `place`.
195
- fn kill_borrows_on_place(&self, trans: &mut GenKillSet <BorrowIndex>, place: &Place<'tcx>) {
196
+ fn kill_borrows_on_place(&self, trans: &mut impl GenKill <BorrowIndex>, place: &Place<'tcx>) {
196
197
debug!("kill_borrows_on_place: place={:?}", place);
197
198
198
- let other_borrows_of_local =
199
- self.borrow_set.local_map.get(&place.local).into_iter().flat_map(|bs| bs.into_iter());
199
+ let other_borrows_of_local = self
200
+ .borrow_set
201
+ .local_map
202
+ .get(&place.local)
203
+ .into_iter()
204
+ .flat_map(|bs| bs.into_iter())
205
+ .copied();
200
206
201
207
// If the borrowed place is a local with no projections, all other borrows of this
202
208
// local must conflict. This is purely an optimization so we don't have to call
@@ -212,7 +218,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
212
218
// pair of array indices are unequal, so that when `places_conflict` returns true, we
213
219
// will be assured that two places being compared definitely denotes the same sets of
214
220
// locations.
215
- let definitely_conflicting_borrows = other_borrows_of_local.filter(|&& i| {
221
+ let definitely_conflicting_borrows = other_borrows_of_local.filter(|&i| {
216
222
places_conflict(
217
223
self.tcx,
218
224
self.body,
@@ -226,36 +232,41 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
226
232
}
227
233
}
228
234
229
- impl<'a, ' tcx> BitDenotation <'tcx> for Borrows<'a , 'tcx> {
235
+ impl<'tcx> generic::AnalysisDomain <'tcx> for Borrows<'_ , 'tcx> {
230
236
type Idx = BorrowIndex;
231
- fn name() -> &'static str {
232
- "borrows"
233
- }
234
- fn bits_per_block(&self) -> usize {
237
+
238
+ const NAME: &'static str = "borrows";
239
+
240
+ fn bits_per_block(&self, _: &mir::Body<'tcx> ) -> usize {
235
241
self.borrow_set.borrows.len() * 2
236
242
}
237
243
238
- fn start_block_effect (&self, _entry_set : &mut BitSet<Self::Idx>) {
244
+ fn initialize_start_block (&self, _: &mir::Body<'tcx>, _ : &mut BitSet<Self::Idx>) {
239
245
// no borrows of code region_scopes have been taken prior to
240
246
// function execution, so this method has no effect.
241
247
}
242
248
243
- fn before_statement_effect(&self, trans: &mut GenKillSet<Self::Idx>, location: Location) {
244
- debug!("Borrows::before_statement_effect trans: {:?} location: {:?}", trans, location);
245
- self.kill_loans_out_of_scope_at_location(trans, location);
249
+ fn pretty_print_idx(&self, w: &mut impl std::io::Write, idx: Self::Idx) -> std::io::Result<()> {
250
+ write!(w, "{:?}", self.location(idx))
246
251
}
252
+ }
247
253
248
- fn statement_effect(&self, trans: &mut GenKillSet<Self::Idx>, location: Location) {
249
- debug!("Borrows::statement_effect: trans={:?} location={:?}", trans, location);
250
-
251
- let block = &self.body.basic_blocks().get(location.block).unwrap_or_else(|| {
252
- panic!("could not find block at location {:?}", location);
253
- });
254
- let stmt = block.statements.get(location.statement_index).unwrap_or_else(|| {
255
- panic!("could not find statement at location {:?}" );
256
- });
254
+ impl<'tcx> generic::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
255
+ fn before_statement_effect(
256
+ &self,
257
+ trans: &mut impl GenKill<Self::Idx>,
258
+ _statement: &mir::Statement<'tcx>,
259
+ location: Location,
260
+ ) {
261
+ self.kill_loans_out_of_scope_at_location(trans, location);
262
+ }
257
263
258
- debug!("Borrows::statement_effect: stmt={:?}", stmt);
264
+ fn statement_effect(
265
+ &self,
266
+ trans: &mut impl GenKill<Self::Idx>,
267
+ stmt: &mir::Statement<'tcx>,
268
+ location: Location,
269
+ ) {
259
270
match stmt.kind {
260
271
mir::StatementKind::Assign(box (ref lhs, ref rhs)) => {
261
272
if let mir::Rvalue::Ref(_, _, ref place) = *rhs {
@@ -301,18 +312,29 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
301
312
}
302
313
}
303
314
304
- fn before_terminator_effect(&self, trans: &mut GenKillSet<Self::Idx>, location: Location) {
305
- debug!("Borrows::before_terminator_effect: trans={:?} location={:?}", trans, location);
315
+ fn before_terminator_effect(
316
+ &self,
317
+ trans: &mut impl GenKill<Self::Idx>,
318
+ _terminator: &mir::Terminator<'tcx>,
319
+ location: Location,
320
+ ) {
306
321
self.kill_loans_out_of_scope_at_location(trans, location);
307
322
}
308
323
309
- fn terminator_effect(&self, _: &mut GenKillSet<Self::Idx>, _: Location) {}
324
+ fn terminator_effect(
325
+ &self,
326
+ _: &mut impl GenKill<Self::Idx>,
327
+ _: &mir::Terminator<'tcx>,
328
+ _: Location,
329
+ ) {
330
+ }
310
331
311
- fn propagate_call_return (
332
+ fn call_return_effect (
312
333
&self,
313
- _in_out: &mut BitSet<BorrowIndex>,
314
- _call_bb: mir::BasicBlock,
315
- _dest_bb: mir::BasicBlock,
334
+ _trans: &mut impl GenKill<Self::Idx>,
335
+ _block: mir::BasicBlock,
336
+ _func: &mir::Operand<'tcx>,
337
+ _args: &[mir::Operand<'tcx>],
316
338
_dest_place: &mir::Place<'tcx>,
317
339
) {
318
340
}
0 commit comments