File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,11 @@ impl<'tcx> CtxtInterners<'tcx> {
153153 . intern ( kind, |kind| {
154154 let flags = super :: flags:: FlagComputation :: for_kind ( & kind) ;
155155
156- let stable_hash = if flags. flags . intersects ( TypeFlags :: HAS_RE_INFER ) {
156+ // It's impossible to hash inference regions (and will ICE), so we don't need to try to cache them.
157+ // Without incremental, we rarely stable-hash types, so let's not do it proactively.
158+ let stable_hash = if flags. flags . intersects ( TypeFlags :: HAS_RE_INFER )
159+ || sess. opts . incremental . is_none ( )
160+ {
157161 Fingerprint :: ZERO
158162 } else {
159163 let mut hasher = StableHasher :: new ( ) ;
Original file line number Diff line number Diff line change @@ -464,8 +464,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Ty<'tcx> {
464464 stable_hash,
465465 } = self . 0 . 0 ;
466466
467- assert_ne ! ( * stable_hash, Fingerprint :: ZERO , "{:#?}" , kind) ;
468- stable_hash. hash_stable ( hcx, hasher) ;
467+ if * stable_hash == Fingerprint :: ZERO {
468+ // No cached hash available. This can only mean that incremental is disabled.
469+ // We don't cache stable hashes in non-incremental mode, because they are used
470+ // so rarely that the performance actually suffers.
471+
472+ let stable_hash: Fingerprint = {
473+ let mut hasher = StableHasher :: new ( ) ;
474+ kind. hash_stable ( hcx, & mut hasher) ;
475+ hasher. finish ( )
476+ } ;
477+ stable_hash. hash_stable ( hcx, hasher) ;
478+ } else {
479+ stable_hash. hash_stable ( hcx, hasher) ;
480+ }
469481 }
470482}
471483
You can’t perform that action at this time.
0 commit comments