@@ -18,7 +18,6 @@ use rustc::ty::maps::Providers;
1818use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Local , Location , Lvalue } ;
1919use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
2020use rustc:: mir:: { Field , Statement , StatementKind , Terminator , TerminatorKind } ;
21- use transform:: nll;
2221
2322use rustc_data_structures:: fx:: FxHashSet ;
2423use rustc_data_structures:: indexed_set:: { self , IdxSetBuf } ;
@@ -40,6 +39,7 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
4039use self :: MutateMode :: { JustWrite , WriteAndRead } ;
4140use self :: ConsumeKind :: Consume ;
4241
42+ pub ( crate ) mod nll;
4343
4444pub fn provide ( providers : & mut Providers ) {
4545 * providers = Providers {
@@ -78,7 +78,21 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
7878 . as_local_node_id ( def_id)
7979 . expect ( "do_mir_borrowck: non-local DefId" ) ;
8080
81- let move_data: MoveData < ' tcx > = match MoveData :: gather_moves ( input_mir, tcx, param_env) {
81+ // Make our own copy of the MIR. This copy will be modified (in place) to
82+ // contain non-lexical lifetimes. It will have a lifetime tied
83+ // to the inference context.
84+ let mut mir: Mir < ' tcx > = input_mir. clone ( ) ;
85+ let free_regions = if !tcx. sess . opts . debugging_opts . nll {
86+ None
87+ } else {
88+ let mir = & mut mir;
89+
90+ // Replace all regions with fresh inference variables.
91+ Some ( nll:: replace_regions_in_mir ( infcx, def_id, mir) )
92+ } ;
93+ let mir = & mir;
94+
95+ let move_data: MoveData < ' tcx > = match MoveData :: gather_moves ( mir, tcx, param_env) {
8296 Ok ( move_data) => move_data,
8397 Err ( ( move_data, move_errors) ) => {
8498 for move_error in move_errors {
@@ -111,60 +125,55 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
111125 }
112126 } ;
113127
114- // Make our own copy of the MIR. This copy will be modified (in place) to
115- // contain non-lexical lifetimes. It will have a lifetime tied
116- // to the inference context.
117- let mut mir: Mir < ' tcx > = input_mir. clone ( ) ;
118- let mir = & mut mir;
119-
120- // If we are in non-lexical mode, compute the non-lexical lifetimes.
121- let opt_regioncx = if !tcx. sess . opts . debugging_opts . nll {
122- None
123- } else {
124- Some ( nll:: compute_regions ( infcx, def_id, param_env, mir) )
125- } ;
126-
127128 let mdpe = MoveDataParamEnv {
128129 move_data : move_data,
129130 param_env : param_env,
130131 } ;
131132 let dead_unwinds = IdxSetBuf :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
132- let flow_borrows = do_dataflow (
133- tcx,
134- mir,
135- id,
136- & attributes,
137- & dead_unwinds,
138- Borrows :: new ( tcx, mir, opt_regioncx. as_ref ( ) ) ,
139- |bd, i| bd. location ( i) ,
140- ) ;
141- let flow_inits = do_dataflow (
133+ let mut flow_inits = FlowInProgress :: new ( do_dataflow (
142134 tcx,
143135 mir,
144136 id,
145137 & attributes,
146138 & dead_unwinds,
147139 MaybeInitializedLvals :: new ( tcx, mir, & mdpe) ,
148140 |bd, i| & bd. move_data ( ) . move_paths [ i] ,
149- ) ;
150- let flow_uninits = do_dataflow (
141+ ) ) ;
142+ let flow_uninits = FlowInProgress :: new ( do_dataflow (
151143 tcx,
152144 mir,
153145 id,
154146 & attributes,
155147 & dead_unwinds,
156148 MaybeUninitializedLvals :: new ( tcx, mir, & mdpe) ,
157149 |bd, i| & bd. move_data ( ) . move_paths [ i] ,
158- ) ;
159- let flow_move_outs = do_dataflow (
150+ ) ) ;
151+ let flow_move_outs = FlowInProgress :: new ( do_dataflow (
160152 tcx,
161153 mir,
162154 id,
163155 & attributes,
164156 & dead_unwinds,
165157 MovingOutStatements :: new ( tcx, mir, & mdpe) ,
166158 |bd, i| & bd. move_data ( ) . moves [ i] ,
167- ) ;
159+ ) ) ;
160+
161+ // If we are in non-lexical mode, compute the non-lexical lifetimes.
162+ let opt_regioncx = if let Some ( free_regions) = free_regions {
163+ Some ( nll:: compute_regions (
164+ infcx,
165+ def_id,
166+ free_regions,
167+ mir,
168+ param_env,
169+ & mut flow_inits,
170+ & mdpe. move_data ,
171+ ) )
172+ } else {
173+ assert ! ( !tcx. sess. opts. debugging_opts. nll) ;
174+ None
175+ } ;
176+ let flow_inits = flow_inits; // remove mut
168177
169178 let mut mbcx = MirBorrowckCtxt {
170179 tcx : tcx,
@@ -175,6 +184,16 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
175184 storage_drop_or_dead_error_reported : FxHashSet ( ) ,
176185 } ;
177186
187+ let flow_borrows = FlowInProgress :: new ( do_dataflow (
188+ tcx,
189+ mir,
190+ id,
191+ & attributes,
192+ & dead_unwinds,
193+ Borrows :: new ( tcx, mir, opt_regioncx) ,
194+ |bd, i| bd. location ( i) ,
195+ ) ) ;
196+
178197 let mut state = InProgress :: new ( flow_borrows, flow_inits, flow_uninits, flow_move_outs) ;
179198
180199 mbcx. analyze_results ( & mut state) ; // entry point for DataflowResultsConsumer
@@ -2160,17 +2179,17 @@ impl ContextKind {
21602179}
21612180
21622181impl < ' b , ' gcx , ' tcx > InProgress < ' b , ' gcx , ' tcx > {
2163- pub ( super ) fn new (
2164- borrows : DataflowResults < Borrows < ' b , ' gcx , ' tcx > > ,
2165- inits : DataflowResults < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
2166- uninits : DataflowResults < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > ,
2167- move_out : DataflowResults < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
2182+ fn new (
2183+ borrows : FlowInProgress < Borrows < ' b , ' gcx , ' tcx > > ,
2184+ inits : FlowInProgress < MaybeInitializedLvals < ' b , ' gcx , ' tcx > > ,
2185+ uninits : FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > ,
2186+ move_outs : FlowInProgress < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
21682187 ) -> Self {
21692188 InProgress {
2170- borrows : FlowInProgress :: new ( borrows ) ,
2171- inits : FlowInProgress :: new ( inits ) ,
2172- uninits : FlowInProgress :: new ( uninits ) ,
2173- move_outs : FlowInProgress :: new ( move_out ) ,
2189+ borrows,
2190+ inits,
2191+ uninits,
2192+ move_outs,
21742193 }
21752194 }
21762195
@@ -2260,8 +2279,11 @@ impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
22602279 }
22612280}
22622281
2263- impl < ' b , ' gcx , ' tcx > FlowInProgress < MaybeUninitializedLvals < ' b , ' gcx , ' tcx > > {
2264- fn has_any_child_of ( & self , mpi : MovePathIndex ) -> Option < MovePathIndex > {
2282+ impl < ' tcx , T > FlowInProgress < T >
2283+ where
2284+ T : HasMoveData < ' tcx > + BitDenotation < Idx = MovePathIndex > ,
2285+ {
2286+ fn has_any_child_of ( & self , mpi : T :: Idx ) -> Option < T :: Idx > {
22652287 let move_data = self . base_results . operator ( ) . move_data ( ) ;
22662288
22672289 let mut todo = vec ! [ mpi] ;
0 commit comments