@@ -20,7 +20,7 @@ enum CachingSourceMap<'a> {
2020/// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e.,
2121/// a reference to the `TyCtxt`) and it holds a few caches for speeding up various
2222/// things (e.g., each `DefId`/`DefPath` is only hashed once).
23- pub struct StableHashState < ' a > {
23+ pub struct StableHashState < ' a , const HASH_SPANS_AS_PARENTLESS : bool = false > {
2424 untracked : & ' a Untracked ,
2525 // The value of `-Z incremental-ignore-spans`.
2626 // This field should only be used by `unstable_opts_incremental_ignore_span`
@@ -29,7 +29,20 @@ pub struct StableHashState<'a> {
2929 stable_hash_controls : StableHashControls ,
3030}
3131
32- impl < ' a > StableHashState < ' a > {
32+ impl < ' a > StableHashState < ' a , false > {
33+ pub fn hash_spans_as_parentless ( self ) -> StableHashState < ' a , true > {
34+ let Self { untracked, incremental_ignore_spans, caching_source_map, stable_hash_controls } =
35+ self ;
36+ StableHashState {
37+ untracked,
38+ incremental_ignore_spans,
39+ caching_source_map,
40+ stable_hash_controls,
41+ }
42+ }
43+ }
44+
45+ impl < ' a , const HASH_SPANS_AS_PARENTLESS : bool > StableHashState < ' a , HASH_SPANS_AS_PARENTLESS > {
3346 #[ inline]
3447 pub fn new ( sess : & ' a Session , untracked : & ' a Untracked ) -> Self {
3548 let hash_spans_initial = !sess. opts . unstable_opts . incremental_ignore_spans ;
@@ -38,18 +51,10 @@ impl<'a> StableHashState<'a> {
3851 untracked,
3952 incremental_ignore_spans : sess. opts . unstable_opts . incremental_ignore_spans ,
4053 caching_source_map : CachingSourceMap :: Unused ( sess. source_map ( ) ) ,
41- stable_hash_controls : StableHashControls {
42- hash_spans : hash_spans_initial,
43- hash_spans_as_parentless : false ,
44- } ,
54+ stable_hash_controls : StableHashControls { hash_spans : hash_spans_initial } ,
4555 }
4656 }
4757
48- #[ inline]
49- pub fn set_hash_spans_as_parentless ( & mut self , hash_spans_as_parentless : bool ) {
50- self . stable_hash_controls . hash_spans_as_parentless = hash_spans_as_parentless;
51- }
52-
5358 #[ inline]
5459 pub fn while_hashing_spans < F : FnOnce ( & mut Self ) > ( & mut self , hash_spans : bool , f : F ) {
5560 let prev_hash_spans = self . stable_hash_controls . hash_spans ;
@@ -80,7 +85,9 @@ impl<'a> StableHashState<'a> {
8085 }
8186}
8287
83- impl < ' a > StableHashCtxt for StableHashState < ' a > {
88+ impl < ' a , const HASH_SPANS_AS_PARENTLESS : bool > StableHashCtxt
89+ for StableHashState < ' a , HASH_SPANS_AS_PARENTLESS >
90+ {
8491 /// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that
8592 /// would be similar to hashing pointers, since those are just offsets into the `SourceMap`).
8693 /// Instead, we hash the (file name, line, column) triple, which stays the same even if the
@@ -104,7 +111,7 @@ impl<'a> StableHashCtxt for StableHashState<'a> {
104111 const TAG_INVALID_SPAN : u8 = 1 ;
105112 const TAG_RELATIVE_SPAN : u8 = 2 ;
106113
107- if self . stable_hash_controls ( ) . hash_spans_as_parentless {
114+ if HASH_SPANS_AS_PARENTLESS {
108115 span. parent = None
109116 }
110117 span. ctxt . stable_hash ( self , hasher) ;
@@ -189,15 +196,7 @@ impl<'a> StableHashCtxt for StableHashState<'a> {
189196 #[ inline]
190197 fn assert_default_stable_hash_controls ( & self , msg : & str ) {
191198 let stable_hash_controls = self . stable_hash_controls ;
192- let StableHashControls {
193- hash_spans,
194- // This is only used for public api hashing of rmeta.
195- //
196- // The expn hashes are encoded in the rmeta and all spans are encoded without their
197- // parent in rmeta. If it is ok to give the information like this to dependent crates
198- // it should be ok to ignore this setting here.
199- hash_spans_as_parentless : _,
200- } = stable_hash_controls;
199+ let StableHashControls { hash_spans } = stable_hash_controls;
201200
202201 // Note that we require that `hash_spans` be the inverse of the global `-Z
203202 // incremental-ignore-spans` option. Normally, this option is disabled, in which case
0 commit comments