@@ -48,14 +48,14 @@ use crate::util::common::ErrorReported;
4848use crate :: util:: nodemap:: { DefIdMap , DefIdSet , ItemLocalMap , ItemLocalSet } ;
4949use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
5050use errors:: DiagnosticBuilder ;
51- use rustc_data_structures:: interner:: HashInterner ;
5251use smallvec:: SmallVec ;
5352use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
5453 StableHasher , StableHasherResult ,
5554 StableVec } ;
5655use arena:: SyncDroplessArena ;
5756use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
5857use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal } ;
58+ use rustc_data_structures:: sharded:: ShardedHashMap ;
5959use std:: any:: Any ;
6060use std:: borrow:: Borrow ;
6161use std:: cmp:: Ordering ;
@@ -93,7 +93,7 @@ impl AllArenas {
9393 }
9494}
9595
96- type InternedSet < ' tcx , T > = Lock < FxHashMap < Interned < ' tcx , T > , ( ) > > ;
96+ type InternedSet < ' tcx , T > = ShardedHashMap < Interned < ' tcx , T > , ( ) > ;
9797
9898pub struct CtxtInterners < ' tcx > {
9999 /// The arena that types, regions, etc are allocated from
@@ -147,7 +147,7 @@ impl<'tcx> CtxtInterners<'tcx> {
147147 // determine that all contents are in the global tcx.
148148 // See comments on Lift for why we can't use that.
149149 if flags. flags . intersects ( ty:: TypeFlags :: KEEP_IN_LOCAL_TCX ) {
150- local. type_ . borrow_mut ( ) . intern ( st, |st| {
150+ local. type_ . intern ( st, |st| {
151151 let ty_struct = TyS {
152152 sty : st,
153153 flags : flags. flags ,
@@ -171,7 +171,7 @@ impl<'tcx> CtxtInterners<'tcx> {
171171 Interned ( local. arena . alloc ( ty_struct) )
172172 } ) . 0
173173 } else {
174- global. type_ . borrow_mut ( ) . intern ( st, |st| {
174+ global. type_ . intern ( st, |st| {
175175 let ty_struct = TyS {
176176 sty : st,
177177 flags : flags. flags ,
@@ -964,7 +964,7 @@ impl<'tcx> CommonTypes<'tcx> {
964964impl < ' tcx > CommonLifetimes < ' tcx > {
965965 fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonLifetimes < ' tcx > {
966966 let mk = |r| {
967- interners. region . borrow_mut ( ) . intern ( r, |r| {
967+ interners. region . intern ( r, |r| {
968968 Interned ( interners. arena . alloc ( r) )
969969 } ) . 0
970970 } ;
@@ -980,7 +980,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
980980impl < ' tcx > CommonConsts < ' tcx > {
981981 fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
982982 let mk_const = |c| {
983- interners. const_ . borrow_mut ( ) . intern ( c, |c| {
983+ interners. const_ . intern ( c, |c| {
984984 Interned ( interners. arena . alloc ( c) )
985985 } ) . 0
986986 } ;
@@ -1096,14 +1096,14 @@ pub struct GlobalCtxt<'tcx> {
10961096 /// Data layout specification for the current target.
10971097 pub data_layout : TargetDataLayout ,
10981098
1099- stability_interner : Lock < FxHashMap < & ' tcx attr:: Stability , ( ) > > ,
1099+ stability_interner : ShardedHashMap < & ' tcx attr:: Stability , ( ) > ,
11001100
11011101 /// Stores the value of constants (and deduplicates the actual memory)
1102- allocation_interner : Lock < FxHashMap < & ' tcx Allocation , ( ) > > ,
1102+ allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
11031103
11041104 pub alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
11051105
1106- layout_interner : Lock < FxHashMap < & ' tcx LayoutDetails , ( ) > > ,
1106+ layout_interner : ShardedHashMap < & ' tcx LayoutDetails , ( ) > ,
11071107
11081108 /// A general purpose channel to throw data out the back towards LLVM worker
11091109 /// threads.
@@ -1148,7 +1148,7 @@ impl<'tcx> TyCtxt<'tcx> {
11481148 }
11491149
11501150 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| {
11521152 self . arena . alloc ( alloc)
11531153 } )
11541154 }
@@ -1162,13 +1162,13 @@ impl<'tcx> TyCtxt<'tcx> {
11621162 }
11631163
11641164 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| {
11661166 self . arena . alloc ( stab)
11671167 } )
11681168 }
11691169
11701170 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| {
11721172 self . arena . alloc ( layout)
11731173 } )
11741174 }
@@ -2110,7 +2110,9 @@ macro_rules! sty_debug_print {
21102110 } ;
21112111 $( let mut $variant = total; ) *
21122112
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 {
21142116 let variant = match t. sty {
21152117 ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
21162118 ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
@@ -2161,11 +2163,11 @@ impl<'tcx> TyCtxt<'tcx> {
21612163 Generator , GeneratorWitness , Dynamic , Closure , Tuple , Bound ,
21622164 Param , Infer , UnnormalizedProjection , Projection , Opaque , Foreign ) ;
21632165
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( ) ) ;
21692171 }
21702172}
21712173
@@ -2298,7 +2300,7 @@ macro_rules! intern_method {
22982300 // determine that all contents are in the global tcx.
22992301 // See comments on Lift for why we can't use that.
23002302 if ( $keep_in_local_tcx) ( & v) {
2301- self . interners. $name. borrow_mut ( ) . intern_ref( key, || {
2303+ self . interners. $name. intern_ref( key, || {
23022304 // Make sure we don't end up with inference
23032305 // types/regions in the global tcx.
23042306 if self . is_global( ) {
@@ -2310,7 +2312,7 @@ macro_rules! intern_method {
23102312 Interned ( $alloc_method( & self . interners. arena, v) )
23112313 } ) . 0
23122314 } else {
2313- self . global_interners. $name. borrow_mut ( ) . intern_ref( key, || {
2315+ self . global_interners. $name. intern_ref( key, || {
23142316 Interned ( $alloc_method( & self . global_interners. arena, v) )
23152317 } ) . 0
23162318 }
0 commit comments