Skip to content

Commit 7b6bfc2

Browse files
Auto merge of #149785 - JonathanBrouwer:attr_hash_perf, r=<try>
[PERF] How much perf does hashing lints cost?
2 parents 5bc3450 + cd828b3 commit 7b6bfc2

File tree

6 files changed

+10
-34
lines changed

6 files changed

+10
-34
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
695695
let bodies = SortedMap::from_presorted_elements(bodies);
696696

697697
// Don't hash unless necessary, because it's expensive.
698-
let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash, delayed_lints_hash } =
699-
self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque);
698+
let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash } =
699+
self.tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
700700
let num_nodes = self.item_local_id_counter.as_usize();
701701
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
702702
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
703703
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
704-
let delayed_lints =
705-
hir::lints::DelayedLints { lints: delayed_lints, opt_hash: delayed_lints_hash };
704+
let delayed_lints = hir::lints::DelayedLints { lints: delayed_lints };
706705

707706
self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints })
708707
}

compiler/rustc_hir/src/lints.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use rustc_data_structures::fingerprint::Fingerprint;
21
pub use rustc_lint_defs::AttributeLintKind;
32
use rustc_lint_defs::LintId;
4-
use rustc_macros::HashStable_Generic;
53
use rustc_span::Span;
64

75
use crate::HirId;
86

97
#[derive(Debug)]
108
pub struct DelayedLints {
119
pub lints: Box<[DelayedLint]>,
12-
// Only present when the crate hash is needed.
13-
pub opt_hash: Option<Fingerprint>,
1410
}
1511

1612
/// During ast lowering, no lints can be emitted.
@@ -19,12 +15,12 @@ pub struct DelayedLints {
1915
/// and then there's a gap where no lints can be emitted until HIR is done.
2016
/// The variants in this enum represent lints that are temporarily stashed during
2117
/// AST lowering to be emitted once HIR is built.
22-
#[derive(Debug, HashStable_Generic)]
18+
#[derive(Debug)]
2319
pub enum DelayedLint {
2420
AttributeParsing(AttributeLint<HirId>),
2521
}
2622

27-
#[derive(Debug, HashStable_Generic)]
23+
#[derive(Debug)]
2824
pub struct AttributeLint<Id> {
2925
pub lint_id: LintId,
3026
pub id: Id,

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
8181
}
8282

8383
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
84-
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
85-
let DelayedLints { opt_hash, .. } = *self;
86-
opt_hash.unwrap().hash_stable(hcx, hasher);
87-
}
84+
fn hash_stable(&self, _hcx: &mut HirCtx, _hasher: &mut StableHasher) {}
8885
}
8986

9087
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub enum BuiltinLintDiag {
700700
AttributeLint(AttributeLintKind),
701701
}
702702

703-
#[derive(Debug, HashStable_Generic)]
703+
#[derive(Debug)]
704704
pub enum AttributeLintKind {
705705
UnusedDuplicate {
706706
this: Span,

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
1313
use rustc_hir::def::{DefKind, Res};
1414
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
15-
use rustc_hir::lints::DelayedLint;
1615
use rustc_hir::*;
1716
use rustc_macros::{Decodable, Encodable, HashStable};
1817
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
@@ -165,15 +164,10 @@ impl<'tcx> TyCtxt<'tcx> {
165164
node: OwnerNode<'_>,
166165
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
167166
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
168-
delayed_lints: &[DelayedLint],
169167
define_opaque: Option<&[(Span, LocalDefId)]>,
170168
) -> Hashes {
171169
if !self.needs_crate_hash() {
172-
return Hashes {
173-
opt_hash_including_bodies: None,
174-
attrs_hash: None,
175-
delayed_lints_hash: None,
176-
};
170+
return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
177171
}
178172

179173
self.with_stable_hashing_context(|mut hcx| {
@@ -191,16 +185,7 @@ impl<'tcx> TyCtxt<'tcx> {
191185

192186
let h2 = stable_hasher.finish();
193187

194-
// hash lints emitted during ast lowering
195-
let mut stable_hasher = StableHasher::new();
196-
delayed_lints.hash_stable(&mut hcx, &mut stable_hasher);
197-
let h3 = stable_hasher.finish();
198-
199-
Hashes {
200-
opt_hash_including_bodies: Some(h1),
201-
attrs_hash: Some(h2),
202-
delayed_lints_hash: Some(h3),
203-
}
188+
Hashes { opt_hash_including_bodies: Some(h1), attrs_hash: Some(h2) }
204189
})
205190
}
206191

@@ -364,7 +349,6 @@ impl<'tcx> TyCtxt<'tcx> {
364349
pub struct Hashes {
365350
pub opt_hash_including_bodies: Option<Fingerprint>,
366351
pub attrs_hash: Option<Fingerprint>,
367-
pub delayed_lints_hash: Option<Fingerprint>,
368352
}
369353

370354
pub fn provide(providers: &mut Providers) {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
14961496
let attrs = hir::AttributeMap::EMPTY;
14971497

14981498
let rustc_middle::hir::Hashes { opt_hash_including_bodies, .. } =
1499-
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, &[], attrs.define_opaque);
1499+
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
15001500
let node = node.into();
15011501
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
15021502
opt_hash_including_bodies,

0 commit comments

Comments
 (0)