Skip to content

Commit 560c90f

Browse files
committed
Adjust assert_default_hashing_controls
1 parent 5580e5e commit 560c90f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

compiler/rustc_query_system/src/ich/hcx.rs

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
2727
pub struct StableHashingContext<'a> {
2828
definitions: &'a Definitions,
2929
cstore: &'a dyn CrateStore,
30+
sess: &'a Session,
3031
pub(super) body_resolver: BodyResolver<'a>,
3132
// Very often, we are hashing something that does not need the
3233
// `CachingSourceMapView`, so we initialize it lazily.
@@ -63,6 +64,7 @@ impl<'a> StableHashingContext<'a> {
6364
body_resolver: BodyResolver::Forbidden,
6465
definitions,
6566
cstore,
67+
sess,
6668
caching_source_map: None,
6769
raw_source_map: sess.source_map(),
6870
hashing_controls: HashingControls {
@@ -197,6 +199,11 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
197199
self.hashing_controls.hash_spans
198200
}
199201

202+
#[inline]
203+
fn debug_opts_incremental_ignore_spans(&self) -> bool {
204+
self.sess.opts.debugging_opts.incremental_ignore_spans
205+
}
206+
200207
#[inline]
201208
fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
202209
self.def_path_hash(def_id)

compiler/rustc_span/src/hygiene.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ rustc_index::newtype_index! {
8989
}
9090
}
9191

92-
// Assert that the provided `HashStableContext` is configured with the 'default'
93-
// `HashingControls`. We should always have bailed out before getting to here
94-
// with a non-default mode. With this check in place, we can avoid the need
95-
// to maintain separate versions of `ExpnData` hashes for each permutation
96-
// of `HashingControls` settings.
92+
/// Assert that the provided `HashStableContext` is configured with the 'default'
93+
/// `HashingControls`. We should always have bailed out before getting to here
94+
/// with a non-default mode. With this check in place, we can avoid the need
95+
/// to maintain separate versions of `ExpnData` hashes for each permutation
96+
/// of `HashingControls` settings.
9797
fn assert_default_hashing_controls<CTX: HashStableContext>(ctx: &CTX, msg: &str) {
9898
match ctx.hashing_controls() {
9999
// Ideally, we would also check that `node_id_hashing_mode` was always
@@ -105,7 +105,13 @@ fn assert_default_hashing_controls<CTX: HashStableContext>(ctx: &CTX, msg: &str)
105105
// FIXME: Enforce that we don't end up transitively hashing any `HirId`s,
106106
// or ensure that this method is always invoked with the same
107107
// `NodeIdHashingMode`
108-
HashingControls { hash_spans: true, node_id_hashing_mode: _ } => {}
108+
//
109+
// Note that we require that `hash_spans` be set according to the global
110+
// `-Z incremental-ignore-spans` option. Normally, this option is disabled,
111+
// which will cause us to require that this method always be called with `Span` hashing
112+
// enabled.
113+
HashingControls { hash_spans, node_id_hashing_mode: _ }
114+
if hash_spans == !ctx.debug_opts_incremental_ignore_spans() => {}
109115
other => panic!("Attempted hashing of {msg} with non-default HashingControls: {:?}", other),
110116
}
111117
}

compiler/rustc_span/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,9 @@ impl InnerSpan {
20582058
pub trait HashStableContext {
20592059
fn def_path_hash(&self, def_id: DefId) -> DefPathHash;
20602060
fn hash_spans(&self) -> bool;
2061+
/// Accesses `sess.opts.debugging_opts.incremental_ignore_spans` since
2062+
/// we don't have easy access to a `Session`
2063+
fn debug_opts_incremental_ignore_spans(&self) -> bool;
20612064
fn def_span(&self, def_id: LocalDefId) -> Span;
20622065
fn span_data_to_lines_and_cols(
20632066
&mut self,

0 commit comments

Comments
 (0)