Skip to content

Commit 79cc509

Browse files
committed
Use RwLock instead of Lock for SourceMap::files
1 parent 2661a4e commit 79cc509

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

compiler/rustc_data_structures/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl<T: Clone> Clone for Lock<T> {
512512
}
513513
}
514514

515-
#[derive(Debug)]
515+
#[derive(Debug, Default)]
516516
pub struct RwLock<T>(InnerRwLock<T>);
517517

518518
impl<T> RwLock<T> {

compiler/rustc_span/src/source_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use crate::*;
1212

1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::stable_hasher::StableHasher;
15-
use rustc_data_structures::sync::{AtomicU32, Lock, LockGuard, Lrc, MappedLockGuard};
15+
use rustc_data_structures::sync::{AtomicU32, Lrc, MappedReadGuard, ReadGuard, RwLock};
1616
use std::cmp;
1717
use std::convert::TryFrom;
1818
use std::hash::Hash;
@@ -168,7 +168,7 @@ pub struct SourceMap {
168168
/// The address space below this value is currently used by the files in the source map.
169169
used_address_space: AtomicU32,
170170

171-
files: Lock<SourceMapFiles>,
171+
files: RwLock<SourceMapFiles>,
172172
file_loader: Box<dyn FileLoader + Sync + Send>,
173173
// This is used to apply the file path remapping as specified via
174174
// `--remap-path-prefix` to all `SourceFile`s allocated within this `SourceMap`.
@@ -236,8 +236,8 @@ impl SourceMap {
236236

237237
// By returning a `MonotonicVec`, we ensure that consumers cannot invalidate
238238
// any existing indices pointing into `files`.
239-
pub fn files(&self) -> MappedLockGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
240-
LockGuard::map(self.files.borrow(), |files| &mut files.source_files)
239+
pub fn files(&self) -> MappedReadGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
240+
ReadGuard::map(self.files.borrow(), |files| &files.source_files)
241241
}
242242

243243
pub fn source_file_by_stable_id(

0 commit comments

Comments
 (0)