@@ -85,6 +85,15 @@ impl methods for ures {
85
85
}
86
86
}
87
87
88
+ // Most of these methods, like tys() and so forth, take two parameters
89
+ // a and b and they are tasked with "ensuring that a is a subtype of
90
+ // b". They return success or failure. They make changes in-place to
91
+ // the variable bindings: these changes are recorded in the `bindings`
92
+ // array, which then allows the changes to be rolled back if needed.
93
+ //
94
+ // The merge() and merge_bnds() methods are somewhat different in that
95
+ // they compute a new type range for a variable (generally a subset of
96
+ // the old range). They therefore return a result.
88
97
impl unify_methods for infer_ctxt {
89
98
fn uok ( ) -> ures {
90
99
#debug[ "Unification OK" ] ;
@@ -177,18 +186,8 @@ impl unify_methods for infer_ctxt {
177
186
}
178
187
}
179
188
180
- // Take bound a if it is set, else take bound b.
181
- fn aelseb ( a : bound , b : bound ) -> bound {
182
- alt ( a, b) {
183
- ( none, none) { none }
184
- ( some ( _) , none) { a }
185
- ( none, some ( _) ) { b }
186
- ( some ( _) , some ( _) ) { a }
187
- }
188
- }
189
-
190
189
// Combines the two bounds. Returns a bounds r where (r.lb <:
191
- // a,b) and (a,b <: r.ub).
190
+ // a,b) and (a,b <: r.ub) (if such a bounds exists) .
192
191
fn merge_bnds ( a : bound , b : bound ) -> result < bounds , ty:: type_err > {
193
192
alt ( a, b) {
194
193
( none, none) {
@@ -215,10 +214,14 @@ impl unify_methods for infer_ctxt {
215
214
}
216
215
}
217
216
218
- // Given a variable with bounds `a`, returns a new set of bounds
219
- // such that `a` <: `b`. The new bounds will always be a subset
220
- // of the old bounds. If this cannot be achieved, the result is
221
- // failure.
217
+ // Updates the bounds for the variable `v_id` to be the intersection
218
+ // of `a` and `b`. That is, the new bounds for `v_id` will be
219
+ // a bounds c such that:
220
+ // c.ub <: a.ub
221
+ // c.ub <: b.ub
222
+ // a.lb <: c.lb
223
+ // b.lb <: c.lb
224
+ // If this cannot be achieved, the result is failure.
222
225
fn merge ( v_id : uint , a : bounds , b : bounds ) -> ures {
223
226
// Think of the two diamonds, we want to find the
224
227
// intersection. There are basically four possibilities (you
0 commit comments