Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff13ca1

Browse files
authoredMay 31, 2024
Rollup merge of rust-lang#125652 - amandasystems:you-dropped-something, r=oli-obk
Revert propagation of drop-live information from Polonius rust-lang#64749 introduced a flow of drop-use data from Polonius to `LivenessResults::add_extra_drop_facts()`, which makes `LivenessResults` agree with Polonius on liveness in the presence of free regions that may be dropped. Later changes accidentally removed this flow. This PR restores it.
2 parents 99cb42c + 8066ebc commit ff13ca1

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed
 

‎compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::rc::Rc;
1414
use crate::{
1515
constraints::OutlivesConstraintSet,
1616
facts::{AllFacts, AllFactsExt},
17-
location::LocationTable,
1817
region_infer::values::LivenessValues,
1918
universal_regions::UniversalRegions,
2019
};
@@ -39,7 +38,6 @@ pub(super) fn generate<'mir, 'tcx>(
3938
elements: &Rc<DenseLocationMap>,
4039
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
4140
move_data: &MoveData<'tcx>,
42-
location_table: &LocationTable,
4341
use_polonius: bool,
4442
) {
4543
debug!("liveness::generate");
@@ -53,11 +51,9 @@ pub(super) fn generate<'mir, 'tcx>(
5351
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
5452
let facts_enabled = use_polonius || AllFacts::enabled(typeck.tcx());
5553

56-
let polonius_drop_used = facts_enabled.then(|| {
57-
let mut drop_used = Vec::new();
58-
polonius::populate_access_facts(typeck, body, location_table, move_data, &mut drop_used);
59-
drop_used
60-
});
54+
if facts_enabled {
55+
polonius::populate_access_facts(typeck, body, move_data);
56+
};
6157

6258
trace::trace(
6359
typeck,
@@ -67,7 +63,6 @@ pub(super) fn generate<'mir, 'tcx>(
6763
move_data,
6864
relevant_live_locals,
6965
boring_locals,
70-
polonius_drop_used,
7166
);
7267

7368
// Mark regions that should be live where they appear within rvalues or within a call: like

‎compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> {
8585
pub(super) fn populate_access_facts<'a, 'tcx>(
8686
typeck: &mut TypeChecker<'a, 'tcx>,
8787
body: &Body<'tcx>,
88-
location_table: &LocationTable,
8988
move_data: &MoveData<'tcx>,
90-
//FIXME: this is not mutated, but expected to be modified as
91-
// out param, bug?
92-
dropped_at: &mut Vec<(Local, Location)>,
9389
) {
9490
debug!("populate_access_facts()");
91+
let location_table = typeck.borrowck_context.location_table;
9592

9693
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
9794
let mut extractor = UseFactsExtractor {
@@ -104,10 +101,6 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
104101
};
105102
extractor.visit_body(body);
106103

107-
facts.var_dropped_at.extend(
108-
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
109-
);
110-
111104
for (local, local_decl) in body.local_decls.iter_enumerated() {
112105
debug!(
113106
"add use_of_var_derefs_origin facts - local={:?}, type={:?}",

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

+25-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1616
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
1717
use rustc_mir_dataflow::ResultsCursor;
1818

19+
use crate::location::RichLocation;
1920
use crate::{
2021
region_infer::values::{self, LiveLoans},
2122
type_check::liveness::local_use_map::LocalUseMap,
@@ -46,7 +47,6 @@ pub(super) fn trace<'mir, 'tcx>(
4647
move_data: &MoveData<'tcx>,
4748
relevant_live_locals: Vec<Local>,
4849
boring_locals: Vec<Local>,
49-
polonius_drop_used: Option<Vec<(Local, Location)>>,
5050
) {
5151
let local_use_map = &LocalUseMap::build(&relevant_live_locals, elements, body);
5252

@@ -93,9 +93,7 @@ pub(super) fn trace<'mir, 'tcx>(
9393

9494
let mut results = LivenessResults::new(cx);
9595

96-
if let Some(drop_used) = polonius_drop_used {
97-
results.add_extra_drop_facts(drop_used, relevant_live_locals.iter().copied().collect())
98-
}
96+
results.add_extra_drop_facts(&relevant_live_locals);
9997

10098
results.compute_for_all_locals(relevant_live_locals);
10199

@@ -218,21 +216,38 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
218216
///
219217
/// Add facts for all locals with free regions, since regions may outlive
220218
/// the function body only at certain nodes in the CFG.
221-
fn add_extra_drop_facts(
222-
&mut self,
223-
drop_used: Vec<(Local, Location)>,
224-
relevant_live_locals: FxIndexSet<Local>,
225-
) {
219+
fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) -> Option<()> {
220+
let drop_used = self
221+
.cx
222+
.typeck
223+
.borrowck_context
224+
.all_facts
225+
.as_ref()
226+
.map(|facts| facts.var_dropped_at.clone())?;
227+
228+
let relevant_live_locals: FxIndexSet<_> = relevant_live_locals.iter().copied().collect();
229+
226230
let locations = IntervalSet::new(self.cx.elements.num_points());
227231

228-
for (local, location) in drop_used {
232+
for (local, location_index) in drop_used {
229233
if !relevant_live_locals.contains(&local) {
230234
let local_ty = self.cx.body.local_decls[local].ty;
231235
if local_ty.has_free_regions() {
236+
let location = match self
237+
.cx
238+
.typeck
239+
.borrowck_context
240+
.location_table
241+
.to_location(location_index)
242+
{
243+
RichLocation::Start(l) => l,
244+
RichLocation::Mid(l) => l,
245+
};
232246
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);
233247
}
234248
}
235249
}
250+
Some(())
236251
}
237252

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

‎compiler/rustc_borrowck/src/type_check/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
188188
checker.equate_inputs_and_outputs(body, universal_regions, &normalized_inputs_and_output);
189189
checker.check_signature_annotation(body);
190190

191-
liveness::generate(
192-
&mut checker,
193-
body,
194-
elements,
195-
flow_inits,
196-
move_data,
197-
location_table,
198-
use_polonius,
199-
);
191+
liveness::generate(&mut checker, body, elements, flow_inits, move_data, use_polonius);
200192

201193
translate_outlives_facts(&mut checker);
202194
let opaque_type_values = infcx.take_opaque_types();

0 commit comments

Comments
 (0)
Please sign in to comment.