From fe636373505b610447b952200d91ae2708ce5947 Mon Sep 17 00:00:00 2001 From: =?utf8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 13 Apr 2018 19:33:31 +0200 Subject: [PATCH] Use locks for Session.lint_store and Session.buffered_lints --- src/librustc/lint/context.rs | 8 ++++---- src/librustc/session/mod.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9f8cc2f8699..d5849ea22b1 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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; @@ -39,7 +40,6 @@ 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}; @@ -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>, @@ -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) -> LintSession<'a, PassObject> { + fn new(store: &'a RwLock) -> LintSession<'a, PassObject> { let mut s = store.borrow_mut(); let passes = PassObject::take_passes(&mut *s); drop(s); @@ -347,7 +347,7 @@ fn new(store: &'a RefCell) -> LintSession<'a, PassObject> { } /// Restores the levels back to the original lint store. - fn restore(self, store: &RefCell) { + fn restore(self, store: &RwLock) { drop(self.lints); let mut s = store.borrow_mut(); PassObject::restore_passes(&mut *s, self.passes); diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 8f2043fdfc6..77dff0950ee 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -26,7 +26,7 @@ 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}; @@ -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>, - pub buffered_lints: OneThread>>, + pub lint_store: RwLock, + pub buffered_lints: Lock>, /// Set of (DiagnosticId, Option, message) tuples tracking /// (sub)diagnostics that have been set once, but should not be set again, @@ -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())), -- 2.44.0