@@ -22,21 +22,25 @@ enum CachingSourceMap<'a> {
2222/// things (e.g., each `DefId`/`DefPath` is only hashed once).
2323pub struct StableHashState < ' a > {
2424 untracked : & ' a Untracked ,
25- // The value of `-Z incremental-ignore-spans`.
26- // This field should only be used by `unstable_opts_incremental_ignore_span`
27- incremental_ignore_spans : bool ,
25+ // The session-wide default for `hash_spans`, computed in `Self::new`. Only
26+ // used by `assert_default_stable_hash_controls`.
27+ default_hash_spans : bool ,
2828 caching_source_map : CachingSourceMap < ' a > ,
2929 stable_hash_controls : StableHashControls ,
3030}
3131
3232impl < ' a > StableHashState < ' a > {
3333 #[ inline]
3434 pub fn new ( sess : & ' a Session , untracked : & ' a Untracked ) -> Self {
35- let hash_spans_initial = !sess. opts . unstable_opts . incremental_ignore_spans ;
35+ // Only hash spans for incremental and coverage, where hashes must react to
36+ // code moving around; otherwise skip them and their source map lookups.
37+ // Spans are also skipped if `-Z incremental-ignore-spans` is set.
38+ let hash_spans_initial = ( sess. opts . incremental . is_some ( ) || sess. instrument_coverage ( ) )
39+ && !sess. opts . unstable_opts . incremental_ignore_spans ;
3640
3741 StableHashState {
3842 untracked,
39- incremental_ignore_spans : sess . opts . unstable_opts . incremental_ignore_spans ,
43+ default_hash_spans : hash_spans_initial ,
4044 caching_source_map : CachingSourceMap :: Unused ( sess. source_map ( ) ) ,
4145 stable_hash_controls : StableHashControls { hash_spans : hash_spans_initial } ,
4246 }
@@ -178,15 +182,15 @@ impl<'a> StableHashCtxt for StableHashState<'a> {
178182 let stable_hash_controls = self . stable_hash_controls ;
179183 let StableHashControls { hash_spans } = stable_hash_controls;
180184
181- // Note that we require that `hash_spans` be the inverse of the global `-Z
182- // incremental-ignore-spans` option. Normally, this option is disabled, in which case
183- // `hash_spans` must be true .
185+ // Note that we require that `hash_spans` matches the session-wide default computed in
186+ // `StableHashState::new` from the compilation mode and the global `-Z
187+ // incremental-ignore-spans` option .
184188 //
185189 // Span hashing can also be disabled without `-Z incremental-ignore-spans`. This is the
186190 // case for instance when building a hash for name mangling. Such configuration must not be
187191 // used for metadata.
188192 assert_eq ! (
189- hash_spans, ! self . incremental_ignore_spans ,
193+ hash_spans, self . default_hash_spans ,
190194 "Attempted hashing of {msg} with non-default StableHashControls: {stable_hash_controls:?}"
191195 ) ;
192196 }
0 commit comments