@@ -46,14 +46,14 @@ use crate::util::common::ErrorReported;
4646use crate :: util:: nodemap:: { DefIdMap , DefIdSet , ItemLocalMap , ItemLocalSet } ;
4747use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
4848use errors:: DiagnosticBuilder ;
49- use rustc_data_structures:: interner:: HashInterner ;
5049use smallvec:: SmallVec ;
5150use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
5251 StableHasher , StableHasherResult ,
5352 StableVec } ;
5453use arena:: SyncDroplessArena ;
5554use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
5655use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal } ;
56+ use rustc_data_structures:: sharded:: ShardedHashMap ;
5757use std:: any:: Any ;
5858use std:: borrow:: Borrow ;
5959use std:: cmp:: Ordering ;
@@ -88,7 +88,7 @@ impl AllArenas {
8888 }
8989}
9090
91- type InternedSet < ' tcx , T > = Lock < FxHashMap < Interned < ' tcx , T > , ( ) > > ;
91+ type InternedSet < ' tcx , T > = ShardedHashMap < Interned < ' tcx , T > , ( ) > ;
9292
9393pub struct CtxtInterners < ' tcx > {
9494 /// The arena that types, regions, etc are allocated from
@@ -135,7 +135,7 @@ impl<'tcx> CtxtInterners<'tcx> {
135135 fn intern_ty ( & self ,
136136 st : TyKind < ' tcx >
137137 ) -> Ty < ' tcx > {
138- self . type_ . borrow_mut ( ) . intern ( st, |st| {
138+ self . type_ . intern ( st, |st| {
139139 let flags = super :: flags:: FlagComputation :: for_sty ( & st) ;
140140
141141 let ty_struct = TyS {
@@ -924,7 +924,7 @@ impl<'tcx> CommonTypes<'tcx> {
924924impl < ' tcx > CommonLifetimes < ' tcx > {
925925 fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonLifetimes < ' tcx > {
926926 let mk = |r| {
927- interners. region . borrow_mut ( ) . intern ( r, |r| {
927+ interners. region . intern ( r, |r| {
928928 Interned ( interners. arena . alloc ( r) )
929929 } ) . 0
930930 } ;
@@ -940,7 +940,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
940940impl < ' tcx > CommonConsts < ' tcx > {
941941 fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
942942 let mk_const = |c| {
943- interners. const_ . borrow_mut ( ) . intern ( c, |c| {
943+ interners. const_ . intern ( c, |c| {
944944 Interned ( interners. arena . alloc ( c) )
945945 } ) . 0
946946 } ;
@@ -1053,14 +1053,14 @@ pub struct GlobalCtxt<'tcx> {
10531053 /// Data layout specification for the current target.
10541054 pub data_layout : TargetDataLayout ,
10551055
1056- stability_interner : Lock < FxHashMap < & ' tcx attr:: Stability , ( ) > > ,
1056+ stability_interner : ShardedHashMap < & ' tcx attr:: Stability , ( ) > ,
10571057
10581058 /// Stores the value of constants (and deduplicates the actual memory)
1059- allocation_interner : Lock < FxHashMap < & ' tcx Allocation , ( ) > > ,
1059+ allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
10601060
10611061 pub alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
10621062
1063- layout_interner : Lock < FxHashMap < & ' tcx LayoutDetails , ( ) > > ,
1063+ layout_interner : ShardedHashMap < & ' tcx LayoutDetails , ( ) > ,
10641064
10651065 /// A general purpose channel to throw data out the back towards LLVM worker
10661066 /// threads.
@@ -1103,7 +1103,7 @@ impl<'tcx> TyCtxt<'tcx> {
11031103 }
11041104
11051105 pub fn intern_const_alloc ( self , alloc : Allocation ) -> & ' tcx Allocation {
1106- self . allocation_interner . borrow_mut ( ) . intern ( alloc, |alloc| {
1106+ self . allocation_interner . intern ( alloc, |alloc| {
11071107 self . arena . alloc ( alloc)
11081108 } )
11091109 }
@@ -1117,13 +1117,13 @@ impl<'tcx> TyCtxt<'tcx> {
11171117 }
11181118
11191119 pub fn intern_stability ( self , stab : attr:: Stability ) -> & ' tcx attr:: Stability {
1120- self . stability_interner . borrow_mut ( ) . intern ( stab, |stab| {
1120+ self . stability_interner . intern ( stab, |stab| {
11211121 self . arena . alloc ( stab)
11221122 } )
11231123 }
11241124
11251125 pub fn intern_layout ( self , layout : LayoutDetails ) -> & ' tcx LayoutDetails {
1126- self . layout_interner . borrow_mut ( ) . intern ( layout, |layout| {
1126+ self . layout_interner . intern ( layout, |layout| {
11271127 self . arena . alloc ( layout)
11281128 } )
11291129 }
@@ -2023,7 +2023,9 @@ macro_rules! sty_debug_print {
20232023 } ;
20242024 $( let mut $variant = total; ) *
20252025
2026- for & Interned ( t) in tcx. interners. type_. borrow( ) . keys( ) {
2026+ let shards = tcx. interners. type_. lock_shards( ) ;
2027+ let types = shards. iter( ) . flat_map( |shard| shard. keys( ) ) ;
2028+ for & Interned ( t) in types {
20272029 let variant = match t. sty {
20282030 ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
20292031 ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
@@ -2074,11 +2076,11 @@ impl<'tcx> TyCtxt<'tcx> {
20742076 Generator , GeneratorWitness , Dynamic , Closure , Tuple , Bound ,
20752077 Param , Infer , UnnormalizedProjection , Projection , Opaque , Foreign ) ;
20762078
2077- println ! ( "InternalSubsts interner: #{}" , self . interners. substs. borrow ( ) . len( ) ) ;
2078- println ! ( "Region interner: #{}" , self . interners. region. borrow ( ) . len( ) ) ;
2079- println ! ( "Stability interner: #{}" , self . stability_interner. borrow ( ) . len( ) ) ;
2080- println ! ( "Allocation interner: #{}" , self . allocation_interner. borrow ( ) . len( ) ) ;
2081- println ! ( "Layout interner: #{}" , self . layout_interner. borrow ( ) . len( ) ) ;
2079+ println ! ( "InternalSubsts interner: #{}" , self . interners. substs. len( ) ) ;
2080+ println ! ( "Region interner: #{}" , self . interners. region. len( ) ) ;
2081+ println ! ( "Stability interner: #{}" , self . stability_interner. len( ) ) ;
2082+ println ! ( "Allocation interner: #{}" , self . allocation_interner. len( ) ) ;
2083+ println ! ( "Layout interner: #{}" , self . layout_interner. len( ) ) ;
20822084 }
20832085}
20842086
@@ -2207,7 +2209,7 @@ macro_rules! intern_method {
22072209 pub fn $method( self , v: $alloc) -> & $lt_tcx $ty {
22082210 let key = ( $alloc_to_key) ( & v) ;
22092211
2210- self . interners. $name. borrow_mut ( ) . intern_ref( key, || {
2212+ self . interners. $name. intern_ref( key, || {
22112213 Interned ( $alloc_method( & self . interners. arena, v) )
22122214
22132215 } ) . 0
0 commit comments