@@ -103,7 +103,7 @@ pub struct RegionVarBindings {
103
103
// actively snapshotting. The reason for this is that otherwise
104
104
// we end up adding entries for things like the lower bound on
105
105
// a variable and so forth, which can never be rolled back.
106
- undo_log : ~[ UndoLogEntry ] ,
106
+ undo_log : RefCell < ~[ UndoLogEntry ] > ,
107
107
108
108
// This contains the results of inference. It begins as an empty
109
109
// option and only acquires a value after inference is complete.
@@ -120,36 +120,45 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
120
120
glbs : RefCell :: new ( HashMap :: new ( ) ) ,
121
121
skolemization_count : Cell :: new ( 0 ) ,
122
122
bound_count : Cell :: new ( 0 ) ,
123
- undo_log : ~[ ]
123
+ undo_log : RefCell :: new ( ~[ ] )
124
124
}
125
125
}
126
126
127
127
impl RegionVarBindings {
128
128
pub fn in_snapshot ( & self ) -> bool {
129
- self . undo_log . len ( ) > 0
129
+ let undo_log = self . undo_log . borrow ( ) ;
130
+ undo_log. get ( ) . len ( ) > 0
130
131
}
131
132
132
133
pub fn start_snapshot ( & mut self ) -> uint {
133
- debug ! ( "RegionVarBindings: snapshot()={}" , self . undo_log . len ( ) ) ;
134
+ debug ! ( "RegionVarBindings: start_snapshot()" ) ;
134
135
if self . in_snapshot ( ) {
135
- self . undo_log . len ( )
136
+ {
137
+ let undo_log = self . undo_log . borrow ( ) ;
138
+ undo_log. get ( ) . len ( )
139
+ }
136
140
} else {
137
- self . undo_log . push ( Snapshot ) ;
138
- 0
141
+ {
142
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
143
+ undo_log. get ( ) . push ( Snapshot ) ;
144
+ 0
145
+ }
139
146
}
140
147
}
141
148
142
149
pub fn commit ( & mut self ) {
143
150
debug ! ( "RegionVarBindings: commit()" ) ;
144
- while self . undo_log . len ( ) > 0 {
145
- self . undo_log . pop ( ) ;
151
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
152
+ while undo_log. get ( ) . len ( ) > 0 {
153
+ undo_log. get ( ) . pop ( ) ;
146
154
}
147
155
}
148
156
149
157
pub fn rollback_to ( & mut self , snapshot : uint ) {
150
158
debug ! ( "RegionVarBindings: rollback_to({})" , snapshot) ;
151
- while self . undo_log . len ( ) > snapshot {
152
- let undo_item = self . undo_log . pop ( ) ;
159
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
160
+ while undo_log. get ( ) . len ( ) > snapshot {
161
+ let undo_item = undo_log. get ( ) . pop ( ) ;
153
162
debug ! ( "undo_item={:?}" , undo_item) ;
154
163
match undo_item {
155
164
Snapshot => { }
@@ -182,7 +191,10 @@ impl RegionVarBindings {
182
191
self . var_origins . push ( origin) ;
183
192
let vid = RegionVid { id : id } ;
184
193
if self . in_snapshot ( ) {
185
- self . undo_log . push ( AddVar ( vid) ) ;
194
+ {
195
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
196
+ undo_log. get ( ) . push ( AddVar ( vid) ) ;
197
+ }
186
198
}
187
199
debug ! ( "created new region variable {:?} with origin {:?}" ,
188
200
vid, origin. repr( self . tcx) ) ;
@@ -235,7 +247,10 @@ impl RegionVarBindings {
235
247
let mut constraints = self . constraints . borrow_mut ( ) ;
236
248
if constraints. get ( ) . insert ( constraint, origin) {
237
249
if self . in_snapshot ( ) {
238
- self . undo_log . push ( AddConstraint ( constraint) ) ;
250
+ {
251
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
252
+ undo_log. get ( ) . push ( AddConstraint ( constraint) ) ;
253
+ }
239
254
}
240
255
}
241
256
}
@@ -380,7 +395,10 @@ impl RegionVarBindings {
380
395
map. get ( ) . insert ( vars, c) ;
381
396
}
382
397
if self . in_snapshot ( ) {
383
- self . undo_log . push ( AddCombination ( t, vars) ) ;
398
+ {
399
+ let mut undo_log = self . undo_log . borrow_mut ( ) ;
400
+ undo_log. get ( ) . push ( AddCombination ( t, vars) ) ;
401
+ }
384
402
}
385
403
relate ( self , a, ReInfer ( ReVar ( c) ) ) ;
386
404
relate ( self , b, ReInfer ( ReVar ( c) ) ) ;
@@ -390,7 +408,8 @@ impl RegionVarBindings {
390
408
391
409
pub fn vars_created_since_snapshot ( & mut self , snapshot : uint )
392
410
-> ~[ RegionVid ] {
393
- self . undo_log . slice_from ( snapshot) . iter ( )
411
+ let undo_log = self . undo_log . borrow ( ) ;
412
+ undo_log. get ( ) . slice_from ( snapshot) . iter ( )
394
413
. filter_map ( |& elt| match elt {
395
414
AddVar ( vid) => Some ( vid) ,
396
415
_ => None
@@ -410,7 +429,10 @@ impl RegionVarBindings {
410
429
debug ! ( "tainted(snapshot={}, r0={:?})" , snapshot, r0) ;
411
430
let _indenter = indenter ( ) ;
412
431
413
- let undo_len = self . undo_log . len ( ) ;
432
+ let undo_len = {
433
+ let undo_log = self . undo_log . borrow ( ) ;
434
+ undo_log. get ( ) . len ( )
435
+ } ;
414
436
415
437
// `result_set` acts as a worklist: we explore all outgoing
416
438
// edges and add any new regions we find to result_set. This
@@ -426,22 +448,25 @@ impl RegionVarBindings {
426
448
let mut undo_index = snapshot;
427
449
while undo_index < undo_len {
428
450
// nb: can't use uint::range() here as we move result_set
429
- let regs = match self . undo_log [ undo_index] {
430
- AddConstraint ( ConstrainVarSubVar ( ref a, ref b) ) => {
431
- Some ( ( ReInfer ( ReVar ( * a) ) ,
432
- ReInfer ( ReVar ( * b) ) ) )
433
- }
434
- AddConstraint ( ConstrainRegSubVar ( ref a, ref b) ) => {
435
- Some ( ( * a, ReInfer ( ReVar ( * b) ) ) )
436
- }
437
- AddConstraint ( ConstrainVarSubReg ( ref a, ref b) ) => {
438
- Some ( ( ReInfer ( ReVar ( * a) ) , * b) )
439
- }
440
- AddConstraint ( ConstrainRegSubReg ( a, b) ) => {
441
- Some ( ( a, b) )
442
- }
443
- _ => {
444
- None
451
+ let regs = {
452
+ let undo_log = self . undo_log . borrow ( ) ;
453
+ match undo_log. get ( ) [ undo_index] {
454
+ AddConstraint ( ConstrainVarSubVar ( ref a, ref b) ) => {
455
+ Some ( ( ReInfer ( ReVar ( * a) ) ,
456
+ ReInfer ( ReVar ( * b) ) ) )
457
+ }
458
+ AddConstraint ( ConstrainRegSubVar ( ref a, ref b) ) => {
459
+ Some ( ( * a, ReInfer ( ReVar ( * b) ) ) )
460
+ }
461
+ AddConstraint ( ConstrainVarSubReg ( ref a, ref b) ) => {
462
+ Some ( ( ReInfer ( ReVar ( * a) ) , * b) )
463
+ }
464
+ AddConstraint ( ConstrainRegSubReg ( a, b) ) => {
465
+ Some ( ( a, b) )
466
+ }
467
+ _ => {
468
+ None
469
+ }
445
470
}
446
471
} ;
447
472
0 commit comments