|
14 | 14 | use super::{CombinedSnapshot,
|
15 | 15 | InferCtxt,
|
16 | 16 | HigherRankedType,
|
17 |
| - SubregionOrigin, |
18 | 17 | SkolemizationMap};
|
19 | 18 | use super::combine::CombineFields;
|
20 | 19 | use super::region_constraints::{TaintDirections};
|
21 | 20 |
|
22 |
| -use ty::{self, TyCtxt, Binder, TypeFoldable}; |
| 21 | +use ty::{self, Binder, TypeFoldable}; |
23 | 22 | use ty::error::TypeError;
|
24 | 23 | use ty::relate::{Relate, RelateResult, TypeRelation};
|
25 | 24 | use syntax_pos::Span;
|
26 | 25 | use util::nodemap::{FxHashMap, FxHashSet};
|
27 | 26 |
|
28 |
| -pub struct HrMatchResult<U> { |
29 |
| - pub value: U, |
30 |
| -} |
31 |
| - |
32 | 27 | impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
|
33 | 28 | pub fn higher_ranked_sub<T>(&mut self, a: &Binder<T>, b: &Binder<T>, a_is_expected: bool)
|
34 | 29 | -> RelateResult<'tcx, Binder<T>>
|
@@ -82,143 +77,6 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
|
82 | 77 | Ok(ty::Binder(result))
|
83 | 78 | });
|
84 | 79 | }
|
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 |
| - }) |
222 | 80 | }
|
223 | 81 |
|
224 | 82 | impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|
0 commit comments