Skip to content

Commit 91367b0

Browse files
committed
Auto merge of #154924 - nnethercote:rm-impl-HashStable-for-Attr-slice, r=JonathanBrouwer
Remove `HashStable` impl for `[hir::Attribute]`. This impl skips: - All doc comments - A handful of other attributes, mostly `rustc_*` ones related to incremental compilation testing. This skipping originated in #36025 and was extended a couple of times, e.g. in #36370. Those PRs don't have any explanation of why the skipping exists. Perhaps the reasoning was that doc comments should only affect rustdoc and rustdoc doesn't use incremental compilation? But doc comments end up in metadata, and there is a query `attrs_for_def` that returns a `&'tcx [hir::Attribute]`. So skipping some attributes just seems plainly wrong. This commit removes the impl, which means `[hir::Attribute]` hashing falls back to the default impl for `[T]`. This has no noticeable effect on the test suite. It does slightly hurt performance, because of the doc comments. This perf regression seems worth it for the correctness benefits.
2 parents d12e1e1 + cc74de3 commit 91367b0

1 file changed

Lines changed: 0 additions & 41 deletions

File tree

compiler/rustc_middle/src/ich/impls_syntax.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
44
use rustc_ast as ast;
55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6-
use rustc_hir as hir;
7-
use rustc_span::{Symbol, sym};
8-
use smallvec::SmallVec;
96

107
use super::StableHashingContext;
118

@@ -16,44 +13,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
1613
}
1714
}
1815

19-
impl<'a> HashStable<StableHashingContext<'a>> for [hir::Attribute] {
20-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
21-
if self.is_empty() {
22-
self.len().hash_stable(hcx, hasher);
23-
return;
24-
}
25-
26-
// Some attributes are always ignored during hashing.
27-
let filtered: SmallVec<[&hir::Attribute; 8]> = self
28-
.iter()
29-
.filter(|attr| {
30-
attr.is_doc_comment().is_none()
31-
// FIXME(jdonszelmann) have a better way to handle ignored attrs
32-
&& !attr.name().is_some_and(|ident| is_ignored_attr(ident))
33-
})
34-
.collect();
35-
36-
filtered.len().hash_stable(hcx, hasher);
37-
for attr in filtered {
38-
attr.hash_stable(hcx, hasher);
39-
}
40-
}
41-
}
42-
43-
#[inline]
44-
fn is_ignored_attr(name: Symbol) -> bool {
45-
const IGNORED_ATTRIBUTES: &[Symbol] = &[
46-
sym::cfg_trace, // FIXME(#138844) should this really be ignored?
47-
sym::rustc_if_this_changed,
48-
sym::rustc_then_this_would_need,
49-
sym::rustc_clean,
50-
sym::rustc_partition_reused,
51-
sym::rustc_partition_codegened,
52-
sym::rustc_expected_cgu_reuse,
53-
];
54-
IGNORED_ATTRIBUTES.contains(&name)
55-
}
56-
5716
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
5817
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
5918
// Unfortunately we cannot exhaustively list fields here, since the

0 commit comments

Comments
 (0)