Skip to content

Commit 996ba93

Browse files
author
Albin Stjerna
committed
NLL: Adapt to the new Polonius types
1 parent 2adb246 commit 996ba93

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/librustc_mir/borrow_check/flows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::borrow_check::location::LocationIndex;
1212
use polonius_engine::Output;
1313

1414
use crate::dataflow::indexes::BorrowIndex;
15-
use crate::dataflow::move_paths::HasMoveData;
15+
use crate::dataflow::move_paths::{HasMoveData, MovePathIndex};
1616
use crate::dataflow::Borrows;
1717
use crate::dataflow::EverInitializedPlaces;
1818
use crate::dataflow::MaybeUninitializedPlaces;
@@ -21,7 +21,7 @@ use either::Either;
2121
use std::fmt;
2222
use std::rc::Rc;
2323

24-
crate type PoloniusOutput = Output<RegionVid, BorrowIndex, LocationIndex, Local>;
24+
crate type PoloniusOutput = Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>;
2525

2626
// (forced to be `pub` due to its use as an associated type below.)
2727
crate struct Flows<'b, 'tcx> {

src/librustc_mir/borrow_check/nll/facts.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::borrow_check::location::{LocationIndex, LocationTable};
2-
use crate::dataflow::indexes::BorrowIndex;
2+
use crate::dataflow::indexes::{BorrowIndex, MovePathIndex};
33
use polonius_engine::AllFacts as PoloniusAllFacts;
44
use polonius_engine::Atom;
55
use rustc::mir::Local;
@@ -11,7 +11,7 @@ use std::fs::{self, File};
1111
use std::io::Write;
1212
use std::path::Path;
1313

14-
crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex, Local>;
14+
crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>;
1515

1616
crate trait AllFactsExt {
1717
/// Returns `true` if there is a need to gather `AllFacts` given the
@@ -65,7 +65,11 @@ impl AllFactsExt for AllFacts {
6565
var_drop_used,
6666
var_uses_region,
6767
var_drops_region,
68-
var_initialized_on_exit,
68+
var_maybe_initialized_on_exit,
69+
parent,
70+
var_starts_path,
71+
initialized_at,
72+
moved_out_at,
6973
])
7074
}
7175
Ok(())
@@ -84,6 +88,12 @@ impl Atom for LocationIndex {
8488
}
8589
}
8690

91+
impl Atom for MovePathIndex {
92+
fn index(self) -> usize {
93+
Idx::index(self)
94+
}
95+
}
96+
8797
struct FactWriter<'w> {
8898
location_table: &'w LocationTable,
8999
dir: &'w Path,

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::borrow_check::nll::facts::AllFactsExt;
44
use crate::borrow_check::nll::type_check::{MirTypeckResults, MirTypeckRegionConstraints};
55
use crate::borrow_check::nll::region_infer::values::RegionValueElements;
66
use crate::dataflow::indexes::BorrowIndex;
7-
use crate::dataflow::move_paths::MoveData;
7+
use crate::dataflow::move_paths::{MoveData, MovePathIndex};
88
use crate::dataflow::FlowAtLocation;
99
use crate::dataflow::MaybeInitializedPlaces;
1010
use crate::transform::MirSource;
@@ -87,7 +87,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
8787
errors_buffer: &mut Vec<Diagnostic>,
8888
) -> (
8989
RegionInferenceContext<'tcx>,
90-
Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local>>>,
90+
Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>>>,
9191
Option<ClosureRegionRequirements<'tcx>>,
9292
) {
9393
let mut all_facts = if AllFacts::enabled(infcx.tcx) {

src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
134134

135135
// FIXME: this is temporary until we can generate our own initialization
136136
if self.cx.typeck.borrowck_context.all_facts.is_some() {
137-
self.add_polonius_var_initialized_on_exit_for(local)
137+
self.add_polonius_var_maybe_initialized_on_exit_for(local)
138138
}
139139

140140
self.compute_use_live_points_for(local);
@@ -161,14 +161,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
161161
//
162162
// FIXME: this analysis (the initialization tracking) should be
163163
// done in Polonius, but isn't yet.
164-
fn add_polonius_var_initialized_on_exit_for(&mut self, local: Local) {
164+
fn add_polonius_var_maybe_initialized_on_exit_for(&mut self, local: Local) {
165165
let move_path = self.cx.move_data.rev_lookup.find_local(local);
166166
let facts = self.cx.typeck.borrowck_context.all_facts.as_mut().unwrap();
167167
for block in self.cx.body.basic_blocks().indices() {
168168
debug!("polonius: generating initialization facts for {:?} in {:?}", local, block);
169169

170170
// iterate through the block, applying the effects of each statement
171-
// up to and including location, and populate `var_initialized_on_exit`
171+
// up to and including location, and populate `var_maybe_initialized_on_exit`
172172
self.cx.flow_inits.reset_to_entry_of(block);
173173
let start_location = Location { block, statement_index: 0 };
174174
self.cx.flow_inits.apply_local_effect(start_location);
@@ -181,7 +181,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
181181
// statement has not yet taken effect:
182182
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
183183
facts
184-
.var_initialized_on_exit
184+
.var_maybe_initialized_on_exit
185185
.push((local, self.cx.location_table.start_index(current_location)));
186186
}
187187

@@ -190,7 +190,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
190190

191191
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
192192
facts
193-
.var_initialized_on_exit
193+
.var_maybe_initialized_on_exit
194194
.push((local, self.cx.location_table.mid_index(current_location)));
195195
}
196196
}
@@ -199,7 +199,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
199199

200200
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
201201
facts
202-
.var_initialized_on_exit
202+
.var_maybe_initialized_on_exit
203203
.push((local, self.cx.location_table.start_index(terminator_location)));
204204
}
205205

@@ -208,7 +208,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
208208

209209
if self.cx.flow_inits.has_any_child_of(move_path).is_some() {
210210
facts
211-
.var_initialized_on_exit
211+
.var_maybe_initialized_on_exit
212212
.push((local, self.cx.location_table.mid_index(terminator_location)));
213213
}
214214
}

0 commit comments

Comments
 (0)