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