Skip to content

Commit e7a67cc

Browse files
committed
Auto merge of rust-lang#86229 - cjgillot:crate-hash-beta, r=Mark-Simulacrum
Integrate attributes as part of the crate hash Backport of rust-lang#83901 r? `@Mark-Simulacrum`
2 parents 0a0f816 + b561bc5 commit e7a67cc

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

compiler/rustc_middle/src/hir/map/collector.rs

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::arena::Arena;
22
use crate::hir::map::{Entry, HirOwnerData, Map};
3-
use crate::hir::{Owner, OwnerNodes, ParentedNode};
3+
use crate::hir::{AttributeMap, Owner, OwnerNodes, ParentedNode};
44
use crate::ich::StableHashingContext;
55
use crate::middle::cstore::CrateStore;
66
use rustc_data_structures::fingerprint::Fingerprint;
@@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99
use rustc_data_structures::svh::Svh;
1010
use rustc_hir as hir;
1111
use rustc_hir::def_id::CRATE_DEF_INDEX;
12-
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
12+
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
1313
use rustc_hir::definitions::{self, DefPathHash};
1414
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1515
use rustc_hir::*;
@@ -58,18 +58,28 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
5858

5959
fn hash_body(
6060
hcx: &mut StableHashingContext<'_>,
61+
def_id: LocalDefId,
6162
def_path_hash: DefPathHash,
6263
item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
64+
krate: &Crate<'_>,
6365
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
6466
) -> Fingerprint {
65-
let hash = {
67+
// Hash of nodes.
68+
let hash: Fingerprint = {
6669
let mut stable_hasher = StableHasher::new();
6770
hcx.while_hashing_hir_bodies(true, |hcx| {
6871
item_like.hash_stable(hcx, &mut stable_hasher);
6972
});
7073
stable_hasher.finish()
7174
};
72-
hir_body_nodes.push((def_path_hash, hash));
75+
// Hash for crate_hash.
76+
let hash_with_attrs: Fingerprint = {
77+
let mut hasher = StableHasher::new();
78+
hash.hash_stable(hcx, &mut hasher);
79+
AttributeMap { map: &krate.attrs, prefix: def_id }.hash_stable(hcx, &mut hasher);
80+
hasher.finish()
81+
};
82+
hir_body_nodes.push((def_path_hash, hash_with_attrs));
7383
hash
7484
}
7585

@@ -120,7 +130,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
120130
attrs: _,
121131
} = *krate;
122132

123-
hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)
133+
hash_body(
134+
&mut hcx,
135+
CRATE_DEF_ID,
136+
root_mod_def_path_hash,
137+
item,
138+
krate,
139+
&mut hir_body_nodes,
140+
)
124141
};
125142

126143
let mut collector = NodeCollector {
@@ -186,6 +203,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186203
let crate_hash_input = (
187204
((node_hashes, upstream_crates), source_file_names),
188205
(commandline_args_hash, crate_disambiguator.to_fingerprint()),
206+
&self.krate.non_exported_macro_attrs,
189207
);
190208

191209
let mut stable_hasher = StableHasher::new();
@@ -297,7 +315,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
297315

298316
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
299317

300-
let hash = hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes);
318+
let hash = hash_body(
319+
&mut self.hcx,
320+
dep_node_owner,
321+
def_path_hash,
322+
item_like,
323+
self.krate,
324+
&mut self.hir_body_nodes,
325+
);
301326

302327
self.current_dep_node_owner = dep_node_owner;
303328
f(self, hash);

0 commit comments

Comments
 (0)