@@ -44,9 +44,9 @@ use ty::relate::TypeRelation;
44
44
use middle:: lang_items;
45
45
use mir:: interpret:: { GlobalId } ;
46
46
47
+ use rustc_data_structures:: sync:: Lock ;
47
48
use rustc_data_structures:: bitvec:: BitVector ;
48
49
use std:: iter;
49
- use std:: cell:: RefCell ;
50
50
use std:: cmp;
51
51
use std:: fmt;
52
52
use std:: mem;
@@ -148,7 +148,7 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> {
148
148
149
149
#[ derive( Clone ) ]
150
150
pub struct SelectionCache < ' tcx > {
151
- hashmap : RefCell < FxHashMap < ty:: TraitRef < ' tcx > ,
151
+ hashmap : Lock < FxHashMap < ty:: TraitRef < ' tcx > ,
152
152
WithDepNode < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > > > ,
153
153
}
154
154
@@ -435,7 +435,7 @@ impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
435
435
436
436
#[ derive( Clone ) ]
437
437
pub struct EvaluationCache < ' tcx > {
438
- hashmap : RefCell < FxHashMap < ty:: PolyTraitRef < ' tcx > , WithDepNode < EvaluationResult > > >
438
+ hashmap : Lock < FxHashMap < ty:: PolyTraitRef < ' tcx > , WithDepNode < EvaluationResult > > >
439
439
}
440
440
441
441
impl < ' cx , ' gcx , ' tcx > SelectionContext < ' cx , ' gcx , ' tcx > {
@@ -1015,14 +1015,19 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1015
1015
}
1016
1016
1017
1017
if self . can_use_global_caches ( param_env) {
1018
- let mut cache = self . tcx ( ) . evaluation_cache . hashmap . borrow_mut ( ) ;
1019
1018
if let Some ( trait_ref) = self . tcx ( ) . lift_to_global ( & trait_ref) {
1020
1019
debug ! (
1021
1020
"insert_evaluation_cache(trait_ref={:?}, candidate={:?}) global" ,
1022
1021
trait_ref,
1023
1022
result,
1024
1023
) ;
1025
- cache. insert ( trait_ref, WithDepNode :: new ( dep_node, result) ) ;
1024
+ // This may overwrite the cache with the same value
1025
+ // FIXME: Due to #50507 this overwrites the different values
1026
+ // This should be changed to use HashMapExt::insert_same
1027
+ // when that is fixed
1028
+ self . tcx ( ) . evaluation_cache
1029
+ . hashmap . borrow_mut ( )
1030
+ . insert ( trait_ref, WithDepNode :: new ( dep_node, result) ) ;
1026
1031
return ;
1027
1032
}
1028
1033
}
@@ -1368,15 +1373,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1368
1373
let tcx = self . tcx ( ) ;
1369
1374
let trait_ref = cache_fresh_trait_pred. skip_binder ( ) . trait_ref ;
1370
1375
if self . can_use_global_caches ( param_env) {
1371
- let mut cache = tcx. selection_cache . hashmap . borrow_mut ( ) ;
1372
1376
if let Some ( trait_ref) = tcx. lift_to_global ( & trait_ref) {
1373
1377
if let Some ( candidate) = tcx. lift_to_global ( & candidate) {
1374
1378
debug ! (
1375
1379
"insert_candidate_cache(trait_ref={:?}, candidate={:?}) global" ,
1376
1380
trait_ref,
1377
1381
candidate,
1378
1382
) ;
1379
- cache. insert ( trait_ref, WithDepNode :: new ( dep_node, candidate) ) ;
1383
+ // This may overwrite the cache with the same value
1384
+ tcx. selection_cache
1385
+ . hashmap . borrow_mut ( )
1386
+ . insert ( trait_ref, WithDepNode :: new ( dep_node, candidate) ) ;
1380
1387
return ;
1381
1388
}
1382
1389
}
@@ -3404,7 +3411,7 @@ impl<'tcx> TraitObligation<'tcx> {
3404
3411
impl < ' tcx > SelectionCache < ' tcx > {
3405
3412
pub fn new ( ) -> SelectionCache < ' tcx > {
3406
3413
SelectionCache {
3407
- hashmap : RefCell :: new ( FxHashMap ( ) )
3414
+ hashmap : Lock :: new ( FxHashMap ( ) )
3408
3415
}
3409
3416
}
3410
3417
@@ -3416,7 +3423,7 @@ impl<'tcx> SelectionCache<'tcx> {
3416
3423
impl < ' tcx > EvaluationCache < ' tcx > {
3417
3424
pub fn new ( ) -> EvaluationCache < ' tcx > {
3418
3425
EvaluationCache {
3419
- hashmap : RefCell :: new ( FxHashMap ( ) )
3426
+ hashmap : Lock :: new ( FxHashMap ( ) )
3420
3427
}
3421
3428
}
3422
3429
@@ -3470,7 +3477,7 @@ impl<'o,'tcx> fmt::Debug for TraitObligationStack<'o,'tcx> {
3470
3477
}
3471
3478
}
3472
3479
3473
- #[ derive( Clone ) ]
3480
+ #[ derive( Clone , Eq , PartialEq ) ]
3474
3481
pub struct WithDepNode < T > {
3475
3482
dep_node : DepNodeIndex ,
3476
3483
cached_value : T
0 commit comments