Skip to content

Do not clone Arc when hashing span. #142388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions compiler/rustc_query_system/src/ich/hcx.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::sync::Arc;

use rustc_ast as ast;
use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::definitions::DefPathHash;
use rustc_session::Session;
use rustc_session::cstore::Untracked;
use rustc_span::source_map::SourceMap;
use rustc_span::{BytePos, CachingSourceMapView, DUMMY_SP, SourceFile, Span, SpanData, Symbol};
use rustc_span::{
BytePos, CachingSourceMapView, DUMMY_SP, Span, SpanData, StableSourceFileId, Symbol,
};

use crate::ich;

Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
fn span_data_to_lines_and_cols(
&mut self,
span: &SpanData,
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)> {
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)> {
self.source_map().span_data_to_lines_and_cols(span)
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_span/src/caching_source_map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::Range;
use std::sync::Arc;

use crate::source_map::SourceMap;
use crate::{BytePos, Pos, RelativeBytePos, SourceFile, SpanData};
use crate::{BytePos, Pos, RelativeBytePos, SourceFile, SpanData, StableSourceFileId};

#[derive(Clone)]
struct CacheEntry {
Expand Down Expand Up @@ -114,7 +114,7 @@ impl<'sm> CachingSourceMapView<'sm> {
pub fn span_data_to_lines_and_cols(
&mut self,
span_data: &SpanData,
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)> {
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)> {
self.time_stamp += 1;

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

(
Arc::clone(&lo.file),
lo.file.stable_id,
lo.line_number,
span_data.lo - lo.line.start,
hi.line_number,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<'sm> CachingSourceMapView<'sm> {
assert_eq!(lo.file_index, hi.file_index);

Some((
Arc::clone(&lo.file),
lo.file.stable_id,
lo.line_number,
span_data.lo - lo.line.start,
hi.line_number,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@ pub trait HashStableContext {
fn span_data_to_lines_and_cols(
&mut self,
span: &SpanData,
) -> Option<(Arc<SourceFile>, usize, BytePos, usize, BytePos)>;
) -> Option<(StableSourceFileId, usize, BytePos, usize, BytePos)>;
fn hashing_controls(&self) -> HashingControls;
}

Expand Down Expand Up @@ -2657,7 +2657,7 @@ where
};

Hash::hash(&TAG_VALID_SPAN, hasher);
Hash::hash(&file.stable_id, hasher);
Hash::hash(&file, 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
Expand Down
Loading