@@ -1865,18 +1865,19 @@ mod unify {
1865
1865
ures_err( type_err, t, t) ;
1866
1866
}
1867
1867
1868
- type var_bindings = rec ( ufind:: ufind sets,
1869
- hashmap[ int , uint] var_ids ,
1870
- mutable vec[ mutable vec[ t] ] types ) ;
1868
+ type bindings [ T ] = rec ( ufind:: ufind sets,
1869
+ hashmap[ T , uint] ids ,
1870
+ mutable vec[ mutable vec[ t] ] types) ;
1871
1871
1872
- fn mk_var_bindings ( ) -> @var_bindings {
1872
+ fn mk_bindings[ T ] ( map:: hashfn[ T ] hasher, map:: eqfn[ T ] eqer)
1873
+ -> @bindings[ T ] {
1873
1874
let vec[ mutable vec[ t] ] types = [ mutable] ;
1874
1875
ret @rec( sets=ufind:: make ( ) ,
1875
- var_ids=common :: new_int_hash [ uint] ( ) ,
1876
+ ids=map :: mk_hashmap [ T , uint] ( hasher , eqer ) ,
1876
1877
mutable types=types) ;
1877
1878
}
1878
1879
1879
- type ctxt = rec ( @var_bindings var_bindings ,
1880
+ type ctxt = rec ( @bindings [ int ] bindings ,
1880
1881
unify_handler handler,
1881
1882
ty_ctxt tcx) ;
1882
1883
@@ -2079,10 +2080,10 @@ mod unify {
2079
2080
2080
2081
fn get_or_create_set ( & @ctxt cx , int id) -> uint {
2081
2082
auto set_num;
2082
- alt ( cx. var_bindings . var_ids . find ( id) ) {
2083
+ alt ( cx. bindings . ids . find ( id) ) {
2083
2084
case ( none[ uint] ) {
2084
- set_num = ufind:: make_set ( cx. var_bindings . sets ) ;
2085
- cx. var_bindings . var_ids . insert ( id, set_num) ;
2085
+ set_num = ufind:: make_set ( cx. bindings . sets ) ;
2086
+ cx. bindings . ids . insert ( id, set_num) ;
2086
2087
}
2087
2088
case ( some[ uint] ( ?n) ) { set_num = n; }
2088
2089
}
@@ -2107,18 +2108,17 @@ mod unify {
2107
2108
alt ( struct ( cx. tcx , expected) ) {
2108
2109
case ( ty:: ty_var ( ?expected_id) ) {
2109
2110
auto expected_n = get_or_create_set ( cx, expected_id) ;
2110
- ufind:: union ( cx. var_bindings . sets , expected_n,
2111
- actual_n) ;
2111
+ ufind:: union ( cx. bindings . sets , expected_n, actual_n) ;
2112
2112
}
2113
2113
2114
2114
case ( _) {
2115
2115
// Just bind the type variable to the expected type.
2116
- auto vlen = vec:: len[ vec[ t] ] ( cx. var_bindings . types ) ;
2116
+ auto vlen = vec:: len[ vec[ t] ] ( cx. bindings . types ) ;
2117
2117
if ( actual_n < vlen) {
2118
- cx. var_bindings . types . ( actual_n) += [ expected] ;
2118
+ cx. bindings . types . ( actual_n) += [ expected] ;
2119
2119
} else {
2120
2120
assert ( actual_n == vlen) ;
2121
- cx. var_bindings . types += [ mutable [ expected] ] ;
2121
+ cx. bindings . types += [ mutable [ expected] ] ;
2122
2122
}
2123
2123
}
2124
2124
}
@@ -2482,12 +2482,12 @@ mod unify {
2482
2482
case ( ty:: ty_var ( ?expected_id) ) {
2483
2483
// Add a binding.
2484
2484
auto expected_n = get_or_create_set ( cx, expected_id) ;
2485
- auto vlen = vec:: len[ vec[ t] ] ( cx. var_bindings . types ) ;
2485
+ auto vlen = vec:: len[ vec[ t] ] ( cx. bindings . types ) ;
2486
2486
if ( expected_n < vlen) {
2487
- cx. var_bindings . types . ( expected_n) += [ actual] ;
2487
+ cx. bindings . types . ( expected_n) += [ actual] ;
2488
2488
} else {
2489
2489
assert ( expected_n == vlen) ;
2490
- cx. var_bindings . types += [ mutable [ actual] ] ;
2490
+ cx. bindings . types += [ mutable [ actual] ] ;
2491
2491
}
2492
2492
ret ures_ok( expected) ;
2493
2493
}
@@ -2519,19 +2519,23 @@ mod unify {
2519
2519
}
2520
2520
2521
2521
// Performs type binding substitution.
2522
- fn substitute ( & ty_ctxt tcx, & @var_bindings var_bindings ,
2523
- & vec[ t] set_types , & t typ ) -> t {
2522
+ fn substitute ( & ty_ctxt tcx,
2523
+ & @bindings[ int] bindings ,
2524
+ & vec[ t] set_types ,
2525
+ & t typ ) -> t {
2524
2526
if ( !type_contains_vars ( tcx, typ) ) {
2525
2527
ret typ;
2526
2528
}
2527
2529
2528
- fn substituter ( ty_ctxt tcx, @var_bindings var_bindings , vec[ t] types ,
2530
+ fn substituter ( ty_ctxt tcx,
2531
+ @bindings[ int] bindings ,
2532
+ vec[ t] types ,
2529
2533
t typ ) -> t {
2530
2534
alt ( struct ( tcx, typ) ) {
2531
2535
case ( ty_var ( ?id) ) {
2532
- alt ( var_bindings . var_ids . find ( id) ) {
2536
+ alt ( bindings . ids . find ( id) ) {
2533
2537
case ( some[ uint] ( ?n) ) {
2534
- auto root = ufind:: find ( var_bindings . sets , n) ;
2538
+ auto root = ufind:: find ( bindings . sets , n) ;
2535
2539
ret types. ( root) ;
2536
2540
}
2537
2541
case ( none[ uint] ) { ret typ; }
@@ -2541,24 +2545,22 @@ mod unify {
2541
2545
}
2542
2546
}
2543
2547
2544
- auto f = bind substituter ( tcx, var_bindings , set_types, _) ;
2548
+ auto f = bind substituter ( tcx, bindings , set_types, _) ;
2545
2549
ret fold_ty( tcx, f, typ) ;
2546
2550
}
2547
2551
2548
- fn unify_sets ( & @var_bindings var_bindings ) -> vec[ t ] {
2549
- let vec[ t] throwaway = [ ] ;
2550
- let vec[ mutable vec[ t] ] set_types = [ mutable throwaway] ;
2551
- vec:: pop[ vec[ t] ] ( set_types) ; // FIXME: botch
2552
+ fn unify_sets[ T ] ( & @bindings[ T ] bindings) -> vec[ t] {
2553
+ let vec[ mutable vec[ t] ] set_types = [ mutable] ;
2552
2554
2553
- for ( ufind:: node node in var_bindings . sets. nodes) {
2555
+ for ( ufind:: node node in bindings . sets. nodes) {
2554
2556
let vec[ t] v = [ ] ;
2555
2557
set_types += [ mutable v] ;
2556
2558
}
2557
2559
2558
2560
auto i = 0 u;
2559
2561
while ( i < vec:: len[ vec[ t] ] ( set_types) ) {
2560
- auto root = ufind:: find ( var_bindings . sets , i) ;
2561
- set_types. ( root) += var_bindings . types . ( i) ;
2562
+ auto root = ufind:: find ( bindings . sets , i) ;
2563
+ set_types. ( root) += bindings . types . ( i) ;
2562
2564
i += 1 u;
2563
2565
}
2564
2566
@@ -2578,15 +2580,15 @@ mod unify {
2578
2580
fn unify ( & t expected ,
2579
2581
& t actual ,
2580
2582
& unify_handler handler,
2581
- & @var_bindings var_bindings ,
2583
+ & @bindings [ int ] bindings ,
2582
2584
& ty_ctxt tcx) -> result {
2583
- auto cx = @rec ( var_bindings=var_bindings , handler=handler, tcx=tcx) ;
2585
+ auto cx = @rec ( bindings=bindings , handler=handler, tcx=tcx) ;
2584
2586
ret unify_step( cx, expected, actual) ;
2585
2587
}
2586
2588
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) ;
2589
+ fn fixup ( & ty_ctxt tcx, & @bindings [ int ] bindings , t typ ) -> t {
2590
+ auto set_types = unify_sets[ int ] ( bindings ) ;
2591
+ ret substitute ( tcx, bindings , set_types, typ) ;
2590
2592
}
2591
2593
}
2592
2594
0 commit comments