Skip to content

Commit fbf48c1

Browse files
committed
simplify add_extra_drop_facts
this is mostly to remove imports of the polonius legacy module also what is going on in this function, what the...
1 parent 50c152f commit fbf48c1

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

compiler/rustc_borrowck/src/facts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,6 @@ impl FactCell for RegionVid {
246246

247247
impl FactCell for LocationIndex {
248248
fn to_string(&self, location_table: &LocationTable) -> String {
249-
format!("{:?}", location_table.to_location(*self))
249+
format!("{:?}", location_table.to_rich_location(*self))
250250
}
251251
}

compiler/rustc_borrowck/src/polonius/legacy/location.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl LocationTable {
6565
LocationIndex::from_usize(start_index + statement_index * 2 + 1)
6666
}
6767

68-
pub fn to_location(&self, index: LocationIndex) -> RichLocation {
68+
pub fn to_rich_location(&self, index: LocationIndex) -> RichLocation {
6969
let point_index = index.index();
7070

7171
// Find the basic block. We have a vector with the
@@ -97,6 +97,13 @@ impl LocationTable {
9797
RichLocation::Mid(Location { block, statement_index })
9898
}
9999
}
100+
101+
pub fn to_location(&self, index: LocationIndex) -> Location {
102+
match self.to_rich_location(index) {
103+
RichLocation::Start(location) => location,
104+
RichLocation::Mid(location) => location,
105+
}
106+
}
100107
}
101108

102109
impl LocationIndex {

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_trait_selection::traits::query::type_op::{DropckOutlives, TypeOp, Type
1616
use tracing::debug;
1717

1818
use crate::polonius;
19-
use crate::polonius::legacy::RichLocation;
2019
use crate::region_infer::values::{self, LiveLoans};
2120
use crate::type_check::liveness::local_use_map::LocalUseMap;
2221
use crate::type_check::{NormalizeLocation, TypeChecker};
@@ -211,7 +210,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
211210
///
212211
/// Add facts for all locals with free regions, since regions may outlive
213212
/// the function body only at certain nodes in the CFG.
214-
fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) -> Option<()> {
213+
fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) {
215214
// This collect is more necessary than immediately apparent
216215
// because these facts go into `add_drop_live_facts_for()`,
217216
// which also writes to `all_facts`, and so this is genuinely
@@ -221,41 +220,30 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
221220
// and probably maybe plausibly does not need to go back in.
222221
// It may be necessary to just pick out the parts of
223222
// `add_drop_live_facts_for()` that make sense.
223+
let Some(facts) = self.cx.typeck.all_facts.as_ref() else { return };
224224
let facts_to_add: Vec<_> = {
225-
let drop_used = &self.cx.typeck.all_facts.as_ref()?.var_dropped_at;
226-
227225
let relevant_live_locals: FxIndexSet<_> =
228226
relevant_live_locals.iter().copied().collect();
229227

230-
drop_used
228+
facts
229+
.var_dropped_at
231230
.iter()
232-
.filter_map(|(local, location_index)| {
233-
let local_ty = self.cx.body.local_decls[*local].ty;
234-
if relevant_live_locals.contains(local) || !local_ty.has_free_regions() {
231+
.filter_map(|&(local, location_index)| {
232+
let local_ty = self.cx.body.local_decls[local].ty;
233+
if relevant_live_locals.contains(&local) || !local_ty.has_free_regions() {
235234
return None;
236235
}
237236

238-
let location = match self.cx.typeck.location_table.to_location(*location_index)
239-
{
240-
RichLocation::Start(l) => l,
241-
RichLocation::Mid(l) => l,
242-
};
243-
244-
Some((*local, local_ty, location))
237+
let location = self.cx.typeck.location_table.to_location(location_index);
238+
Some((local, local_ty, location))
245239
})
246240
.collect()
247241
};
248242

249-
// FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end,
250-
// ...), but I don't know which one. Please help me rename it to something descriptive!
251-
// Also, if this IntervalSet is used in many places, it maybe should have a newtype'd
252-
// name with a description of what it means for future mortals passing by.
253-
let locations = IntervalSet::new(self.cx.elements.num_points());
254-
243+
let live_at = IntervalSet::new(self.cx.elements.num_points());
255244
for (local, local_ty, location) in facts_to_add {
256-
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);
245+
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &live_at);
257246
}
258-
Some(())
259247
}
260248

261249
/// Clear the value of fields that are "per local variable".

0 commit comments

Comments
 (0)