@@ -21,7 +21,6 @@ use session::Session;
21
21
use util:: nodemap:: { FxHashMap , NodeMap , NodeSet } ;
22
22
use ty;
23
23
24
- use std:: cell:: RefCell ;
25
24
use std:: collections:: hash_map:: Entry ;
26
25
use std:: fmt;
27
26
use std:: mem;
@@ -50,7 +49,7 @@ impl fmt::Debug for CodeExtent {
50
49
let region_maps = tcx. region_maps ( ) ;
51
50
{
52
51
let code_extents = & region_maps. code_extents ;
53
- if let Some ( data) = code_extents. borrow ( ) . get ( self . 0 as usize ) {
52
+ if let Some ( data) = code_extents. get ( self . 0 as usize ) {
54
53
write ! ( f, "/{:?}" , data) ?;
55
54
}
56
55
mem:: drop ( code_extents) ; // FIXME why is this necessary?
@@ -258,34 +257,34 @@ impl CodeExtent {
258
257
259
258
/// The region maps encode information about region relationships.
260
259
pub struct RegionMaps {
261
- code_extents : RefCell < Vec < CodeExtentData > > ,
262
- code_extent_interner : RefCell < FxHashMap < CodeExtentData , CodeExtent > > ,
260
+ code_extents : Vec < CodeExtentData > ,
261
+ code_extent_interner : FxHashMap < CodeExtentData , CodeExtent > ,
263
262
/// `scope_map` maps from a scope id to the enclosing scope id;
264
263
/// this is usually corresponding to the lexical nesting, though
265
264
/// in the case of closures the parent scope is the innermost
266
265
/// conditional expression or repeating block. (Note that the
267
266
/// enclosing scope id for the block associated with a closure is
268
267
/// the closure itself.)
269
- scope_map : RefCell < Vec < CodeExtent > > ,
268
+ scope_map : Vec < CodeExtent > ,
270
269
271
270
/// `var_map` maps from a variable or binding id to the block in
272
271
/// which that variable is declared.
273
- var_map : RefCell < NodeMap < CodeExtent > > ,
272
+ var_map : NodeMap < CodeExtent > ,
274
273
275
274
/// `rvalue_scopes` includes entries for those expressions whose cleanup scope is
276
275
/// larger than the default. The map goes from the expression id
277
276
/// to the cleanup scope id. For rvalues not present in this
278
277
/// table, the appropriate cleanup scope is the innermost
279
278
/// enclosing statement, conditional expression, or repeating
280
279
/// block (see `terminating_scopes`).
281
- rvalue_scopes : RefCell < NodeMap < CodeExtent > > ,
280
+ rvalue_scopes : NodeMap < CodeExtent > ,
282
281
283
282
/// Records the value of rvalue scopes before they were shrunk by
284
283
/// #36082, for error reporting.
285
284
///
286
285
/// FIXME: this should be temporary. Remove this by 1.18.0 or
287
286
/// so.
288
- shrunk_rvalue_scopes : RefCell < NodeMap < CodeExtent > > ,
287
+ shrunk_rvalue_scopes : NodeMap < CodeExtent > ,
289
288
290
289
/// Encodes the hierarchy of fn bodies. Every fn body (including
291
290
/// closures) forms its own distinct region hierarchy, rooted in
@@ -297,7 +296,7 @@ pub struct RegionMaps {
297
296
/// closure defined by that fn. See the "Modeling closures"
298
297
/// section of the README in infer::region_inference for
299
298
/// more details.
300
- fn_tree : RefCell < NodeMap < ast:: NodeId > > ,
299
+ fn_tree : NodeMap < ast:: NodeId > ,
301
300
}
302
301
303
302
#[ derive( Debug , Copy , Clone ) ]
@@ -321,7 +320,7 @@ struct RegionResolutionVisitor<'hir: 'a, 'a> {
321
320
sess : & ' a Session ,
322
321
323
322
// Generated maps:
324
- region_maps : & ' a RegionMaps ,
323
+ region_maps : & ' a mut RegionMaps ,
325
324
326
325
cx : Context ,
327
326
@@ -354,11 +353,11 @@ struct RegionResolutionVisitor<'hir: 'a, 'a> {
354
353
impl RegionMaps {
355
354
/// create a bogus code extent for the regions in astencode types. Nobody
356
355
/// really cares about the contents of these.
357
- pub fn bogus_code_extent ( & self , e : CodeExtentData ) -> CodeExtent {
356
+ pub fn bogus_code_extent ( & mut self , e : CodeExtentData ) -> CodeExtent {
358
357
self . intern_code_extent ( e, DUMMY_CODE_EXTENT )
359
358
}
360
359
pub fn lookup_code_extent ( & self , e : CodeExtentData ) -> CodeExtent {
361
- match self . code_extent_interner . borrow ( ) . get ( & e) {
360
+ match self . code_extent_interner . get ( & e) {
362
361
Some ( & d) => d,
363
362
None => bug ! ( "unknown code extent {:?}" , e)
364
363
}
@@ -375,12 +374,12 @@ impl RegionMaps {
375
374
self . lookup_code_extent ( CodeExtentData :: CallSiteScope { fn_id : fn_id, body_id : body_id } )
376
375
}
377
376
pub fn opt_destruction_extent ( & self , n : ast:: NodeId ) -> Option < CodeExtent > {
378
- self . code_extent_interner . borrow ( ) . get ( & CodeExtentData :: DestructionScope ( n) ) . cloned ( )
377
+ self . code_extent_interner . get ( & CodeExtentData :: DestructionScope ( n) ) . cloned ( )
379
378
}
380
- pub fn intern_code_extent ( & self ,
379
+ pub fn intern_code_extent ( & mut self ,
381
380
e : CodeExtentData ,
382
381
parent : CodeExtent ) -> CodeExtent {
383
- match self . code_extent_interner . borrow_mut ( ) . entry ( e) {
382
+ match self . code_extent_interner . entry ( e) {
384
383
Entry :: Occupied ( o) => {
385
384
// this can happen when the bogus code extents from tydecode
386
385
// have (bogus) NodeId-s that overlap items created during
@@ -392,91 +391,90 @@ impl RegionMaps {
392
391
info ! ( "CodeExtent({}) = {:?} [parent={}] BOGUS!" ,
393
392
idx. 0 , e, parent. 0 ) ;
394
393
} else {
395
- assert_eq ! ( self . scope_map. borrow ( ) [ idx. 0 as usize ] ,
394
+ assert_eq ! ( self . scope_map[ idx. 0 as usize ] ,
396
395
DUMMY_CODE_EXTENT ) ;
397
396
info ! ( "CodeExtent({}) = {:?} [parent={}] RECLAIMED!" ,
398
397
idx. 0 , e, parent. 0 ) ;
399
- self . scope_map . borrow_mut ( ) [ idx. 0 as usize ] = parent;
398
+ self . scope_map [ idx. 0 as usize ] = parent;
400
399
}
401
400
idx
402
401
}
403
402
Entry :: Vacant ( v) => {
404
- if self . code_extents . borrow ( ) . len ( ) > 0xffffffffusize {
403
+ if self . code_extents . len ( ) > 0xffffffffusize {
405
404
bug ! ( ) // should pass a sess,
406
405
// but this isn't the only place
407
406
}
408
- let idx = CodeExtent ( self . code_extents . borrow ( ) . len ( ) as u32 ) ;
407
+ let idx = CodeExtent ( self . code_extents . len ( ) as u32 ) ;
409
408
debug ! ( "CodeExtent({}) = {:?} [parent={}]" , idx. 0 , e, parent. 0 ) ;
410
- self . code_extents . borrow_mut ( ) . push ( e) ;
411
- self . scope_map . borrow_mut ( ) . push ( parent) ;
409
+ self . code_extents . push ( e) ;
410
+ self . scope_map . push ( parent) ;
412
411
* v. insert ( idx)
413
412
}
414
413
}
415
414
}
416
- pub fn intern_node ( & self ,
415
+ pub fn intern_node ( & mut self ,
417
416
n : ast:: NodeId ,
418
417
parent : CodeExtent ) -> CodeExtent {
419
418
self . intern_code_extent ( CodeExtentData :: Misc ( n) , parent)
420
419
}
421
420
pub fn code_extent_data ( & self , e : CodeExtent ) -> CodeExtentData {
422
- self . code_extents . borrow ( ) [ e. 0 as usize ]
421
+ self . code_extents [ e. 0 as usize ]
423
422
}
424
423
pub fn each_encl_scope < E > ( & self , mut e : E ) where E : FnMut ( & CodeExtent , & CodeExtent ) {
425
- for child_id in 1 ..self . code_extents . borrow ( ) . len ( ) {
424
+ for child_id in 1 ..self . code_extents . len ( ) {
426
425
let child = CodeExtent ( child_id as u32 ) ;
427
426
if let Some ( parent) = self . opt_encl_scope ( child) {
428
427
e ( & child, & parent)
429
428
}
430
429
}
431
430
}
432
431
pub fn each_var_scope < E > ( & self , mut e : E ) where E : FnMut ( & ast:: NodeId , & CodeExtent ) {
433
- for ( child, parent) in self . var_map . borrow ( ) . iter ( ) {
432
+ for ( child, parent) in self . var_map . iter ( ) {
434
433
e ( child, parent)
435
434
}
436
435
}
437
436
438
437
/// Records that `sub_fn` is defined within `sup_fn`. These ids
439
438
/// should be the id of the block that is the fn body, which is
440
439
/// also the root of the region hierarchy for that fn.
441
- fn record_fn_parent ( & self , sub_fn : ast:: NodeId , sup_fn : ast:: NodeId ) {
440
+ fn record_fn_parent ( & mut self , sub_fn : ast:: NodeId , sup_fn : ast:: NodeId ) {
442
441
debug ! ( "record_fn_parent(sub_fn={:?}, sup_fn={:?})" , sub_fn, sup_fn) ;
443
442
assert ! ( sub_fn != sup_fn) ;
444
- let previous = self . fn_tree . borrow_mut ( ) . insert ( sub_fn, sup_fn) ;
443
+ let previous = self . fn_tree . insert ( sub_fn, sup_fn) ;
445
444
assert ! ( previous. is_none( ) ) ;
446
445
}
447
446
448
447
fn fn_is_enclosed_by ( & self , mut sub_fn : ast:: NodeId , sup_fn : ast:: NodeId ) -> bool {
449
- let fn_tree = self . fn_tree . borrow ( ) ;
450
448
loop {
451
449
if sub_fn == sup_fn { return true ; }
452
- match fn_tree. get ( & sub_fn) {
450
+ match self . fn_tree . get ( & sub_fn) {
453
451
Some ( & s) => { sub_fn = s; }
454
452
None => { return false ; }
455
453
}
456
454
}
457
455
}
458
456
459
- fn record_var_scope ( & self , var : ast:: NodeId , lifetime : CodeExtent ) {
457
+ fn record_var_scope ( & mut self , var : ast:: NodeId , lifetime : CodeExtent ) {
460
458
debug ! ( "record_var_scope(sub={:?}, sup={:?})" , var, lifetime) ;
461
459
assert ! ( var != lifetime. node_id( self ) ) ;
462
- self . var_map . borrow_mut ( ) . insert ( var, lifetime) ;
460
+ self . var_map . insert ( var, lifetime) ;
463
461
}
464
462
465
- fn record_rvalue_scope ( & self , var : ast:: NodeId , lifetime : CodeExtent ) {
463
+ fn record_rvalue_scope ( & mut self , var : ast:: NodeId , lifetime : CodeExtent ) {
466
464
debug ! ( "record_rvalue_scope(sub={:?}, sup={:?})" , var, lifetime) ;
467
465
assert ! ( var != lifetime. node_id( self ) ) ;
468
- self . rvalue_scopes . borrow_mut ( ) . insert ( var, lifetime) ;
466
+ self . rvalue_scopes . insert ( var, lifetime) ;
469
467
}
470
468
471
- fn record_shrunk_rvalue_scope ( & self , var : ast:: NodeId , lifetime : CodeExtent ) {
469
+ fn record_shrunk_rvalue_scope ( & mut self , var : ast:: NodeId , lifetime : CodeExtent ) {
472
470
debug ! ( "record_rvalue_scope(sub={:?}, sup={:?})" , var, lifetime) ;
473
471
assert ! ( var != lifetime. node_id( self ) ) ;
474
- self . shrunk_rvalue_scopes . borrow_mut ( ) . insert ( var, lifetime) ;
472
+ self . shrunk_rvalue_scopes . insert ( var, lifetime) ;
475
473
}
476
474
477
475
pub fn opt_encl_scope ( & self , id : CodeExtent ) -> Option < CodeExtent > {
478
476
//! Returns the narrowest scope that encloses `id`, if any.
479
- self . scope_map . borrow ( ) [ id. 0 as usize ] . into_option ( )
477
+ self . scope_map [ id. 0 as usize ] . into_option ( )
480
478
}
481
479
482
480
#[ allow( dead_code) ] // used in cfg
@@ -487,15 +485,15 @@ impl RegionMaps {
487
485
488
486
/// Returns the lifetime of the local variable `var_id`
489
487
pub fn var_scope ( & self , var_id : ast:: NodeId ) -> CodeExtent {
490
- match self . var_map . borrow ( ) . get ( & var_id) {
488
+ match self . var_map . get ( & var_id) {
491
489
Some ( & r) => r,
492
490
None => { bug ! ( "no enclosing scope for id {:?}" , var_id) ; }
493
491
}
494
492
}
495
493
496
494
pub fn temporary_scope2 ( & self , expr_id : ast:: NodeId ) -> ( Option < CodeExtent > , bool ) {
497
495
let temporary_scope = self . temporary_scope ( expr_id) ;
498
- let was_shrunk = match self . shrunk_rvalue_scopes . borrow ( ) . get ( & expr_id) {
496
+ let was_shrunk = match self . shrunk_rvalue_scopes . get ( & expr_id) {
499
497
Some ( & s) => {
500
498
info ! ( "temporary_scope2({:?}, scope={:?}, shrunk={:?})" ,
501
499
expr_id, temporary_scope, s) ;
@@ -513,21 +511,21 @@ impl RegionMaps {
513
511
let temporary_scope = self . temporary_scope ( expr_id) ;
514
512
( temporary_scope,
515
513
self . shrunk_rvalue_scopes
516
- . borrow ( ) . get ( & expr_id) . cloned ( )
514
+ . get ( & expr_id) . cloned ( )
517
515
. or ( temporary_scope) )
518
516
}
519
517
520
518
pub fn temporary_scope ( & self , expr_id : ast:: NodeId ) -> Option < CodeExtent > {
521
519
//! Returns the scope when temp created by expr_id will be cleaned up
522
520
523
521
// check for a designated rvalue scope
524
- if let Some ( & s) = self . rvalue_scopes . borrow ( ) . get ( & expr_id) {
522
+ if let Some ( & s) = self . rvalue_scopes . get ( & expr_id) {
525
523
debug ! ( "temporary_scope({:?}) = {:?} [custom]" , expr_id, s) ;
526
524
return Some ( s) ;
527
525
}
528
526
529
- let scope_map : & [ CodeExtent ] = & self . scope_map . borrow ( ) ;
530
- let code_extents: & [ CodeExtentData ] = & self . code_extents . borrow ( ) ;
527
+ let scope_map : & [ CodeExtent ] = & self . scope_map ;
528
+ let code_extents: & [ CodeExtentData ] = & self . code_extents ;
531
529
532
530
// else, locate the innermost terminating scope
533
531
// if there's one. Static items, for instance, won't
@@ -601,7 +599,7 @@ impl RegionMaps {
601
599
let mut a_vec: Vec < CodeExtent > = vec ! [ ] ;
602
600
let mut b_buf: [ CodeExtent ; 32 ] = [ ROOT_CODE_EXTENT ; 32 ] ;
603
601
let mut b_vec: Vec < CodeExtent > = vec ! [ ] ;
604
- let scope_map : & [ CodeExtent ] = & self . scope_map . borrow ( ) ;
602
+ let scope_map : & [ CodeExtent ] = & self . scope_map ;
605
603
let a_ancestors = ancestors_of ( scope_map,
606
604
scope_a, & mut a_buf, & mut a_vec) ;
607
605
let b_ancestors = ancestors_of ( scope_map,
@@ -1216,7 +1214,7 @@ impl<'hir, 'a> RegionResolutionVisitor<'hir, 'a> {
1216
1214
// functions put their destruction scopes *inside* their parameter
1217
1215
// scopes.
1218
1216
let scope = CodeExtentData :: DestructionScope ( id) ;
1219
- if !self . region_maps . code_extent_interner . borrow ( ) . contains_key ( & scope) {
1217
+ if !self . region_maps . code_extent_interner . contains_key ( & scope) {
1220
1218
self . region_maps . intern_code_extent ( scope, ROOT_CODE_EXTENT ) ;
1221
1219
}
1222
1220
}
@@ -1278,14 +1276,14 @@ fn region_resolve_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateN
1278
1276
1279
1277
let krate = hir_map. krate ( ) ;
1280
1278
1281
- let maps = RegionMaps {
1282
- code_extents : RefCell :: new ( vec ! [ ] ) ,
1283
- code_extent_interner : RefCell :: new ( FxHashMap ( ) ) ,
1284
- scope_map : RefCell :: new ( vec ! [ ] ) ,
1285
- var_map : RefCell :: new ( NodeMap ( ) ) ,
1286
- rvalue_scopes : RefCell :: new ( NodeMap ( ) ) ,
1287
- shrunk_rvalue_scopes : RefCell :: new ( NodeMap ( ) ) ,
1288
- fn_tree : RefCell :: new ( NodeMap ( ) ) ,
1279
+ let mut maps = RegionMaps {
1280
+ code_extents : vec ! [ ] ,
1281
+ code_extent_interner : FxHashMap ( ) ,
1282
+ scope_map : vec ! [ ] ,
1283
+ var_map : NodeMap ( ) ,
1284
+ rvalue_scopes : NodeMap ( ) ,
1285
+ shrunk_rvalue_scopes : NodeMap ( ) ,
1286
+ fn_tree : NodeMap ( ) ,
1289
1287
} ;
1290
1288
let root_extent = maps. bogus_code_extent (
1291
1289
CodeExtentData :: DestructionScope ( ast:: DUMMY_NODE_ID ) ) ;
@@ -1296,7 +1294,7 @@ fn region_resolve_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateN
1296
1294
{
1297
1295
let mut visitor = RegionResolutionVisitor {
1298
1296
sess : sess,
1299
- region_maps : & maps,
1297
+ region_maps : & mut maps,
1300
1298
map : hir_map,
1301
1299
cx : Context {
1302
1300
root_id : None ,
0 commit comments