Skip to content

Commit df4ffb9

Browse files
committed
Pre-hash visibilities in resolver.
1 parent 6d091b2 commit df4ffb9

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
@@ -27,6 +27,7 @@ pub use intrinsic::IntrinsicDef;
2727
use rustc_abi::{Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, VariantIdx};
2828
use rustc_ast::node_id::NodeMap;
2929
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
30+
use rustc_data_structures::fingerprint::Fingerprint;
3031
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3132
use rustc_data_structures::intern::Interned;
3233
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -170,7 +171,7 @@ mod visit;
170171

171172
#[derive(Debug, HashStable)]
172173
pub struct ResolverGlobalCtxt {
173-
pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
174+
pub visibilities_hash: Fingerprint,
174175
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
175176
pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
176177
pub effective_visibilities: EffectiveVisibilities,

compiler/rustc_resolve/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use rustc_ast::{
4343
};
4444
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
4545
use rustc_data_structures::intern::Interned;
46+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4647
use rustc_data_structures::steal::Steal;
4748
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
4849
use rustc_data_structures::unord::{UnordMap, UnordSet};
@@ -1701,6 +1702,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17011702
}
17021703

17031704
pub fn into_outputs(self) -> ResolverOutputs {
1705+
let visibilities_hash = {
1706+
let mut hasher = StableHasher::new();
1707+
let mut hcx = self.create_stable_hashing_context();
1708+
self.visibilities_for_hashing.hash_stable(&mut hcx, &mut hasher);
1709+
hasher.finish()
1710+
};
1711+
17041712
let proc_macros = self.proc_macros;
17051713
let expn_that_defined = self.expn_that_defined;
17061714
let extern_crate_map = self.extern_crate_map;
@@ -1722,7 +1730,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17221730

17231731
let global_ctxt = ResolverGlobalCtxt {
17241732
expn_that_defined,
1725-
visibilities_for_hashing: self.visibilities_for_hashing,
1733+
visibilities_hash,
17261734
effective_visibilities,
17271735
extern_crate_map,
17281736
module_children: self.module_children,

0 commit comments

Comments
 (0)