Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions compiler/rustc_middle/src/ich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_data_structures::stable_hash::{
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_session::Session;
use rustc_span::source_map::SourceMap;
use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span};
use rustc_span::{BytePos, CachingSourceMapView, DUMMY_SP, Pos, Span};

// Very often, we are hashing something that does not need the `CachingSourceMapView`, so we
// initialize it lazily.
Expand Down Expand Up @@ -91,6 +91,20 @@ impl<'a> StableHashCtxt for StableHashState<'a> {
const TAG_INVALID_SPAN: u8 = 1;
const TAG_RELATIVE_SPAN: u8 = 2;

#[inline]
fn pack_span_location(
line_lo: usize,
col_lo: BytePos,
line_hi: usize,
col_hi: BytePos,
) -> u64 {
let col_lo_trunc = (col_lo.0 as u64) & 0xFF;
let line_lo_trunc = ((line_lo as u64) & 0xFF_FF_FF) << 8;
let col_hi_trunc = ((col_hi.0 as u64) & 0xFF) << 32;
let line_hi_trunc = ((line_hi as u64) & 0xFF_FF_FF) << 40;
col_lo_trunc | line_lo_trunc | col_hi_trunc | line_hi_trunc
}

if !self.stable_hash_controls().hash_spans {
return;
}
Expand Down Expand Up @@ -149,11 +163,7 @@ impl<'a> StableHashCtxt for StableHashState<'a> {
// issue #74890). A similar analysis applies if some query depends specifically on the
// length of the span, but we only hash the end location. So hash both.

let col_lo_trunc = (col_lo.0 as u64) & 0xFF;
let line_lo_trunc = ((line_lo as u64) & 0xFF_FF_FF) << 8;
let col_hi_trunc = (col_hi.0 as u64) & 0xFF << 32;
let line_hi_trunc = ((line_hi as u64) & 0xFF_FF_FF) << 40;
let col_line = col_lo_trunc | line_lo_trunc | col_hi_trunc | line_hi_trunc;
let col_line = pack_span_location(line_lo, col_lo, line_hi, col_hi);
let len = (span.hi - span.lo).0;
Hash::hash(&col_line, hasher);
Hash::hash(&len, hasher);
Expand Down
Loading