Skip to content

Commit 673ed4b

Browse files
committed
merge stable_hash_span and stable_hash_span_data
1 parent 7b58439 commit 673ed4b

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

  • compiler/rustc_middle/src

compiler/rustc_middle/src/ich.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
77
use rustc_session::Session;
88
use rustc_session::cstore::Untracked;
99
use rustc_span::source_map::SourceMap;
10-
use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span, SpanData};
10+
use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span};
1111

1212
// Very often, we are hashing something that does not need the `CachingSourceMapView`, so we
1313
// initialize it lazily.
@@ -78,9 +78,28 @@ impl<'a> StableHashState<'a> {
7878
pub fn stable_hash_controls(&self) -> StableHashControls {
7979
self.stable_hash_controls
8080
}
81+
}
8182

82-
#[inline(always)]
83-
fn stable_hash_span_data(&mut self, mut span: SpanData, hasher: &mut StableHasher) {
83+
impl<'a> StableHashCtxt for StableHashState<'a> {
84+
/// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that
85+
/// would be similar to hashing pointers, since those are just offsets into the `SourceMap`).
86+
/// Instead, we hash the (file name, line, column) triple, which stays the same even if the
87+
/// containing `SourceFile` has moved within the `SourceMap`.
88+
///
89+
/// Also note that we are hashing byte offsets for the column, not unicode codepoint offsets.
90+
/// For the purpose of the hash that's sufficient. Also, hashing filenames is expensive so we
91+
/// avoid doing it twice when the span starts and ends in the same file, which is almost always
92+
/// the case.
93+
///
94+
/// IMPORTANT: changes to this method should be reflected in implementations of `SpanEncoder`.
95+
#[inline]
96+
fn stable_hash_span(&mut self, raw_span: RawSpan, hasher: &mut StableHasher) {
97+
if !self.stable_hash_controls().hash_spans {
98+
return;
99+
}
100+
101+
let span = Span::from_raw_span(raw_span);
102+
let mut span = span.data_untracked();
84103
const TAG_VALID_SPAN: u8 = 0;
85104
const TAG_INVALID_SPAN: u8 = 1;
86105
const TAG_RELATIVE_SPAN: u8 = 2;
@@ -151,30 +170,6 @@ impl<'a> StableHashState<'a> {
151170
Hash::hash(&col_line, hasher);
152171
Hash::hash(&len, hasher);
153172
}
154-
}
155-
156-
impl<'a> StableHashCtxt for StableHashState<'a> {
157-
/// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that
158-
/// would be similar to hashing pointers, since those are just offsets into the `SourceMap`).
159-
/// Instead, we hash the (file name, line, column) triple, which stays the same even if the
160-
/// containing `SourceFile` has moved within the `SourceMap`.
161-
///
162-
/// Also note that we are hashing byte offsets for the column, not unicode codepoint offsets.
163-
/// For the purpose of the hash that's sufficient. Also, hashing filenames is expensive so we
164-
/// avoid doing it twice when the span starts and ends in the same file, which is almost always
165-
/// the case.
166-
///
167-
/// IMPORTANT: changes to this method should be reflected in implementations of `SpanEncoder`.
168-
#[inline]
169-
fn stable_hash_span(&mut self, raw_span: RawSpan, hasher: &mut StableHasher) {
170-
if !self.stable_hash_controls().hash_spans {
171-
return;
172-
}
173-
174-
let span = Span::from_raw_span(raw_span);
175-
let span = span.data_untracked();
176-
self.stable_hash_span_data(span, hasher);
177-
}
178173

179174
#[inline]
180175
fn def_path_hash(&self, raw_def_id: RawDefId) -> RawDefPathHash {

0 commit comments

Comments
 (0)