Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
let bodies = SortedMap::from_presorted_elements(bodies);

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

self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints })
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ pub struct OwnerInfo<'hir> {

/// Lints delayed during ast lowering to be emitted
/// after hir has completely built
#[stable_hasher(ignore)]
Copy link
Copy Markdown
Contributor Author

@JonathanBrouwer JonathanBrouwer Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since the review

Actually but that I'm looking at this diff again I'd like to double check that this line is sound, so please wait with merging

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it again, I'm actually pretty sure this is not sound :c
The hash of the lints can change without the hash of the HIR itself changing, crazily enough. And if delayed_lints here changes we need to rerun HIR analysis as that is what actually emits the lints, rather than re-using the cached result

pub delayed_lints: DelayedLints,
}

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_hir/src/lints.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_error_messages::MultiSpan;
use rustc_lint_defs::LintId;
pub use rustc_lint_defs::{AttributeLintKind, FormatWarning};
use rustc_macros::HashStable_Generic;

use crate::HirId;

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

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

#[derive(Debug, HashStable_Generic)]
#[derive(Debug)]
pub struct AttributeLint<Id> {
pub lint_id: LintId,
pub id: Id,
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_hir/src/stable_hash_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::hir::{
AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
};
use crate::hir_id::ItemLocalId;
use crate::lints::DelayedLints;

impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
type KeyType = (DefPathHash, ItemLocalId);
Expand Down Expand Up @@ -74,13 +73,6 @@ impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
}
}

impl<Hcx: HashStableContext> HashStable<Hcx> for DelayedLints {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let DelayedLints { opt_hash, .. } = *self;
opt_hash.unwrap().hash_stable(hcx, hasher);
}
}

impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// We ignore the `map` since it refers to information included in `opt_hash` which is
Expand Down
20 changes: 2 additions & 18 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{DynSend, DynSync, spawn, try_par_for_each_in};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lints::DelayedLint;
use rustc_hir::*;
use rustc_index::IndexVec;
use rustc_macros::{Decodable, Encodable, HashStable};
Expand Down Expand Up @@ -255,15 +254,10 @@ impl<'tcx> TyCtxt<'tcx> {
node: OwnerNode<'_>,
bodies: &SortedMap<ItemLocalId, &Body<'_>>,
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
delayed_lints: &[DelayedLint],
define_opaque: Option<&[(Span, LocalDefId)]>,
) -> Hashes {
if !self.needs_crate_hash() {
return Hashes {
opt_hash_including_bodies: None,
attrs_hash: None,
delayed_lints_hash: None,
};
return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
}

self.with_stable_hashing_context(|mut hcx| {
Expand All @@ -281,16 +275,7 @@ impl<'tcx> TyCtxt<'tcx> {

let h2 = stable_hasher.finish();

// hash lints emitted during ast lowering
let mut stable_hasher = StableHasher::new();
delayed_lints.hash_stable(&mut hcx, &mut stable_hasher);
let h3 = stable_hasher.finish();

Hashes {
opt_hash_including_bodies: Some(h1),
attrs_hash: Some(h2),
delayed_lints_hash: Some(h3),
}
Hashes { opt_hash_including_bodies: Some(h1), attrs_hash: Some(h2) }
})
}

Expand Down Expand Up @@ -484,7 +469,6 @@ impl<'tcx> TyCtxt<'tcx> {
pub struct Hashes {
pub opt_hash_including_bodies: Option<Fingerprint>,
pub attrs_hash: Option<Fingerprint>,
pub delayed_lints_hash: Option<Fingerprint>,
}

pub fn provide(providers: &mut Providers) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ rustc_queries! {
/// Avoid calling this query directly.
query opt_ast_lowering_delayed_lints(key: hir::OwnerId) -> Option<&'tcx hir::lints::DelayedLints> {
desc { "getting AST lowering delayed lints in `{}`", tcx.def_path_str(key) }
no_hash
Copy link
Copy Markdown
Contributor Author

@JonathanBrouwer JonathanBrouwer Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since the review

By marking the query as no_hash it will always be recomputed, but it is very cheap to rerun, in fact according to my local benchmarks rerunning is cheaper than hashing :3

}

/// Returns the *default* of the const pararameter given by `DefId`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
let attrs = hir::AttributeMap::EMPTY;

let rustc_middle::hir::Hashes { opt_hash_including_bodies, .. } =
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, &[], attrs.define_opaque);
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
let node = node.into();
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
opt_hash_including_bodies,
Expand Down
Loading