Skip to content

Commit 3339872

Browse files
committed
---
yaml --- r: 97132 b: refs/heads/dist-snap c: 12c5c19 h: refs/heads/master v: v3
1 parent 6ad151f commit 3339872

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 026364ca26a35f0d710d9b7d6501d267f8f82684
9+
refs/heads/dist-snap: 12c5c198715d23f29f9f130052b15ed90d7218ba
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/borrowck/move_data.rs

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ comments in the section "Moves and initialization" and in `doc.rs`.
1515
1616
*/
1717

18+
use std::cell::RefCell;
1819
use std::hashmap::{HashMap, HashSet};
1920
use std::uint;
2021
use middle::borrowck::*;
@@ -31,7 +32,7 @@ use util::ppaux::Repr;
3132

3233
pub struct MoveData {
3334
/// Move paths. See section "Move paths" in `doc.rs`.
34-
paths: ~[MovePath],
35+
paths: RefCell<~[MovePath]>,
3536

3637
/// Cache of loan path to move path index, for easy lookup.
3738
path_map: HashMap<@LoanPath, MovePathIndex>,
@@ -164,7 +165,7 @@ pub type AssignDataFlow = DataFlowContext<AssignDataFlowOperator>;
164165
impl MoveData {
165166
pub fn new() -> MoveData {
166167
MoveData {
167-
paths: ~[],
168+
paths: RefCell::new(~[]),
168169
path_map: HashMap::new(),
169170
moves: ~[],
170171
path_assignments: ~[],
@@ -174,35 +175,42 @@ impl MoveData {
174175
}
175176

176177
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
178180
}
179181

180182
fn path_parent(&self, index: MovePathIndex) -> MovePathIndex {
181-
self.paths[*index].parent
183+
let paths = self.paths.borrow();
184+
paths.get()[*index].parent
182185
}
183186

184187
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
186190
}
187191

188192
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
190195
}
191196

192197
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
194200
}
195201

196202
fn set_path_first_move(&mut self,
197203
index: MovePathIndex,
198204
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
200207
}
201208

202209
fn set_path_first_child(&mut self,
203210
index: MovePathIndex,
204211
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
206214
}
207215

208216

@@ -234,9 +242,10 @@ impl MoveData {
234242

235243
let index = match *lp {
236244
LpVar(..) => {
237-
let index = MovePathIndex(self.paths.len());
245+
let mut paths = self.paths.borrow_mut();
246+
let index = MovePathIndex(paths.get().len());
238247

239-
self.paths.push(MovePath {
248+
paths.get().push(MovePath {
240249
loan_path: lp,
241250
parent: InvalidMovePathIndex,
242251
first_move: InvalidMoveIndex,
@@ -249,18 +258,25 @@ impl MoveData {
249258

250259
LpExtend(base, _, _) => {
251260
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+
};
253266

254267
let next_sibling = self.path_first_child(parent_index);
255268
self.set_path_first_child(parent_index, index);
256269

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+
}
264280

265281
index
266282
}
@@ -270,7 +286,8 @@ impl MoveData {
270286
lp.repr(tcx),
271287
index);
272288

273-
assert_eq!(*index, self.paths.len() - 1);
289+
let paths = self.paths.borrow();
290+
assert_eq!(*index, paths.get().len() - 1);
274291
self.path_map.insert(lp, index);
275292
return index;
276293
}
@@ -409,14 +426,17 @@ impl MoveData {
409426

410427
// Kill all moves related to a variable `x` when it goes out
411428
// 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(..) => {}
418439
}
419-
LpExtend(..) => {}
420440
}
421441
}
422442

0 commit comments

Comments
 (0)