Skip to content

Commit 27f66fe

Browse files
committed
Remove WithCachedTypeInfo::stable_hash.
1 parent 14196db commit 27f66fe

8 files changed

Lines changed: 23 additions & 123 deletions

File tree

compiler/rustc_middle/src/ty/context.rs

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ use std::{fmt, iter, mem};
1818
use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
1919
use rustc_ast as ast;
2020
use rustc_data_structures::defer;
21-
use rustc_data_structures::fingerprint::Fingerprint;
2221
use rustc_data_structures::fx::FxHashMap;
2322
use rustc_data_structures::intern::Interned;
2423
use rustc_data_structures::jobserver::Proxy;
2524
use rustc_data_structures::profiling::SelfProfilerRef;
2625
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
27-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
26+
use rustc_data_structures::stable_hasher::HashStable;
2827
use rustc_data_structures::steal::Steal;
2928
use rustc_data_structures::sync::{
3029
self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal,
@@ -47,7 +46,7 @@ use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
4746
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
4847
use rustc_type_ir::TyKind::*;
4948
pub use rustc_type_ir::lift::Lift;
50-
use rustc_type_ir::{CollectAndApply, TypeFlags, WithCachedTypeInfo, elaborate, search_graph};
49+
use rustc_type_ir::{CollectAndApply, WithCachedTypeInfo, elaborate, search_graph};
5150
use tracing::{debug, instrument};
5251

5352
use crate::arena::Arena;
@@ -207,16 +206,13 @@ impl<'tcx> CtxtInterners<'tcx> {
207206
/// Interns a type. (Use `mk_*` functions instead, where possible.)
208207
#[allow(rustc::usage_of_ty_tykind)]
209208
#[inline(never)]
210-
fn intern_ty(&self, kind: TyKind<'tcx>, sess: &Session, untracked: &Untracked) -> Ty<'tcx> {
209+
fn intern_ty(&self, kind: TyKind<'tcx>) -> Ty<'tcx> {
211210
Ty(Interned::new_unchecked(
212211
self.type_
213212
.intern(kind, |kind| {
214213
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_kind(&kind);
215-
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
216-
217214
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
218215
internee: kind,
219-
stable_hash,
220216
flags: flags.flags,
221217
outer_exclusive_binder: flags.outer_exclusive_binder,
222218
}))
@@ -228,21 +224,13 @@ impl<'tcx> CtxtInterners<'tcx> {
228224
/// Interns a const. (Use `mk_*` functions instead, where possible.)
229225
#[allow(rustc::usage_of_ty_tykind)]
230226
#[inline(never)]
231-
fn intern_const(
232-
&self,
233-
kind: ty::ConstKind<'tcx>,
234-
sess: &Session,
235-
untracked: &Untracked,
236-
) -> Const<'tcx> {
227+
fn intern_const(&self, kind: ty::ConstKind<'tcx>) -> Const<'tcx> {
237228
Const(Interned::new_unchecked(
238229
self.const_
239230
.intern(kind, |kind: ty::ConstKind<'_>| {
240231
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_const_kind(&kind);
241-
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
242-
243232
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
244233
internee: kind,
245-
stable_hash,
246234
flags: flags.flags,
247235
outer_exclusive_binder: flags.outer_exclusive_binder,
248236
}))
@@ -251,43 +239,15 @@ impl<'tcx> CtxtInterners<'tcx> {
251239
))
252240
}
253241

254-
fn stable_hash<'a, T: HashStable<StableHashingContext<'a>>>(
255-
&self,
256-
flags: &ty::FlagComputation<TyCtxt<'tcx>>,
257-
sess: &'a Session,
258-
untracked: &'a Untracked,
259-
val: &T,
260-
) -> Fingerprint {
261-
// It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
262-
// Without incremental, we rarely stable-hash types, so let's not do it proactively.
263-
if flags.flags.intersects(TypeFlags::HAS_INFER) || sess.opts.incremental.is_none() {
264-
Fingerprint::ZERO
265-
} else {
266-
let mut hasher = StableHasher::new();
267-
let mut hcx = StableHashingContext::new(sess, untracked);
268-
val.hash_stable(&mut hcx, &mut hasher);
269-
hasher.finish()
270-
}
271-
}
272-
273242
/// Interns a predicate. (Use `mk_predicate` instead, where possible.)
274243
#[inline(never)]
275-
fn intern_predicate(
276-
&self,
277-
kind: Binder<'tcx, PredicateKind<'tcx>>,
278-
sess: &Session,
279-
untracked: &Untracked,
280-
) -> Predicate<'tcx> {
244+
fn intern_predicate(&self, kind: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> {
281245
Predicate(Interned::new_unchecked(
282246
self.predicate
283247
.intern(kind, |kind| {
284248
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_predicate(kind);
285-
286-
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
287-
288249
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
289250
internee: kind,
290-
stable_hash,
291251
flags: flags.flags,
292252
outer_exclusive_binder: flags.outer_exclusive_binder,
293253
}))
@@ -423,12 +383,8 @@ pub struct CommonConsts<'tcx> {
423383
}
424384

425385
impl<'tcx> CommonTypes<'tcx> {
426-
fn new(
427-
interners: &CtxtInterners<'tcx>,
428-
sess: &Session,
429-
untracked: &Untracked,
430-
) -> CommonTypes<'tcx> {
431-
let mk = |ty| interners.intern_ty(ty, sess, untracked);
386+
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
387+
let mk = |ty| interners.intern_ty(ty);
432388

433389
let ty_vars =
434390
(0..NUM_PREINTERNED_TY_VARS).map(|n| mk(Infer(ty::TyVar(TyVid::from(n))))).collect();
@@ -544,18 +500,8 @@ impl<'tcx> CommonLifetimes<'tcx> {
544500
}
545501

546502
impl<'tcx> CommonConsts<'tcx> {
547-
fn new(
548-
interners: &CtxtInterners<'tcx>,
549-
types: &CommonTypes<'tcx>,
550-
sess: &Session,
551-
untracked: &Untracked,
552-
) -> CommonConsts<'tcx> {
553-
let mk_const = |c| {
554-
interners.intern_const(
555-
c, sess, // This is only used to create a stable hashing context.
556-
untracked,
557-
)
558-
};
503+
fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonConsts<'tcx> {
504+
let mk_const = |c| interners.intern_const(c);
559505

560506
let mk_valtree = |v| {
561507
ty::ValTree(Interned::new_unchecked(
@@ -1030,9 +976,9 @@ impl<'tcx> TyCtxt<'tcx> {
1030976
s.dcx().emit_fatal(err);
1031977
});
1032978
let interners = CtxtInterners::new(arena);
1033-
let common_types = CommonTypes::new(&interners, s, &untracked);
979+
let common_types = CommonTypes::new(&interners);
1034980
let common_lifetimes = CommonLifetimes::new(&interners);
1035-
let common_consts = CommonConsts::new(&interners, &common_types, s, &untracked);
981+
let common_consts = CommonConsts::new(&interners, &common_types);
1036982

1037983
let gcx = gcx_cell.get_or_init(|| GlobalCtxt {
1038984
sess: s,
@@ -2148,12 +2094,7 @@ impl<'tcx> TyCtxt<'tcx> {
21482094

21492095
#[inline]
21502096
pub fn mk_predicate(self, binder: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> {
2151-
self.interners.intern_predicate(
2152-
binder,
2153-
self.sess,
2154-
// This is only used to create a stable hashing context.
2155-
&self.untracked,
2156-
)
2097+
self.interners.intern_predicate(binder)
21572098
}
21582099

21592100
#[inline]
@@ -2274,24 +2215,14 @@ impl<'tcx> TyCtxt<'tcx> {
22742215

22752216
#[inline]
22762217
pub fn mk_ct_from_kind(self, kind: ty::ConstKind<'tcx>) -> Const<'tcx> {
2277-
self.interners.intern_const(
2278-
kind,
2279-
self.sess,
2280-
// This is only used to create a stable hashing context.
2281-
&self.untracked,
2282-
)
2218+
self.interners.intern_const(kind)
22832219
}
22842220

22852221
// Avoid this in favour of more specific `Ty::new_*` methods, where possible.
22862222
#[allow(rustc::usage_of_ty_tykind)]
22872223
#[inline]
22882224
pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> {
2289-
self.interners.intern_ty(
2290-
st,
2291-
self.sess,
2292-
// This is only used to create a stable hashing context.
2293-
&self.untracked,
2294-
)
2225+
self.interners.intern_ty(st)
22952226
}
22962227

22972228
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,6 @@ mod size_asserts {
653653
use super::*;
654654
// tidy-alphabetical-start
655655
static_assert_size!(PredicateKind<'_>, 32);
656-
static_assert_size!(WithCachedTypeInfo<PredicateKind<'_>>, 56);
656+
static_assert_size!(WithCachedTypeInfo<PredicateKind<'_>>, 40);
657657
// tidy-alphabetical-end
658658
}

compiler/rustc_middle/src/ty/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,6 @@ mod size_asserts {
460460
use super::*;
461461
// tidy-alphabetical-start
462462
static_assert_size!(RegionKind<'_>, 20);
463-
static_assert_size!(ty::WithCachedTypeInfo<RegionKind<'_>>, 48);
463+
static_assert_size!(ty::WithCachedTypeInfo<RegionKind<'_>>, 28);
464464
// tidy-alphabetical-end
465465
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,6 @@ mod size_asserts {
21612161
use super::*;
21622162
// tidy-alphabetical-start
21632163
static_assert_size!(TyKind<'_>, 32);
2164-
static_assert_size!(ty::WithCachedTypeInfo<TyKind<'_>>, 56);
2164+
static_assert_size!(ty::WithCachedTypeInfo<TyKind<'_>>, 40);
21652165
// tidy-alphabetical-end
21662166
}

compiler/rustc_type_ir/src/ty_info.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use std::cmp::Ordering;
22
use std::hash::{Hash, Hasher};
33
use std::ops::Deref;
44

5-
#[cfg(feature = "nightly")]
6-
use rustc_data_structures::fingerprint::Fingerprint;
75
#[cfg(feature = "nightly")]
86
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
97
use rustc_type_ir_macros::GenericTypeVisitable;
@@ -21,9 +19,6 @@ use crate::{DebruijnIndex, TypeFlags};
2119
pub struct WithCachedTypeInfo<T> {
2220
pub internee: T,
2321

24-
#[cfg(feature = "nightly")]
25-
pub stable_hash: Fingerprint,
26-
2722
/// This field provides fast access to information that is also contained
2823
/// in `kind`.
2924
///
@@ -87,39 +82,13 @@ impl<T> Deref for WithCachedTypeInfo<T> {
8782
impl<T: Hash> Hash for WithCachedTypeInfo<T> {
8883
#[inline]
8984
fn hash<H: Hasher>(&self, s: &mut H) {
90-
#[cfg(feature = "nightly")]
91-
if self.stable_hash != Fingerprint::ZERO {
92-
return self.stable_hash.hash(s);
93-
}
94-
9585
self.internee.hash(s)
9686
}
9787
}
9888

9989
#[cfg(feature = "nightly")]
10090
impl<T: HashStable<Hcx>, Hcx> HashStable<Hcx> for WithCachedTypeInfo<T> {
10191
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
102-
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
103-
// No cached hash available. This can only mean that incremental is disabled.
104-
// We don't cache stable hashes in non-incremental mode, because they are used
105-
// so rarely that the performance actually suffers.
106-
107-
// We need to build the hash as if we cached it and then hash that hash, as
108-
// otherwise the hashes will differ between cached and non-cached mode.
109-
let stable_hash: Fingerprint = {
110-
let mut hasher = StableHasher::new();
111-
self.internee.hash_stable(hcx, &mut hasher);
112-
hasher.finish()
113-
};
114-
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {
115-
assert_eq!(
116-
stable_hash, self.stable_hash,
117-
"cached stable hash does not match freshly computed stable hash"
118-
);
119-
}
120-
stable_hash.hash_stable(hcx, hasher);
121-
} else {
122-
self.stable_hash.hash_stable(hcx, hasher);
123-
}
92+
self.internee.hash_stable(hcx, hasher);
12493
}
12594
}

tests/debuginfo/function-names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// Const generic parameter
4040
//@ gdb-command:info functions -q function_names::const_generic_fn.*
4141
//@ gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
42-
//@ gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#6dd80cc0c950c171}>();
42+
//@ gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#68cf9e429c783d36}>();
4343
//@ gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
4444
//@ gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
4545

tests/ui/symbol-names/basic.legacy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN5basic4main17h1dddcfd03744167fE)
1+
error: symbol-name(_ZN5basic4main17hada6eff52bd1baecE)
22
--> $DIR/basic.rs:8:1
33
|
44
LL | #[rustc_dump_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(basic::main::h1dddcfd03744167f)
7+
error: demangling(basic::main::hada6eff52bd1baec)
88
--> $DIR/basic.rs:8:1
99
|
1010
LL | #[rustc_dump_symbol_name]

tests/ui/symbol-names/issue-60925.legacy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h4b3099ec5dc5d306E)
1+
error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17h91bf17e30395b22aE)
22
--> $DIR/issue-60925.rs:21:9
33
|
44
LL | #[rustc_dump_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h4b3099ec5dc5d306)
7+
error: demangling(issue_60925::foo::Foo<issue_60925::llvm::Foo>::foo::h91bf17e30395b22a)
88
--> $DIR/issue-60925.rs:21:9
99
|
1010
LL | #[rustc_dump_symbol_name]

0 commit comments

Comments
 (0)