@@ -24,6 +24,7 @@ use middle::graph::{Direction, NodeIndex};
24
24
use util:: common:: indenter;
25
25
use util:: ppaux:: { Repr } ;
26
26
27
+ use std:: cell:: RefCell ;
27
28
use std:: hashmap:: { HashMap , HashSet } ;
28
29
use std:: uint;
29
30
use std:: vec;
@@ -88,7 +89,7 @@ type CombineMap = HashMap<TwoRegions, RegionVid>;
88
89
pub struct RegionVarBindings {
89
90
tcx : ty:: ctxt ,
90
91
var_origins : ~[ RegionVariableOrigin ] ,
91
- constraints : HashMap < Constraint , SubregionOrigin > ,
92
+ constraints : RefCell < HashMap < Constraint , SubregionOrigin > > ,
92
93
lubs : CombineMap ,
93
94
glbs : CombineMap ,
94
95
skolemization_count : uint ,
@@ -114,7 +115,7 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
114
115
tcx : tcx,
115
116
var_origins : ~[ ] ,
116
117
values : None ,
117
- constraints : HashMap :: new ( ) ,
118
+ constraints : RefCell :: new ( HashMap :: new ( ) ) ,
118
119
lubs : HashMap :: new ( ) ,
119
120
glbs : HashMap :: new ( ) ,
120
121
skolemization_count : 0 ,
@@ -157,7 +158,8 @@ impl RegionVarBindings {
157
158
self . var_origins . pop ( ) ;
158
159
}
159
160
AddConstraint ( ref constraint) => {
160
- self . constraints . remove ( constraint) ;
161
+ let mut constraints = self . constraints . borrow_mut ( ) ;
162
+ constraints. get ( ) . remove ( constraint) ;
161
163
}
162
164
AddCombination ( Glb , ref regions) => {
163
165
self . glbs . remove ( regions) ;
@@ -228,7 +230,8 @@ impl RegionVarBindings {
228
230
229
231
debug ! ( "RegionVarBindings: add_constraint({:?})" , constraint) ;
230
232
231
- if self . constraints . insert ( constraint, origin) {
233
+ let mut constraints = self . constraints . borrow_mut ( ) ;
234
+ if constraints. get ( ) . insert ( constraint, origin) {
232
235
if self . in_snapshot ( ) {
233
236
self . undo_log . push ( AddConstraint ( constraint) ) ;
234
237
}
@@ -925,7 +928,8 @@ impl RegionVarBindings {
925
928
& self ,
926
929
errors : & mut OptVec < RegionResolutionError > )
927
930
{
928
- for ( constraint, _) in self . constraints . iter ( ) {
931
+ let constraints = self . constraints . borrow ( ) ;
932
+ for ( constraint, _) in constraints. get ( ) . iter ( ) {
929
933
let ( sub, sup) = match * constraint {
930
934
ConstrainVarSubVar ( ..) |
931
935
ConstrainRegSubVar ( ..) |
@@ -943,7 +947,7 @@ impl RegionVarBindings {
943
947
944
948
debug ! ( "ConcreteFailure: !(sub <= sup): sub={:?}, sup={:?}" ,
945
949
sub, sup) ;
946
- let origin = self . constraints . get_copy ( constraint) ;
950
+ let origin = constraints. get ( ) . get_copy ( constraint) ;
947
951
errors. push ( ConcreteFailure ( origin, sub, sup) ) ;
948
952
}
949
953
}
@@ -1031,7 +1035,9 @@ impl RegionVarBindings {
1031
1035
1032
1036
fn construct_graph ( & self ) -> RegionGraph {
1033
1037
let num_vars = self . num_vars ( ) ;
1034
- let num_edges = self . constraints . len ( ) ;
1038
+
1039
+ let constraints = self . constraints . borrow ( ) ;
1040
+ let num_edges = constraints. get ( ) . len ( ) ;
1035
1041
1036
1042
let mut graph = graph:: Graph :: with_capacity ( num_vars + 1 ,
1037
1043
num_edges) ;
@@ -1041,7 +1047,7 @@ impl RegionVarBindings {
1041
1047
}
1042
1048
let dummy_idx = graph. add_node ( ( ) ) ;
1043
1049
1044
- for ( constraint, _) in self . constraints . iter ( ) {
1050
+ for ( constraint, _) in constraints. get ( ) . iter ( ) {
1045
1051
match * constraint {
1046
1052
ConstrainVarSubVar ( a_id, b_id) => {
1047
1053
graph. add_edge ( NodeIndex ( a_id. to_uint ( ) ) ,
@@ -1230,9 +1236,10 @@ impl RegionVarBindings {
1230
1236
1231
1237
ConstrainRegSubVar ( region, _) |
1232
1238
ConstrainVarSubReg ( _, region) => {
1239
+ let constraints = this. constraints . borrow ( ) ;
1233
1240
state. result . push ( RegionAndOrigin {
1234
1241
region : region,
1235
- origin : this . constraints . get_copy ( & edge. data )
1242
+ origin : constraints. get ( ) . get_copy ( & edge. data )
1236
1243
} ) ;
1237
1244
}
1238
1245
@@ -1252,7 +1259,8 @@ impl RegionVarBindings {
1252
1259
changed = false ;
1253
1260
iteration += 1 ;
1254
1261
debug ! ( "---- {} Iteration \\ #{}" , tag, iteration) ;
1255
- for ( constraint, _) in self . constraints . iter ( ) {
1262
+ let constraints = self . constraints . borrow ( ) ;
1263
+ for ( constraint, _) in constraints. get ( ) . iter ( ) {
1256
1264
let edge_changed = body ( constraint) ;
1257
1265
if edge_changed {
1258
1266
debug ! ( "Updated due to constraint {}" ,
0 commit comments