Skip to content

Commit ab964df

Browse files
committed
WIP rewrite to TaintIterator -- seems to work
1 parent 48ce90a commit ab964df

File tree

5 files changed

+142
-159
lines changed

5 files changed

+142
-159
lines changed

src/librustc/infer/fudge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
156156
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
157157
match *r {
158158
ty::ReVar(v) if self.region_vars.contains(&v) => {
159-
// TODO -- I am not entirely sur how fudging and
159+
// FIXME -- I am not entirely sure how fudging and
160160
// universes should work, but using root is a
161161
// conservative choice here, and I suspect it doesn't
162162
// much matter.

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ use super::{CombinedSnapshot,
1616
HigherRankedType,
1717
SkolemizationMap};
1818
use super::combine::CombineFields;
19-
use super::region_inference::taint::TaintDirections;
19+
use super::region_inference::taint::TaintIterator;
2020

2121
use ty::{self, TyCtxt, Binder, TypeFoldable};
2222
use ty::relate::{Relate, RelateResult, TypeRelation};
23+
use std::usize;
2324
use syntax_pos::Span;
2425
use util::nodemap::{FxHashMap, FxHashSet};
2526

@@ -108,7 +109,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
108109
fold_regions_in(
109110
self.tcx(),
110111
&result0,
111-
|r, debruijn| generalize_region(self.infcx, span, snapshot, debruijn,
112+
|r, debruijn| generalize_region(self.infcx, span, snapshot, param_env, debruijn,
112113
&new_vars, &a_map, r));
113114

114115
debug!("lub({:?},{:?}) = {:?}",
@@ -122,6 +123,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
122123
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
123124
span: Span,
124125
snapshot: &CombinedSnapshot<'a, 'tcx>,
126+
param_env: ty::ParamEnv<'tcx>,
125127
debruijn: ty::DebruijnIndex,
126128
new_vars: &[ty::RegionVid],
127129
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
@@ -134,33 +136,39 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
134136
return r0;
135137
}
136138

137-
let tainted = infcx.tainted_regions(snapshot, r0, TaintDirections::both());
139+
let mut best_index = usize::MAX;
138140

139-
// Variables created during LUB computation which are
140-
// *related* to regions that pre-date the LUB computation
141-
// stay as they are.
142-
if !tainted.iter().all(|&r| is_var_in_set(new_vars, r)) {
143-
debug!("generalize_region(r0={:?}): \
144-
non-new-variables found in {:?}",
145-
r0, tainted);
146-
assert!(!r0.is_late_bound());
147-
return r0;
148-
}
149-
150-
// Otherwise, the variable must be associated with at
151-
// least one of the variables representing bound regions
152-
// in both A and B. Replace the variable with the "first"
153-
// bound region from A that we find it to be associated
154-
// with.
155-
for (a_br, a_r) in a_map {
156-
if tainted.iter().any(|x| x == a_r) {
141+
for r in infcx.tainted_regions(snapshot, param_env, r0) {
142+
// Variables created during LUB computation which are
143+
// *related* to regions that pre-date the LUB computation
144+
// stay as they are.
145+
if !is_var_in_set(new_vars, r) {
157146
debug!("generalize_region(r0={:?}): \
158-
replacing with {:?}, tainted={:?}",
159-
r0, *a_br, tainted);
160-
return infcx.tcx.mk_region(ty::ReLateBound(debruijn, *a_br));
147+
non-new-variable `{:?}` found in taint regions",
148+
r0, r);
149+
assert!(!r0.is_late_bound());
150+
return r0;
151+
}
152+
153+
// Otherwise, the variable must be associated with at
154+
// least one of the variables representing bound regions
155+
// in both A and B. Replace the variable with the "first"
156+
// bound region from A that we find it to be associated
157+
// with.
158+
for (index, (_, &a_r)) in a_map.iter().enumerate() {
159+
if r == a_r && index < best_index {
160+
best_index = index;
161+
}
161162
}
162163
}
163164

165+
for (a_br, a_r) in a_map.iter().skip(best_index) {
166+
debug!("generalize_region(r0={:?}): \
167+
replacing with {:?}, tainted={:?}",
168+
r0, *a_br, a_r);
169+
return infcx.tcx.mk_region(ty::ReLateBound(debruijn, *a_br));
170+
}
171+
164172
span_bug!(
165173
span,
166174
"region {:?} is not associated with any bound region from A!",
@@ -206,8 +214,8 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
206214
fold_regions_in(
207215
self.tcx(),
208216
&result0,
209-
|r, debruijn| generalize_region(self.infcx, span, snapshot, debruijn,
210-
&new_vars,
217+
|r, debruijn| generalize_region(self.infcx, span, snapshot, param_env,
218+
debruijn, &new_vars,
211219
&a_map, &a_vars, &b_vars,
212220
r));
213221

@@ -222,6 +230,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
222230
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
223231
span: Span,
224232
snapshot: &CombinedSnapshot<'a, 'tcx>,
233+
param_env: ty::ParamEnv<'tcx>,
225234
debruijn: ty::DebruijnIndex,
226235
new_vars: &[ty::RegionVid],
227236
a_map: &FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
@@ -234,25 +243,24 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
234243
return r0;
235244
}
236245

237-
let tainted = infcx.tainted_regions(snapshot, r0, TaintDirections::both());
238-
239246
let mut a_r = None;
240247
let mut b_r = None;
241248
let mut only_new_vars = true;
242-
for r in &tainted {
243-
if is_var_in_set(a_vars, *r) {
249+
250+
for r in infcx.tainted_regions(snapshot, param_env, r0) {
251+
if is_var_in_set(a_vars, r) {
244252
if a_r.is_some() {
245253
return fresh_bound_variable(infcx, debruijn);
246254
} else {
247-
a_r = Some(*r);
255+
a_r = Some(r);
248256
}
249-
} else if is_var_in_set(b_vars, *r) {
257+
} else if is_var_in_set(b_vars, r) {
250258
if b_r.is_some() {
251259
return fresh_bound_variable(infcx, debruijn);
252260
} else {
253-
b_r = Some(*r);
261+
b_r = Some(r);
254262
}
255-
} else if !is_var_in_set(new_vars, *r) {
263+
} else if !is_var_in_set(new_vars, r) {
256264
only_new_vars = false;
257265
}
258266
}
@@ -359,12 +367,12 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
359367
}
360368

361369
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
362-
fn tainted_regions(&self,
363-
snapshot: &CombinedSnapshot<'a, 'tcx>,
364-
r: ty::Region<'tcx>,
365-
directions: TaintDirections)
366-
-> FxHashSet<ty::Region<'tcx>> {
367-
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
370+
fn tainted_regions<'this>(&'this self,
371+
snapshot: &CombinedSnapshot<'a, 'tcx>,
372+
param_env: ty::ParamEnv<'tcx>,
373+
r: ty::Region<'tcx>)
374+
-> TaintIterator<'this, 'gcx, 'tcx> {
375+
self.region_vars.tainted(&snapshot.region_vars_snapshot, param_env, r)
368376
}
369377

370378
fn region_vars_confined_to_snapshot(&self,

src/librustc/infer/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
946946
self.tcx.mk_var(self.next_ty_var_id(universe, false, origin))
947947
}
948948

949-
pub fn next_diverging_ty_var(&self, universe: ty::UniverseIndex, origin: TypeVariableOrigin) -> Ty<'tcx> {
949+
pub fn next_diverging_ty_var(&self,
950+
universe: ty::UniverseIndex,
951+
origin: TypeVariableOrigin)
952+
-> Ty<'tcx> {
950953
self.tcx.mk_var(self.next_ty_var_id(universe, true, origin))
951954
}
952955

src/librustc/infer/region_inference/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,20 +1379,6 @@ impl<'a, 'gcx, 'tcx> GenericKind<'tcx> {
13791379
}
13801380

13811381
impl<'a, 'gcx, 'tcx> VerifyBound<'tcx> {
1382-
fn for_each_region(&self, f: &mut FnMut(ty::Region<'tcx>)) {
1383-
match self {
1384-
&VerifyBound::AnyRegion(ref rs) |
1385-
&VerifyBound::AllRegions(ref rs) => for &r in rs {
1386-
f(r);
1387-
},
1388-
1389-
&VerifyBound::AnyBound(ref bs) |
1390-
&VerifyBound::AllBounds(ref bs) => for b in bs {
1391-
b.for_each_region(f);
1392-
},
1393-
}
1394-
}
1395-
13961382
pub fn must_hold(&self) -> bool {
13971383
match self {
13981384
&VerifyBound::AnyRegion(ref bs) => bs.contains(&&ty::ReStatic),

0 commit comments

Comments
 (0)