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