@@ -77,8 +77,8 @@ tag sty {
77
77
78
78
type unify_handler = obj {
79
79
fn resolve_local ( ast. def_id id ) -> option . t[ @t] ;
80
- fn record_local ( ast. def_id id , @t ty ) ; // TODO: -> unify_result
81
- fn record_param ( uint index , @t binding ) -> unify_result ;
80
+ fn record_local ( ast. def_id id , @t ty ) ; // TODO: -> Unify.result
81
+ fn record_param ( uint index , @t binding ) -> Unify . result ;
82
82
} ;
83
83
84
84
tag type_err {
@@ -95,11 +95,6 @@ tag type_err {
95
95
terr_arg_count;
96
96
}
97
97
98
- tag unify_result {
99
- ures_ok( @ty. t) ;
100
- ures_err ( type_err, @ty. t, @ty. t) ;
101
- }
102
-
103
98
104
99
type ty_param_count_and_ty = tup ( uint , @t ) ;
105
100
type type_cache = hashmap [ ast. def_id , ty_param_count_and_ty] ;
@@ -1551,12 +1546,16 @@ fn is_lval(@ast.expr expr) -> bool {
1551
1546
//
1552
1547
// http://www.cs.man.ac.uk/~hoderk/ubench/unification_full.pdf
1553
1548
1554
- type var_bindings = rec ( UFind . ufind sets,
1555
- hashmap[ int, uint] var_ids ,
1556
- mutable vec[ mutable vec[ @t] ] types ) ;
1549
+ mod Unify {
1550
+ tag result {
1551
+ ures_ok( @ty. t) ;
1552
+ ures_err( type_err, @ty. t, @ty. t) ;
1553
+ }
1554
+
1555
+ type var_bindings = rec ( UFind . ufind sets,
1556
+ hashmap[ int, uint] var_ids ,
1557
+ mutable vec[ mutable vec[ @t] ] types ) ;
1557
1558
1558
- fn unify ( @ty. t expected , @ty. t actual , & unify_handler handler)
1559
- -> unify_result {
1560
1559
// Wraps the given type in an appropriate cname.
1561
1560
//
1562
1561
// TODO: This doesn't do anything yet. We should carry the cname up from
@@ -1565,7 +1564,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1565
1564
// something we'll probably need to develop over time.
1566
1565
1567
1566
// Simple structural type comparison.
1568
- fn struct_cmp ( @ty. t expected , @ty. t actual ) -> unify_result {
1567
+ fn struct_cmp ( @ty. t expected , @ty. t actual ) -> result {
1569
1568
if ( expected. struct == actual. struct ) {
1570
1569
ret ures_ok ( expected) ;
1571
1570
}
@@ -1589,7 +1588,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1589
1588
}
1590
1589
1591
1590
tag fn_common_res {
1592
- fn_common_res_err( unify_result ) ;
1591
+ fn_common_res_err( result ) ;
1593
1592
fn_common_res_ok ( vec[ arg] , @t) ;
1594
1593
}
1595
1594
@@ -1666,7 +1665,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1666
1665
& unify_handler handler,
1667
1666
vec[ arg] expected_inputs , @t expected_output ,
1668
1667
vec[ arg] actual_inputs , @t actual_output )
1669
- -> unify_result {
1668
+ -> result {
1670
1669
1671
1670
if ( e_proto != a_proto) {
1672
1671
ret ures_err ( terr_mismatch, expected, actual) ;
@@ -1693,7 +1692,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1693
1692
& unify_handler handler,
1694
1693
vec[ arg] expected_inputs , @t expected_output ,
1695
1694
vec[ arg] actual_inputs , @t actual_output )
1696
- -> unify_result {
1695
+ -> result {
1697
1696
if ( e_abi != a_abi) {
1698
1697
ret ures_err ( terr_mismatch, expected, actual) ;
1699
1698
}
@@ -1717,7 +1716,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1717
1716
@ty. t actual ,
1718
1717
& unify_handler handler,
1719
1718
vec[ method] expected_meths ,
1720
- vec[ method] actual_meths ) -> unify_result {
1719
+ vec[ method] actual_meths ) -> result {
1721
1720
let vec[ method] result_meths = vec ( ) ;
1722
1721
let uint i = 0 u;
1723
1722
let uint expected_len = _vec. len [ method] ( expected_meths) ;
@@ -1772,7 +1771,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
1772
1771
}
1773
1772
1774
1773
fn unify_step ( & var_bindings bindings, @ty. t expected , @ty. t actual ,
1775
- & unify_handler handler) -> unify_result {
1774
+ & unify_handler handler) -> result {
1776
1775
// TODO: rewrite this using tuple pattern matching when available, to
1777
1776
// avoid all this rightward drift and spikiness.
1778
1777
@@ -2261,24 +2260,27 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
2261
2260
ret result;
2262
2261
}
2263
2262
2264
- let vec[ @t] throwaway = vec ( ) ;
2265
- let vec[ mutable vec[ @t] ] types = vec ( mutable throwaway) ;
2266
- _vec. pop [ mutable vec[ @t] ] ( types) ; // FIXME: botch
2263
+ fn unify ( @ty. t expected , @ty. t actual , & unify_handler handler)
2264
+ -> result {
2265
+ let vec[ @t] throwaway = vec ( ) ;
2266
+ let vec[ mutable vec[ @t] ] types = vec ( mutable throwaway) ;
2267
+ _vec. pop [ mutable vec[ @t] ] ( types) ; // FIXME: botch
2267
2268
2268
- auto bindings = rec ( sets=UFind . make ( ) ,
2269
- var_ids=common. new_int_hash [ uint] ( ) ,
2270
- mutable types=types) ;
2269
+ auto bindings = rec ( sets=UFind . make ( ) ,
2270
+ var_ids=common. new_int_hash [ uint] ( ) ,
2271
+ mutable types=types) ;
2271
2272
2272
- auto ures = unify_step ( bindings, expected, actual, handler) ;
2273
- alt ( ures) {
2274
- case ( ures_ok ( ?t) ) {
2275
- auto set_types = unify_sets ( bindings) ;
2276
- auto t2 = substitute ( bindings, set_types, t) ;
2277
- ret ures_ok ( t2) ;
2278
- }
2279
- case ( _) { ret ures; }
2273
+ auto ures = unify_step ( bindings, expected, actual, handler) ;
2274
+ alt ( ures) {
2275
+ case ( ures_ok ( ?t) ) {
2276
+ auto set_types = unify_sets ( bindings) ;
2277
+ auto t2 = substitute ( bindings, set_types, t) ;
2278
+ ret ures_ok ( t2) ;
2279
+ }
2280
+ case ( _) { ret ures; }
2281
+ }
2282
+ fail; // not reached
2280
2283
}
2281
- fail; // not reached
2282
2284
}
2283
2285
2284
2286
fn type_err_to_str ( & ty. type_err err ) -> str {
0 commit comments