Skip to content

Commit d6570ab

Browse files
committed
---
yaml --- r: 2616 b: refs/heads/master c: 37d5dd9 h: refs/heads/master v: v3
1 parent f212ae5 commit d6570ab

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a795d0e5b24a8a74cf2529bfc738af275b5a3e78
2+
refs/heads/master: 37d5dd94718a902a5e76e9e87d888a3999744c37

trunk/src/comp/middle/ty.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,9 +1865,18 @@ mod unify {
18651865
ures_err(type_err, t, t);
18661866
}
18671867

1868-
type ctxt = rec(ufind::ufind sets,
1869-
hashmap[int,uint] var_ids,
1870-
mutable vec[mutable vec[t]] types,
1868+
type var_bindings = rec(ufind::ufind sets,
1869+
hashmap[int,uint] var_ids,
1870+
mutable vec[mutable vec[t]] types);
1871+
1872+
fn mk_var_bindings() -> var_bindings {
1873+
let vec[mutable vec[t]] types = [mutable];
1874+
ret rec(sets=ufind::make(),
1875+
var_ids=common::new_int_hash[uint](),
1876+
mutable types=types);
1877+
}
1878+
1879+
type ctxt = rec(var_bindings var_bindings,
18711880
unify_handler handler,
18721881
ty_ctxt tcx);
18731882

@@ -2070,12 +2079,12 @@ mod unify {
20702079

20712080
fn get_or_create_set(&@ctxt cx, int id) -> uint {
20722081
auto set_num;
2073-
alt (cx.var_ids.find(id)) {
2074-
case (none[uint]) {
2075-
set_num = ufind::make_set(cx.sets);
2076-
cx.var_ids.insert(id, set_num);
2077-
}
2078-
case (some[uint](?n)) { set_num = n; }
2082+
alt (cx.var_bindings.var_ids.find(id)) {
2083+
case (none[uint]) {
2084+
set_num = ufind::make_set(cx.var_bindings.sets);
2085+
cx.var_bindings.var_ids.insert(id, set_num);
2086+
}
2087+
case (some[uint](?n)) { set_num = n; }
20792088
}
20802089
ret set_num;
20812090
}
@@ -2098,17 +2107,18 @@ mod unify {
20982107
alt (struct(cx.tcx, expected)) {
20992108
case (ty::ty_var(?expected_id)) {
21002109
auto expected_n = get_or_create_set(cx, expected_id);
2101-
ufind::union(cx.sets, expected_n, actual_n);
2110+
ufind::union(cx.var_bindings.sets, expected_n,
2111+
actual_n);
21022112
}
21032113

21042114
case (_) {
21052115
// Just bind the type variable to the expected type.
2106-
auto vlen = vec::len[vec[t]](cx.types);
2116+
auto vlen = vec::len[vec[t]](cx.var_bindings.types);
21072117
if (actual_n < vlen) {
2108-
cx.types.(actual_n) += [expected];
2118+
cx.var_bindings.types.(actual_n) += [expected];
21092119
} else {
21102120
assert (actual_n == vlen);
2111-
cx.types += [mutable [expected]];
2121+
cx.var_bindings.types += [mutable [expected]];
21122122
}
21132123
}
21142124
}
@@ -2472,12 +2482,12 @@ mod unify {
24722482
case (ty::ty_var(?expected_id)) {
24732483
// Add a binding.
24742484
auto expected_n = get_or_create_set(cx, expected_id);
2475-
auto vlen = vec::len[vec[t]](cx.types);
2485+
auto vlen = vec::len[vec[t]](cx.var_bindings.types);
24762486
if (expected_n < vlen) {
2477-
cx.types.(expected_n) += [actual];
2487+
cx.var_bindings.types.(expected_n) += [actual];
24782488
} else {
24792489
assert (expected_n == vlen);
2480-
cx.types += [mutable [actual]];
2490+
cx.var_bindings.types += [mutable [actual]];
24812491
}
24822492
ret ures_ok(expected);
24832493
}
@@ -2517,9 +2527,9 @@ mod unify {
25172527
fn substituter(@ctxt cx, vec[t] types, t typ) -> t {
25182528
alt (struct(cx.tcx, typ)) {
25192529
case (ty_var(?id)) {
2520-
alt (cx.var_ids.find(id)) {
2530+
alt (cx.var_bindings.var_ids.find(id)) {
25212531
case (some[uint](?n)) {
2522-
auto root = ufind::find(cx.sets, n);
2532+
auto root = ufind::find(cx.var_bindings.sets, n);
25232533
ret types.(root);
25242534
}
25252535
case (none[uint]) { ret typ; }
@@ -2538,15 +2548,15 @@ mod unify {
25382548
let vec[mutable vec[t]] set_types = [mutable throwaway];
25392549
vec::pop[vec[t]](set_types); // FIXME: botch
25402550

2541-
for (ufind::node node in cx.sets.nodes) {
2551+
for (ufind::node node in cx.var_bindings.sets.nodes) {
25422552
let vec[t] v = [];
25432553
set_types += [mutable v];
25442554
}
25452555

25462556
auto i = 0u;
25472557
while (i < vec::len[vec[t]](set_types)) {
2548-
auto root = ufind::find(cx.sets, i);
2549-
set_types.(root) += cx.types.(i);
2558+
auto root = ufind::find(cx.var_bindings.sets, i);
2559+
set_types.(root) += cx.var_bindings.types.(i);
25502560
i += 1u;
25512561
}
25522562

@@ -2567,13 +2577,7 @@ mod unify {
25672577
&t actual,
25682578
&unify_handler handler,
25692579
&ty_ctxt tcx) -> result {
2570-
let vec[t] throwaway = [];
2571-
let vec[mutable vec[t]] types = [mutable throwaway];
2572-
vec::pop[vec[t]](types); // FIXME: botch
2573-
2574-
auto cx = @rec(sets=ufind::make(),
2575-
var_ids=common::new_int_hash[uint](),
2576-
mutable types=types,
2580+
auto cx = @rec(var_bindings=mk_var_bindings(),
25772581
handler=handler,
25782582
tcx=tcx);
25792583

@@ -2582,7 +2586,7 @@ mod unify {
25822586
case (ures_ok(?typ)) {
25832587
// Fast path: if there are no local variables, don't perform
25842588
// substitutions.
2585-
if (vec::len(cx.sets.nodes) == 0u) {
2589+
if (vec::len(cx.var_bindings.sets.nodes) == 0u) {
25862590
ret ures_ok(typ);
25872591
}
25882592

0 commit comments

Comments
 (0)