@@ -46,14 +46,14 @@ use crate::util::common::ErrorReported;
46
46
use crate :: util:: nodemap:: { DefIdMap , DefIdSet , ItemLocalMap , ItemLocalSet } ;
47
47
use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
48
48
use errors:: DiagnosticBuilder ;
49
- use rustc_data_structures:: interner:: HashInterner ;
50
49
use smallvec:: SmallVec ;
51
50
use rustc_data_structures:: stable_hasher:: { HashStable , hash_stable_hashmap,
52
51
StableHasher , StableHasherResult ,
53
52
StableVec } ;
54
53
use arena:: SyncDroplessArena ;
55
54
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
56
55
use rustc_data_structures:: sync:: { Lrc , Lock , WorkerLocal } ;
56
+ use rustc_data_structures:: sharded:: ShardedHashMap ;
57
57
use std:: any:: Any ;
58
58
use std:: borrow:: Borrow ;
59
59
use std:: cmp:: Ordering ;
@@ -88,7 +88,7 @@ impl AllArenas {
88
88
}
89
89
}
90
90
91
- type InternedSet < ' tcx , T > = Lock < FxHashMap < Interned < ' tcx , T > , ( ) > > ;
91
+ type InternedSet < ' tcx , T > = ShardedHashMap < Interned < ' tcx , T > , ( ) > ;
92
92
93
93
pub struct CtxtInterners < ' tcx > {
94
94
/// The arena that types, regions, etc are allocated from
@@ -135,7 +135,7 @@ impl<'tcx> CtxtInterners<'tcx> {
135
135
fn intern_ty ( & self ,
136
136
st : TyKind < ' tcx >
137
137
) -> Ty < ' tcx > {
138
- self . type_ . borrow_mut ( ) . intern ( st, |st| {
138
+ self . type_ . intern ( st, |st| {
139
139
let flags = super :: flags:: FlagComputation :: for_sty ( & st) ;
140
140
141
141
let ty_struct = TyS {
@@ -924,7 +924,7 @@ impl<'tcx> CommonTypes<'tcx> {
924
924
impl < ' tcx > CommonLifetimes < ' tcx > {
925
925
fn new ( interners : & CtxtInterners < ' tcx > ) -> CommonLifetimes < ' tcx > {
926
926
let mk = |r| {
927
- interners. region . borrow_mut ( ) . intern ( r, |r| {
927
+ interners. region . intern ( r, |r| {
928
928
Interned ( interners. arena . alloc ( r) )
929
929
} ) . 0
930
930
} ;
@@ -940,7 +940,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
940
940
impl < ' tcx > CommonConsts < ' tcx > {
941
941
fn new ( interners : & CtxtInterners < ' tcx > , types : & CommonTypes < ' tcx > ) -> CommonConsts < ' tcx > {
942
942
let mk_const = |c| {
943
- interners. const_ . borrow_mut ( ) . intern ( c, |c| {
943
+ interners. const_ . intern ( c, |c| {
944
944
Interned ( interners. arena . alloc ( c) )
945
945
} ) . 0
946
946
} ;
@@ -1053,14 +1053,14 @@ pub struct GlobalCtxt<'tcx> {
1053
1053
/// Data layout specification for the current target.
1054
1054
pub data_layout : TargetDataLayout ,
1055
1055
1056
- stability_interner : Lock < FxHashMap < & ' tcx attr:: Stability , ( ) > > ,
1056
+ stability_interner : ShardedHashMap < & ' tcx attr:: Stability , ( ) > ,
1057
1057
1058
1058
/// Stores the value of constants (and deduplicates the actual memory)
1059
- allocation_interner : Lock < FxHashMap < & ' tcx Allocation , ( ) > > ,
1059
+ allocation_interner : ShardedHashMap < & ' tcx Allocation , ( ) > ,
1060
1060
1061
1061
pub alloc_map : Lock < interpret:: AllocMap < ' tcx > > ,
1062
1062
1063
- layout_interner : Lock < FxHashMap < & ' tcx LayoutDetails , ( ) > > ,
1063
+ layout_interner : ShardedHashMap < & ' tcx LayoutDetails , ( ) > ,
1064
1064
1065
1065
/// A general purpose channel to throw data out the back towards LLVM worker
1066
1066
/// threads.
@@ -1103,7 +1103,7 @@ impl<'tcx> TyCtxt<'tcx> {
1103
1103
}
1104
1104
1105
1105
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| {
1107
1107
self . arena . alloc ( alloc)
1108
1108
} )
1109
1109
}
@@ -1117,13 +1117,13 @@ impl<'tcx> TyCtxt<'tcx> {
1117
1117
}
1118
1118
1119
1119
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| {
1121
1121
self . arena . alloc ( stab)
1122
1122
} )
1123
1123
}
1124
1124
1125
1125
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| {
1127
1127
self . arena . alloc ( layout)
1128
1128
} )
1129
1129
}
@@ -2023,7 +2023,9 @@ macro_rules! sty_debug_print {
2023
2023
} ;
2024
2024
$( let mut $variant = total; ) *
2025
2025
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 {
2027
2029
let variant = match t. sty {
2028
2030
ty:: Bool | ty:: Char | ty:: Int ( ..) | ty:: Uint ( ..) |
2029
2031
ty:: Float ( ..) | ty:: Str | ty:: Never => continue ,
@@ -2074,11 +2076,11 @@ impl<'tcx> TyCtxt<'tcx> {
2074
2076
Generator , GeneratorWitness , Dynamic , Closure , Tuple , Bound ,
2075
2077
Param , Infer , UnnormalizedProjection , Projection , Opaque , Foreign ) ;
2076
2078
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( ) ) ;
2082
2084
}
2083
2085
}
2084
2086
@@ -2207,7 +2209,7 @@ macro_rules! intern_method {
2207
2209
pub fn $method( self , v: $alloc) -> & $lt_tcx $ty {
2208
2210
let key = ( $alloc_to_key) ( & v) ;
2209
2211
2210
- self . interners. $name. borrow_mut ( ) . intern_ref( key, || {
2212
+ self . interners. $name. intern_ref( key, || {
2211
2213
Interned ( $alloc_method( & self . interners. arena, v) )
2212
2214
2213
2215
} ) . 0
0 commit comments