Skip to content

Commit ccb550f

Browse files
committed
Auto merge of #53109 - nikomatsakis:nll-escaping-into-return-revert, r=nikomatsakis
revert #52991 Reverts #52991 which is flawed. I have an idea how to fix it but might as well revert first since it is so wildly flawed. That's what I get for opening PRs while on PTO =) r? @pnkfelix
2 parents 39e9516 + 3b4ed18 commit ccb550f

11 files changed

+108
-331
lines changed

src/librustc_mir/borrow_check/nll/escaping_locals.rs

-229
This file was deleted.

src/librustc_mir/borrow_check/nll/liveness_map.rs

+13-35
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
//! liveness code so that it only operates over variables with regions in their
1717
//! types, instead of all variables.
1818
19-
use borrow_check::nll::escaping_locals::EscapingLocals;
20-
use rustc::mir::{Local, Mir};
2119
use rustc::ty::TypeFoldable;
2220
use rustc_data_structures::indexed_vec::IndexVec;
21+
use rustc::mir::{Mir, Local};
2322
use util::liveness::LiveVariableMap;
2423

2524
use rustc_data_structures::indexed_vec::Idx;
@@ -30,13 +29,14 @@ use rustc_data_structures::indexed_vec::Idx;
3029
crate struct NllLivenessMap {
3130
/// For each local variable, contains either None (if the type has no regions)
3231
/// or Some(i) with a suitable index.
33-
from_local: IndexVec<Local, Option<LocalWithRegion>>,
34-
32+
pub from_local: IndexVec<Local, Option<LocalWithRegion>>,
3533
/// For each LocalWithRegion, maps back to the original Local index.
36-
to_local: IndexVec<LocalWithRegion, Local>,
34+
pub to_local: IndexVec<LocalWithRegion, Local>,
35+
3736
}
3837

3938
impl LiveVariableMap for NllLivenessMap {
39+
4040
fn from_local(&self, local: Local) -> Option<Self::LiveVar> {
4141
self.from_local[local]
4242
}
@@ -55,43 +55,21 @@ impl LiveVariableMap for NllLivenessMap {
5555
impl NllLivenessMap {
5656
/// Iterates over the variables in Mir and assigns each Local whose type contains
5757
/// regions a LocalWithRegion index. Returns a map for converting back and forth.
58-
crate fn compute(mir: &Mir<'tcx>) -> Self {
59-
let mut escaping_locals = EscapingLocals::compute(mir);
60-
58+
pub fn compute(mir: &Mir) -> Self {
6159
let mut to_local = IndexVec::default();
62-
let mut escapes_into_return = 0;
63-
let mut no_regions = 0;
64-
let from_local: IndexVec<Local, Option<_>> = mir
60+
let from_local: IndexVec<Local,Option<_>> = mir
6561
.local_decls
6662
.iter_enumerated()
6763
.map(|(local, local_decl)| {
68-
if escaping_locals.escapes_into_return(local) {
69-
// If the local escapes into the return value,
70-
// then the return value will force all of the
71-
// regions in its type to outlive free regions
72-
// (e.g., `'static`) and hence liveness is not
73-
// needed. This is particularly important for big
74-
// statics.
75-
escapes_into_return += 1;
76-
None
77-
} else if local_decl.ty.has_free_regions() {
78-
let l = to_local.push(local);
79-
debug!("liveness_map: {:?} = {:?}", local, l);
80-
Some(l)
81-
} else {
82-
no_regions += 1;
83-
None
64+
if local_decl.ty.has_free_regions() {
65+
Some(to_local.push(local))
8466
}
67+
else {
68+
None
69+
}
8570
}).collect();
8671

87-
debug!("liveness_map: {} variables need liveness", to_local.len());
88-
debug!("liveness_map: {} escapes into return", escapes_into_return);
89-
debug!("liveness_map: {} no regions", no_regions);
90-
91-
Self {
92-
from_local,
93-
to_local,
94-
}
72+
Self { from_local, to_local }
9573
}
9674
}
9775

src/librustc_mir/borrow_check/nll/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ use polonius_engine::{Algorithm, Output};
3939
use util as mir_util;
4040
use util::pretty::{self, ALIGN};
4141

42-
mod constraints;
4342
mod constraint_generation;
44-
mod escaping_locals;
4543
pub mod explain_borrow;
4644
mod facts;
4745
mod invalidation;
@@ -51,6 +49,8 @@ crate mod type_check;
5149
mod universal_regions;
5250
crate mod liveness_map;
5351

52+
mod constraints;
53+
5454
use self::facts::AllFacts;
5555
use self::region_infer::RegionInferenceContext;
5656
use self::universal_regions::UniversalRegions;
@@ -120,7 +120,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
120120
location_table,
121121
borrow_set,
122122
&liveness,
123-
&liveness_map,
124123
&mut all_facts,
125124
flow_inits,
126125
move_data,
@@ -206,7 +205,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
206205
dump_mir_results(
207206
infcx,
208207
&liveness,
209-
&liveness_map,
210208
MirSource::item(def_id),
211209
&mir,
212210
&regioncx,
@@ -223,7 +221,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
223221
fn dump_mir_results<'a, 'gcx, 'tcx>(
224222
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
225223
liveness: &LivenessResults<LocalWithRegion>,
226-
liveness_map: &NllLivenessMap,
227224
source: MirSource,
228225
mir: &Mir<'tcx>,
229226
regioncx: &RegionInferenceContext,
@@ -233,14 +230,16 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
233230
return;
234231
}
235232

233+
let map = &NllLivenessMap::compute(mir);
234+
236235
let regular_liveness_per_location: FxHashMap<_, _> = mir
237236
.basic_blocks()
238237
.indices()
239238
.flat_map(|bb| {
240239
let mut results = vec![];
241240
liveness
242241
.regular
243-
.simulate_block(&mir, bb, liveness_map, |location, local_set| {
242+
.simulate_block(&mir, bb, map, |location, local_set| {
244243
results.push((location, local_set.clone()));
245244
});
246245
results
@@ -254,7 +253,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
254253
let mut results = vec![];
255254
liveness
256255
.drop
257-
.simulate_block(&mir, bb, liveness_map, |location, local_set| {
256+
.simulate_block(&mir, bb, map, |location, local_set| {
258257
results.push((location, local_set.clone()));
259258
});
260259
results

0 commit comments

Comments
 (0)