@@ -18,7 +18,6 @@ use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Location, Lvalue, Local}
18
18
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
19
19
use rustc:: mir:: { Statement , StatementKind , Terminator , TerminatorKind } ;
20
20
use rustc:: mir:: transform:: MirSource ;
21
- use transform:: nll;
22
21
23
22
use rustc_data_structures:: indexed_set:: { self , IdxSetBuf } ;
24
23
use rustc_data_structures:: indexed_vec:: { Idx } ;
@@ -38,6 +37,7 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
38
37
use self :: MutateMode :: { JustWrite , WriteAndRead } ;
39
38
use self :: ConsumeKind :: { Consume } ;
40
39
40
+ pub ( crate ) mod nll;
41
41
42
42
pub fn provide ( providers : & mut Providers ) {
43
43
* providers = Providers {
@@ -77,7 +77,16 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
77
77
78
78
let id = src. item_id ( ) ;
79
79
80
- let move_data: MoveData < ' tcx > = match MoveData :: gather_moves ( input_mir, tcx, param_env) {
80
+ // Make our own copy of the MIR. This copy will be modified (in place) to
81
+ // contain non-lexical lifetimes. It will have a lifetime tied
82
+ // to the inference context.
83
+ let mut mir: Mir < ' tcx > = input_mir. clone ( ) ;
84
+ let mir = & mut mir;
85
+
86
+ // Replace all regions with fresh inference variables.
87
+ let num_region_variables = nll:: renumber:: renumber_mir ( infcx, mir) ;
88
+
89
+ let move_data: MoveData < ' tcx > = match MoveData :: gather_moves ( mir, tcx, param_env) {
81
90
Ok ( move_data) => move_data,
82
91
Err ( ( move_data, move_errors) ) => {
83
92
for move_error in move_errors {
@@ -105,31 +114,22 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
105
114
}
106
115
} ;
107
116
108
- // Make our own copy of the MIR. This copy will be modified (in place) to
109
- // contain non-lexical lifetimes. It will have a lifetime tied
110
- // to the inference context.
111
- let mut mir: Mir < ' tcx > = input_mir. clone ( ) ;
112
- let mir = & mut mir;
117
+ let mdpe = MoveDataParamEnv { move_data : move_data, param_env : param_env } ;
118
+ let dead_unwinds = IdxSetBuf :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
119
+ let flow_inits = FlowInProgress :: new ( do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
120
+ MaybeInitializedLvals :: new ( tcx, mir, & mdpe) ,
121
+ |bd, i| & bd. move_data ( ) . move_paths [ i] ) ) ;
122
+ let flow_uninits = FlowInProgress :: new ( do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
123
+ MaybeUninitializedLvals :: new ( tcx, mir, & mdpe) ,
124
+ |bd, i| & bd. move_data ( ) . move_paths [ i] ) ) ;
113
125
114
126
// If we are in non-lexical mode, compute the non-lexical lifetimes.
115
127
let opt_regioncx = if !tcx. sess . opts . debugging_opts . nll {
116
128
None
117
129
} else {
118
- Some ( nll:: compute_regions ( infcx, src, param_env, mir) )
130
+ Some ( nll:: compute_regions ( infcx, src, param_env, mir, num_region_variables , & flow_inits , & mdpe . move_data ) )
119
131
} ;
120
132
121
- let mdpe = MoveDataParamEnv { move_data : move_data, param_env : param_env } ;
122
- let dead_unwinds = IdxSetBuf :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
123
- let flow_borrows = do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
124
- Borrows :: new ( tcx, mir, opt_regioncx. as_ref ( ) ) ,
125
- |bd, i| bd. location ( i) ) ;
126
- let flow_inits = do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
127
- MaybeInitializedLvals :: new ( tcx, mir, & mdpe) ,
128
- |bd, i| & bd. move_data ( ) . move_paths [ i] ) ;
129
- let flow_uninits = do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
130
- MaybeUninitializedLvals :: new ( tcx, mir, & mdpe) ,
131
- |bd, i| & bd. move_data ( ) . move_paths [ i] ) ;
132
-
133
133
let mut mbcx = MirBorrowckCtxt {
134
134
tcx : tcx,
135
135
mir : mir,
@@ -138,6 +138,10 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
138
138
param_env : param_env,
139
139
} ;
140
140
141
+ let flow_borrows = FlowInProgress :: new ( do_dataflow ( tcx, mir, id, & attributes, & dead_unwinds,
142
+ Borrows :: new ( tcx, mir, opt_regioncx. as_ref ( ) ) ,
143
+ |bd, i| bd. location ( i) ) ) ;
144
+
141
145
let mut state = InProgress :: new ( flow_borrows,
142
146
flow_inits,
143
147
flow_uninits) ;
@@ -1401,14 +1405,14 @@ impl ContextKind {
1401
1405
}
1402
1406
1403
1407
impl < ' b , ' gcx , ' tcx > InProgress < ' b , ' gcx , ' tcx > {
1404
- pub ( super ) fn new ( borrows : DataflowResults < Borrows < ' b , ' gcx , ' tcx > > ,
1405
- inits : DataflowResults < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
1406
- uninits : DataflowResults < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > )
1408
+ fn new ( borrows : FlowInProgress < Borrows < ' b , ' gcx , ' tcx > > ,
1409
+ inits : FlowInProgress < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
1410
+ uninits : FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > )
1407
1411
-> Self {
1408
1412
InProgress {
1409
- borrows : FlowInProgress :: new ( borrows ) ,
1410
- inits : FlowInProgress :: new ( inits ) ,
1411
- uninits : FlowInProgress :: new ( uninits ) ,
1413
+ borrows,
1414
+ inits,
1415
+ uninits,
1412
1416
}
1413
1417
}
1414
1418
@@ -1474,35 +1478,42 @@ impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
1474
1478
}
1475
1479
}
1476
1480
1477
- impl < ' b , ' gcx , ' tcx > FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > {
1478
- fn has_any_child_of ( & self , mpi : MovePathIndex ) -> Option < MovePathIndex > {
1479
- let move_data = self . base_results . operator ( ) . move_data ( ) ;
1480
-
1481
- let mut todo = vec ! [ mpi] ;
1482
- let mut push_siblings = false ; // don't look at siblings of original `mpi`.
1483
- while let Some ( mpi) = todo. pop ( ) {
1484
- if self . curr_state . contains ( & mpi) {
1485
- return Some ( mpi) ;
1486
- }
1487
- let move_path = & move_data. move_paths [ mpi] ;
1488
- if let Some ( child) = move_path. first_child {
1489
- todo. push ( child) ;
1490
- }
1491
- if push_siblings {
1492
- if let Some ( sibling) = move_path. next_sibling {
1493
- todo. push ( sibling) ;
1481
+ macro_rules! has_any_child_of_impl {
1482
+ ( $MaybeTLvals: ident) => {
1483
+ impl <' b, ' gcx, ' tcx> FlowInProgress <$MaybeTLvals<' b, ' gcx, ' tcx>> {
1484
+ fn has_any_child_of( & self , mpi: MovePathIndex ) -> Option <MovePathIndex > {
1485
+ let move_data = self . base_results. operator( ) . move_data( ) ;
1486
+
1487
+ let mut todo = vec![ mpi] ;
1488
+ let mut push_siblings = false ; // don't look at siblings of original `mpi`.
1489
+ while let Some ( mpi) = todo. pop( ) {
1490
+ if self . curr_state. contains( & mpi) {
1491
+ return Some ( mpi) ;
1492
+ }
1493
+ let move_path = & move_data. move_paths[ mpi] ;
1494
+ if let Some ( child) = move_path. first_child {
1495
+ todo. push( child) ;
1496
+ }
1497
+ if push_siblings {
1498
+ if let Some ( sibling) = move_path. next_sibling {
1499
+ todo. push( sibling) ;
1500
+ }
1501
+ } else {
1502
+ // after we've processed the original `mpi`, we should
1503
+ // always traverse the siblings of any of its
1504
+ // children.
1505
+ push_siblings = true ;
1506
+ }
1494
1507
}
1495
- } else {
1496
- // after we've processed the original `mpi`, we should
1497
- // always traverse the siblings of any of its
1498
- // children.
1499
- push_siblings = true ;
1508
+ return None ;
1500
1509
}
1501
1510
}
1502
- return None ;
1503
- }
1511
+ } ;
1504
1512
}
1505
1513
1514
+ has_any_child_of_impl ! ( MaybeInitializedLvals ) ;
1515
+ has_any_child_of_impl ! ( MaybeUninitializedLvals ) ;
1516
+
1506
1517
impl < BD > FlowInProgress < BD > where BD : BitDenotation {
1507
1518
fn each_state_bit < F > ( & self , f : F ) where F : FnMut ( BD :: Idx ) {
1508
1519
self . curr_state . each_bit ( self . base_results . operator ( ) . bits_per_block ( ) , f)
0 commit comments