@@ -15,6 +15,7 @@ comments in the section "Moves and initialization" and in `doc.rs`.
15
15
16
16
*/
17
17
18
+ use std:: cell:: RefCell ;
18
19
use std:: hashmap:: { HashMap , HashSet } ;
19
20
use std:: uint;
20
21
use middle:: borrowck:: * ;
@@ -31,7 +32,7 @@ use util::ppaux::Repr;
31
32
32
33
pub struct MoveData {
33
34
/// Move paths. See section "Move paths" in `doc.rs`.
34
- paths : ~[ MovePath ] ,
35
+ paths : RefCell < ~[ MovePath ] > ,
35
36
36
37
/// Cache of loan path to move path index, for easy lookup.
37
38
path_map : HashMap < @LoanPath , MovePathIndex > ,
@@ -164,7 +165,7 @@ pub type AssignDataFlow = DataFlowContext<AssignDataFlowOperator>;
164
165
impl MoveData {
165
166
pub fn new ( ) -> MoveData {
166
167
MoveData {
167
- paths : ~[ ] ,
168
+ paths : RefCell :: new ( ~[ ] ) ,
168
169
path_map : HashMap :: new ( ) ,
169
170
moves : ~[ ] ,
170
171
path_assignments : ~[ ] ,
@@ -174,35 +175,42 @@ impl MoveData {
174
175
}
175
176
176
177
fn path_loan_path ( & self , index : MovePathIndex ) -> @LoanPath {
177
- self . paths [ * index] . loan_path
178
+ let paths = self . paths . borrow ( ) ;
179
+ paths. get ( ) [ * index] . loan_path
178
180
}
179
181
180
182
fn path_parent ( & self , index : MovePathIndex ) -> MovePathIndex {
181
- self . paths [ * index] . parent
183
+ let paths = self . paths . borrow ( ) ;
184
+ paths. get ( ) [ * index] . parent
182
185
}
183
186
184
187
fn path_first_move ( & self , index : MovePathIndex ) -> MoveIndex {
185
- self . paths [ * index] . first_move
188
+ let paths = self . paths . borrow ( ) ;
189
+ paths. get ( ) [ * index] . first_move
186
190
}
187
191
188
192
fn path_first_child ( & self , index : MovePathIndex ) -> MovePathIndex {
189
- self . paths [ * index] . first_child
193
+ let paths = self . paths . borrow ( ) ;
194
+ paths. get ( ) [ * index] . first_child
190
195
}
191
196
192
197
fn path_next_sibling ( & self , index : MovePathIndex ) -> MovePathIndex {
193
- self . paths [ * index] . next_sibling
198
+ let paths = self . paths . borrow ( ) ;
199
+ paths. get ( ) [ * index] . next_sibling
194
200
}
195
201
196
202
fn set_path_first_move ( & mut self ,
197
203
index : MovePathIndex ,
198
204
first_move : MoveIndex ) {
199
- self . paths [ * index] . first_move = first_move
205
+ let mut paths = self . paths . borrow_mut ( ) ;
206
+ paths. get ( ) [ * index] . first_move = first_move
200
207
}
201
208
202
209
fn set_path_first_child ( & mut self ,
203
210
index : MovePathIndex ,
204
211
first_child : MovePathIndex ) {
205
- self . paths [ * index] . first_child = first_child
212
+ let mut paths = self . paths . borrow_mut ( ) ;
213
+ paths. get ( ) [ * index] . first_child = first_child
206
214
}
207
215
208
216
@@ -234,9 +242,10 @@ impl MoveData {
234
242
235
243
let index = match * lp {
236
244
LpVar ( ..) => {
237
- let index = MovePathIndex ( self . paths . len ( ) ) ;
245
+ let mut paths = self . paths . borrow_mut ( ) ;
246
+ let index = MovePathIndex ( paths. get ( ) . len ( ) ) ;
238
247
239
- self . paths . push ( MovePath {
248
+ paths. get ( ) . push ( MovePath {
240
249
loan_path : lp,
241
250
parent : InvalidMovePathIndex ,
242
251
first_move : InvalidMoveIndex ,
@@ -249,18 +258,25 @@ impl MoveData {
249
258
250
259
LpExtend ( base, _, _) => {
251
260
let parent_index = self . move_path ( tcx, base) ;
252
- let index = MovePathIndex ( self . paths . len ( ) ) ;
261
+
262
+ let index = {
263
+ let paths = self . paths . borrow ( ) ;
264
+ MovePathIndex ( paths. get ( ) . len ( ) )
265
+ } ;
253
266
254
267
let next_sibling = self . path_first_child ( parent_index) ;
255
268
self . set_path_first_child ( parent_index, index) ;
256
269
257
- self . paths . push ( MovePath {
258
- loan_path : lp,
259
- parent : parent_index,
260
- first_move : InvalidMoveIndex ,
261
- first_child : InvalidMovePathIndex ,
262
- next_sibling : next_sibling,
263
- } ) ;
270
+ {
271
+ let mut paths = self . paths . borrow_mut ( ) ;
272
+ paths. get ( ) . push ( MovePath {
273
+ loan_path : lp,
274
+ parent : parent_index,
275
+ first_move : InvalidMoveIndex ,
276
+ first_child : InvalidMovePathIndex ,
277
+ next_sibling : next_sibling,
278
+ } ) ;
279
+ }
264
280
265
281
index
266
282
}
@@ -270,7 +286,8 @@ impl MoveData {
270
286
lp. repr( tcx) ,
271
287
index) ;
272
288
273
- assert_eq ! ( * index, self . paths. len( ) - 1 ) ;
289
+ let paths = self . paths . borrow ( ) ;
290
+ assert_eq ! ( * index, paths. get( ) . len( ) - 1 ) ;
274
291
self . path_map . insert ( lp, index) ;
275
292
return index;
276
293
}
@@ -409,14 +426,17 @@ impl MoveData {
409
426
410
427
// Kill all moves related to a variable `x` when it goes out
411
428
// of scope:
412
- for path in self . paths . iter ( ) {
413
- match * path. loan_path {
414
- LpVar ( id) => {
415
- let kill_id = tcx. region_maps . encl_scope ( id) ;
416
- let path = * self . path_map . get ( & path. loan_path ) ;
417
- self . kill_moves ( path, kill_id, dfcx_moves) ;
429
+ {
430
+ let paths = self . paths . borrow ( ) ;
431
+ for path in paths. get ( ) . iter ( ) {
432
+ match * path. loan_path {
433
+ LpVar ( id) => {
434
+ let kill_id = tcx. region_maps . encl_scope ( id) ;
435
+ let path = * self . path_map . get ( & path. loan_path ) ;
436
+ self . kill_moves ( path, kill_id, dfcx_moves) ;
437
+ }
438
+ LpExtend ( ..) => { }
418
439
}
419
- LpExtend ( ..) => { }
420
440
}
421
441
}
422
442
0 commit comments