Skip to content

Commit f49382c

Browse files
committed
Use Freeze for SourceFile.lines
1 parent c5996b8 commit f49382c

File tree

11 files changed

+203
-183
lines changed

11 files changed

+203
-183
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl DebugContext {
8181

8282
match tcx.sess.source_map().lookup_line(span.lo()) {
8383
Ok(SourceFileAndLine { sf: file, line }) => {
84-
let line_pos = file.lines(|lines| lines[line]);
84+
let line_pos = file.lines()[line];
8585
let col = file.relative_position(span.lo()) - line_pos;
8686

8787
(file, u64::try_from(line).unwrap() + 1, u64::from(col.to_u32()) + 1)

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl CodegenCx<'_, '_> {
263263
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
264264
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
265265
Ok(SourceFileAndLine { sf: file, line }) => {
266-
let line_pos = file.lines(|lines| lines[line]);
266+
let line_pos = file.lines()[line];
267267

268268
// Use 1-based indexing.
269269
let line = (line + 1) as u32;

compiler/rustc_data_structures/src/sync/freeze.rs

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::sync::{AtomicBool, ReadGuard, RwLock, WriteGuard};
33
use crate::sync::{DynSend, DynSync};
44
use std::{
55
cell::UnsafeCell,
6+
intrinsics::likely,
67
marker::PhantomData,
78
ops::{Deref, DerefMut},
89
sync::atomic::Ordering,
@@ -49,6 +50,17 @@ impl<T> FreezeLock<T> {
4950
self.frozen.load(Ordering::Acquire)
5051
}
5152

53+
/// Get the inner value if frozen.
54+
#[inline]
55+
pub fn get(&self) -> Option<&T> {
56+
if likely(self.frozen.load(Ordering::Acquire)) {
57+
// SAFETY: This is frozen so the data cannot be modified.
58+
unsafe { Some(&*self.data.get()) }
59+
} else {
60+
None
61+
}
62+
}
63+
5264
#[inline]
5365
pub fn read(&self) -> FreezeReadGuard<'_, T> {
5466
FreezeReadGuard {

compiler/rustc_middle/src/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Span {
692692
let len = BytePos::decode(decoder);
693693

694694
let file_lo = decoder.file_index_to_file(file_lo_index);
695-
let lo = file_lo.lines(|lines| lines[line_lo - 1] + col_lo);
695+
let lo = file_lo.lines()[line_lo - 1] + col_lo;
696696
let lo = file_lo.absolute_position(lo);
697697
let hi = lo + len;
698698

compiler/rustc_query_system/src/ich/impls_syntax.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7979

8080
src_hash.hash_stable(hcx, hasher);
8181

82-
// We are always in `Lines` form by the time we reach here.
83-
assert!(self.lines.borrow().is_lines());
84-
self.lines(|lines| {
82+
{
83+
// We are always in `Lines` form by the time we reach here.
84+
assert!(self.lines.read().is_lines());
85+
let lines = self.lines();
8586
// We only hash the relative position within this source_file
8687
lines.len().hash_stable(hcx, hasher);
8788
for &line in lines.iter() {
8889
line.hash_stable(hcx, hasher);
8990
}
90-
});
91+
}
9192

9293
// We only hash the relative position within this source_file
9394
multibyte_chars.len().hash_stable(hcx, hasher);

0 commit comments

Comments
 (0)