@@ -18,7 +18,6 @@ use rustc::ty::maps::Providers;
18
18
use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Local , Location , Lvalue } ;
19
19
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
20
20
use rustc:: mir:: { Statement , StatementKind , Terminator , TerminatorKind } ;
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 ;
@@ -39,6 +38,7 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
39
38
use self :: MutateMode :: { JustWrite , WriteAndRead } ;
40
39
use self :: ConsumeKind :: Consume ;
41
40
41
+ pub ( crate ) mod nll;
42
42
43
43
pub fn provide ( providers : & mut Providers ) {
44
44
* providers = Providers {
@@ -77,7 +77,21 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
77
77
. as_local_node_id ( def_id)
78
78
. expect ( "do_mir_borrowck: non-local DefId" ) ;
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 free_regions = if !tcx. sess . opts . debugging_opts . nll {
85
+ None
86
+ } else {
87
+ let mir = & mut mir;
88
+
89
+ // Replace all regions with fresh inference variables.
90
+ Some ( nll:: replace_regions_in_mir ( infcx, def_id, mir) )
91
+ } ;
92
+ let mir = & mir;
93
+
94
+ let move_data: MoveData < ' tcx > = match MoveData :: gather_moves ( mir, tcx, param_env) {
81
95
Ok ( move_data) => move_data,
82
96
Err ( ( move_data, move_errors) ) => {
83
97
for move_error in move_errors {
@@ -110,60 +124,55 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
110
124
}
111
125
} ;
112
126
113
- // Make our own copy of the MIR. This copy will be modified (in place) to
114
- // contain non-lexical lifetimes. It will have a lifetime tied
115
- // to the inference context.
116
- let mut mir: Mir < ' tcx > = input_mir. clone ( ) ;
117
- let mir = & mut mir;
118
-
119
- // If we are in non-lexical mode, compute the non-lexical lifetimes.
120
- let opt_regioncx = if !tcx. sess . opts . debugging_opts . nll {
121
- None
122
- } else {
123
- Some ( nll:: compute_regions ( infcx, def_id, param_env, mir) )
124
- } ;
125
-
126
127
let mdpe = MoveDataParamEnv {
127
128
move_data : move_data,
128
129
param_env : param_env,
129
130
} ;
130
131
let dead_unwinds = IdxSetBuf :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
131
- let flow_borrows = do_dataflow (
132
- tcx,
133
- mir,
134
- id,
135
- & attributes,
136
- & dead_unwinds,
137
- Borrows :: new ( tcx, mir, opt_regioncx. as_ref ( ) ) ,
138
- |bd, i| bd. location ( i) ,
139
- ) ;
140
- let flow_inits = do_dataflow (
132
+ let mut flow_inits = FlowInProgress :: new ( do_dataflow (
141
133
tcx,
142
134
mir,
143
135
id,
144
136
& attributes,
145
137
& dead_unwinds,
146
138
MaybeInitializedLvals :: new ( tcx, mir, & mdpe) ,
147
139
|bd, i| & bd. move_data ( ) . move_paths [ i] ,
148
- ) ;
149
- let flow_uninits = do_dataflow (
140
+ ) ) ;
141
+ let flow_uninits = FlowInProgress :: new ( do_dataflow (
150
142
tcx,
151
143
mir,
152
144
id,
153
145
& attributes,
154
146
& dead_unwinds,
155
147
MaybeUninitializedLvals :: new ( tcx, mir, & mdpe) ,
156
148
|bd, i| & bd. move_data ( ) . move_paths [ i] ,
157
- ) ;
158
- let flow_move_outs = do_dataflow (
149
+ ) ) ;
150
+ let flow_move_outs = FlowInProgress :: new ( do_dataflow (
159
151
tcx,
160
152
mir,
161
153
id,
162
154
& attributes,
163
155
& dead_unwinds,
164
156
MovingOutStatements :: new ( tcx, mir, & mdpe) ,
165
157
|bd, i| & bd. move_data ( ) . moves [ i] ,
166
- ) ;
158
+ ) ) ;
159
+
160
+ // If we are in non-lexical mode, compute the non-lexical lifetimes.
161
+ let opt_regioncx = if let Some ( free_regions) = free_regions {
162
+ Some ( nll:: compute_regions (
163
+ infcx,
164
+ def_id,
165
+ free_regions,
166
+ mir,
167
+ param_env,
168
+ & mut flow_inits,
169
+ & mdpe. move_data ,
170
+ ) )
171
+ } else {
172
+ assert ! ( !tcx. sess. opts. debugging_opts. nll) ;
173
+ None
174
+ } ;
175
+ let flow_inits = flow_inits; // remove mut
167
176
168
177
let mut mbcx = MirBorrowckCtxt {
169
178
tcx : tcx,
@@ -173,6 +182,16 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
173
182
param_env : param_env,
174
183
} ;
175
184
185
+ let flow_borrows = FlowInProgress :: new ( do_dataflow (
186
+ tcx,
187
+ mir,
188
+ id,
189
+ & attributes,
190
+ & dead_unwinds,
191
+ Borrows :: new ( tcx, mir, opt_regioncx) ,
192
+ |bd, i| bd. location ( i) ,
193
+ ) ) ;
194
+
176
195
let mut state = InProgress :: new ( flow_borrows, flow_inits, flow_uninits, flow_move_outs) ;
177
196
178
197
mbcx. analyze_results ( & mut state) ; // entry point for DataflowResultsConsumer
@@ -2018,17 +2037,17 @@ impl ContextKind {
2018
2037
}
2019
2038
2020
2039
impl < ' b , ' gcx , ' tcx > InProgress < ' b , ' gcx , ' tcx > {
2021
- pub ( super ) fn new (
2022
- borrows : DataflowResults < Borrows < ' b , ' gcx , ' tcx > > ,
2023
- inits : DataflowResults < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
2024
- uninits : DataflowResults < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > ,
2025
- move_out : DataflowResults < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
2040
+ fn new (
2041
+ borrows : FlowInProgress < Borrows < ' b , ' gcx , ' tcx > > ,
2042
+ inits : FlowInProgress < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
2043
+ uninits : FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > ,
2044
+ move_outs : FlowInProgress < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
2026
2045
) -> Self {
2027
2046
InProgress {
2028
- borrows : FlowInProgress :: new ( borrows ) ,
2029
- inits : FlowInProgress :: new ( inits ) ,
2030
- uninits : FlowInProgress :: new ( uninits ) ,
2031
- move_outs : FlowInProgress :: new ( move_out ) ,
2047
+ borrows,
2048
+ inits,
2049
+ uninits,
2050
+ move_outs,
2032
2051
}
2033
2052
}
2034
2053
@@ -2118,8 +2137,11 @@ impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
2118
2137
}
2119
2138
}
2120
2139
2121
- impl < ' b , ' gcx , ' tcx > FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > {
2122
- fn has_any_child_of ( & self , mpi : MovePathIndex ) -> Option < MovePathIndex > {
2140
+ impl < ' tcx , T > FlowInProgress < T >
2141
+ where
2142
+ T : HasMoveData < ' tcx > + BitDenotation < Idx = MovePathIndex > ,
2143
+ {
2144
+ fn has_any_child_of ( & self , mpi : T :: Idx ) -> Option < T :: Idx > {
2123
2145
let move_data = self . base_results . operator ( ) . move_data ( ) ;
2124
2146
2125
2147
let mut todo = vec ! [ mpi] ;
0 commit comments