Skip to content

Commit 0cbc076

Browse files
committed
Auto merge of rust-lang#142388 - cjgillot:span-hash, r=davidtwco
Do not clone Arc when hashing span. Tiny improvement I was when trying to profile span hashing.
2 parents 32b5152 + a5ff3cc commit 0cbc076

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

compiler/rustc_query_system/src/ich/hcx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use std::sync::Arc;
2-
31
use rustc_ast as ast;
42
use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher};
53
use rustc_hir::def_id::{DefId, LocalDefId};
64
use rustc_hir::definitions::DefPathHash;
75
use rustc_session::Session;
86
use rustc_session::cstore::Untracked;
97
use rustc_span::source_map::SourceMap;
10-
use rustc_span::{BytePos, CachingSourceMapView, DUMMY_SP, SourceFile, Span, SpanData, Symbol};
8+
use rustc_span::{
9+
BytePos, CachingSourceMapView, DUMMY_SP, Span, SpanData, StableSourceFileId, Symbol,
10+
};
1111

1212
use crate::ich;
1313

@@ -118,7 +118,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
118118
fn span_data_to_lines_and_cols(
119119
&mut self,
120120
span: &SpanData,
121-
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)> {
121+
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)> {
122122
self.source_map().span_data_to_lines_and_cols(span)
123123
}
124124

compiler/rustc_span/src/caching_source_map_view.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::Range;
22
use std::sync::Arc;
33

44
use crate::source_map::SourceMap;
5-
use crate::{BytePos, Pos, RelativeBytePos, SourceFile, SpanData};
5+
use crate::{BytePos, Pos, RelativeBytePos, SourceFile, SpanData, StableSourceFileId};
66

77
#[derive(Clone)]
88
struct CacheEntry {
@@ -114,7 +114,7 @@ impl<'sm> CachingSourceMapView<'sm> {
114114
pub fn span_data_to_lines_and_cols(
115115
&mut self,
116116
span_data: &SpanData,
117-
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)> {
117+
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)> {
118118
self.time_stamp += 1;
119119

120120
// Check if lo and hi are in the cached lines.
@@ -132,7 +132,7 @@ impl<'sm> CachingSourceMapView<'sm> {
132132
}
133133

134134
(
135-
Arc::clone(&lo.file),
135+
lo.file.stable_id,
136136
lo.line_number,
137137
span_data.lo - lo.line.start,
138138
hi.line_number,
@@ -226,7 +226,7 @@ impl<'sm> CachingSourceMapView<'sm> {
226226
assert_eq!(lo.file_index, hi.file_index);
227227

228228
Some((
229-
Arc::clone(&lo.file),
229+
lo.file.stable_id,
230230
lo.line_number,
231231
span_data.lo - lo.line.start,
232232
hi.line_number,

compiler/rustc_span/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ pub trait HashStableContext {
26002600
fn span_data_to_lines_and_cols(
26012601
&mut self,
26022602
span: &SpanData,
2603-
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)>;
2603+
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)>;
26042604
fn hashing_controls(&self) -> HashingControls;
26052605
}
26062606

@@ -2657,7 +2657,7 @@ where
26572657
};
26582658

26592659
Hash::hash(&TAG_VALID_SPAN, hasher);
2660-
Hash::hash(&file.stable_id, hasher);
2660+
Hash::hash(&file, hasher);
26612661

26622662
// Hash both the length and the end location (line/column) of a span. If we
26632663
// hash only the length, for example, then two otherwise equal spans with

0 commit comments

Comments
 (0)