@@ -25,6 +25,7 @@ use driver::session::Session;
25
25
use middle:: ty:: { FreeRegion } ;
26
26
use middle:: ty;
27
27
28
+ use std:: cell:: RefCell ;
28
29
use std:: hashmap:: { HashMap , HashSet } ;
29
30
use syntax:: codemap:: Span ;
30
31
use syntax:: { ast, visit} ;
@@ -50,7 +51,7 @@ The region maps encode information about region relationships.
50
51
necessarily how I think things ought to work
51
52
*/
52
53
pub struct RegionMaps {
53
- priv scope_map : HashMap < ast:: NodeId , ast:: NodeId > ,
54
+ priv scope_map : RefCell < HashMap < ast:: NodeId , ast:: NodeId > > ,
54
55
priv free_region_map : HashMap < FreeRegion , ~[ FreeRegion ] > ,
55
56
priv cleanup_scopes : HashSet < ast:: NodeId >
56
57
}
@@ -93,7 +94,8 @@ impl RegionMaps {
93
94
debug ! ( "record_parent(sub={:?}, sup={:?})" , sub, sup) ;
94
95
assert ! ( sub != sup) ;
95
96
96
- self . scope_map . insert ( sub, sup) ;
97
+ let mut scope_map = self . scope_map . borrow_mut ( ) ;
98
+ scope_map. get ( ) . insert ( sub, sup) ;
97
99
}
98
100
99
101
pub fn record_cleanup_scope ( & mut self , scope_id : ast:: NodeId ) {
@@ -108,13 +110,15 @@ impl RegionMaps {
108
110
pub fn opt_encl_scope ( & self , id : ast:: NodeId ) -> Option < ast:: NodeId > {
109
111
//! Returns the narrowest scope that encloses `id`, if any.
110
112
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)
112
115
}
113
116
114
117
pub fn encl_scope ( & self , id : ast:: NodeId ) -> ast:: NodeId {
115
118
//! Returns the narrowest scope that encloses `id`, if any.
116
119
117
- match self . scope_map . find ( & id) {
120
+ let scope_map = self . scope_map . borrow ( ) ;
121
+ match scope_map. get ( ) . find ( & id) {
118
122
Some ( & r) => r,
119
123
None => { fail ! ( "No enclosing scope for id {:?}" , id) ; }
120
124
}
@@ -157,7 +161,8 @@ impl RegionMaps {
157
161
158
162
let mut s = subscope;
159
163
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) {
161
166
None => {
162
167
debug ! ( "is_subscope_of({:?}, {:?}, s={:?})=false" ,
163
168
subscope, superscope, s) ;
@@ -298,7 +303,8 @@ impl RegionMaps {
298
303
let mut result = ~[ scope] ;
299
304
let mut scope = scope;
300
305
loop {
301
- match this. scope_map . find ( & scope) {
306
+ let scope_map = this. scope_map . borrow ( ) ;
307
+ match scope_map. get ( ) . find ( & scope) {
302
308
None => return result,
303
309
Some ( & superscope) => {
304
310
result. push ( superscope) ;
@@ -497,7 +503,7 @@ pub fn resolve_crate(sess: Session,
497
503
crate : & ast:: Crate ) -> @mut RegionMaps
498
504
{
499
505
let region_maps = @mut RegionMaps {
500
- scope_map : HashMap :: new ( ) ,
506
+ scope_map : RefCell :: new ( HashMap :: new ( ) ) ,
501
507
free_region_map : HashMap :: new ( ) ,
502
508
cleanup_scopes : HashSet :: new ( ) ,
503
509
} ;
0 commit comments