Skip to content

Commit 8c70364

Browse files
committed
librustc: De-@mut the reachability worklist
1 parent 4b4ff2c commit 8c70364

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/librustc/middle/reachable.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ struct ReachableContext {
8888
reachable_symbols: @RefCell<HashSet<ast::NodeId>>,
8989
// A worklist of item IDs. Each item ID in this worklist will be inlined
9090
// and will be scanned for further references.
91-
worklist: @mut ~[ast::NodeId],
91+
worklist: @RefCell<~[ast::NodeId]>,
9292
}
9393

9494
struct MarkSymbolVisitor {
95-
worklist: @mut ~[ast::NodeId],
95+
worklist: @RefCell<~[ast::NodeId]>,
9696
method_map: typeck::method_map,
9797
tcx: ty::ctxt,
9898
reachable_symbols: @RefCell<HashSet<ast::NodeId>>,
@@ -116,15 +116,19 @@ impl Visitor<()> for MarkSymbolVisitor {
116116
if is_local(def_id) {
117117
if ReachableContext::
118118
def_id_represents_local_inlined_item(self.tcx, def_id) {
119-
self.worklist.push(def_id.node)
119+
{
120+
let mut worklist = self.worklist.borrow_mut();
121+
worklist.get().push(def_id.node)
122+
}
120123
} else {
121124
match def {
122125
// If this path leads to a static, then we may have
123126
// to do some work to figure out whether the static
124127
// is indeed reachable (address_insignificant
125128
// statics are *never* reachable).
126129
ast::DefStatic(..) => {
127-
self.worklist.push(def_id.node);
130+
let mut worklist = self.worklist.borrow_mut();
131+
worklist.get().push(def_id.node);
128132
}
129133

130134
// If this wasn't a static, then this destination is
@@ -150,7 +154,11 @@ impl Visitor<()> for MarkSymbolVisitor {
150154
def_id_represents_local_inlined_item(
151155
self.tcx,
152156
def_id) {
153-
self.worklist.push(def_id.node)
157+
{
158+
let mut worklist = self.worklist
159+
.borrow_mut();
160+
worklist.get().push(def_id.node)
161+
}
154162
}
155163
{
156164
let mut reachable_symbols =
@@ -186,7 +194,7 @@ impl ReachableContext {
186194
tcx: tcx,
187195
method_map: method_map,
188196
reachable_symbols: @RefCell::new(HashSet::new()),
189-
worklist: @mut ~[],
197+
worklist: @RefCell::new(~[]),
190198
}
191199
}
192200

@@ -265,11 +273,19 @@ impl ReachableContext {
265273
fn propagate(&self) {
266274
let mut visitor = self.init_visitor();
267275
let mut scanned = HashSet::new();
268-
while self.worklist.len() > 0 {
269-
let search_item = self.worklist.pop();
270-
if scanned.contains(&search_item) {
271-
continue
272-
}
276+
loop {
277+
let search_item = {
278+
let mut worklist = self.worklist.borrow_mut();
279+
if worklist.get().len() == 0 {
280+
break
281+
}
282+
let search_item = worklist.get().pop();
283+
if scanned.contains(&search_item) {
284+
continue
285+
}
286+
search_item
287+
};
288+
273289
scanned.insert(search_item);
274290
match self.tcx.items.find(&search_item) {
275291
Some(item) => self.propagate_node(item, search_item,
@@ -407,7 +423,8 @@ pub fn find_reachable(tcx: ty::ctxt,
407423
// Step 1: Seed the worklist with all nodes which were found to be public as
408424
// a result of the privacy pass
409425
for &id in exported_items.iter() {
410-
reachable_context.worklist.push(id);
426+
let mut worklist = reachable_context.worklist.borrow_mut();
427+
worklist.get().push(id);
411428
}
412429

413430
// Step 2: Mark all symbols that the symbols on the worklist touch.

0 commit comments

Comments
 (0)