Skip to content

Commit f7a825c

Browse files
committed
Split record_var_binding into methods for expected and actual
This allows unify to maintain the same subtype relationship between expected and actual throughout unify, which we are going to need for mutable? and for function types.
1 parent 1a64153 commit f7a825c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/comp/middle/ty.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,13 +1840,35 @@ mod unify {
18401840
}
18411841
}
18421842
}
1843-
fn record_var_binding(cx: @ctxt, key: int, typ: t) -> result {
1843+
1844+
fn record_var_binding_for_expected(
1845+
cx: @ctxt, key: int, typ: t) -> result {
1846+
record_var_binding(
1847+
cx, key, typ,
1848+
fn (cx: @ctxt, old_type: t, new_type: t) -> result {
1849+
unify_step(cx, old_type, new_type)
1850+
})
1851+
}
1852+
1853+
fn record_var_binding_for_actual(
1854+
cx: @ctxt, key: int, typ: t) -> result {
1855+
record_var_binding(
1856+
cx, key, typ,
1857+
fn (cx: @ctxt, old_type: t, new_type: t) -> result {
1858+
unify_step(cx, new_type, old_type)
1859+
})
1860+
}
1861+
1862+
fn record_var_binding(
1863+
cx: @ctxt, key: int, typ: t,
1864+
unify_types: fn(@ctxt, t, t) -> result) -> result {
1865+
18441866
ufind::grow(cx.vb.sets, (key as uint) + 1u);
18451867
let root = ufind::find(cx.vb.sets, key as uint);
18461868
let result_type = typ;
18471869
alt smallintmap::find::<t>(cx.vb.types, root) {
18481870
some(old_type) {
1849-
alt unify_step(cx, old_type, typ) {
1871+
alt unify_types(cx, old_type, typ) {
18501872
ures_ok(unified_type) { result_type = unified_type; }
18511873
rs { ret rs; }
18521874
}
@@ -2099,7 +2121,7 @@ mod unify {
20992121
}
21002122
_ {
21012123
// Just bind the type variable to the expected type.
2102-
alt record_var_binding(cx, actual_id, expected) {
2124+
alt record_var_binding_for_actual(cx, actual_id, expected) {
21032125
ures_ok(_) {/* fall through */ }
21042126
rs { ret rs; }
21052127
}
@@ -2113,7 +2135,7 @@ mod unify {
21132135
ty::ty_var(expected_id) {
21142136
// Add a binding. (`actual` can't actually be a var here.)
21152137

2116-
alt record_var_binding(cx, expected_id, actual) {
2138+
alt record_var_binding_for_expected(cx, expected_id, actual) {
21172139
ures_ok(_) {/* fall through */ }
21182140
rs { ret rs; }
21192141
}

0 commit comments

Comments
 (0)