Rollup merge of #108480 - Zoxc:rayon-tlv, r=cuviper
Use Rayon's TLV directly This accesses Rayon's `TLV` thread local directly avoiding wrapper functions. This makes rustc work with https://github.com/rust-lang/rustc-rayon/pull/10. r? `@cuviper`
This commit is contained in:
commit
c31f75209f
13 changed files with 38 additions and 71 deletions
14
Cargo.lock
14
Cargo.lock
|
@ -2689,9 +2689,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.2"
|
version = "1.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
|
@ -4160,21 +4160,19 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-rayon"
|
name = "rustc-rayon"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1a79f0b0b2609e2eacf9758013f50e7176cb4b29fd6436a747b14a5362c8727a"
|
checksum = "eb81aadc8837ca6ecebe0fe1353f15df83b3b3cc2cf7a8afd571bc22aa121710"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
|
||||||
"crossbeam-deque",
|
|
||||||
"either",
|
"either",
|
||||||
"rustc-rayon-core",
|
"rustc-rayon-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-rayon-core"
|
name = "rustc-rayon-core"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "02269144a0db9bb55cf5d4a41a5a0e95b334b0b78b08269018ca9b0250718c30"
|
checksum = "67668daaf00e359c126f6dcb40d652d89b458a008c8afa727a42a2d20fca0b7f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossbeam-deque",
|
"crossbeam-deque",
|
||||||
|
|
|
@ -235,9 +235,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.2"
|
version = "1.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
|
|
@ -25,7 +25,7 @@ target-lexicon = "0.12.0"
|
||||||
gimli = { version = "0.26.0", default-features = false, features = ["write"]}
|
gimli = { version = "0.26.0", default-features = false, features = ["write"]}
|
||||||
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
|
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
|
||||||
|
|
||||||
indexmap = "1.9.1"
|
indexmap = "1.9.3"
|
||||||
libloading = { version = "0.7.3", optional = true }
|
libloading = { version = "0.7.3", optional = true }
|
||||||
once_cell = "1.10.0"
|
once_cell = "1.10.0"
|
||||||
smallvec = "1.8.1"
|
smallvec = "1.8.1"
|
||||||
|
|
|
@ -10,12 +10,12 @@ arrayvec = { version = "0.7", default-features = false }
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
ena = "0.14.2"
|
ena = "0.14.2"
|
||||||
indexmap = { version = "1.9.1" }
|
indexmap = { version = "1.9.3" }
|
||||||
jobserver_crate = { version = "0.1.13", package = "jobserver" }
|
jobserver_crate = { version = "0.1.13", package = "jobserver" }
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
measureme = "10.0.0"
|
measureme = "10.0.0"
|
||||||
rayon-core = { version = "0.4.0", package = "rustc-rayon-core", optional = true }
|
rustc-rayon-core = { version = "0.5.0", optional = true }
|
||||||
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
|
rustc-rayon = { version = "0.5.0", optional = true }
|
||||||
rustc_graphviz = { path = "../rustc_graphviz" }
|
rustc_graphviz = { path = "../rustc_graphviz" }
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
rustc_index = { path = "../rustc_index", package = "rustc_index" }
|
rustc_index = { path = "../rustc_index", package = "rustc_index" }
|
||||||
|
@ -51,4 +51,4 @@ features = [
|
||||||
memmap2 = "0.2.1"
|
memmap2 = "0.2.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rayon", "rayon-core"]
|
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rustc-rayon", "rustc-rayon-core"]
|
||||||
|
|
|
@ -8,8 +8,8 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libloading = "0.7.1"
|
libloading = "0.7.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
rustc-rayon-core = { version = "0.4.0", optional = true }
|
rustc-rayon-core = { version = "0.5.0", optional = true }
|
||||||
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
|
rustc-rayon = { version = "0.5.0", optional = true }
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
|
@ -52,4 +52,4 @@ rustc_ty_utils = { path = "../rustc_ty_utils" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
llvm = ['rustc_codegen_llvm']
|
llvm = ['rustc_codegen_llvm']
|
||||||
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
|
rustc_use_parallel_compiler = ['rustc-rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
|
||||||
|
|
|
@ -183,7 +183,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
|
||||||
.try_collect_active_jobs()
|
.try_collect_active_jobs()
|
||||||
.expect("active jobs shouldn't be locked in deadlock handler")
|
.expect("active jobs shouldn't be locked in deadlock handler")
|
||||||
});
|
});
|
||||||
let registry = rustc_rayon_core::Registry::current();
|
let registry = rayon_core::Registry::current();
|
||||||
thread::spawn(move || deadlock(query_map, ®istry));
|
thread::spawn(move || deadlock(query_map, ®istry));
|
||||||
});
|
});
|
||||||
if let Some(size) = get_stack_size() {
|
if let Some(size) = get_stack_size() {
|
||||||
|
|
|
@ -26,8 +26,8 @@ rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_query_system = { path = "../rustc_query_system" }
|
rustc_query_system = { path = "../rustc_query_system" }
|
||||||
rustc-rayon-core = { version = "0.4.0", optional = true }
|
rustc-rayon-core = { version = "0.5.0", optional = true }
|
||||||
rustc-rayon = { version = "0.4.0", optional = true }
|
rustc-rayon = { version = "0.5.0", optional = true }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
|
|
|
@ -4,6 +4,8 @@ use crate::dep_graph::TaskDepsRef;
|
||||||
use crate::ty::query;
|
use crate::ty::query;
|
||||||
use rustc_data_structures::sync::{self, Lock};
|
use rustc_data_structures::sync::{self, Lock};
|
||||||
use rustc_errors::Diagnostic;
|
use rustc_errors::Diagnostic;
|
||||||
|
#[cfg(not(parallel_compiler))]
|
||||||
|
use std::cell::Cell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
@ -47,52 +49,15 @@ impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Import the thread-local variable from Rayon, which is preserved for Rayon jobs.
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
mod tlv {
|
use rayon_core::tlv::TLV;
|
||||||
use rustc_rayon_core as rayon_core;
|
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
/// Gets Rayon's thread-local variable, which is preserved for Rayon jobs.
|
|
||||||
/// This is used to get the pointer to the current `ImplicitCtxt`.
|
|
||||||
#[inline]
|
|
||||||
pub(super) fn get_tlv() -> *const () {
|
|
||||||
ptr::from_exposed_addr(rayon_core::tlv::get())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets Rayon's thread-local variable, which is preserved for Rayon jobs
|
|
||||||
/// to `value` during the call to `f`. It is restored to its previous value after.
|
|
||||||
/// This is used to set the pointer to the new `ImplicitCtxt`.
|
|
||||||
#[inline]
|
|
||||||
pub(super) fn with_tlv<F: FnOnce() -> R, R>(value: *const (), f: F) -> R {
|
|
||||||
rayon_core::tlv::with(value.expose_addr(), f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Otherwise define our own
|
||||||
#[cfg(not(parallel_compiler))]
|
#[cfg(not(parallel_compiler))]
|
||||||
mod tlv {
|
thread_local! {
|
||||||
use std::cell::Cell;
|
/// A thread local variable that stores a pointer to the current `ImplicitCtxt`.
|
||||||
use std::ptr;
|
static TLV: Cell<*const ()> = const { Cell::new(ptr::null()) };
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
/// A thread local variable that stores a pointer to the current `ImplicitCtxt`.
|
|
||||||
static TLV: Cell<*const ()> = const { Cell::new(ptr::null()) };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the pointer to the current `ImplicitCtxt`.
|
|
||||||
#[inline]
|
|
||||||
pub(super) fn get_tlv() -> *const () {
|
|
||||||
TLV.with(|tlv| tlv.get())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets TLV to `value` during the call to `f`.
|
|
||||||
/// It is restored to its previous value after.
|
|
||||||
/// This is used to set the pointer to the new `ImplicitCtxt`.
|
|
||||||
#[inline]
|
|
||||||
pub(super) fn with_tlv<F: FnOnce() -> R, R>(value: *const (), f: F) -> R {
|
|
||||||
let old = TLV.replace(value);
|
|
||||||
let _reset = rustc_data_structures::OnDrop(move || TLV.set(old));
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -111,7 +76,11 @@ pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) ->
|
||||||
where
|
where
|
||||||
F: FnOnce() -> R,
|
F: FnOnce() -> R,
|
||||||
{
|
{
|
||||||
tlv::with_tlv(erase(context), f)
|
TLV.with(|tlv| {
|
||||||
|
let old = tlv.replace(erase(context));
|
||||||
|
let _reset = rustc_data_structures::OnDrop(move || tlv.set(old));
|
||||||
|
f()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
|
/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
|
||||||
|
@ -120,7 +89,7 @@ pub fn with_context_opt<F, R>(f: F) -> R
|
||||||
where
|
where
|
||||||
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
|
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
|
||||||
{
|
{
|
||||||
let context = tlv::get_tlv();
|
let context = TLV.get();
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
f(None)
|
f(None)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,7 +16,7 @@ rustc_index = { path = "../rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_middle = { path = "../rustc_middle" }
|
rustc_middle = { path = "../rustc_middle" }
|
||||||
rustc_query_system = { path = "../rustc_query_system" }
|
rustc_query_system = { path = "../rustc_query_system" }
|
||||||
rustc-rayon-core = { version = "0.4.0", optional = true }
|
rustc-rayon-core = { version = "0.5.0", optional = true }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
|
|
|
@ -15,7 +15,7 @@ rustc_feature = { path = "../rustc_feature" }
|
||||||
rustc_hir = { path = "../rustc_hir" }
|
rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc-rayon-core = { version = "0.4.0", optional = true }
|
rustc-rayon-core = { version = "0.5.0", optional = true }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
|
|
|
@ -18,11 +18,11 @@ use std::num::NonZeroU64;
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
use {
|
use {
|
||||||
parking_lot::{Condvar, Mutex},
|
parking_lot::{Condvar, Mutex},
|
||||||
|
rayon_core,
|
||||||
rustc_data_structures::fx::FxHashSet,
|
rustc_data_structures::fx::FxHashSet,
|
||||||
rustc_data_structures::sync::Lock,
|
rustc_data_structures::sync::Lock,
|
||||||
rustc_data_structures::sync::Lrc,
|
rustc_data_structures::sync::Lrc,
|
||||||
rustc_data_structures::{jobserver, OnDrop},
|
rustc_data_structures::{jobserver, OnDrop},
|
||||||
rustc_rayon_core as rayon_core,
|
|
||||||
rustc_span::DUMMY_SP,
|
rustc_span::DUMMY_SP,
|
||||||
std::iter,
|
std::iter,
|
||||||
std::process,
|
std::process,
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
indexmap = "1.9.1"
|
indexmap = "1.9.3"
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
thin-vec = "0.2.12"
|
thin-vec = "0.2.12"
|
||||||
|
|
||||||
|
|
|
@ -18,4 +18,4 @@ tracing = "0.1"
|
||||||
sha1 = "0.10.0"
|
sha1 = "0.10.0"
|
||||||
sha2 = "0.10.1"
|
sha2 = "0.10.1"
|
||||||
md5 = { package = "md-5", version = "0.10.0" }
|
md5 = { package = "md-5", version = "0.10.0" }
|
||||||
indexmap = { version = "1.9.1" }
|
indexmap = { version = "1.9.3" }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue