@@ -48,14 +48,14 @@ use crate::util::common::ErrorReported;
48
48
use crate :: util:: nodemap:: { DefIdMap , DefIdSet , ItemLocalMap , ItemLocalSet } ;
49
49
use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
50
50
use errors:: DiagnosticBuilder ;
51
- use rustc_data_structures:: interner:: HashInterner ;
52
51
use smallvec:: SmallVec ;
53
52
use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
54
53
StableHasher , StableHasherResult ,
55
54
StableVec } ;
56
55
use arena:: SyncDroplessArena ;
57
56
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
58
57
use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal } ;
58
+ use rustc_data_structures:: sharded:: ShardedHashMap ;
59
59
use std:: any:: Any ;
60
60
use std:: borrow:: Borrow ;
61
61
use std:: cmp:: Ordering ;
@@ -93,7 +93,7 @@ impl AllArenas {
93
93
}
94
94
}
95
95
96
- type InternedSet < ' tcx , T > = Lock < FxHashMap < Interned < ' tcx , T > , ( ) > > ;
96
+ type InternedSet < ' tcx , T > = ShardedHashMap < Interned < ' tcx , T > , ( ) > ;
97
97
98
98
pub struct CtxtInterners < ' tcx > {
99
99
/// The arena that types, regions, etc are allocated from
@@ -147,7 +147,7 @@ impl<'tcx> CtxtInterners<'tcx> {
147
147
// determine that all contents are in the global tcx.
148
148
// See comments on Lift for why we can't use that.
149
149
if flags. flags . intersects ( ty:: TypeFlags :: KEEP_IN_LOCAL_TCX ) {
150
- local. type_ . borrow_mut ( ) . intern ( st, |st| {
150
+ local. type_ . intern ( st, |st| {
151
151
let ty_struct = TyS {
152
152
sty : st,
153
153
flags : flags. flags ,
@@ -171,7 +171,7 @@ impl<'tcx> CtxtInterners<'tcx> {
171
171
Interned ( local. arena . alloc ( ty_struct) )
172
172
} ) . 0
173
173
} else {
174
- global. type_ . borrow_mut ( ) . intern ( st, |st| {
174
+ global. type_ . intern ( st, |st| {
175
175
let ty_struct = TyS {
176
176
sty : st,
177
177
flags : flags. flags ,
@@ -964,7 +964,7 @@ impl<'tcx> CommonTypes<'tcx> {
964
964
impl < ' tcx > CommonLifetimes < ' tcx > {
965
965
fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonLifetimes < ' tcx > {
966
966
let mk = |r| {
967
- interners. region . borrow_mut ( ) . intern ( r, |r| {
967
+ interners. region . intern ( r, |r| {
968
968
Interned ( interners. arena . alloc ( r) )
969
969
} ) . 0
970
970
} ;
@@ -980,7 +980,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
980
980
impl < ' tcx > CommonConsts < ' tcx > {
981
981
fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
982
982
let mk_const = |c| {
983
- interners. const_ . borrow_mut ( ) . intern ( c, |c| {
983
+ interners. const_ . intern ( c, |c| {
984
984
Interned ( interners. arena . alloc ( c) )
985
985
} ) . 0
986
986
} ;
@@ -1096,14 +1096,14 @@ pub struct GlobalCtxt<'tcx> {
1096
1096
/// Data layout specification for the current target.
1097
1097
pub data_layout : TargetDataLayout ,
1098
1098
1099
- stability_interner : Lock < FxHashMap < & ' tcx attr:: Stability , ( ) > > ,
1099
+ stability_interner : ShardedHashMap < & ' tcx attr:: Stability , ( ) > ,
1100
1100
1101
1101
/// Stores the value of constants (and deduplicates the actual memory)
1102
- allocation_interner : Lock < FxHashMap < & ' tcx Allocation , ( ) > > ,
1102
+ allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
1103
1103
1104
1104
pub alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
1105
1105
1106
- layout_interner : Lock < FxHashMap < & ' tcx LayoutDetails , ( ) > > ,
1106
+ layout_interner : ShardedHashMap < & ' tcx LayoutDetails , ( ) > ,
1107
1107
1108
1108
/// A general purpose channel to throw data out the back towards LLVM worker
1109
1109
/// threads.
@@ -1148,7 +1148,7 @@ impl<'tcx> TyCtxt<'tcx> {
1148
1148
}
1149
1149
1150
1150
pub fn intern_const_alloc ( self , alloc : Allocation ) -> & ' tcx Allocation {
1151
- self . allocation_interner . borrow_mut ( ) . intern ( alloc, |alloc| {
1151
+ self . allocation_interner . intern ( alloc, |alloc| {
1152
1152
self . arena . alloc ( alloc)
1153
1153
} )
1154
1154
}
@@ -1162,13 +1162,13 @@ impl<'tcx> TyCtxt<'tcx> {
1162
1162
}
1163
1163
1164
1164
pub fn intern_stability ( self , stab : attr:: Stability ) -> & ' tcx attr:: Stability {
1165
- self . stability_interner . borrow_mut ( ) . intern ( stab, |stab| {
1165
+ self . stability_interner . intern ( stab, |stab| {
1166
1166
self . arena . alloc ( stab)
1167
1167
} )
1168
1168
}
1169
1169
1170
1170
pub fn intern_layout ( self , layout : LayoutDetails ) -> & ' tcx LayoutDetails {
1171
- self . layout_interner . borrow_mut ( ) . intern ( layout, |layout| {
1171
+ self . layout_interner . intern ( layout, |layout| {
1172
1172
self . arena . alloc ( layout)
1173
1173
} )
1174
1174
}
@@ -2110,7 +2110,9 @@ macro_rules! sty_debug_print {
2110
2110
} ;
2111
2111
$( let mut $variant = total; ) *
2112
2112
2113
- for & Interned ( t) in tcx. interners. type_. borrow( ) . keys( ) {
2113
+ let shards = tcx. interners. type_. lock_shards( ) ;
2114
+ let types = shards. iter( ) . flat_map( |shard| shard. keys( ) ) ;
2115
+ for & Interned ( t) in types {
2114
2116
let variant = match t. sty {
2115
2117
ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
2116
2118
ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
@@ -2161,11 +2163,11 @@ impl<'tcx> TyCtxt<'tcx> {
2161
2163
Generator , GeneratorWitness , Dynamic , Closure , Tuple , Bound ,
2162
2164
Param , Infer , UnnormalizedProjection , Projection , Opaque , Foreign ) ;
2163
2165
2164
- println ! ( "InternalSubsts interner: #{}" , self . interners. substs. borrow ( ) . len( ) ) ;
2165
- println ! ( "Region interner: #{}" , self . interners. region. borrow ( ) . len( ) ) ;
2166
- println ! ( "Stability interner: #{}" , self . stability_interner. borrow ( ) . len( ) ) ;
2167
- println ! ( "Allocation interner: #{}" , self . allocation_interner. borrow ( ) . len( ) ) ;
2168
- println ! ( "Layout interner: #{}" , self . layout_interner. borrow ( ) . len( ) ) ;
2166
+ println ! ( "InternalSubsts interner: #{}" , self . interners. substs. len( ) ) ;
2167
+ println ! ( "Region interner: #{}" , self . interners. region. len( ) ) ;
2168
+ println ! ( "Stability interner: #{}" , self . stability_interner. len( ) ) ;
2169
+ println ! ( "Allocation interner: #{}" , self . allocation_interner. len( ) ) ;
2170
+ println ! ( "Layout interner: #{}" , self . layout_interner. len( ) ) ;
2169
2171
}
2170
2172
}
2171
2173
@@ -2298,7 +2300,7 @@ macro_rules! intern_method {
2298
2300
// determine that all contents are in the global tcx.
2299
2301
// See comments on Lift for why we can't use that.
2300
2302
if ( $keep_in_local_tcx) ( & v) {
2301
- self . interners. $name. borrow_mut ( ) . intern_ref( key, || {
2303
+ self . interners. $name. intern_ref( key, || {
2302
2304
// Make sure we don't end up with inference
2303
2305
// types/regions in the global tcx.
2304
2306
if self . is_global( ) {
@@ -2310,7 +2312,7 @@ macro_rules! intern_method {
2310
2312
Interned ( $alloc_method( & self . interners. arena, v) )
2311
2313
} ) . 0
2312
2314
} else {
2313
- self . global_interners. $name. borrow_mut ( ) . intern_ref( key, || {
2315
+ self . global_interners. $name. intern_ref( key, || {
2314
2316
Interned ( $alloc_method( & self . global_interners. arena, v) )
2315
2317
} ) . 0
2316
2318
}
0 commit comments