@@ -308,14 +308,14 @@ enum infer_ctxt = @{
308
308
// We instantiate vals_and_bindings with bounds<ty::t> because the
309
309
// types that might instantiate a general type variable have an
310
310
// order, represented by its upper and lower bounds.
311
- tvb : vals_and_bindings <ty:: tv_vid , bounds < ty:: t > >,
311
+ ty_var_bindings : vals_and_bindings <ty:: tv_vid , bounds < ty:: t > >,
312
312
313
313
// The types that might instantiate an integral type variable are
314
314
// represented by an int_ty_set.
315
- tvib : vals_and_bindings<ty:: tvi_vid, int_ty_set>,
315
+ ty_var_integral_bindings : vals_and_bindings<ty:: tvi_vid, int_ty_set>,
316
316
317
317
// For region variables.
318
- rb : vals_and_bindings<ty:: region_vid, bounds<ty:: region>>,
318
+ region_var_bindings : vals_and_bindings<ty:: region_vid, bounds<ty:: region>>,
319
319
320
320
// For keeping track of existing type and region variables.
321
321
ty_var_counter: @mut uint,
@@ -352,11 +352,15 @@ fn fixup_err_to_str(f: fixup_err) -> ~str {
352
352
type ures = result:: result < ( ) , ty:: type_err > ;
353
353
type fres < T > = result:: result < T , fixup_err > ;
354
354
355
+ fn new_vals_and_bindings < V : copy , T : copy > ( ) -> vals_and_bindings < V , T > {
356
+ { vals: smallintmap:: mk ( ) , mut bindings: ~[ ] }
357
+ }
358
+
355
359
fn new_infer_ctxt ( tcx : ty:: ctxt ) -> infer_ctxt {
356
360
infer_ctxt ( @{ tcx: tcx,
357
- tvb : { vals : smallintmap :: mk ( ) , mut bindings : ~ [ ] } ,
358
- tvib : { vals : smallintmap :: mk ( ) , mut bindings : ~ [ ] } ,
359
- rb : { vals : smallintmap :: mk ( ) , mut bindings : ~ [ ] } ,
361
+ ty_var_bindings : new_vals_and_bindings ( ) ,
362
+ ty_var_integral_bindings : new_vals_and_bindings ( ) ,
363
+ region_var_bindings : new_vals_and_bindings ( ) ,
360
364
ty_var_counter: @mut 0 u,
361
365
ty_var_integral_counter: @mut 0 u,
362
366
region_var_counter: @mut 0 u,
@@ -582,24 +586,24 @@ impl infer_ctxt {
582
586
/// Execute `f` and commit the bindings if successful
583
587
fn commit < T , E > ( f : fn ( ) -> result < T , E > ) -> result < T , E > {
584
588
585
- assert self. tvb . bindings . len ( ) == 0 u;
586
- assert self. rb . bindings . len ( ) == 0 u;
589
+ assert self. ty_var_bindings . bindings . len ( ) == 0 u;
590
+ assert self. region_var_bindings . bindings . len ( ) == 0 u;
587
591
588
592
let r <- self . try( f ) ;
589
593
590
594
// FIXME (#2814)---could use a vec::clear() that ran destructors but
591
595
// kept the vec at its currently allocated length
592
- self . tvb . bindings = ~[ ] ;
593
- self . rb . bindings = ~[ ] ;
596
+ self . ty_var_bindings . bindings = ~[ ] ;
597
+ self . region_var_bindings . bindings = ~[ ] ;
594
598
595
599
return r;
596
600
}
597
601
598
602
/// Execute `f`, unroll bindings on failure
599
603
fn try < T , E > ( f : fn ( ) -> result < T , E > ) -> result < T , E > {
600
604
601
- let tvbl = self . tvb . bindings . len ( ) ;
602
- let rbl = self . rb . bindings . len ( ) ;
605
+ let tvbl = self . ty_var_bindings . bindings . len ( ) ;
606
+ let rbl = self . region_var_bindings . bindings . len ( ) ;
603
607
let bl = self . borrowings . len ( ) ;
604
608
605
609
debug ! { "try(tvbl=%u, rbl=%u)" , tvbl, rbl} ;
@@ -608,8 +612,8 @@ impl infer_ctxt {
608
612
result:: ok( _) => debug ! { "try--ok" } ,
609
613
result:: err( _) => {
610
614
debug ! { "try--rollback" } ;
611
- rollback_to ( & self . tvb , tvbl) ;
612
- rollback_to ( & self . rb , rbl) ;
615
+ rollback_to ( & self . ty_var_bindings , tvbl) ;
616
+ rollback_to ( & self . region_var_bindings , rbl) ;
613
617
while self . borrowings . len ( ) != bl { self . borrowings . pop ( ) ; }
614
618
}
615
619
}
@@ -618,11 +622,11 @@ impl infer_ctxt {
618
622
619
623
/// Execute `f` then unroll any bindings it creates
620
624
fn probe < T , E > ( f : fn ( ) -> result < T , E > ) -> result < T , E > {
621
- assert self. tvb . bindings . len ( ) == 0 u;
622
- assert self. rb . bindings . len ( ) == 0 u;
625
+ assert self. ty_var_bindings . bindings . len ( ) == 0 u;
626
+ assert self. region_var_bindings . bindings . len ( ) == 0 u;
623
627
let r <- f ( ) ;
624
- rollback_to ( & self . tvb , 0 u ) ;
625
- rollback_to ( & self . rb , 0 u ) ;
628
+ rollback_to ( & self . ty_var_bindings , 0 u ) ;
629
+ rollback_to ( & self . region_var_bindings , 0 u ) ;
626
630
return r;
627
631
}
628
632
}
@@ -631,7 +635,7 @@ impl infer_ctxt {
631
635
fn next_ty_var_id ( ) -> tv_vid {
632
636
let id = * self . ty_var_counter ;
633
637
* self . ty_var_counter += 1 u;
634
- self . tvb . vals . insert ( id,
638
+ self . ty_var_bindings . vals . insert ( id,
635
639
root ( { lb: none, ub: none} , 0 u) ) ;
636
640
return tv_vid ( id) ;
637
641
}
@@ -648,7 +652,7 @@ impl infer_ctxt {
648
652
let id = * self . ty_var_integral_counter ;
649
653
* self . ty_var_integral_counter += 1 u;
650
654
651
- self . tvib . vals . insert ( id,
655
+ self . ty_var_integral_bindings . vals . insert ( id,
652
656
root ( int_ty_set_all ( ) , 0 u) ) ;
653
657
return tvi_vid ( id) ;
654
658
}
@@ -660,7 +664,7 @@ impl infer_ctxt {
660
664
fn next_region_var_id ( bnds : bounds < ty:: region > ) -> region_vid {
661
665
let id = * self . region_var_counter ;
662
666
* self . region_var_counter += 1 u;
663
- self . rb . vals . insert ( id, root ( bnds, 0 ) ) ;
667
+ self . region_var_bindings . vals . insert ( id, root ( bnds, 0 ) ) ;
664
668
return region_vid ( id) ;
665
669
}
666
670
@@ -947,6 +951,7 @@ impl infer_ctxt {
947
951
uok ( )
948
952
}
949
953
954
+ /// make variable a subtype of T
950
955
fn vart < V : copy vid, T : copy to_str st> (
951
956
vb : & vals_and_bindings < V , bounds < T > > ,
952
957
a_id : V , b : T ) -> ures {
@@ -983,6 +988,7 @@ impl infer_ctxt {
983
988
uok ( )
984
989
}
985
990
991
+ /// make T a subtype of variable
986
992
fn tvar < V : copy vid, T : copy to_str st> (
987
993
vb : & vals_and_bindings < V , bounds < T > > ,
988
994
a : T , b_id : V ) -> ures {
@@ -1213,7 +1219,7 @@ impl resolve_state {
1213
1219
if !self . should ( resolve_rvar) {
1214
1220
return ty:: re_var ( rid)
1215
1221
}
1216
- let nde = self . infcx . get ( & self . infcx . rb , rid) ;
1222
+ let nde = self . infcx . get ( & self . infcx . region_var_bindings , rid) ;
1217
1223
let bounds = nde. possible_types ;
1218
1224
match bounds {
1219
1225
{ ub: _, lb: some( r) } => { self . assert_not_rvar ( rid, r) ; r }
@@ -1250,7 +1256,7 @@ impl resolve_state {
1250
1256
// tend to carry more restrictions or higher
1251
1257
// perf. penalties, so it pays to know more.
1252
1258
1253
- let nde = self . infcx . get ( & self . infcx . tvb , vid) ;
1259
+ let nde = self . infcx . get ( & self . infcx . ty_var_bindings , vid) ;
1254
1260
let bounds = nde. possible_types ;
1255
1261
1256
1262
let t1 = match bounds {
@@ -1274,7 +1280,7 @@ impl resolve_state {
1274
1280
return ty:: mk_var_integral ( self . infcx . tcx , vid) ;
1275
1281
}
1276
1282
1277
- let nde = self . infcx . get ( & self . infcx . tvib , vid) ;
1283
+ let nde = self . infcx . get ( & self . infcx . ty_var_integral_bindings , vid) ;
1278
1284
let pt = nde. possible_types ;
1279
1285
1280
1286
// If there's only one type in the set of possible types, then
@@ -1286,7 +1292,7 @@ impl resolve_state {
1286
1292
// As a last resort, default to int.
1287
1293
let ty = ty:: mk_int ( self . infcx . tcx ) ;
1288
1294
self . infcx . set (
1289
- & self . infcx . tvib , vid,
1295
+ & self . infcx . ty_var_integral_bindings , vid,
1290
1296
root ( convert_integral_ty_to_int_ty_set ( self . infcx . tcx ,
1291
1297
ty) ,
1292
1298
nde. rank ) ) ;
@@ -1372,8 +1378,8 @@ impl infer_ctxt {
1372
1378
}
1373
1379
1374
1380
( ty:: ty_var( a_id) , ty:: ty_var( b_id) ) => {
1375
- let nde_a = self . get ( & self . tvb , a_id) ;
1376
- let nde_b = self . get ( & self . tvb , b_id) ;
1381
+ let nde_a = self . get ( & self . ty_var_bindings , a_id) ;
1382
+ let nde_b = self . get ( & self . ty_var_bindings , b_id) ;
1377
1383
let a_bounds = nde_a. possible_types ;
1378
1384
let b_bounds = nde_b. possible_types ;
1379
1385
@@ -1383,15 +1389,15 @@ impl infer_ctxt {
1383
1389
}
1384
1390
1385
1391
( ty:: ty_var( a_id) , _) => {
1386
- let nde_a = self . get ( & self . tvb , a_id) ;
1392
+ let nde_a = self . get ( & self . ty_var_bindings , a_id) ;
1387
1393
let a_bounds = nde_a. possible_types ;
1388
1394
1389
1395
let a_bnd = select ( a_bounds. ub , a_bounds. lb ) ;
1390
1396
self . assign_tys_or_sub ( anmnt, a, b, a_bnd, some ( b) )
1391
1397
}
1392
1398
1393
1399
( _, ty:: ty_var( b_id) ) => {
1394
- let nde_b = self . get ( & self . tvb , b_id) ;
1400
+ let nde_b = self . get ( & self . ty_var_bindings , b_id) ;
1395
1401
let b_bounds = nde_b. possible_types ;
1396
1402
1397
1403
let b_bnd = select ( b_bounds. lb , b_bounds. ub ) ;
@@ -1750,17 +1756,20 @@ fn super_tys<C:combine>(
1750
1756
1751
1757
// Have to handle these first
1752
1758
( ty:: ty_var_integral( a_id) , ty:: ty_var_integral( b_id) ) => {
1753
- self . infcx ( ) . vars_integral ( & self . infcx ( ) . tvib , a_id, b_id)
1759
+ self . infcx ( ) . vars_integral ( & self . infcx ( ) . ty_var_integral_bindings ,
1760
+ a_id, b_id)
1754
1761
. then ( || ok ( a) )
1755
1762
}
1756
1763
( ty:: ty_var_integral( a_id) , ty:: ty_int( _) ) |
1757
1764
( ty:: ty_var_integral( a_id) , ty:: ty_uint( _) ) => {
1758
- self . infcx ( ) . vart_integral ( & self . infcx ( ) . tvib , a_id, b)
1765
+ self . infcx ( ) . vart_integral ( & self . infcx ( ) . ty_var_integral_bindings ,
1766
+ a_id, b)
1759
1767
. then ( || ok ( a) )
1760
1768
}
1761
1769
( ty:: ty_int( _) , ty:: ty_var_integral( b_id) ) |
1762
1770
( ty:: ty_uint( _) , ty:: ty_var_integral( b_id) ) => {
1763
- self . infcx ( ) . tvar_integral ( & self . infcx ( ) . tvib , a, b_id)
1771
+ self . infcx ( ) . tvar_integral ( & self . infcx ( ) . ty_var_integral_bindings ,
1772
+ a, b_id)
1764
1773
. then ( || ok ( a) )
1765
1774
}
1766
1775
@@ -1902,17 +1911,20 @@ impl sub: combine {
1902
1911
do indent {
1903
1912
match ( a, b) {
1904
1913
( ty:: re_var ( a_id) , ty:: re_var ( b_id) ) => {
1905
- do self . infcx ( ) . vars ( & self . rb , a_id, b_id) . then {
1914
+ do self . infcx ( ) . vars ( & self . region_var_bindings ,
1915
+ a_id, b_id) . then {
1906
1916
ok ( a)
1907
1917
}
1908
1918
}
1909
1919
( ty:: re_var ( a_id) , _) => {
1910
- do self . infcx ( ) . vart ( & self . rb , a_id, b) . then {
1920
+ do self . infcx ( ) . vart ( & self . region_var_bindings ,
1921
+ a_id, b) . then {
1911
1922
ok ( a)
1912
1923
}
1913
1924
}
1914
1925
( _, ty:: re_var ( b_id) ) => {
1915
- do self . infcx ( ) . tvar ( & self . rb , a, b_id) . then {
1926
+ do self . infcx ( ) . tvar ( & self . region_var_bindings ,
1927
+ a, b_id) . then {
1916
1928
ok ( a)
1917
1929
}
1918
1930
}
@@ -1973,13 +1985,16 @@ impl sub: combine {
1973
1985
ok ( a)
1974
1986
}
1975
1987
( ty:: ty_var ( a_id) , ty:: ty_var ( b_id) ) => {
1976
- self . infcx ( ) . vars ( & self . tvb , a_id, b_id) . then ( || ok ( a) )
1988
+ self . infcx ( ) . vars ( & self . ty_var_bindings ,
1989
+ a_id, b_id) . then ( || ok ( a) )
1977
1990
}
1978
1991
( ty:: ty_var ( a_id) , _) => {
1979
- self . infcx ( ) . vart ( & self . tvb , a_id, b) . then ( || ok ( a) )
1992
+ self . infcx ( ) . vart ( & self . ty_var_bindings ,
1993
+ a_id, b) . then ( || ok ( a) )
1980
1994
}
1981
1995
( _, ty:: ty_var ( b_id) ) => {
1982
- self . infcx ( ) . tvar ( & self . tvb , a, b_id) . then ( || ok ( a) )
1996
+ self . infcx ( ) . tvar ( & self . ty_var_bindings ,
1997
+ a, b_id) . then ( || ok ( a) )
1983
1998
}
1984
1999
( _, ty:: ty_bot) => {
1985
2000
err ( ty:: terr_sorts ( b, a) )
@@ -2483,18 +2498,18 @@ fn lattice_tys<L:lattice_ops combine>(
2483
2498
( _, ty:: ty_bot) => self . ty_bot ( a) ,
2484
2499
2485
2500
( ty:: ty_var ( a_id) , ty:: ty_var ( b_id) ) => {
2486
- lattice_vars ( self , & self . infcx ( ) . tvb ,
2501
+ lattice_vars ( self , & self . infcx ( ) . ty_var_bindings ,
2487
2502
a, a_id, b_id,
2488
2503
|x, y| self . tys ( x, y) )
2489
2504
}
2490
2505
2491
2506
( ty:: ty_var ( a_id) , _) => {
2492
- lattice_var_t ( self , & self . infcx ( ) . tvb , a_id, b,
2507
+ lattice_var_t ( self , & self . infcx ( ) . ty_var_bindings , a_id, b,
2493
2508
|x, y| self . tys ( x, y) )
2494
2509
}
2495
2510
2496
2511
( _, ty:: ty_var ( b_id) ) => {
2497
- lattice_var_t ( self , & self . infcx ( ) . tvb , b_id, a,
2512
+ lattice_var_t ( self , & self . infcx ( ) . ty_var_bindings , b_id, a,
2498
2513
|x, y| self . tys ( x, y) )
2499
2514
}
2500
2515
_ => {
@@ -2510,13 +2525,13 @@ fn lattice_rvars<L:lattice_ops combine>(
2510
2525
2511
2526
match ( a, b) {
2512
2527
( ty:: re_var( a_id) , ty:: re_var( b_id) ) => {
2513
- lattice_vars ( self , & self . infcx ( ) . rb ,
2528
+ lattice_vars ( self , & self . infcx ( ) . region_var_bindings ,
2514
2529
a, a_id, b_id,
2515
2530
|x, y| self . regions ( x, y) )
2516
2531
}
2517
2532
2518
2533
( ty:: re_var( v_id) , r) | ( r, ty:: re_var( v_id) ) => {
2519
- lattice_var_t ( self , & self . infcx ( ) . rb ,
2534
+ lattice_var_t ( self , & self . infcx ( ) . region_var_bindings ,
2520
2535
v_id, r,
2521
2536
|x, y| self . regions ( x, y) )
2522
2537
}
0 commit comments