Skip to content

Commit

Permalink
Use locks for Session.lint_store and Session.buffered_lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Apr 16, 2018
1 parent 2741690 commit fe63637
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use self::TargetLint::*;

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

use std::default::Default as StdDefault;
use std::cell::{Ref, RefCell};
use syntax::ast;
use syntax::edition;
use syntax_pos::{MultiSpan, Span};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub struct LintStore {

pub struct LintSession<'a, PassObject> {
/// Reference to the store of registered lints.
lints: Ref<'a, LintStore>,
lints: ReadGuard<'a, LintStore>,

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

/// Restores the levels back to the original lint store.
fn restore(self, store: &RefCell<LintStore>) {
fn restore(self, store: &RwLock<LintStore>) {
drop(self.lints);
let mut s = store.borrow_mut();
PassObject::restore_passes(&mut *s, self.passes);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use util::nodemap::{FxHashSet};
use util::common::{duration_to_secs_str, ErrorReported};
use util::common::ProfileQueriesMsg;

use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once};
use rustc_data_structures::sync::{Lrc, Lock, LockCell, OneThread, Once, RwLock};

use syntax::ast::NodeId;
use errors::{self, DiagnosticBuilder, DiagnosticId};
Expand Down Expand Up @@ -83,8 +83,8 @@ pub struct Session {

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

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

0 comments on commit fe63637

Please sign in to comment.