Skip to content

Commit caf7300

Browse files
committed
Auto merge of rust-lang#118216 - lqd:constraint-generation-non-non, r=matthewjasper
Refactor NLL constraint generation and most of polonius fact generation As discussed in rust-lang#118175, NLL "constraint generation" is only about liveness, but currently also contains legacy polonius fact generation. The latter is quite messy, and this PR cleans this up to prepare for its future removal: - splits polonius fact generation out of NLL constraint generation - merges NLL constraint generation to its more natural place, liveness - extracts all of the polonius fact generation from NLLs apart from MIR typeck (as fact generation is somewhat in a single place there already, but should be cleaned up) into its own explicit module, with a single entry point instead of many. There should be no behavior changes, and tests seem to behave the same as master: without polonius, with legacy polonius, with the in-tree polonius. I've split everything into smaller logical commits for easier review, as it required quite a bit of code to be split and moved around, but it should all be trivial changes. r? `@matthewjasper`
2 parents 9bf30eb + f969af2 commit caf7300

File tree

7 files changed

+454
-432
lines changed

7 files changed

+454
-432
lines changed

compiler/rustc_borrowck/src/constraint_generation.rs

-248
This file was deleted.

compiler/rustc_borrowck/src/lib.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@ use self::path_utils::*;
6565

6666
pub mod borrow_set;
6767
mod borrowck_errors;
68-
mod constraint_generation;
6968
mod constraints;
7069
mod dataflow;
7170
mod def_use;
7271
mod diagnostics;
7372
mod facts;
74-
mod invalidation;
7573
mod location;
7674
mod member_constraints;
7775
mod nll;
7876
mod path_utils;
7977
mod place_ext;
8078
mod places_conflict;
79+
mod polonius;
8180
mod prefixes;
8281
mod region_infer;
8382
mod renumber;
@@ -195,8 +194,7 @@ fn do_mir_borrowck<'tcx>(
195194
nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted);
196195
let body = &body_owned; // no further changes
197196

198-
let location_table_owned = LocationTable::new(body);
199-
let location_table = &location_table_owned;
197+
let location_table = LocationTable::new(body);
200198

201199
let move_data = MoveData::gather_moves(body, tcx, param_env, |_| true);
202200
let promoted_move_data = promoted
@@ -228,7 +226,7 @@ fn do_mir_borrowck<'tcx>(
228226
free_regions,
229227
body,
230228
&promoted,
231-
location_table,
229+
&location_table,
232230
param_env,
233231
&mut flow_inits,
234232
&mdpe.move_data,
@@ -292,7 +290,7 @@ fn do_mir_borrowck<'tcx>(
292290
param_env,
293291
body: promoted_body,
294292
move_data: &move_data,
295-
location_table, // no need to create a real one for the promoted, it is not used
293+
location_table: &location_table, // no need to create a real one for the promoted, it is not used
296294
movable_coroutine,
297295
fn_self_span_reported: Default::default(),
298296
locals_are_invalidated_at_exit,
@@ -333,7 +331,7 @@ fn do_mir_borrowck<'tcx>(
333331
param_env,
334332
body,
335333
move_data: &mdpe.move_data,
336-
location_table,
334+
location_table: &location_table,
337335
movable_coroutine,
338336
locals_are_invalidated_at_exit,
339337
fn_self_span_reported: Default::default(),
@@ -435,7 +433,7 @@ fn do_mir_borrowck<'tcx>(
435433
promoted,
436434
borrow_set,
437435
region_inference_context: regioncx,
438-
location_table: polonius_input.as_ref().map(|_| location_table_owned),
436+
location_table: polonius_input.as_ref().map(|_| location_table),
439437
input_facts: polonius_input,
440438
output_facts,
441439
}))
@@ -1020,9 +1018,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10201018
flow_state: &Flows<'cx, 'tcx>,
10211019
) -> bool {
10221020
let mut error_reported = false;
1023-
let tcx = self.infcx.tcx;
1024-
let body = self.body;
1025-
let borrow_set = self.borrow_set.clone();
1021+
let borrow_set = Rc::clone(&self.borrow_set);
10261022

10271023
// Use polonius output if it has been enabled.
10281024
let mut polonius_output;
@@ -1039,8 +1035,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10391035

10401036
each_borrow_involving_path(
10411037
self,
1042-
tcx,
1043-
body,
1038+
self.infcx.tcx,
1039+
self.body,
10441040
location,
10451041
(sd, place_span.0),
10461042
&borrow_set,

0 commit comments

Comments
 (0)