Skip to content

Commit 2a49c4c

Browse files
committed
Pre-hash visibilities in resolver.
1 parent 8f08b3a commit 2a49c4c

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

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustc_abi::{Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, V
2828
use rustc_ast::node_id::NodeMap;
2929
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
3030
use rustc_attr_data_structures::{AttributeKind, StrippedCfgItem, find_attr};
31+
use rustc_data_structures::fingerprint::Fingerprint;
3132
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3233
use rustc_data_structures::intern::Interned;
3334
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -177,7 +178,7 @@ pub struct ResolverOutputs {
177178

178179
#[derive(Debug, HashStable)]
179180
pub struct ResolverGlobalCtxt {
180-
pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
181+
pub visibilities_hash: Fingerprint,
181182
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
182183
pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
183184
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
use rustc_attr_data_structures::StrippedCfgItem;
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};
@@ -1679,6 +1680,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16791680
}
16801681

16811682
pub fn into_outputs(self) -> ResolverOutputs {
1683+
let visibilities_hash = {
1684+
let mut hasher = StableHasher::new();
1685+
let mut hcx = self.create_stable_hashing_context();
1686+
self.visibilities_for_hashing.hash_stable(&mut hcx, &mut hasher);
1687+
hasher.finish()
1688+
};
1689+
16821690
let proc_macros = self.proc_macros;
16831691
let expn_that_defined = self.expn_that_defined;
16841692
let extern_crate_map = self.extern_crate_map;
@@ -1700,7 +1708,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17001708

17011709
let global_ctxt = ResolverGlobalCtxt {
17021710
expn_that_defined,
1703-
visibilities_for_hashing: self.visibilities_for_hashing,
1711+
visibilities_hash,
17041712
effective_visibilities,
17051713
extern_crate_map,
17061714
module_children: self.module_children,

0 commit comments

Comments
 (0)