Skip to content

Commit d5e3272

Browse files
committed
librustc: De-@mut the scope map in the region maps
1 parent 2551344 commit d5e3272

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/librustc/middle/region.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use driver::session::Session;
2525
use middle::ty::{FreeRegion};
2626
use middle::ty;
2727

28+
use std::cell::RefCell;
2829
use std::hashmap::{HashMap, HashSet};
2930
use syntax::codemap::Span;
3031
use syntax::{ast, visit};
@@ -50,7 +51,7 @@ The region maps encode information about region relationships.
5051
necessarily how I think things ought to work
5152
*/
5253
pub struct RegionMaps {
53-
priv scope_map: HashMap<ast::NodeId, ast::NodeId>,
54+
priv scope_map: RefCell<HashMap<ast::NodeId, ast::NodeId>>,
5455
priv free_region_map: HashMap<FreeRegion, ~[FreeRegion]>,
5556
priv cleanup_scopes: HashSet<ast::NodeId>
5657
}
@@ -93,7 +94,8 @@ impl RegionMaps {
9394
debug!("record_parent(sub={:?}, sup={:?})", sub, sup);
9495
assert!(sub != sup);
9596

96-
self.scope_map.insert(sub, sup);
97+
let mut scope_map = self.scope_map.borrow_mut();
98+
scope_map.get().insert(sub, sup);
9799
}
98100

99101
pub fn record_cleanup_scope(&mut self, scope_id: ast::NodeId) {
@@ -108,13 +110,15 @@ impl RegionMaps {
108110
pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
109111
//! Returns the narrowest scope that encloses `id`, if any.
110112
111-
self.scope_map.find(&id).map(|x| *x)
113+
let scope_map = self.scope_map.borrow();
114+
scope_map.get().find(&id).map(|x| *x)
112115
}
113116

114117
pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId {
115118
//! Returns the narrowest scope that encloses `id`, if any.
116119
117-
match self.scope_map.find(&id) {
120+
let scope_map = self.scope_map.borrow();
121+
match scope_map.get().find(&id) {
118122
Some(&r) => r,
119123
None => { fail!("No enclosing scope for id {:?}", id); }
120124
}
@@ -157,7 +161,8 @@ impl RegionMaps {
157161

158162
let mut s = subscope;
159163
while superscope != s {
160-
match self.scope_map.find(&s) {
164+
let scope_map = self.scope_map.borrow();
165+
match scope_map.get().find(&s) {
161166
None => {
162167
debug!("is_subscope_of({:?}, {:?}, s={:?})=false",
163168
subscope, superscope, s);
@@ -298,7 +303,8 @@ impl RegionMaps {
298303
let mut result = ~[scope];
299304
let mut scope = scope;
300305
loop {
301-
match this.scope_map.find(&scope) {
306+
let scope_map = this.scope_map.borrow();
307+
match scope_map.get().find(&scope) {
302308
None => return result,
303309
Some(&superscope) => {
304310
result.push(superscope);
@@ -497,7 +503,7 @@ pub fn resolve_crate(sess: Session,
497503
crate: &ast::Crate) -> @mut RegionMaps
498504
{
499505
let region_maps = @mut RegionMaps {
500-
scope_map: HashMap::new(),
506+
scope_map: RefCell::new(HashMap::new()),
501507
free_region_map: HashMap::new(),
502508
cleanup_scopes: HashSet::new(),
503509
};

0 commit comments

Comments
 (0)