Skip to content

Commit fe63637

Browse files
committed
Use locks for Session.lint_store and Session.buffered_lints
1 parent 2741690 commit fe63637

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/librustc/lint/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use self::TargetLint::*;
2828

2929
use std::slice;
30+
use rustc_data_structures::sync::{RwLock, ReadGuard};
3031
use lint::{EarlyLintPassObject, LateLintPassObject};
3132
use lint::{Level, Lint, LintId, LintPass, LintBuffer};
3233
use lint::builtin::BuiltinLintDiagnostics;
@@ -39,7 +40,6 @@ use ty::layout::{LayoutError, LayoutOf, TyLayout};
3940
use util::nodemap::FxHashMap;
4041

4142
use std::default::Default as StdDefault;
42-
use std::cell::{Ref, RefCell};
4343
use syntax::ast;
4444
use syntax::edition;
4545
use syntax_pos::{MultiSpan, Span};
@@ -78,7 +78,7 @@ pub struct LintStore {
7878

7979
pub struct LintSession<'a, PassObject> {
8080
/// Reference to the store of registered lints.
81-
lints: Ref<'a, LintStore>,
81+
lints: ReadGuard<'a, LintStore>,
8282

8383
/// Trait objects for each lint pass.
8484
passes: Option<Vec<PassObject>>,
@@ -336,7 +336,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> {
336336
/// Creates a new `LintSession`, by moving out the `LintStore`'s initial
337337
/// lint levels and pass objects. These can be restored using the `restore`
338338
/// method.
339-
fn new(store: &'a RefCell<LintStore>) -> LintSession<'a, PassObject> {
339+
fn new(store: &'a RwLock<LintStore>) -> LintSession<'a, PassObject> {
340340
let mut s = store.borrow_mut();
341341
let passes = PassObject::take_passes(&mut *s);
342342
drop(s);
@@ -347,7 +347,7 @@ impl<'a, PassObject: LintPassObject> LintSession<'a, PassObject> {
347347
}
348348

349349
/// Restores the levels back to the original lint store.
350-
fn restore(self, store: &RefCell<LintStore>) {
350+
fn restore(self, store: &RwLock<LintStore>) {
351351
drop(self.lints);
352352
let mut s = store.borrow_mut();
353353
PassObject::restore_passes(&mut *s, self.passes);

src/librustc/session/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use util::nodemap::{FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
2727
use util::common::ProfileQueriesMsg;
2828

29-
use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once};
29+
use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once, RwLock};
3030

3131
use syntax::ast::NodeId;
3232
use errors::{self, DiagnosticBuilder, DiagnosticId};
@@ -83,8 +83,8 @@ pub struct Session {
8383

8484
// FIXME: lint_store and buffered_lints are not thread-safe,
8585
// but are only used in a single thread
86-
pub lint_store: OneThread<RefCell<lint::LintStore>>,
87-
pub buffered_lints: OneThread<RefCell<Option<lint::LintBuffer>>>,
86+
pub lint_store: RwLock<lint::LintStore>,
87+
pub buffered_lints: Lock<Option<lint::LintBuffer>>,
8888

8989
/// Set of (DiagnosticId, Option<Span>, message) tuples tracking
9090
/// (sub)diagnostics that have been set once, but should not be set again,
@@ -1091,8 +1091,8 @@ pub fn build_session_(
10911091
default_sysroot,
10921092
local_crate_source_file,
10931093
working_dir,
1094-
lint_store: OneThread::new(RefCell::new(lint::LintStore::new())),
1095-
buffered_lints: OneThread::new(RefCell::new(Some(lint::LintBuffer::new()))),
1094+
lint_store: RwLock::new(lint::LintStore::new()),
1095+
buffered_lints: Lock::new(Some(lint::LintBuffer::new())),
10961096
one_time_diagnostics: RefCell::new(FxHashSet()),
10971097
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
10981098
plugin_attributes: OneThread::new(RefCell::new(Vec::new())),

0 commit comments

Comments
 (0)