Skip to content

Commit 72f9cbe

Browse files
committed
librustc: De-@mut the borrow check's root map
1 parent c4661fd commit 72f9cbe

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

src/librustc/middle/borrowck/gather_loans/lifetime.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ impl<'a> GuaranteeLifetimeContext<'a> {
279279
// Add a record of what is required
280280
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
281281
let root_info = RootInfo {scope: root_scope, freeze: opt_dyna};
282-
self.bccx.root_map.insert(rm_key, root_info);
282+
283+
let mut root_map = self.bccx.root_map.borrow_mut();
284+
root_map.get().insert(rm_key, root_info);
283285

284286
debug!("root_key: {:?} root_info: {:?}", rm_key, root_info);
285287
Ok(())

src/librustc/middle/borrowck/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use middle::dataflow::DataFlowOperator;
2020
use util::common::stmt_set;
2121
use util::ppaux::{note_and_explain_region, Repr, UserString};
2222

23+
use std::cell::RefCell;
2324
use std::hashmap::{HashSet, HashMap};
2425
use std::ops::{BitOr, BitAnd};
2526
use std::result::{Result};
@@ -413,10 +414,10 @@ pub struct RootInfo {
413414
freeze: Option<DynaFreezeKind> // Some() if we should freeze box at runtime
414415
}
415416

416-
pub type root_map = @mut HashMap<root_map_key, RootInfo>;
417+
pub type root_map = @RefCell<HashMap<root_map_key, RootInfo>>;
417418

418419
pub fn root_map() -> root_map {
419-
return @mut HashMap::new();
420+
return @RefCell::new(HashMap::new());
420421
}
421422

422423
pub enum DynaFreezeKind {

src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use syntax::visit;
1919
use syntax::visit::Visitor;
2020
use syntax::ast::*;
2121

22+
use std::cell::RefCell;
2223
use std::hashmap::{HashMap, HashSet};
2324

2425
//
@@ -119,7 +120,7 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,
119120
}
120121
}
121122
let maps = astencode::Maps {
122-
root_map: @mut HashMap::new(),
123+
root_map: @RefCell::new(HashMap::new()),
123124
method_map: @mut HashMap::new(),
124125
vtable_map: @mut HashMap::new(),
125126
write_guard_map: @mut HashSet::new(),
@@ -169,7 +170,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
169170
}
170171
}
171172
let maps = astencode::Maps {
172-
root_map: @mut HashMap::new(),
173+
root_map: @RefCell::new(HashMap::new()),
173174
method_map: @mut HashMap::new(),
174175
vtable_map: @mut HashMap::new(),
175176
write_guard_map: @mut HashSet::new(),

src/librustc/middle/trans/_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ fn pats_require_rooting(bcx: @Block,
11121112
m.iter().any(|br| {
11131113
let pat_id = br.pats[col].id;
11141114
let key = root_map_key {id: pat_id, derefs: 0u };
1115-
bcx.ccx().maps.root_map.contains_key(&key)
1115+
let root_map = bcx.ccx().maps.root_map.borrow();
1116+
root_map.get().contains_key(&key)
11161117
})
11171118
}
11181119

src/librustc/middle/trans/write_guard.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ pub fn root_and_write_guard(datum: &Datum,
4545
//
4646
// (Note: root'd values are always boxes)
4747
let ccx = bcx.ccx();
48-
bcx = match ccx.maps.root_map.find(&key) {
49-
None => bcx,
50-
Some(&root_info) => root(datum, bcx, span, key, root_info)
48+
bcx = {
49+
let root_map = ccx.maps.root_map.borrow();
50+
match root_map.get().find(&key) {
51+
None => bcx,
52+
Some(&root_info) => root(datum, bcx, span, key, root_info)
53+
}
5154
};
5255

5356
// Perform the write guard, if necessary.

0 commit comments

Comments
 (0)