Auto merge of #79012 - tgnottingham:span_data_to_lines_and_cols, r=estebank
rustc_span: add span_data_to_lines_and_cols to caching source map view
This commit is contained in:
commit
fe531d5a5f
3 changed files with 221 additions and 55 deletions
|
@ -1871,6 +1871,10 @@ pub trait HashStableContext {
|
|||
&mut self,
|
||||
byte: BytePos,
|
||||
) -> Option<(Lrc<SourceFile>, usize, BytePos)>;
|
||||
fn span_data_to_lines_and_cols(
|
||||
&mut self,
|
||||
span: &SpanData,
|
||||
) -> Option<(Lrc<SourceFile>, usize, BytePos, usize, BytePos)>;
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for Span
|
||||
|
@ -1904,22 +1908,8 @@ where
|
|||
// position that belongs to it, as opposed to hashing the first
|
||||
// position past it.
|
||||
let span = self.data();
|
||||
let (file_lo, line_lo, col_lo) = match ctx.byte_pos_to_line_and_col(span.lo) {
|
||||
Some(pos) => pos,
|
||||
None => {
|
||||
Hash::hash(&TAG_INVALID_SPAN, hasher);
|
||||
span.ctxt.hash_stable(ctx, hasher);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if !file_lo.contains(span.hi) {
|
||||
Hash::hash(&TAG_INVALID_SPAN, hasher);
|
||||
span.ctxt.hash_stable(ctx, hasher);
|
||||
return;
|
||||
}
|
||||
|
||||
let (_, line_hi, col_hi) = match ctx.byte_pos_to_line_and_col(span.hi) {
|
||||
let (file, line_lo, col_lo, line_hi, col_hi) = match ctx.span_data_to_lines_and_cols(&span)
|
||||
{
|
||||
Some(pos) => pos,
|
||||
None => {
|
||||
Hash::hash(&TAG_INVALID_SPAN, hasher);
|
||||
|
@ -1931,7 +1921,7 @@ where
|
|||
Hash::hash(&TAG_VALID_SPAN, hasher);
|
||||
// We truncate the stable ID hash and line and column numbers. The chances
|
||||
// of causing a collision this way should be minimal.
|
||||
Hash::hash(&(file_lo.name_hash as u64), hasher);
|
||||
Hash::hash(&(file.name_hash as u64), hasher);
|
||||
|
||||
// Hash both the length and the end location (line/column) of a span. If we
|
||||
// hash only the length, for example, then two otherwise equal spans with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue