diff options
| author | bors <bors@rust-lang.org> | 2018-04-05 16:38:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-04-05 16:38:15 +0000 |
| commit | 7222241e7c2d7caf9ad6ee6e34748e4addfb8dd3 (patch) | |
| tree | 307f491346376bb59d85e371c6c2a4fff1464b18 /src/librustc_errors | |
| parent | 56714acc5eb0687ed9a7566fdebe5528657fc5b3 (diff) | |
| parent | 4f7d0fde1c5f577c1f956d5d4edfbb202a5bc3cf (diff) | |
| download | rust-7222241e7c2d7caf9ad6ee6e34748e4addfb8dd3.tar.gz rust-7222241e7c2d7caf9ad6ee6e34748e4addfb8dd3.zip | |
Auto merge of #49045 - Zoxc:tls, r=michaelwoerister
Make queries thread safe This makes queries thread safe by removing the query stack and making queries point to their parents. Queries write to the query map when starting and cycles are detected by checking if there's already an entry in the query map. This makes cycle detection O(1) instead of O(n), where `n` is the size of the query stack. This is mostly corresponds to the method I described [here](https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606). cc @rust-lang/compiler r? @michaelwoerister
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 37ae64cef57..990ae2fc544 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()), } @@ -631,17 +633,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 @@ -653,9 +644,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()); |
