remove NLL liveness from polonius constraint generation
This commit is contained in:
parent
9f14698680
commit
f53412ab7c
@ -159,7 +159,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
|||||||
);
|
);
|
||||||
polonius::emit_cfg_and_loan_kills_facts(
|
polonius::emit_cfg_and_loan_kills_facts(
|
||||||
infcx,
|
infcx,
|
||||||
&mut liveness_constraints,
|
|
||||||
&mut all_facts,
|
&mut all_facts,
|
||||||
location_table,
|
location_table,
|
||||||
body,
|
body,
|
||||||
|
@ -1,38 +1,23 @@
|
|||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::visit::TyContext;
|
|
||||||
use rustc_middle::mir::visit::Visitor;
|
use rustc_middle::mir::visit::Visitor;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, SourceInfo, Statement,
|
Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind,
|
||||||
StatementKind, Terminator, TerminatorKind, UserTypeProjection,
|
Terminator, TerminatorKind, UserTypeProjection,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::visit::TypeVisitable;
|
use rustc_middle::ty::{self};
|
||||||
use rustc_middle::ty::GenericArgsRef;
|
|
||||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict};
|
||||||
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict,
|
|
||||||
region_infer::values::LivenessValues,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(super) fn generate_constraints<'tcx>(
|
pub(super) fn generate_constraints<'tcx>(
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
liveness_constraints: &mut LivenessValues<RegionVid>,
|
|
||||||
all_facts: &mut Option<AllFacts>,
|
all_facts: &mut Option<AllFacts>,
|
||||||
location_table: &LocationTable,
|
location_table: &LocationTable,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
borrow_set: &BorrowSet<'tcx>,
|
borrow_set: &BorrowSet<'tcx>,
|
||||||
) {
|
) {
|
||||||
let mut cg = ConstraintGeneration {
|
let mut cg = ConstraintGeneration { borrow_set, infcx, location_table, all_facts, body };
|
||||||
borrow_set,
|
|
||||||
infcx,
|
|
||||||
liveness_constraints,
|
|
||||||
location_table,
|
|
||||||
all_facts,
|
|
||||||
body,
|
|
||||||
};
|
|
||||||
|
|
||||||
for (bb, data) in body.basic_blocks.iter_enumerated() {
|
for (bb, data) in body.basic_blocks.iter_enumerated() {
|
||||||
cg.visit_basic_block_data(bb, data);
|
cg.visit_basic_block_data(bb, data);
|
||||||
}
|
}
|
||||||
@ -43,44 +28,11 @@ struct ConstraintGeneration<'cg, 'tcx> {
|
|||||||
infcx: &'cg InferCtxt<'tcx>,
|
infcx: &'cg InferCtxt<'tcx>,
|
||||||
all_facts: &'cg mut Option<AllFacts>,
|
all_facts: &'cg mut Option<AllFacts>,
|
||||||
location_table: &'cg LocationTable,
|
location_table: &'cg LocationTable,
|
||||||
liveness_constraints: &'cg mut LivenessValues<RegionVid>,
|
|
||||||
borrow_set: &'cg BorrowSet<'tcx>,
|
borrow_set: &'cg BorrowSet<'tcx>,
|
||||||
body: &'cg Body<'tcx>,
|
body: &'cg Body<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
|
impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
|
||||||
/// We sometimes have `args` within an rvalue, or within a
|
|
||||||
/// call. Make them live at the location where they appear.
|
|
||||||
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
|
|
||||||
self.add_regular_live_constraint(*args, location);
|
|
||||||
self.super_args(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// We sometimes have `region` within an rvalue, or within a
|
|
||||||
/// call. Make them live at the location where they appear.
|
|
||||||
fn visit_region(&mut self, region: ty::Region<'tcx>, location: Location) {
|
|
||||||
self.add_regular_live_constraint(region, location);
|
|
||||||
self.super_region(region);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// We sometimes have `ty` within an rvalue, or within a
|
|
||||||
/// call. Make them live at the location where they appear.
|
|
||||||
fn visit_ty(&mut self, ty: Ty<'tcx>, ty_context: TyContext) {
|
|
||||||
match ty_context {
|
|
||||||
TyContext::ReturnTy(SourceInfo { span, .. })
|
|
||||||
| TyContext::YieldTy(SourceInfo { span, .. })
|
|
||||||
| TyContext::UserTy(span)
|
|
||||||
| TyContext::LocalDecl { source_info: SourceInfo { span, .. }, .. } => {
|
|
||||||
span_bug!(span, "should not be visiting outside of the CFG: {:?}", ty_context);
|
|
||||||
}
|
|
||||||
TyContext::Location(location) => {
|
|
||||||
self.add_regular_live_constraint(ty, location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.super_ty(ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||||
if let Some(all_facts) = self.all_facts {
|
if let Some(all_facts) = self.all_facts {
|
||||||
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
|
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
|
||||||
@ -155,22 +107,6 @@ fn visit_ascribe_user_ty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
|
impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
|
||||||
/// Some variable with type `live_ty` is "regular live" at
|
|
||||||
/// `location` -- i.e., it may be used later. This means that all
|
|
||||||
/// regions appearing in the type `live_ty` must be live at
|
|
||||||
/// `location`.
|
|
||||||
fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
|
|
||||||
where
|
|
||||||
T: TypeVisitable<TyCtxt<'tcx>>,
|
|
||||||
{
|
|
||||||
debug!("add_regular_live_constraint(live_ty={:?}, location={:?})", live_ty, location);
|
|
||||||
|
|
||||||
self.infcx.tcx.for_each_free_region(&live_ty, |live_region| {
|
|
||||||
let vid = live_region.as_var();
|
|
||||||
self.liveness_constraints.add_element(vid, location);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When recording facts for Polonius, records the borrows on the specified place
|
/// When recording facts for Polonius, records the borrows on the specified place
|
||||||
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
|
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
|
||||||
fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) {
|
fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) {
|
||||||
|
@ -5,13 +5,12 @@
|
|||||||
|
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
|
use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
|
||||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
|
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
|
||||||
|
|
||||||
use crate::borrow_set::BorrowSet;
|
use crate::borrow_set::BorrowSet;
|
||||||
use crate::facts::AllFacts;
|
use crate::facts::AllFacts;
|
||||||
use crate::location::LocationTable;
|
use crate::location::LocationTable;
|
||||||
use crate::region_infer::values::LivenessValues;
|
|
||||||
use crate::type_check::free_region_relations::UniversalRegionRelations;
|
use crate::type_check::free_region_relations::UniversalRegionRelations;
|
||||||
use crate::universal_regions::UniversalRegions;
|
use crate::universal_regions::UniversalRegions;
|
||||||
|
|
||||||
@ -152,18 +151,10 @@ pub(crate) fn emit_loan_invalidations_facts<'tcx>(
|
|||||||
/// Emit facts about CFG points and edges, as well as locations where loans are killed.
|
/// Emit facts about CFG points and edges, as well as locations where loans are killed.
|
||||||
pub(crate) fn emit_cfg_and_loan_kills_facts<'tcx>(
|
pub(crate) fn emit_cfg_and_loan_kills_facts<'tcx>(
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
liveness_constraints: &mut LivenessValues<RegionVid>,
|
|
||||||
all_facts: &mut Option<AllFacts>,
|
all_facts: &mut Option<AllFacts>,
|
||||||
location_table: &LocationTable,
|
location_table: &LocationTable,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
borrow_set: &BorrowSet<'tcx>,
|
borrow_set: &BorrowSet<'tcx>,
|
||||||
) {
|
) {
|
||||||
constraint_generation::generate_constraints(
|
constraint_generation::generate_constraints(infcx, all_facts, location_table, body, borrow_set);
|
||||||
infcx,
|
|
||||||
liveness_constraints,
|
|
||||||
all_facts,
|
|
||||||
location_table,
|
|
||||||
body,
|
|
||||||
borrow_set,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user