Skip to content

Commit ff66d3d

Browse files
committed
---
yaml --- r: 2619 b: refs/heads/master c: 13d9f6a h: refs/heads/master i: 2617: a1dfb8f 2615: f212ae5 v: v3
1 parent f1ffef8 commit ff66d3d

File tree

3 files changed

+41
-38
lines changed

3 files changed

+41
-38
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: 96516e9ca263574fa58c2f0a48348fa0d876be10
2+
refs/heads/master: 13d9f6a2640815aa1fa2a299e0ab364cd292cbfa

trunk/src/comp/middle/ty.rs

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,14 +1869,14 @@ mod unify {
18691869
hashmap[int,uint] var_ids,
18701870
mutable vec[mutable vec[t]] types);
18711871

1872-
fn mk_var_bindings() -> var_bindings {
1872+
fn mk_var_bindings() -> @var_bindings {
18731873
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);
1874+
ret @rec(sets=ufind::make(),
1875+
var_ids=common::new_int_hash[uint](),
1876+
mutable types=types);
18771877
}
18781878

1879-
type ctxt = rec(var_bindings var_bindings,
1879+
type ctxt = rec(@var_bindings var_bindings,
18801880
unify_handler handler,
18811881
ty_ctxt tcx);
18821882

@@ -2519,17 +2519,19 @@ mod unify {
25192519
}
25202520

25212521
// Performs type binding substitution.
2522-
fn substitute(&@ctxt cx, &vec[t] set_types, &t typ) -> t {
2523-
if (!type_contains_vars(cx.tcx, typ)) {
2522+
fn substitute(&ty_ctxt tcx, &@var_bindings var_bindings,
2523+
&vec[t] set_types, &t typ) -> t {
2524+
if (!type_contains_vars(tcx, typ)) {
25242525
ret typ;
25252526
}
25262527

2527-
fn substituter(@ctxt cx, vec[t] types, t typ) -> t {
2528-
alt (struct(cx.tcx, typ)) {
2528+
fn substituter(ty_ctxt tcx, @var_bindings var_bindings, vec[t] types,
2529+
t typ) -> t {
2530+
alt (struct(tcx, typ)) {
25292531
case (ty_var(?id)) {
2530-
alt (cx.var_bindings.var_ids.find(id)) {
2532+
alt (var_bindings.var_ids.find(id)) {
25312533
case (some[uint](?n)) {
2532-
auto root = ufind::find(cx.var_bindings.sets, n);
2534+
auto root = ufind::find(var_bindings.sets, n);
25332535
ret types.(root);
25342536
}
25352537
case (none[uint]) { ret typ; }
@@ -2539,24 +2541,24 @@ mod unify {
25392541
}
25402542
}
25412543

2542-
auto f = bind substituter(cx, set_types, _);
2543-
ret fold_ty(cx.tcx, f, typ);
2544+
auto f = bind substituter(tcx, var_bindings, set_types, _);
2545+
ret fold_ty(tcx, f, typ);
25442546
}
25452547

2546-
fn unify_sets(&@ctxt cx) -> vec[t] {
2548+
fn unify_sets(&@var_bindings var_bindings) -> vec[t] {
25472549
let vec[t] throwaway = [];
25482550
let vec[mutable vec[t]] set_types = [mutable throwaway];
25492551
vec::pop[vec[t]](set_types); // FIXME: botch
25502552

2551-
for (ufind::node node in cx.var_bindings.sets.nodes) {
2553+
for (ufind::node node in var_bindings.sets.nodes) {
25522554
let vec[t] v = [];
25532555
set_types += [mutable v];
25542556
}
25552557

25562558
auto i = 0u;
25572559
while (i < vec::len[vec[t]](set_types)) {
2558-
auto root = ufind::find(cx.var_bindings.sets, i);
2559-
set_types.(root) += cx.var_bindings.types.(i);
2560+
auto root = ufind::find(var_bindings.sets, i);
2561+
set_types.(root) += var_bindings.types.(i);
25602562
i += 1u;
25612563
}
25622564

@@ -2576,27 +2578,15 @@ mod unify {
25762578
fn unify(&t expected,
25772579
&t actual,
25782580
&unify_handler handler,
2581+
&@var_bindings var_bindings,
25792582
&ty_ctxt tcx) -> result {
2580-
auto cx = @rec(var_bindings=mk_var_bindings(),
2581-
handler=handler,
2582-
tcx=tcx);
2583-
2584-
auto ures = unify_step(cx, expected, actual);
2585-
alt (ures) {
2586-
case (ures_ok(?typ)) {
2587-
// Fast path: if there are no local variables, don't perform
2588-
// substitutions.
2589-
if (vec::len(cx.var_bindings.sets.nodes) == 0u) {
2590-
ret ures_ok(typ);
2591-
}
2583+
auto cx = @rec(var_bindings=var_bindings, handler=handler, tcx=tcx);
2584+
ret unify_step(cx, expected, actual);
2585+
}
25922586

2593-
auto set_types = unify_sets(cx);
2594-
auto t2 = substitute(cx, set_types, typ);
2595-
ret ures_ok(t2);
2596-
}
2597-
case (_) { ret ures; }
2598-
}
2599-
fail; // not reached
2587+
fn fixup(&ty_ctxt tcx, &@var_bindings var_bindings, t typ) -> t {
2588+
auto set_types = unify_sets(var_bindings);
2589+
ret substitute(tcx, var_bindings, set_types, typ);
26002590
}
26012591
}
26022592

trunk/src/comp/middle/typeck.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,21 @@ mod unify {
934934

935935

936936
auto handler = unify_handler(fcx, param_substs);
937+
938+
auto var_bindings = ty::unify::mk_var_bindings();
937939
auto result = ty::unify::unify(expected, actual, handler,
938-
fcx.ccx.tcx);
940+
var_bindings, fcx.ccx.tcx);
941+
942+
alt (result) {
943+
case (ures_ok(?rty)) {
944+
if (ty::type_contains_vars(fcx.ccx.tcx, rty)) {
945+
result = ures_ok(ty::unify::fixup(fcx.ccx.tcx,
946+
var_bindings, rty));
947+
}
948+
}
949+
case (_) { /* nothing */ }
950+
}
951+
939952
fcx.ccx.unify_cache.insert(cache_key, result);
940953
ret result;
941954
}

0 commit comments

Comments
 (0)