NLL: Adapt to the new Polonius types
This commit is contained in:
parent
2adb246b5c
commit
996ba932cc
4 changed files with 24 additions and 14 deletions
|
@ -12,7 +12,7 @@ use crate::borrow_check::location::LocationIndex;
|
||||||
use polonius_engine::Output;
|
use polonius_engine::Output;
|
||||||
|
|
||||||
use crate::dataflow::indexes::BorrowIndex;
|
use crate::dataflow::indexes::BorrowIndex;
|
||||||
use crate::dataflow::move_paths::HasMoveData;
|
use crate::dataflow::move_paths::{HasMoveData, MovePathIndex};
|
||||||
use crate::dataflow::Borrows;
|
use crate::dataflow::Borrows;
|
||||||
use crate::dataflow::EverInitializedPlaces;
|
use crate::dataflow::EverInitializedPlaces;
|
||||||
use crate::dataflow::MaybeUninitializedPlaces;
|
use crate::dataflow::MaybeUninitializedPlaces;
|
||||||
|
@ -21,7 +21,7 @@ use either::Either;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
crate type PoloniusOutput = Output<RegionVid, BorrowIndex, LocationIndex, Local>;
|
crate type PoloniusOutput = Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>;
|
||||||
|
|
||||||
// (forced to be `pub` due to its use as an associated type below.)
|
// (forced to be `pub` due to its use as an associated type below.)
|
||||||
crate struct Flows<'b, 'tcx> {
|
crate struct Flows<'b, 'tcx> {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::borrow_check::location::{LocationIndex, LocationTable};
|
use crate::borrow_check::location::{LocationIndex, LocationTable};
|
||||||
use crate::dataflow::indexes::BorrowIndex;
|
use crate::dataflow::indexes::{BorrowIndex, MovePathIndex};
|
||||||
use polonius_engine::AllFacts as PoloniusAllFacts;
|
use polonius_engine::AllFacts as PoloniusAllFacts;
|
||||||
use polonius_engine::Atom;
|
use polonius_engine::Atom;
|
||||||
use rustc::mir::Local;
|
use rustc::mir::Local;
|
||||||
|
@ -11,7 +11,7 @@ use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex, Local>;
|
crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>;
|
||||||
|
|
||||||
crate trait AllFactsExt {
|
crate trait AllFactsExt {
|
||||||
/// Returns `true` if there is a need to gather `AllFacts` given the
|
/// Returns `true` if there is a need to gather `AllFacts` given the
|
||||||
|
@ -65,7 +65,11 @@ impl AllFactsExt for AllFacts {
|
||||||
var_drop_used,
|
var_drop_used,
|
||||||
var_uses_region,
|
var_uses_region,
|
||||||
var_drops_region,
|
var_drops_region,
|
||||||
var_initialized_on_exit,
|
var_maybe_initialized_on_exit,
|
||||||
|
parent,
|
||||||
|
var_starts_path,
|
||||||
|
initialized_at,
|
||||||
|
moved_out_at,
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -84,6 +88,12 @@ impl Atom for LocationIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Atom for MovePathIndex {
|
||||||
|
fn index(self) -> usize {
|
||||||
|
Idx::index(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct FactWriter<'w> {
|
struct FactWriter<'w> {
|
||||||
location_table: &'w LocationTable,
|
location_table: &'w LocationTable,
|
||||||
dir: &'w Path,
|
dir: &'w Path,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::borrow_check::nll::facts::AllFactsExt;
|
||||||
use crate::borrow_check::nll::type_check::{MirTypeckResults, MirTypeckRegionConstraints};
|
use crate::borrow_check::nll::type_check::{MirTypeckResults, MirTypeckRegionConstraints};
|
||||||
use crate::borrow_check::nll::region_infer::values::RegionValueElements;
|
use crate::borrow_check::nll::region_infer::values::RegionValueElements;
|
||||||
use crate::dataflow::indexes::BorrowIndex;
|
use crate::dataflow::indexes::BorrowIndex;
|
||||||
use crate::dataflow::move_paths::MoveData;
|
use crate::dataflow::move_paths::{MoveData, MovePathIndex};
|
||||||
use crate::dataflow::FlowAtLocation;
|
use crate::dataflow::FlowAtLocation;
|
||||||
use crate::dataflow::MaybeInitializedPlaces;
|
use crate::dataflow::MaybeInitializedPlaces;
|
||||||
use crate::transform::MirSource;
|
use crate::transform::MirSource;
|
||||||
|
@ -87,7 +87,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
|
||||||
errors_buffer: &mut Vec<Diagnostic>,
|
errors_buffer: &mut Vec<Diagnostic>,
|
||||||
) -> (
|
) -> (
|
||||||
RegionInferenceContext<'tcx>,
|
RegionInferenceContext<'tcx>,
|
||||||
Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local>>>,
|
Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>>>,
|
||||||
Option<ClosureRegionRequirements<'tcx>>,
|
Option<ClosureRegionRequirements<'tcx>>,
|
||||||
) {
|
) {
|
||||||
let mut all_facts = if AllFacts::enabled(infcx.tcx) {
|
let mut all_facts = if AllFacts::enabled(infcx.tcx) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
|
||||||
// FIXME: this is temporary until we can generate our own initialization
|
// FIXME: this is temporary until we can generate our own initialization
|
||||||
if self.cx.typeck.borrowck_context.all_facts.is_some() {
|
if self.cx.typeck.borrowck_context.all_facts.is_some() {
|
||||||
self.add_polonius_var_initialized_on_exit_for(local)
|
self.add_polonius_var_maybe_initialized_on_exit_for(local)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compute_use_live_points_for(local);
|
self.compute_use_live_points_for(local);
|
||||||
|
@ -161,14 +161,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
//
|
//
|
||||||
// FIXME: this analysis (the initialization tracking) should be
|
// FIXME: this analysis (the initialization tracking) should be
|
||||||
// done in Polonius, but isn't yet.
|
// done in Polonius, but isn't yet.
|
||||||
fn add_polonius_var_initialized_on_exit_for(&mut self, local: Local) {
|
fn add_polonius_var_maybe_initialized_on_exit_for(&mut self, local: Local) {
|
||||||
let move_path = self.cx.move_data.rev_lookup.find_local(local);
|
let move_path = self.cx.move_data.rev_lookup.find_local(local);
|
||||||
let facts = self.cx.typeck.borrowck_context.all_facts.as_mut().unwrap();
|
let facts = self.cx.typeck.borrowck_context.all_facts.as_mut().unwrap();
|
||||||
for block in self.cx.body.basic_blocks().indices() {
|
for block in self.cx.body.basic_blocks().indices() {
|
||||||
debug!("polonius: generating initialization facts for {:?} in {:?}", local, block);
|
debug!("polonius: generating initialization facts for {:?} in {:?}", local, block);
|
||||||
|
|
||||||
// iterate through the block, applying the effects of each statement
|
// iterate through the block, applying the effects of each statement
|
||||||
// up to and including location, and populate `var_initialized_on_exit`
|
// up to and including location, and populate `var_maybe_initialized_on_exit`
|
||||||
self.cx.flow_inits.reset_to_entry_of(block);
|
self.cx.flow_inits.reset_to_entry_of(block);
|
||||||
let start_location = Location { block, statement_index: 0 };
|
let start_location = Location { block, statement_index: 0 };
|
||||||
self.cx.flow_inits.apply_local_effect(start_location);
|
self.cx.flow_inits.apply_local_effect(start_location);
|
||||||
|
@ -181,7 +181,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
// statement has not yet taken effect:
|
// statement has not yet taken effect:
|
||||||
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
||||||
facts
|
facts
|
||||||
.var_initialized_on_exit
|
.var_maybe_initialized_on_exit
|
||||||
.push((local, self.cx.location_table.start_index(current_location)));
|
.push((local, self.cx.location_table.start_index(current_location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
|
||||||
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
||||||
facts
|
facts
|
||||||
.var_initialized_on_exit
|
.var_maybe_initialized_on_exit
|
||||||
.push((local, self.cx.location_table.mid_index(current_location)));
|
.push((local, self.cx.location_table.mid_index(current_location)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
|
||||||
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
||||||
facts
|
facts
|
||||||
.var_initialized_on_exit
|
.var_maybe_initialized_on_exit
|
||||||
.push((local, self.cx.location_table.start_index(terminator_location)));
|
.push((local, self.cx.location_table.start_index(terminator_location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
|
||||||
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
|
||||||
facts
|
facts
|
||||||
.var_initialized_on_exit
|
.var_maybe_initialized_on_exit
|
||||||
.push((local, self.cx.location_table.mid_index(terminator_location)));
|
.push((local, self.cx.location_table.mid_index(terminator_location)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue