@@ -141,7 +141,7 @@ pub struct CtxtInterners<'tcx> {
141
141
canonical_var_infos : InternedSet < ' tcx , List < CanonicalVarInfo < ' tcx > > > ,
142
142
region : InternedSet < ' tcx , RegionKind < ' tcx > > ,
143
143
poly_existential_predicates : InternedSet < ' tcx , List < PolyExistentialPredicate < ' tcx > > > ,
144
- predicate : InternedSet < ' tcx , PredicateS < ' tcx > > ,
144
+ predicate : InternedSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > ,
145
145
predicates : InternedSet < ' tcx , List < Predicate < ' tcx > > > ,
146
146
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
147
147
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
@@ -188,20 +188,8 @@ impl<'tcx> CtxtInterners<'tcx> {
188
188
self . type_
189
189
. intern ( kind, |kind| {
190
190
let flags = super :: flags:: FlagComputation :: for_kind ( & kind) ;
191
-
192
- // It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
193
- // Without incremental, we rarely stable-hash types, so let's not do it proactively.
194
- let stable_hash = if flags. flags . intersects ( TypeFlags :: NEEDS_INFER )
195
- || sess. opts . incremental . is_none ( )
196
- {
197
- Fingerprint :: ZERO
198
- } else {
199
- let mut hasher = StableHasher :: new ( ) ;
200
- let mut hcx =
201
- StableHashingContext :: new ( sess, definitions, cstore, source_span) ;
202
- kind. hash_stable ( & mut hcx, & mut hasher) ;
203
- hasher. finish ( )
204
- } ;
191
+ let stable_hash =
192
+ self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
205
193
206
194
let ty_struct = TyS {
207
195
kind,
@@ -217,20 +205,54 @@ impl<'tcx> CtxtInterners<'tcx> {
217
205
) )
218
206
}
219
207
208
+ fn stable_hash < ' a , T : HashStable < StableHashingContext < ' a > > > (
209
+ & self ,
210
+ flags : & ty:: flags:: FlagComputation ,
211
+ sess : & ' a Session ,
212
+ definitions : & ' a rustc_hir:: definitions:: Definitions ,
213
+ cstore : & ' a CrateStoreDyn ,
214
+ source_span : & ' a IndexVec < LocalDefId , Span > ,
215
+ val : & T ,
216
+ ) -> Fingerprint {
217
+ // It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
218
+ // Without incremental, we rarely stable-hash types, so let's not do it proactively.
219
+ if flags. flags . intersects ( TypeFlags :: NEEDS_INFER ) || sess. opts . incremental . is_none ( ) {
220
+ Fingerprint :: ZERO
221
+ } else {
222
+ let mut hasher = StableHasher :: new ( ) ;
223
+ let mut hcx = StableHashingContext :: new ( sess, definitions, cstore, source_span) ;
224
+ val. hash_stable ( & mut hcx, & mut hasher) ;
225
+ hasher. finish ( )
226
+ }
227
+ }
228
+
220
229
#[ inline( never) ]
221
- fn intern_predicate ( & self , kind : Binder < ' tcx , PredicateKind < ' tcx > > ) -> Predicate < ' tcx > {
230
+ fn intern_predicate (
231
+ & self ,
232
+ kind : Binder < ' tcx , PredicateKind < ' tcx > > ,
233
+ sess : & Session ,
234
+ definitions : & rustc_hir:: definitions:: Definitions ,
235
+ cstore : & CrateStoreDyn ,
236
+ source_span : & IndexVec < LocalDefId , Span > ,
237
+ ) -> Predicate < ' tcx > {
222
238
Predicate ( Interned :: new_unchecked (
223
239
self . predicate
224
240
. intern ( kind, |kind| {
225
241
let flags = super :: flags:: FlagComputation :: for_predicate ( kind) ;
226
242
243
+ let stable_hash =
244
+ self . stable_hash ( & flags, sess, definitions, cstore, source_span, & kind) ;
245
+
227
246
let predicate_struct = PredicateS {
228
247
kind,
229
248
flags : flags. flags ,
230
249
outer_exclusive_binder : flags. outer_exclusive_binder ,
231
250
} ;
232
251
233
- InternedInSet ( self . arena . alloc ( predicate_struct) )
252
+ InternedInSet (
253
+ self . arena
254
+ . alloc ( WithStableHash { internee : predicate_struct, stable_hash } ) ,
255
+ )
234
256
} )
235
257
. 0 ,
236
258
) )
@@ -2158,23 +2180,25 @@ impl<'tcx> Hash for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> {
2158
2180
}
2159
2181
}
2160
2182
2161
- impl < ' tcx > Borrow < Binder < ' tcx , PredicateKind < ' tcx > > > for InternedInSet < ' tcx , PredicateS < ' tcx > > {
2183
+ impl < ' tcx > Borrow < Binder < ' tcx , PredicateKind < ' tcx > > >
2184
+ for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > >
2185
+ {
2162
2186
fn borrow < ' a > ( & ' a self ) -> & ' a Binder < ' tcx , PredicateKind < ' tcx > > {
2163
2187
& self . 0 . kind
2164
2188
}
2165
2189
}
2166
2190
2167
- impl < ' tcx > PartialEq for InternedInSet < ' tcx , PredicateS < ' tcx > > {
2168
- fn eq ( & self , other : & InternedInSet < ' tcx , PredicateS < ' tcx > > ) -> bool {
2191
+ impl < ' tcx > PartialEq for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > {
2192
+ fn eq ( & self , other : & InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > ) -> bool {
2169
2193
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
2170
2194
// `x == y`.
2171
2195
self . 0 . kind == other. 0 . kind
2172
2196
}
2173
2197
}
2174
2198
2175
- impl < ' tcx > Eq for InternedInSet < ' tcx , PredicateS < ' tcx > > { }
2199
+ impl < ' tcx > Eq for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > { }
2176
2200
2177
- impl < ' tcx > Hash for InternedInSet < ' tcx , PredicateS < ' tcx > > {
2201
+ impl < ' tcx > Hash for InternedInSet < ' tcx , WithStableHash < PredicateS < ' tcx > > > {
2178
2202
fn hash < H : Hasher > ( & self , s : & mut H ) {
2179
2203
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2180
2204
self . 0 . kind . hash ( s)
@@ -2373,7 +2397,14 @@ impl<'tcx> TyCtxt<'tcx> {
2373
2397
2374
2398
#[ inline]
2375
2399
pub fn mk_predicate ( self , binder : Binder < ' tcx , PredicateKind < ' tcx > > ) -> Predicate < ' tcx > {
2376
- self . interners . intern_predicate ( binder)
2400
+ self . interners . intern_predicate (
2401
+ binder,
2402
+ self . sess ,
2403
+ & self . definitions . read ( ) ,
2404
+ & * self . untracked_resolutions . cstore ,
2405
+ // This is only used to create a stable hashing context.
2406
+ & self . untracked_resolutions . source_span ,
2407
+ )
2377
2408
}
2378
2409
2379
2410
#[ inline]
0 commit comments