Skip to content

Commit 367be87

Browse files
nikomatsakissgrif
authored andcommitted
remove hr_match -- no longer needed
1 parent 24478c4 commit 367be87

File tree

3 files changed

+18
-186
lines changed

3 files changed

+18
-186
lines changed

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 1 addition & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@
1414
use super::{CombinedSnapshot,
1515
InferCtxt,
1616
HigherRankedType,
17-
SubregionOrigin,
1817
SkolemizationMap};
1918
use super::combine::CombineFields;
2019
use super::region_constraints::{TaintDirections};
2120

22-
use ty::{self, TyCtxt, Binder, TypeFoldable};
21+
use ty::{self, Binder, TypeFoldable};
2322
use ty::error::TypeError;
2423
use ty::relate::{Relate, RelateResult, TypeRelation};
2524
use syntax_pos::Span;
2625
use util::nodemap::{FxHashMap, FxHashSet};
2726

28-
pub struct HrMatchResult<U> {
29-
pub value: U,
30-
}
31-
3227
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
3328
pub fn higher_ranked_sub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
3429
-> RelateResult<'tcx, Binder<T>>
@@ -82,143 +77,6 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
8277
Ok(ty::Binder(result))
8378
});
8479
}
85-
86-
/// The value consists of a pair `(t, u)` where `t` is the
87-
/// *matcher* and `u` is a *value*. The idea is to find a
88-
/// substitution `S` such that `S(t) == b`, and then return
89-
/// `S(u)`. In other words, find values for the late-bound regions
90-
/// in `a` that can make `t == b` and then replace the LBR in `u`
91-
/// with those values.
92-
///
93-
/// This routine is (as of this writing) used in trait matching,
94-
/// particularly projection.
95-
///
96-
/// NB. It should not happen that there are LBR appearing in `U`
97-
/// that do not appear in `T`. If that happens, those regions are
98-
/// unconstrained, and this routine replaces them with `'static`.
99-
pub fn higher_ranked_match<T, U>(&mut self,
100-
a_pair: &Binder<(T, U)>,
101-
b_match: &T,
102-
a_is_expected: bool)
103-
-> RelateResult<'tcx, HrMatchResult<U>>
104-
where T: Relate<'tcx>,
105-
U: TypeFoldable<'tcx>
106-
{
107-
debug!("higher_ranked_match(a={:?}, b={:?})",
108-
a_pair, b_match);
109-
110-
// Start a snapshot so we can examine "all bindings that were
111-
// created as part of this type comparison".
112-
return self.infcx.commit_if_ok(|snapshot| {
113-
// First, we instantiate each bound region in the matcher
114-
// with a skolemized region.
115-
let ((a_match, a_value), skol_map) =
116-
self.infcx.skolemize_late_bound_regions(a_pair, snapshot);
117-
118-
debug!("higher_ranked_match: a_match={:?}", a_match);
119-
debug!("higher_ranked_match: skol_map={:?}", skol_map);
120-
121-
// Equate types now that bound regions have been replaced.
122-
self.equate(a_is_expected).relate(&a_match, &b_match)?;
123-
124-
// Map each skolemized region to a vector of other regions that it
125-
// must be equated with. (Note that this vector may include other
126-
// skolemized regions from `skol_map`.)
127-
let skol_resolution_map: FxHashMap<_, _> =
128-
skol_map
129-
.iter()
130-
.map(|(&br, &skol)| {
131-
let tainted_regions =
132-
self.infcx.tainted_regions(snapshot,
133-
skol,
134-
TaintDirections::incoming()); // [1]
135-
136-
// [1] this routine executes after the skolemized
137-
// regions have been *equated* with something
138-
// else, so examining the incoming edges ought to
139-
// be enough to collect all constraints
140-
141-
(skol, (br, tainted_regions))
142-
})
143-
.collect();
144-
145-
// For each skolemized region, pick a representative -- which can
146-
// be any region from the sets above, except for other members of
147-
// `skol_map`. There should always be a representative if things
148-
// are properly well-formed.
149-
let skol_representatives: FxHashMap<_, _> =
150-
skol_resolution_map
151-
.iter()
152-
.map(|(&skol, &(_, ref regions))| {
153-
let representative =
154-
regions.iter()
155-
.filter(|&&r| !skol_resolution_map.contains_key(r))
156-
.cloned()
157-
.next()
158-
.unwrap_or_else(|| {
159-
bug!("no representative region for `{:?}` in `{:?}`",
160-
skol, regions)
161-
});
162-
163-
(skol, representative)
164-
})
165-
.collect();
166-
167-
// Equate all the members of each skolemization set with the
168-
// representative.
169-
for (skol, &(_br, ref regions)) in &skol_resolution_map {
170-
let representative = &skol_representatives[skol];
171-
debug!("higher_ranked_match: \
172-
skol={:?} representative={:?} regions={:?}",
173-
skol, representative, regions);
174-
for region in regions.iter()
175-
.filter(|&r| !skol_resolution_map.contains_key(r))
176-
.filter(|&r| r != representative)
177-
{
178-
let origin = SubregionOrigin::Subtype(self.trace.clone());
179-
self.infcx.borrow_region_constraints()
180-
.make_eqregion(origin,
181-
*representative,
182-
*region);
183-
}
184-
}
185-
186-
// Replace the skolemized regions appearing in value with
187-
// their representatives
188-
let a_value =
189-
fold_regions_in(
190-
self.tcx(),
191-
&a_value,
192-
|r, _| skol_representatives.get(&r).cloned().unwrap_or(r));
193-
194-
debug!("higher_ranked_match: value={:?}", a_value);
195-
196-
// We are now done with these skolemized variables.
197-
self.infcx.pop_skolemized(skol_map, snapshot);
198-
199-
Ok(HrMatchResult { value: a_value })
200-
});
201-
}
202-
}
203-
204-
fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
205-
unbound_value: &T,
206-
mut fldr: F)
207-
-> T
208-
where T: TypeFoldable<'tcx>,
209-
F: FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
210-
{
211-
tcx.fold_regions(unbound_value, &mut false, |region, current_depth| {
212-
// we should only be encountering "escaping" late-bound regions here,
213-
// because the ones at the current level should have been replaced
214-
// with fresh variables
215-
assert!(match *region {
216-
ty::ReLateBound(..) => false,
217-
_ => true
218-
});
219-
220-
fldr(region, ty::DebruijnIndex::new(current_depth))
221-
})
22280
}
22381

22482
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

src/librustc/infer/mod.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use util::nodemap::FxHashMap;
3939
use arena::DroplessArena;
4040

4141
use self::combine::CombineFields;
42-
use self::higher_ranked::HrMatchResult;
4342
use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
4443
use self::region_constraints::{GenericKind, VerifyBound, RegionConstraintData, VarInfos};
4544
use self::lexical_region_resolve::LexicalRegionResolutions;
@@ -1238,40 +1237,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12381237
|br| self.next_region_var(LateBoundRegion(span, br, lbrct)))
12391238
}
12401239

1241-
/// Given a higher-ranked projection predicate like:
1242-
///
1243-
/// for<'a> <T as Fn<&'a u32>>::Output = &'a u32
1244-
///
1245-
/// and a target trait-ref like:
1246-
///
1247-
/// <T as Fn<&'x u32>>
1248-
///
1249-
/// find a substitution `S` for the higher-ranked regions (here,
1250-
/// `['a => 'x]`) such that the predicate matches the trait-ref,
1251-
/// and then return the value (here, `&'a u32`) but with the
1252-
/// substitution applied (hence, `&'x u32`).
1253-
///
1254-
/// See `higher_ranked_match` in `higher_ranked/mod.rs` for more
1255-
/// details.
1256-
pub fn match_poly_projection_predicate(&self,
1257-
cause: ObligationCause<'tcx>,
1258-
param_env: ty::ParamEnv<'tcx>,
1259-
match_a: ty::PolyProjectionPredicate<'tcx>,
1260-
match_b: ty::TraitRef<'tcx>)
1261-
-> InferResult<'tcx, HrMatchResult<Ty<'tcx>>>
1262-
{
1263-
let match_pair = match_a.map_bound(|p| (p.projection_ty.trait_ref(self.tcx), p.ty));
1264-
let trace = TypeTrace {
1265-
cause,
1266-
values: TraitRefs(ExpectedFound::new(true, match_pair.skip_binder().0, match_b))
1267-
};
1268-
1269-
let mut combine = self.combine_fields(trace, param_env);
1270-
let result = combine.higher_ranked_match(&match_pair, &match_b, true)?;
1271-
Ok(InferOk { value: result, obligations: combine.obligations })
1272-
}
1273-
1274-
/// See `verify_generic_bound` method in `region_constraints`
1240+
/// See `verify_generic_bound` method in `region_inference`
12751241
pub fn verify_generic_bound(&self,
12761242
origin: SubregionOrigin<'tcx>,
12771243
kind: GenericKind<'tcx>,

src/librustc/traits/project.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::VtableImplData;
2626
use super::util;
2727

2828
use hir::def_id::DefId;
29-
use infer::{InferCtxt, InferOk};
29+
use infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
3030
use infer::type_variable::TypeVariableOrigin;
3131
use middle::const_val::ConstVal;
3232
use mir::interpret::{GlobalId};
@@ -1422,17 +1422,25 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
14221422
fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
14231423
selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
14241424
obligation: &ProjectionTyObligation<'tcx>,
1425-
poly_projection: ty::PolyProjectionPredicate<'tcx>)
1425+
poly_cache_entry: ty::PolyProjectionPredicate<'tcx>)
14261426
-> Progress<'tcx>
14271427
{
14281428
let infcx = selcx.infcx();
1429-
let cause = obligation.cause.clone();
1429+
let cause = &obligation.cause;
14301430
let param_env = obligation.param_env;
1431-
let trait_ref = obligation.predicate.trait_ref(infcx.tcx);
1432-
match infcx.match_poly_projection_predicate(cause, param_env, poly_projection, trait_ref) {
1433-
Ok(InferOk { value: ty_match, obligations }) => {
1431+
1432+
let (cache_entry, _skol_map) =
1433+
infcx.replace_late_bound_regions_with_fresh_var(
1434+
cause.span,
1435+
LateBoundRegionConversionTime::HigherRankedType,
1436+
&poly_cache_entry);
1437+
1438+
let cache_trait_ref = cache_entry.projection_ty.trait_ref(infcx.tcx);
1439+
let obligation_trait_ref = obligation.predicate.trait_ref(infcx.tcx);
1440+
match infcx.at(cause, param_env).eq(cache_trait_ref, obligation_trait_ref) {
1441+
Ok(InferOk { value: _, obligations }) => {
14341442
Progress {
1435-
ty: ty_match.value,
1443+
ty: cache_entry.ty,
14361444
obligations,
14371445
}
14381446
}
@@ -1442,7 +1450,7 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
14421450
"Failed to unify obligation `{:?}` \
14431451
with poly_projection `{:?}`: {:?}",
14441452
obligation,
1445-
poly_projection,
1453+
poly_cache_entry,
14461454
e);
14471455
}
14481456
}

0 commit comments

Comments
 (0)