Skip to content

Commit ef09956

Browse files
committed
Remove OneThread
1 parent 6710e33 commit ef09956

File tree

3 files changed

+7
-64
lines changed

3 files changed

+7
-64
lines changed

compiler/rustc_data_structures/src/marker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ cfg_if!(
171171
[Vec<T, A> where T: DynSync, A: std::alloc::Allocator + DynSync]
172172
[Box<T, A> where T: ?Sized + DynSync, A: std::alloc::Allocator + DynSync]
173173
[crate::sync::RwLock<T> where T: DynSend + DynSync]
174-
[crate::sync::OneThread<T> where T]
175174
[crate::sync::WorkerLocal<T> where T: DynSend]
176175
[crate::intern::Interned<'a, T> where 'a, T: DynSync]
177176
[crate::tagged_ptr::CopyTaggedPtr<P, T, CP> where P: Sync + crate::tagged_ptr::Pointer, T: Sync + crate::tagged_ptr::Tag, const CP: bool]

compiler/rustc_data_structures/src/sync.rs

-56
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
pub use crate::marker::*;
4444
use std::collections::HashMap;
4545
use std::hash::{BuildHasher, Hash};
46-
use std::ops::{Deref, DerefMut};
4746

4847
mod lock;
4948
pub use lock::{Lock, LockGuard, Mode};
@@ -303,8 +302,6 @@ cfg_if! {
303302

304303
use parking_lot::RwLock as InnerRwLock;
305304

306-
use std::thread;
307-
308305
/// This makes locks panic if they are already held.
309306
/// It is only useful when you are running in a single thread
310307
const ERROR_CHECKING: bool = false;
@@ -439,56 +436,3 @@ impl<T: Clone> Clone for RwLock<T> {
439436
RwLock::new(self.borrow().clone())
440437
}
441438
}
442-
443-
/// A type which only allows its inner value to be used in one thread.
444-
/// It will panic if it is used on multiple threads.
445-
#[derive(Debug)]
446-
pub struct OneThread<T> {
447-
#[cfg(parallel_compiler)]
448-
thread: thread::ThreadId,
449-
inner: T,
450-
}
451-
452-
#[cfg(parallel_compiler)]
453-
unsafe impl<T> std::marker::Sync for OneThread<T> {}
454-
#[cfg(parallel_compiler)]
455-
unsafe impl<T> std::marker::Send for OneThread<T> {}
456-
457-
impl<T> OneThread<T> {
458-
#[inline(always)]
459-
fn check(&self) {
460-
#[cfg(parallel_compiler)]
461-
assert_eq!(thread::current().id(), self.thread);
462-
}
463-
464-
#[inline(always)]
465-
pub fn new(inner: T) -> Self {
466-
OneThread {
467-
#[cfg(parallel_compiler)]
468-
thread: thread::current().id(),
469-
inner,
470-
}
471-
}
472-
473-
#[inline(always)]
474-
pub fn into_inner(value: Self) -> T {
475-
value.check();
476-
value.inner
477-
}
478-
}
479-
480-
impl<T> Deref for OneThread<T> {
481-
type Target = T;
482-
483-
fn deref(&self) -> &T {
484-
self.check();
485-
&self.inner
486-
}
487-
}
488-
489-
impl<T> DerefMut for OneThread<T> {
490-
fn deref_mut(&mut self) -> &mut T {
491-
self.check();
492-
&mut self.inner
493-
}
494-
}

compiler/rustc_session/src/session.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1717
use rustc_data_structures::jobserver::{self, Client};
1818
use rustc_data_structures::profiling::{duration_to_secs_str, SelfProfiler, SelfProfilerRef};
1919
use rustc_data_structures::sync::{
20-
AtomicU64, AtomicUsize, Lock, Lrc, OneThread, Ordering, Ordering::SeqCst,
20+
AtomicU64, AtomicUsize, Lock, Lrc, MappedReadGuard, Ordering, Ordering::SeqCst, ReadGuard,
21+
RwLock,
2122
};
2223
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
2324
use rustc_errors::emitter::{DynEmitter, EmitterWriter, HumanReadableErrorType};
@@ -39,7 +40,6 @@ use rustc_target::spec::{
3940
DebuginfoKind, SanitizerSet, SplitDebuginfo, StackProtector, Target, TargetTriple, TlsModel,
4041
};
4142

42-
use std::cell::{self, RefCell};
4343
use std::env;
4444
use std::fmt;
4545
use std::ops::{Div, Mul};
@@ -152,7 +152,7 @@ pub struct Session {
152152
/// Input, input file path and output file path to this compilation process.
153153
pub io: CompilerIO,
154154

155-
incr_comp_session: OneThread<RefCell<IncrCompSession>>,
155+
incr_comp_session: RwLock<IncrCompSession>,
156156
/// Used for incremental compilation tests. Will only be populated if
157157
/// `-Zquery-dep-graph` is specified.
158158
pub cgu_reuse_tracker: CguReuseTracker,
@@ -853,9 +853,9 @@ impl Session {
853853
*incr_comp_session = IncrCompSession::InvalidBecauseOfErrors { session_directory };
854854
}
855855

856-
pub fn incr_comp_session_dir(&self) -> cell::Ref<'_, PathBuf> {
856+
pub fn incr_comp_session_dir(&self) -> MappedReadGuard<'_, PathBuf> {
857857
let incr_comp_session = self.incr_comp_session.borrow();
858-
cell::Ref::map(incr_comp_session, |incr_comp_session| match *incr_comp_session {
858+
ReadGuard::map(incr_comp_session, |incr_comp_session| match *incr_comp_session {
859859
IncrCompSession::NotInitialized => panic!(
860860
"trying to get session directory from `IncrCompSession`: {:?}",
861861
*incr_comp_session,
@@ -868,7 +868,7 @@ impl Session {
868868
})
869869
}
870870

871-
pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> {
871+
pub fn incr_comp_session_dir_opt(&self) -> Option<MappedReadGuard<'_, PathBuf>> {
872872
self.opts.incremental.as_ref().map(|_| self.incr_comp_session_dir())
873873
}
874874

@@ -1460,7 +1460,7 @@ pub fn build_session(
14601460
parse_sess,
14611461
sysroot,
14621462
io,
1463-
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
1463+
incr_comp_session: RwLock::new(IncrCompSession::NotInitialized),
14641464
cgu_reuse_tracker,
14651465
prof,
14661466
perf_stats: PerfStats {

0 commit comments

Comments
 (0)