Skip to content

Commit 11751ce

Browse files
committed
Pre-hash visibilities in resolver.
1 parent 556d20a commit 11751ce

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rustc_ast::{
4444
};
4545
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
4646
use rustc_data_structures::intern::Interned;
47+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4748
use rustc_data_structures::steal::Steal;
4849
use rustc_data_structures::sync::FreezeReadGuard;
4950
use rustc_data_structures::unord::{UnordMap, UnordSet};
@@ -1644,6 +1645,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16441645
}
16451646

16461647
pub fn into_outputs(self) -> ResolverOutputs {
1648+
let visibilities_hash = {
1649+
let mut hasher = StableHasher::new();
1650+
let mut hcx = self.create_stable_hashing_context();
1651+
self.visibilities_for_hashing.hash_stable(&mut hcx, &mut hasher);
1652+
hasher.finish()
1653+
};
1654+
16471655
let proc_macros = self.proc_macros;
16481656
let expn_that_defined = self.expn_that_defined;
16491657
let extern_crate_map = self.extern_crate_map;
@@ -1665,7 +1673,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16651673

16661674
let global_ctxt = ResolverGlobalCtxt {
16671675
expn_that_defined,
1668-
visibilities_for_hashing: self.visibilities_for_hashing,
1676+
visibilities_hash,
16691677
effective_visibilities,
16701678
extern_crate_map,
16711679
module_children: self.module_children,

0 commit comments

Comments
 (0)