Skip to content

Commit f53412a

Browse files
committed
remove NLL liveness from polonius constraint generation
1 parent 9f14698 commit f53412a

File tree

3 files changed

+7
-81
lines changed

3 files changed

+7
-81
lines changed

compiler/rustc_borrowck/src/nll.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
159159
);
160160
polonius::emit_cfg_and_loan_kills_facts(
161161
infcx,
162-
&mut liveness_constraints,
163162
&mut all_facts,
164163
location_table,
165164
body,

compiler/rustc_borrowck/src/polonius/constraint_generation.rs

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
use rustc_infer::infer::InferCtxt;
4-
use rustc_middle::mir::visit::TyContext;
54
use rustc_middle::mir::visit::Visitor;
65
use rustc_middle::mir::{
7-
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, SourceInfo, Statement,
8-
StatementKind, Terminator, TerminatorKind, UserTypeProjection,
6+
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind,
7+
Terminator, TerminatorKind, UserTypeProjection,
98
};
10-
use rustc_middle::ty::visit::TypeVisitable;
11-
use rustc_middle::ty::GenericArgsRef;
12-
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
9+
use rustc_middle::ty::{self};
1310

14-
use crate::{
15-
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict,
16-
region_infer::values::LivenessValues,
17-
};
11+
use crate::{borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict};
1812

1913
pub(super) fn generate_constraints<'tcx>(
2014
infcx: &InferCtxt<'tcx>,
21-
liveness_constraints: &mut LivenessValues<RegionVid>,
2215
all_facts: &mut Option<AllFacts>,
2316
location_table: &LocationTable,
2417
body: &Body<'tcx>,
2518
borrow_set: &BorrowSet<'tcx>,
2619
) {
27-
let mut cg = ConstraintGeneration {
28-
borrow_set,
29-
infcx,
30-
liveness_constraints,
31-
location_table,
32-
all_facts,
33-
body,
34-
};
35-
20+
let mut cg = ConstraintGeneration { borrow_set, infcx, location_table, all_facts, body };
3621
for (bb, data) in body.basic_blocks.iter_enumerated() {
3722
cg.visit_basic_block_data(bb, data);
3823
}
@@ -43,44 +28,11 @@ struct ConstraintGeneration<'cg, 'tcx> {
4328
infcx: &'cg InferCtxt<'tcx>,
4429
all_facts: &'cg mut Option<AllFacts>,
4530
location_table: &'cg LocationTable,
46-
liveness_constraints: &'cg mut LivenessValues<RegionVid>,
4731
borrow_set: &'cg BorrowSet<'tcx>,
4832
body: &'cg Body<'tcx>,
4933
}
5034

5135
impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
52-
/// We sometimes have `args` within an rvalue, or within a
53-
/// call. Make them live at the location where they appear.
54-
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
55-
self.add_regular_live_constraint(*args, location);
56-
self.super_args(args);
57-
}
58-
59-
/// We sometimes have `region` within an rvalue, or within a
60-
/// call. Make them live at the location where they appear.
61-
fn visit_region(&mut self, region: ty::Region<'tcx>, location: Location) {
62-
self.add_regular_live_constraint(region, location);
63-
self.super_region(region);
64-
}
65-
66-
/// We sometimes have `ty` within an rvalue, or within a
67-
/// call. Make them live at the location where they appear.
68-
fn visit_ty(&mut self, ty: Ty<'tcx>, ty_context: TyContext) {
69-
match ty_context {
70-
TyContext::ReturnTy(SourceInfo { span, .. })
71-
| TyContext::YieldTy(SourceInfo { span, .. })
72-
| TyContext::UserTy(span)
73-
| TyContext::LocalDecl { source_info: SourceInfo { span, .. }, .. } => {
74-
span_bug!(span, "should not be visiting outside of the CFG: {:?}", ty_context);
75-
}
76-
TyContext::Location(location) => {
77-
self.add_regular_live_constraint(ty, location);
78-
}
79-
}
80-
81-
self.super_ty(ty);
82-
}
83-
8436
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
8537
if let Some(all_facts) = self.all_facts {
8638
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
@@ -155,22 +107,6 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
155107
}
156108

157109
impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
158-
/// Some variable with type `live_ty` is "regular live" at
159-
/// `location` -- i.e., it may be used later. This means that all
160-
/// regions appearing in the type `live_ty` must be live at
161-
/// `location`.
162-
fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
163-
where
164-
T: TypeVisitable<TyCtxt<'tcx>>,
165-
{
166-
debug!("add_regular_live_constraint(live_ty={:?}, location={:?})", live_ty, location);
167-
168-
self.infcx.tcx.for_each_free_region(&live_ty, |live_region| {
169-
let vid = live_region.as_var();
170-
self.liveness_constraints.add_element(vid, location);
171-
});
172-
}
173-
174110
/// When recording facts for Polonius, records the borrows on the specified place
175111
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
176112
fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) {

compiler/rustc_borrowck/src/polonius/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
66
use rustc_infer::infer::InferCtxt;
77
use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
8-
use rustc_middle::ty::{RegionVid, TyCtxt};
8+
use rustc_middle::ty::TyCtxt;
99
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
1010

1111
use crate::borrow_set::BorrowSet;
1212
use crate::facts::AllFacts;
1313
use crate::location::LocationTable;
14-
use crate::region_infer::values::LivenessValues;
1514
use crate::type_check::free_region_relations::UniversalRegionRelations;
1615
use crate::universal_regions::UniversalRegions;
1716

@@ -152,18 +151,10 @@ pub(crate) fn emit_loan_invalidations_facts<'tcx>(
152151
/// Emit facts about CFG points and edges, as well as locations where loans are killed.
153152
pub(crate) fn emit_cfg_and_loan_kills_facts<'tcx>(
154153
infcx: &InferCtxt<'tcx>,
155-
liveness_constraints: &mut LivenessValues<RegionVid>,
156154
all_facts: &mut Option<AllFacts>,
157155
location_table: &LocationTable,
158156
body: &Body<'tcx>,
159157
borrow_set: &BorrowSet<'tcx>,
160158
) {
161-
constraint_generation::generate_constraints(
162-
infcx,
163-
liveness_constraints,
164-
all_facts,
165-
location_table,
166-
body,
167-
borrow_set,
168-
);
159+
constraint_generation::generate_constraints(infcx, all_facts, location_table, body, borrow_set);
169160
}

0 commit comments

Comments
 (0)