diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-03-15 10:03:36 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-03-24 05:21:50 +0100 |
| commit | 29a4ec0d434dba190dfe9e4d46f16e4c026dd6cc (patch) | |
| tree | 2f6791deaa99d94fe7edb9bc6b8bd6cdf4658c64 /src/librustc_errors | |
| parent | 4be5d360cd8a9338d1408b3998874313240db395 (diff) | |
| download | rust-29a4ec0d434dba190dfe9e4d46f16e4c026dd6cc.tar.gz rust-29a4ec0d434dba190dfe9e4d46f16e4c026dd6cc.zip | |
Make queries thread safe. Remove the query stack and make queries point to their parents instead.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/lib.rs | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index a25c3668bb1..23a688636e9 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -42,7 +42,6 @@ use rustc_data_structures::stable_hasher::StableHasher; use std::borrow::Cow; use std::cell::{RefCell, Cell}; -use std::mem; use std::{error, fmt}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; @@ -269,7 +268,6 @@ pub struct Handler { emitter: RefCell<Box<Emitter>>, continue_after_error: Cell<bool>, delayed_span_bug: RefCell<Option<Diagnostic>>, - tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>, // This set contains the `DiagnosticId` of all emitted diagnostics to avoid // emitting the same diagnostic with extended help (`--teach`) twice, which @@ -282,6 +280,11 @@ pub struct Handler { emitted_diagnostics: RefCell<FxHashSet<u128>>, } +fn default_track_diagnostic(_: &Diagnostic) {} + +thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> = + Cell::new(default_track_diagnostic)); + #[derive(Default)] pub struct HandlerFlags { pub can_emit_warnings: bool, @@ -333,7 +336,6 @@ impl Handler { emitter: RefCell::new(e), continue_after_error: Cell::new(true), delayed_span_bug: RefCell::new(None), - tracked_diagnostics: RefCell::new(None), tracked_diagnostic_codes: RefCell::new(FxHashSet()), emitted_diagnostics: RefCell::new(FxHashSet()), } @@ -629,17 +631,6 @@ impl Handler { } } - pub fn track_diagnostics<F, R>(&self, f: F) -> (R, Vec<Diagnostic>) - where F: FnOnce() -> R - { - let prev = mem::replace(&mut *self.tracked_diagnostics.borrow_mut(), - Some(Vec::new())); - let ret = f(); - let diagnostics = mem::replace(&mut *self.tracked_diagnostics.borrow_mut(), prev) - .unwrap(); - (ret, diagnostics) - } - /// `true` if a diagnostic with this code has already been emitted in this handler. /// /// Used to suppress emitting the same error multiple times with extended explanation when @@ -651,9 +642,9 @@ impl Handler { fn emit_db(&self, db: &DiagnosticBuilder) { let diagnostic = &**db; - if let Some(ref mut list) = *self.tracked_diagnostics.borrow_mut() { - list.push(diagnostic.clone()); - } + TRACK_DIAGNOSTICS.with(|track_diagnostics| { + track_diagnostics.get()(diagnostic); + }); if let Some(ref code) = diagnostic.code { self.tracked_diagnostic_codes.borrow_mut().insert(code.clone()); |
