Skip to content

Commit 7815482

Browse files
committed
Remove OneThread
1 parent 57fec79 commit 7815482

File tree

3 files changed

+6
-64
lines changed

3 files changed

+6
-64
lines changed

compiler/rustc_data_structures/src/marker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ cfg_match! {
177177
[Vec<T, A> where T: DynSync, A: std::alloc::Allocator + DynSync]
178178
[Box<T, A> where T: ?Sized + DynSync, A: std::alloc::Allocator + DynSync]
179179
[crate::sync::RwLock<T> where T: DynSend + DynSync]
180-
[crate::sync::OneThread<T> where T]
181180
[crate::sync::WorkerLocal<T> where T: DynSend]
182181
[crate::intern::Interned<'a, T> where 'a, T: DynSync]
183182
[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};
@@ -312,8 +311,6 @@ cfg_match! {
312311

313312
use parking_lot::RwLock as InnerRwLock;
314313

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

compiler/rustc_session/src/session.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1515
use rustc_data_structures::jobserver::{self, Client};
1616
use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
1717
use rustc_data_structures::sync::{
18-
AtomicU64, DynSend, DynSync, Lock, Lrc, OneThread, Ordering::SeqCst,
18+
AtomicU64, DynSend, DynSync, Lock, Lrc, MappedReadGuard, Ordering::SeqCst, ReadGuard, RwLock,
1919
};
2020
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
2121
use rustc_errors::emitter::{DynEmitter, EmitterWriter, HumanReadableErrorType};
@@ -38,7 +38,6 @@ use rustc_target::spec::{
3838
};
3939

4040
use std::any::Any;
41-
use std::cell::{self, RefCell};
4241
use std::env;
4342
use std::fmt;
4443
use std::ops::{Div, Mul};
@@ -152,7 +151,7 @@ pub struct Session {
152151
/// Input, input file path and output file path to this compilation process.
153152
pub io: CompilerIO,
154153

155-
incr_comp_session: OneThread<RefCell<IncrCompSession>>,
154+
incr_comp_session: RwLock<IncrCompSession>,
156155

157156
/// Used by `-Z self-profile`.
158157
pub prof: SelfProfilerRef,
@@ -848,9 +847,9 @@ impl Session {
848847
*incr_comp_session = IncrCompSession::InvalidBecauseOfErrors { session_directory };
849848
}
850849

851-
pub fn incr_comp_session_dir(&self) -> cell::Ref<'_, PathBuf> {
850+
pub fn incr_comp_session_dir(&self) -> MappedReadGuard<'_, PathBuf> {
852851
let incr_comp_session = self.incr_comp_session.borrow();
853-
cell::Ref::map(incr_comp_session, |incr_comp_session| match *incr_comp_session {
852+
ReadGuard::map(incr_comp_session, |incr_comp_session| match *incr_comp_session {
854853
IncrCompSession::NotInitialized => panic!(
855854
"trying to get session directory from `IncrCompSession`: {:?}",
856855
*incr_comp_session,
@@ -863,7 +862,7 @@ impl Session {
863862
})
864863
}
865864

866-
pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> {
865+
pub fn incr_comp_session_dir_opt(&self) -> Option<MappedReadGuard<'_, PathBuf>> {
867866
self.opts.incremental.as_ref().map(|_| self.incr_comp_session_dir())
868867
}
869868

@@ -1494,7 +1493,7 @@ pub fn build_session(
14941493
parse_sess,
14951494
sysroot,
14961495
io,
1497-
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
1496+
incr_comp_session: RwLock::new(IncrCompSession::NotInitialized),
14981497
prof,
14991498
code_stats: Default::default(),
15001499
optimization_fuel,

0 commit comments

Comments
 (0)