Skip to content

Commit aaaefd1

Browse files
committed
Pre-hash visibilities in resolver.
1 parent 9490320 commit aaaefd1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

compiler/rustc_middle/src/hir/map.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,11 +1177,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
11771177
}
11781178
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);
11791179
tcx.stable_crate_id(LOCAL_CRATE).hash_stable(&mut hcx, &mut stable_hasher);
1180-
// Hash visibility information since it does not appear in HIR.
1181-
// FIXME: Figure out how to remove `visibilities_for_hashing` by hashing visibilities on
1182-
// the fly in the resolver, storing only their accumulated hash in `ResolverGlobalCtxt`,
1183-
// and combining it with other hashes here.
1184-
resolutions.visibilities_for_hashing.hash_stable(&mut hcx, &mut stable_hasher);
1180+
resolutions.visibilities_hash.hash_stable(&mut hcx, &mut stable_hasher);
11851181
with_metavar_spans(|mspans| {
11861182
mspans.freeze_and_get_read_spans().hash_stable(&mut hcx, &mut stable_hasher);
11871183
});

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_ast::expand::StrippedCfgItem;
2929
use rustc_ast::node_id::NodeMap;
3030
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
3131
use rustc_attr_data_structures::AttributeKind;
32+
use rustc_data_structures::fingerprint::Fingerprint;
3233
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3334
use rustc_data_structures::intern::Interned;
3435
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -178,7 +179,7 @@ pub struct ResolverOutputs {
178179

179180
#[derive(Debug, HashStable)]
180181
pub struct ResolverGlobalCtxt {
181-
pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
182+
pub visibilities_hash: Fingerprint,
182183
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
183184
pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
184185
pub effective_visibilities: EffectiveVisibilities,

compiler/rustc_resolve/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,9 +1663,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16631663
})
16641664
.collect();
16651665

1666+
let visibilities_hash = {
1667+
let mut hasher = StableHasher::new();
1668+
let mut hcx = self.create_stable_hashing_context();
1669+
self.visibilities_for_hashing.hash_stable(&mut hcx, &mut hasher);
1670+
hasher.finish()
1671+
};
1672+
16661673
let global_ctxt = ResolverGlobalCtxt {
16671674
expn_that_defined,
1668-
visibilities_for_hashing: self.visibilities_for_hashing,
1675+
visibilities_hash,
16691676
effective_visibilities,
16701677
extern_crate_map,
16711678
module_children: self.module_children,

0 commit comments

Comments
 (0)