Skip to content

Commit 1383653

Browse files
Finally start down the right path
1 parent 580467d commit 1383653

File tree

9 files changed

+427
-431
lines changed

9 files changed

+427
-431
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::sync::Lrc;
1818

1919
use super::{Context, MirBorrowckCtxt};
2020
use super::{InitializationRequiringAction, PrefixSet};
21-
use dataflow::{ActiveBorrows, BorrowData, FlowAtLocation, MovingOutStatements};
21+
use dataflow::{Borrows, BorrowData, FlowAtLocation, MovingOutStatements};
2222
use dataflow::move_paths::MovePathIndex;
2323
use util::borrowck_errors::{BorrowckErrors, Origin};
2424

@@ -372,10 +372,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
372372
context: Context,
373373
borrow: &BorrowData<'tcx>,
374374
drop_span: Span,
375-
borrows: &ActiveBorrows<'cx, 'gcx, 'tcx>,
375+
borrows: &Borrows<'cx, 'gcx, 'tcx>
376376
) {
377377
let end_span = borrows.opt_region_end_span(&borrow.region);
378-
let scope_tree = borrows.0.scope_tree();
378+
let scope_tree = borrows.scope_tree();
379379
let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All)
380380
.last()
381381
.unwrap();

src/librustc_mir/borrow_check/flows.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use rustc::mir::{BasicBlock, Location};
1717

1818
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
1919
use dataflow::{EverInitializedPlaces, MovingOutStatements};
20-
use dataflow::{ActiveBorrows, FlowAtLocation, FlowsAtLocation};
20+
use dataflow::{Borrows};
21+
use dataflow::{FlowAtLocation, FlowsAtLocation};
2122
use dataflow::move_paths::HasMoveData;
2223
use std::fmt;
2324

2425
// (forced to be `pub` due to its use as an associated type below.)
2526
pub(crate) struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
26-
pub borrows: FlowAtLocation<ActiveBorrows<'b, 'gcx, 'tcx>>,
27+
pub borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>,
2728
pub inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>,
2829
pub uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
2930
pub move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
@@ -32,7 +33,7 @@ pub(crate) struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
3233

3334
impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
3435
pub fn new(
35-
borrows: FlowAtLocation<ActiveBorrows<'b, 'gcx, 'tcx>>,
36+
borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>,
3637
inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>,
3738
uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
3839
move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,

src/librustc_mir/borrow_check/mod.rs

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ use syntax_pos::Span;
3434
use dataflow::{do_dataflow, DebugFormatted};
3535
use dataflow::FlowAtLocation;
3636
use dataflow::MoveDataParamEnv;
37-
use dataflow::{DataflowAnalysis, DataflowResultsConsumer};
37+
use dataflow::{DataflowResultsConsumer};
3838
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
3939
use dataflow::{EverInitializedPlaces, MovingOutStatements};
4040
use dataflow::{BorrowData, Borrows, ReserveOrActivateIndex};
41-
use dataflow::{ActiveBorrows, Reservations};
4241
use dataflow::indexes::BorrowIndex;
4342
use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
4443
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
@@ -54,8 +53,6 @@ mod error_reporting;
5453
mod flows;
5554
mod prefixes;
5655

57-
use std::borrow::Cow;
58-
5956
pub(crate) mod nll;
6057

6158
pub fn provide(providers: &mut Providers) {
@@ -209,6 +206,18 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
209206
};
210207
let flow_inits = flow_inits; // remove mut
211208

209+
let flow_borrows = FlowAtLocation::new(do_dataflow(
210+
tcx,
211+
mir,
212+
id,
213+
&attributes,
214+
&dead_unwinds,
215+
Borrows::new(tcx, mir, opt_regioncx.clone(), def_id, body_id),
216+
|rs, i| {
217+
DebugFormatted::new(&(i.kind(), rs.location(i.borrow_index())))
218+
}
219+
));
220+
212221
let movable_generator = !match tcx.hir.get(id) {
213222
hir::map::Node::NodeExpr(&hir::Expr {
214223
node: hir::ExprClosure(.., Some(hir::GeneratorMovability::Static)),
@@ -230,44 +239,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
230239
},
231240
access_place_error_reported: FxHashSet(),
232241
reservation_error_reported: FxHashSet(),
233-
nonlexical_regioncx: opt_regioncx.clone(),
242+
nonlexical_regioncx: opt_regioncx,
234243
nonlexical_cause_info: None,
235244
};
236245

237-
let borrows = Borrows::new(tcx, mir, opt_regioncx, def_id, body_id);
238-
let flow_reservations = do_dataflow(
239-
tcx,
240-
mir,
241-
id,
242-
&attributes,
243-
&dead_unwinds,
244-
Reservations::new(borrows),
245-
|rs, i| {
246-
// In principle we could make the dataflow ensure that
247-
// only reservation bits show up, and assert so here.
248-
//
249-
// In practice it is easier to be looser; in particular,
250-
// it is okay for the kill-sets to hold activation bits.
251-
DebugFormatted::new(&(i.kind(), rs.location(i)))
252-
},
253-
);
254-
let flow_active_borrows = {
255-
let reservations_on_entry = flow_reservations.0.sets.entry_set_state();
256-
let reservations = flow_reservations.0.operator;
257-
let a = DataflowAnalysis::new_with_entry_sets(
258-
mir,
259-
&dead_unwinds,
260-
Cow::Borrowed(reservations_on_entry),
261-
ActiveBorrows::new(reservations),
262-
);
263-
let results = a.run(tcx, id, &attributes, |ab, i| {
264-
DebugFormatted::new(&(i.kind(), ab.location(i)))
265-
});
266-
FlowAtLocation::new(results)
267-
};
268-
269246
let mut state = Flows::new(
270-
flow_active_borrows,
247+
flow_borrows,
271248
flow_inits,
272249
flow_uninits,
273250
flow_move_outs,

0 commit comments

Comments
 (0)