diff options
| author | bors <bors@rust-lang.org> | 2018-06-01 22:49:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-01 22:49:43 +0000 |
| commit | bfa41f28010b336e43e2896693b26853ecc1f492 (patch) | |
| tree | 40db91d4f6f40f691186fca3620825743b9ed9e0 | |
| parent | aa094a43cc041c8483b7c80fb0ec4be233dd01b7 (diff) | |
| parent | 2119d04b2d4f5f6aaa922e529aff5378d2036420 (diff) | |
| download | rust-bfa41f28010b336e43e2896693b26853ecc1f492.tar.gz rust-bfa41f28010b336e43e2896693b26853ecc1f492.zip | |
Auto merge of #50108 - Zoxc:sync-gcx, r=mw
Make GlobalCtxt thread-safe r? @michaelwoerister
| -rw-r--r-- | src/Cargo.lock | 1 | ||||
| -rw-r--r-- | src/libproc_macro/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc/session/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 16 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_codegen_utils/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_data_structures/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_data_structures/sync.rs | 33 | ||||
| -rw-r--r-- | src/librustc_metadata/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_privacy/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc_traits/lib.rs | 2 |
13 files changed, 62 insertions, 7 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock index 3a27107f825..d5a1d18a676 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2044,6 +2044,7 @@ dependencies = [ "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "serialize 0.0.0", "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 9d037cefcee..befc1ba064a 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -36,6 +36,8 @@ #![feature(lang_items)] #![feature(optin_builtin_traits)] +#![recursion_limit="256"] + extern crate syntax; extern crate syntax_pos; extern crate rustc_errors; diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 8df66d8d688..076d56fb808 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -845,10 +845,10 @@ impl Session { /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n. /// This expends fuel if applicable, and records fuel if applicable. pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool { - assert!(self.query_threads() == 1); let mut ret = true; match self.optimization_fuel_crate { Some(ref c) if c == crate_name => { + assert!(self.query_threads() == 1); let fuel = self.optimization_fuel_limit.get(); ret = fuel != 0; if fuel == 0 && !self.out_of_fuel.get() { @@ -862,6 +862,7 @@ impl Session { } match self.print_fuel_crate { Some(ref c) if c == crate_name => { + assert!(self.query_threads() == 1); self.print_fuel.set(self.print_fuel.get() + 1); } _ => {} diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 68f55b49933..35b2ce50da7 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -58,7 +58,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap, StableVec}; use arena::{TypedArena, SyncDroplessArena}; use rustc_data_structures::indexed_vec::IndexVec; -use rustc_data_structures::sync::{Lrc, Lock}; +use rustc_data_structures::sync::{self, Lrc, Lock, WorkerLocal}; use std::any::Any; use std::borrow::Borrow; use std::cmp::Ordering; @@ -80,14 +80,14 @@ use syntax_pos::Span; use hir; pub struct AllArenas<'tcx> { - pub global: GlobalArenas<'tcx>, + pub global: WorkerLocal<GlobalArenas<'tcx>>, pub interner: SyncDroplessArena, } impl<'tcx> AllArenas<'tcx> { pub fn new() -> Self { AllArenas { - global: GlobalArenas::new(), + global: WorkerLocal::new(|_| GlobalArenas::new()), interner: SyncDroplessArena::new(), } } @@ -854,7 +854,7 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> { } pub struct GlobalCtxt<'tcx> { - global_arenas: &'tcx GlobalArenas<'tcx>, + global_arenas: &'tcx WorkerLocal<GlobalArenas<'tcx>>, global_interners: CtxtInterners<'tcx>, cstore: &'tcx CrateStoreDyn, @@ -1179,6 +1179,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { output_filenames: Arc::new(output_filenames.clone()), }; + sync::assert_send_val(&gcx); + tls::enter_global(gcx, f) } @@ -1704,7 +1706,7 @@ pub mod tls { use ty::maps; use errors::{Diagnostic, TRACK_DIAGNOSTICS}; use rustc_data_structures::OnDrop; - use rustc_data_structures::sync::Lrc; + use rustc_data_structures::sync::{self, Lrc}; use dep_graph::OpenTask; /// This is the implicit state of rustc. It contains the current @@ -1832,6 +1834,10 @@ pub mod tls { if context == 0 { f(None) } else { + // We could get a ImplicitCtxt pointer from another thread. + // Ensure that ImplicitCtxt is Sync + sync::assert_sync::<ImplicitCtxt>(); + unsafe { f(Some(&*(context as *const ImplicitCtxt))) } } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 646c60c139c..f0f4adde7ee 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -617,6 +617,8 @@ pub struct Slice<T> { opaque: OpaqueSliceContents, } +unsafe impl<T: Sync> Sync for Slice<T> {} + impl<T: Copy> Slice<T> { #[inline] fn from_arena<'tcx>(arena: &'tcx SyncDroplessArena, slice: &[T]) -> &'tcx Slice<T> { diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 0c18571f4ff..d09e8f4845e 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -23,6 +23,8 @@ #![feature(quote)] #![feature(rustc_diagnostic_macros)] +#![recursion_limit="256"] + extern crate ar; extern crate flate2; #[macro_use] diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml index 15956829ff9..17ee771e529 100644 --- a/src/librustc_data_structures/Cargo.toml +++ b/src/librustc_data_structures/Cargo.toml @@ -17,6 +17,7 @@ cfg-if = "0.1.2" stable_deref_trait = "1.0.0" parking_lot_core = "0.2.8" rustc-rayon = "0.1.0" +rustc-rayon-core = "0.1.0" rustc-hash = "1.0.1" [dependencies.parking_lot] diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 23a920739b9..7046a2a2a49 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -44,6 +44,7 @@ extern crate parking_lot; extern crate cfg_if; extern crate stable_deref_trait; extern crate rustc_rayon as rayon; +extern crate rustc_rayon_core as rayon_core; extern crate rustc_hash; // See librustc_cratesio_shim/Cargo.toml for a comment explaining this. diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 36617631330..6f7d9e1b54b 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -36,7 +36,6 @@ use std::marker::PhantomData; use std::fmt::Debug; use std::fmt::Formatter; use std::fmt; -use std; use std::ops::{Deref, DerefMut}; use owning_ref::{Erased, OwningRef}; @@ -101,6 +100,33 @@ cfg_if! { use std::cell::Cell; #[derive(Debug)] + pub struct WorkerLocal<T>(OneThread<T>); + + impl<T> WorkerLocal<T> { + /// Creates a new worker local where the `initial` closure computes the + /// value this worker local should take for each thread in the thread pool. + #[inline] + pub fn new<F: FnMut(usize) -> T>(mut f: F) -> WorkerLocal<T> { + WorkerLocal(OneThread::new(f(0))) + } + + /// Returns the worker-local value for each thread + #[inline] + pub fn into_inner(self) -> Vec<T> { + vec![OneThread::into_inner(self.0)] + } + } + + impl<T> Deref for WorkerLocal<T> { + type Target = T; + + #[inline(always)] + fn deref(&self) -> &T { + &*self.0 + } + } + + #[derive(Debug)] pub struct MTLock<T>(T); impl<T> MTLock<T> { @@ -200,9 +226,12 @@ cfg_if! { use parking_lot::Mutex as InnerLock; use parking_lot::RwLock as InnerRwLock; + use std; use std::thread; pub use rayon::{join, scope}; + pub use rayon_core::WorkerLocal; + pub use rayon::iter::ParallelIterator; use rayon::iter::IntoParallelIterator; @@ -638,7 +667,9 @@ pub struct OneThread<T> { inner: T, } +#[cfg(parallel_queries)] unsafe impl<T> std::marker::Sync for OneThread<T> {} +#[cfg(parallel_queries)] unsafe impl<T> std::marker::Send for OneThread<T> {} impl<T> OneThread<T> { diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index 7ecf2eba43d..d76ca5bdf27 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -23,6 +23,8 @@ #![feature(specialization)] #![feature(rustc_private)] +#![recursion_limit="256"] + extern crate libc; #[macro_use] extern crate log; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index bfb8c282d37..f32f6eda8ff 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -14,6 +14,8 @@ #![feature(rustc_diagnostic_macros)] +#![recursion_limit="256"] + #[macro_use] extern crate rustc; #[macro_use] extern crate syntax; extern crate rustc_typeck; diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index e57a793ff42..64dcd3e5175 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -15,6 +15,8 @@ #![cfg_attr(stage0, feature(macro_lifetime_matcher))] #![allow(unused_attributes)] +#![recursion_limit="256"] + #[macro_use] extern crate rustc; diff --git a/src/librustc_traits/lib.rs b/src/librustc_traits/lib.rs index 733d8e1708e..7fa69cb9833 100644 --- a/src/librustc_traits/lib.rs +++ b/src/librustc_traits/lib.rs @@ -17,6 +17,8 @@ #![feature(iterator_find_map)] #![feature(in_band_lifetimes)] +#![recursion_limit="256"] + extern crate chalk_engine; #[macro_use] extern crate log; |
