@@ -35,6 +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
39
use std:: hashmap:: HashMap ;
39
40
use std:: result;
40
41
use std:: vec;
@@ -43,8 +44,8 @@ use syntax::ast;
43
44
use syntax:: codemap;
44
45
use syntax:: codemap:: Span ;
45
46
use util:: common:: indent;
46
- use util:: ppaux:: { bound_region_to_str, ty_to_str, trait_ref_to_str, Repr ,
47
- UserString } ;
47
+ use util:: ppaux:: { bound_region_to_str, ty_to_str, trait_ref_to_str, Repr } ;
48
+ use util :: ppaux :: { UserString } ;
48
49
49
50
pub mod doc;
50
51
pub mod macros;
@@ -80,15 +81,15 @@ pub struct InferCtxt {
80
81
// types that might instantiate a general type variable have an
81
82
// order, represented by its upper and lower bounds.
82
83
ty_var_bindings : ValsAndBindings < ty:: TyVid , Bounds < ty:: t > > ,
83
- ty_var_counter : uint ,
84
+ ty_var_counter : Cell < uint > ,
84
85
85
86
// Map from integral variable to the kind of integer it represents
86
87
int_var_bindings : ValsAndBindings < ty:: IntVid , Option < IntVarValue > > ,
87
- int_var_counter : uint ,
88
+ int_var_counter : Cell < uint > ,
88
89
89
90
// Map from floating variable to the kind of float it represents
90
91
float_var_bindings : ValsAndBindings < ty:: FloatVid , Option < ast:: float_ty > > ,
91
- float_var_counter : uint ,
92
+ float_var_counter : Cell < uint > ,
92
93
93
94
// For region variables.
94
95
region_vars : RegionVarBindings ,
@@ -260,13 +261,13 @@ pub fn new_infer_ctxt(tcx: ty::ctxt) -> @mut InferCtxt {
260
261
tcx : tcx,
261
262
262
263
ty_var_bindings : new_ValsAndBindings ( ) ,
263
- ty_var_counter : 0 ,
264
+ ty_var_counter : Cell :: new ( 0 ) ,
264
265
265
266
int_var_bindings : new_ValsAndBindings ( ) ,
266
- int_var_counter : 0 ,
267
+ int_var_counter : Cell :: new ( 0 ) ,
267
268
268
269
float_var_bindings : new_ValsAndBindings ( ) ,
269
- float_var_counter : 0 ,
270
+ float_var_counter : Cell :: new ( 0 ) ,
270
271
271
272
region_vars : RegionVarBindings ( tcx) ,
272
273
}
@@ -599,8 +600,8 @@ fn next_simple_var<V:Clone,T:Clone>(counter: &mut uint,
599
600
600
601
impl InferCtxt {
601
602
pub fn next_ty_var_id ( & mut self ) -> TyVid {
602
- let id = self . ty_var_counter;
603
- self . ty_var_counter += 1 ;
603
+ let id = self . ty_var_counter. get ( ) ;
604
+ self . ty_var_counter. set ( id + 1 ) ;
604
605
{
605
606
let vals = & mut self . ty_var_bindings. vals;
606
607
vals. insert( id, Root ( Bounds { lb : None , ub : None } , 0 u) ) ;
@@ -617,17 +618,23 @@ impl InferCtxt {
617
618
}
618
619
619
620
pub fn next_int_var_id ( & mut self ) -> IntVid {
620
- IntVid ( next_simple_var( & mut self . int_var_counter,
621
- & mut self . int_var_bindings) )
621
+ let mut int_var_counter = self . int_var_counter. get( ) ;
622
+ let result = IntVid ( next_simple_var( & mut int_var_counter,
623
+ & mut self . int_var_bindings) ) ;
624
+ self . int_var_counter. set( int_var_counter) ;
625
+ result
622
626
}
623
627
624
628
pub fn next_int_var ( & mut self ) -> ty:: t {
625
629
ty:: mk_int_var ( self . tcx, self . next_int_var_id ( ) )
626
630
}
627
631
628
632
pub fn next_float_var_id ( & mut self ) -> FloatVid {
629
- FloatVid ( next_simple_var( & mut self . float_var_counter,
630
- & mut self . float_var_bindings) )
633
+ let mut float_var_counter = self . float_var_counter. get( ) ;
634
+ let result = FloatVid ( next_simple_var( & mut float_var_counter,
635
+ & mut self . float_var_bindings) ) ;
636
+ self . float_var_counter. set( float_var_counter) ;
637
+ result
631
638
}
632
639
633
640
pub fn next_float_var ( & mut self ) -> ty:: t {
0 commit comments