@@ -35,7 +35,7 @@ use middle::typeck::infer::lub::Lub;
35
35
use middle:: typeck:: infer:: to_str:: InferStr ;
36
36
use middle:: typeck:: infer:: unify:: { ValsAndBindings , Root } ;
37
37
use middle:: typeck:: infer:: error_reporting:: ErrorReporting ;
38
- use std:: cell:: Cell ;
38
+ use std:: cell:: { Cell , RefCell } ;
39
39
use std:: hashmap:: HashMap ;
40
40
use std:: result;
41
41
use std:: vec;
@@ -80,15 +80,17 @@ pub struct InferCtxt {
80
80
// We instantiate ValsAndBindings with bounds<ty::t> because the
81
81
// types that might instantiate a general type variable have an
82
82
// order, represented by its upper and lower bounds.
83
- ty_var_bindings : ValsAndBindings < ty:: TyVid , Bounds < ty:: t > > ,
83
+ ty_var_bindings : RefCell < ValsAndBindings < ty:: TyVid , Bounds < ty:: t > > > ,
84
84
ty_var_counter : Cell < uint > ,
85
85
86
86
// Map from integral variable to the kind of integer it represents
87
- int_var_bindings : ValsAndBindings < ty:: IntVid , Option < IntVarValue > > ,
87
+ int_var_bindings : RefCell < ValsAndBindings < ty:: IntVid ,
88
+ Option < IntVarValue > > > ,
88
89
int_var_counter : Cell < uint > ,
89
90
90
91
// Map from floating variable to the kind of float it represents
91
- float_var_bindings : ValsAndBindings < ty:: FloatVid , Option < ast:: float_ty > > ,
92
+ float_var_bindings : RefCell < ValsAndBindings < ty:: FloatVid ,
93
+ Option < ast:: float_ty > > > ,
92
94
float_var_counter : Cell < uint > ,
93
95
94
96
// For region variables.
@@ -260,13 +262,13 @@ pub fn new_infer_ctxt(tcx: ty::ctxt) -> @mut InferCtxt {
260
262
@mut InferCtxt {
261
263
tcx : tcx,
262
264
263
- ty_var_bindings : new_ValsAndBindings ( ) ,
265
+ ty_var_bindings : RefCell :: new ( new_ValsAndBindings ( ) ) ,
264
266
ty_var_counter : Cell :: new ( 0 ) ,
265
267
266
- int_var_bindings : new_ValsAndBindings ( ) ,
268
+ int_var_bindings : RefCell :: new ( new_ValsAndBindings ( ) ) ,
267
269
int_var_counter : Cell :: new ( 0 ) ,
268
270
269
- float_var_bindings : new_ValsAndBindings ( ) ,
271
+ float_var_bindings : RefCell :: new ( new_ValsAndBindings ( ) ) ,
270
272
float_var_counter : Cell :: new ( 0 ) ,
271
273
272
274
region_vars : RegionVarBindings ( tcx) ,
@@ -522,25 +524,25 @@ impl InferCtxt {
522
524
}
523
525
524
526
pub fn start_snapshot ( & mut self ) -> Snapshot {
527
+ let ty_var_bindings = self . ty_var_bindings . borrow ( ) ;
528
+ let int_var_bindings = self . int_var_bindings . borrow ( ) ;
529
+ let float_var_bindings = self . float_var_bindings . borrow ( ) ;
525
530
Snapshot {
526
- ty_var_bindings_len :
527
- self . ty_var_bindings . bindings . len ( ) ,
528
- int_var_bindings_len :
529
- self . int_var_bindings . bindings . len ( ) ,
530
- float_var_bindings_len :
531
- self . float_var_bindings . bindings . len ( ) ,
532
- region_vars_snapshot :
533
- self . region_vars . start_snapshot ( ) ,
531
+ ty_var_bindings_len : ty_var_bindings. get ( ) . bindings . len ( ) ,
532
+ int_var_bindings_len : int_var_bindings. get ( ) . bindings . len ( ) ,
533
+ float_var_bindings_len : float_var_bindings. get ( ) . bindings . len ( ) ,
534
+ region_vars_snapshot : self . region_vars . start_snapshot ( ) ,
534
535
}
535
536
}
536
537
537
538
pub fn rollback_to ( & mut self , snapshot : & Snapshot ) {
538
539
debug ! ( "rollback!" ) ;
539
- rollback_to ( & mut self . ty_var_bindings , snapshot. ty_var_bindings_len ) ;
540
-
541
- rollback_to ( & mut self . int_var_bindings ,
542
- snapshot. int_var_bindings_len ) ;
543
- rollback_to ( & mut self . float_var_bindings ,
540
+ let mut ty_var_bindings = self . ty_var_bindings . borrow_mut ( ) ;
541
+ let mut int_var_bindings = self . int_var_bindings . borrow_mut ( ) ;
542
+ let mut float_var_bindings = self . float_var_bindings . borrow_mut ( ) ;
543
+ rollback_to ( ty_var_bindings. get ( ) , snapshot. ty_var_bindings_len ) ;
544
+ rollback_to ( int_var_bindings. get ( ) , snapshot. int_var_bindings_len ) ;
545
+ rollback_to ( float_var_bindings. get ( ) ,
544
546
snapshot. float_var_bindings_len ) ;
545
547
546
548
self . region_vars . rollback_to ( snapshot. region_vars_snapshot ) ;
@@ -554,8 +556,10 @@ impl InferCtxt {
554
556
indent( || {
555
557
let r = self . try( || f ( ) ) ;
556
558
557
- self . ty_var_bindings. bindings. truncate( 0 ) ;
558
- self . int_var_bindings. bindings. truncate( 0 ) ;
559
+ let mut ty_var_bindings = self . ty_var_bindings. borrow_mut( ) ;
560
+ let mut int_var_bindings = self . int_var_bindings. borrow_mut( ) ;
561
+ ty_var_bindings. get( ) . bindings. truncate( 0 ) ;
562
+ int_var_bindings. get( ) . bindings. truncate( 0 ) ;
559
563
self . region_vars. commit( ) ;
560
564
r
561
565
} )
@@ -603,7 +607,8 @@ impl InferCtxt {
603
607
let id = self . ty_var_counter . get ( ) ;
604
608
self . ty_var_counter . set ( id + 1 ) ;
605
609
{
606
- let vals = & mut self . ty_var_bindings. vals;
610
+ let mut ty_var_bindings = self . ty_var_bindings . borrow_mut ( ) ;
611
+ let vals = & mut ty_var_bindings. get ( ) . vals ;
607
612
vals. insert ( id, Root ( Bounds { lb : None , ub : None } , 0 u) ) ;
608
613
}
609
614
return TyVid ( id) ;
@@ -619,8 +624,9 @@ impl InferCtxt {
619
624
620
625
pub fn next_int_var_id ( & mut self ) -> IntVid {
621
626
let mut int_var_counter = self . int_var_counter . get ( ) ;
627
+ let mut int_var_bindings = self . int_var_bindings . borrow_mut ( ) ;
622
628
let result = IntVid ( next_simple_var ( & mut int_var_counter,
623
- & mut self . int_var_bindings) ) ;
629
+ int_var_bindings. get ( ) ) ) ;
624
630
self . int_var_counter . set ( int_var_counter) ;
625
631
result
626
632
}
@@ -631,8 +637,9 @@ impl InferCtxt {
631
637
632
638
pub fn next_float_var_id ( & mut self ) -> FloatVid {
633
639
let mut float_var_counter = self . float_var_counter . get ( ) ;
640
+ let mut float_var_bindings = self . float_var_bindings . borrow_mut ( ) ;
634
641
let result = FloatVid ( next_simple_var ( & mut float_var_counter,
635
- & mut self . float_var_bindings) ) ;
642
+ float_var_bindings. get ( ) ) ) ;
636
643
self . float_var_counter . set ( float_var_counter) ;
637
644
result
638
645
}
0 commit comments