Skip to content

Commit c31f752

Browse files
authored
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 rust-lang/rustc-rayon#10. r? `@cuviper`
2 parents 4bd33fd + 27c44d2 commit c31f752

File tree

13 files changed

+38
-71
lines changed

13 files changed

+38
-71
lines changed

Diff for: Cargo.lock

+6-8
Original file line numberDiff line numberDiff line change
@@ -2689,9 +2689,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
26892689

26902690
[[package]]
26912691
name = "indexmap"
2692-
version = "1.9.2"
2692+
version = "1.9.3"
26932693
source = "registry+https://github.com/rust-lang/crates.io-index"
2694-
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
2694+
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
26952695
dependencies = [
26962696
"autocfg",
26972697
"hashbrown 0.12.3",
@@ -4160,21 +4160,19 @@ dependencies = [
41604160

41614161
[[package]]
41624162
name = "rustc-rayon"
4163-
version = "0.4.0"
4163+
version = "0.5.0"
41644164
source = "registry+https://github.com/rust-lang/crates.io-index"
4165-
checksum = "1a79f0b0b2609e2eacf9758013f50e7176cb4b29fd6436a747b14a5362c8727a"
4165+
checksum = "eb81aadc8837ca6ecebe0fe1353f15df83b3b3cc2cf7a8afd571bc22aa121710"
41664166
dependencies = [
4167-
"autocfg",
4168-
"crossbeam-deque",
41694167
"either",
41704168
"rustc-rayon-core",
41714169
]
41724170

41734171
[[package]]
41744172
name = "rustc-rayon-core"
4175-
version = "0.4.1"
4173+
version = "0.5.0"
41764174
source = "registry+https://github.com/rust-lang/crates.io-index"
4177-
checksum = "02269144a0db9bb55cf5d4a41a5a0e95b334b0b78b08269018ca9b0250718c30"
4175+
checksum = "67668daaf00e359c126f6dcb40d652d89b458a008c8afa727a42a2d20fca0b7f"
41784176
dependencies = [
41794177
"crossbeam-channel",
41804178
"crossbeam-deque",

Diff for: compiler/rustc_codegen_cranelift/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ dependencies = [
235235

236236
[[package]]
237237
name = "indexmap"
238-
version = "1.9.2"
238+
version = "1.9.3"
239239
source = "registry+https://github.com/rust-lang/crates.io-index"
240-
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
240+
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
241241
dependencies = [
242242
"autocfg",
243243
"hashbrown",

Diff for: compiler/rustc_codegen_cranelift/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target-lexicon = "0.12.0"
2525
gimli = { version = "0.26.0", default-features = false, features = ["write"]}
2626
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
2727

28-
indexmap = "1.9.1"
28+
indexmap = "1.9.3"
2929
libloading = { version = "0.7.3", optional = true }
3030
once_cell = "1.10.0"
3131
smallvec = "1.8.1"

Diff for: compiler/rustc_data_structures/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "1.2.1"
1111
cfg-if = "1.0"
1212
ena = "0.14.2"
13-
indexmap = { version = "1.9.1" }
13+
indexmap = { version = "1.9.3" }
1414
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1515
libc = "0.2"
1616
measureme = "10.0.0"
17-
rayon-core = { version = "0.4.0", package = "rustc-rayon-core", optional = true }
18-
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
17+
rustc-rayon-core = { version = "0.5.0", optional = true }
18+
rustc-rayon = { version = "0.5.0", optional = true }
1919
rustc_graphviz = { path = "../rustc_graphviz" }
2020
rustc-hash = "1.1.0"
2121
rustc_index = { path = "../rustc_index", package = "rustc_index" }
@@ -51,4 +51,4 @@ features = [
5151
memmap2 = "0.2.1"
5252

5353
[features]
54-
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rayon", "rayon-core"]
54+
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rustc-rayon", "rustc-rayon-core"]

Diff for: compiler/rustc_interface/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ edition = "2021"
88
[dependencies]
99
libloading = "0.7.1"
1010
tracing = "0.1"
11-
rustc-rayon-core = { version = "0.4.0", optional = true }
12-
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
11+
rustc-rayon-core = { version = "0.5.0", optional = true }
12+
rustc-rayon = { version = "0.5.0", optional = true }
1313
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1414
rustc_ast = { path = "../rustc_ast" }
1515
rustc_attr = { path = "../rustc_attr" }
@@ -52,4 +52,4 @@ rustc_ty_utils = { path = "../rustc_ty_utils" }
5252

5353
[features]
5454
llvm = ['rustc_codegen_llvm']
55-
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
55+
rustc_use_parallel_compiler = ['rustc-rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']

Diff for: compiler/rustc_interface/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
183183
.try_collect_active_jobs()
184184
.expect("active jobs shouldn't be locked in deadlock handler")
185185
});
186-
let registry = rustc_rayon_core::Registry::current();
186+
let registry = rayon_core::Registry::current();
187187
thread::spawn(move || deadlock(query_map, &registry));
188188
});
189189
if let Some(size) = get_stack_size() {

Diff for: compiler/rustc_middle/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ rustc_hir = { path = "../rustc_hir" }
2626
rustc_index = { path = "../rustc_index" }
2727
rustc_macros = { path = "../rustc_macros" }
2828
rustc_query_system = { path = "../rustc_query_system" }
29-
rustc-rayon-core = { version = "0.4.0", optional = true }
30-
rustc-rayon = { version = "0.4.0", optional = true }
29+
rustc-rayon-core = { version = "0.5.0", optional = true }
30+
rustc-rayon = { version = "0.5.0", optional = true }
3131
rustc_serialize = { path = "../rustc_serialize" }
3232
rustc_session = { path = "../rustc_session" }
3333
rustc_span = { path = "../rustc_span" }

Diff for: compiler/rustc_middle/src/ty/context/tls.rs

+14-45
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::dep_graph::TaskDepsRef;
44
use crate::ty::query;
55
use rustc_data_structures::sync::{self, Lock};
66
use rustc_errors::Diagnostic;
7+
#[cfg(not(parallel_compiler))]
8+
use std::cell::Cell;
79
use std::mem;
810
use std::ptr;
911
use thin_vec::ThinVec;
@@ -47,52 +49,15 @@ impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
4749
}
4850
}
4951

52+
// Import the thread-local variable from Rayon, which is preserved for Rayon jobs.
5053
#[cfg(parallel_compiler)]
51-
mod tlv {
52-
use rustc_rayon_core as rayon_core;
53-
use std::ptr;
54-
55-
/// Gets Rayon's thread-local variable, which is preserved for Rayon jobs.
56-
/// This is used to get the pointer to the current `ImplicitCtxt`.
57-
#[inline]
58-
pub(super) fn get_tlv() -> *const () {
59-
ptr::from_exposed_addr(rayon_core::tlv::get())
60-
}
61-
62-
/// Sets Rayon's thread-local variable, which is preserved for Rayon jobs
63-
/// to `value` during the call to `f`. It is restored to its previous value after.
64-
/// This is used to set the pointer to the new `ImplicitCtxt`.
65-
#[inline]
66-
pub(super) fn with_tlv<F: FnOnce() -> R, R>(value: *const (), f: F) -> R {
67-
rayon_core::tlv::with(value.expose_addr(), f)
68-
}
69-
}
54+
use rayon_core::tlv::TLV;
7055

56+
// Otherwise define our own
7157
#[cfg(not(parallel_compiler))]
72-
mod tlv {
73-
use std::cell::Cell;
74-
use std::ptr;
75-
76-
thread_local! {
77-
/// A thread local variable that stores a pointer to the current `ImplicitCtxt`.
78-
static TLV: Cell<*const ()> = const { Cell::new(ptr::null()) };
79-
}
80-
81-
/// Gets the pointer to the current `ImplicitCtxt`.
82-
#[inline]
83-
pub(super) fn get_tlv() -> *const () {
84-
TLV.with(|tlv| tlv.get())
85-
}
86-
87-
/// Sets TLV to `value` during the call to `f`.
88-
/// It is restored to its previous value after.
89-
/// This is used to set the pointer to the new `ImplicitCtxt`.
90-
#[inline]
91-
pub(super) fn with_tlv<F: FnOnce() -> R, R>(value: *const (), f: F) -> R {
92-
let old = TLV.replace(value);
93-
let _reset = rustc_data_structures::OnDrop(move || TLV.set(old));
94-
f()
95-
}
58+
thread_local! {
59+
/// A thread local variable that stores a pointer to the current `ImplicitCtxt`.
60+
static TLV: Cell<*const ()> = const { Cell::new(ptr::null()) };
9661
}
9762

9863
#[inline]
@@ -111,7 +76,11 @@ pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) ->
11176
where
11277
F: FnOnce() -> R,
11378
{
114-
tlv::with_tlv(erase(context), f)
79+
TLV.with(|tlv| {
80+
let old = tlv.replace(erase(context));
81+
let _reset = rustc_data_structures::OnDrop(move || tlv.set(old));
82+
f()
83+
})
11584
}
11685

11786
/// 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
12089
where
12190
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
12291
{
123-
let context = tlv::get_tlv();
92+
let context = TLV.get();
12493
if context.is_null() {
12594
f(None)
12695
} else {

Diff for: compiler/rustc_query_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustc_index = { path = "../rustc_index" }
1616
rustc_macros = { path = "../rustc_macros" }
1717
rustc_middle = { path = "../rustc_middle" }
1818
rustc_query_system = { path = "../rustc_query_system" }
19-
rustc-rayon-core = { version = "0.4.0", optional = true }
19+
rustc-rayon-core = { version = "0.5.0", optional = true }
2020
rustc_serialize = { path = "../rustc_serialize" }
2121
rustc_session = { path = "../rustc_session" }
2222
rustc_span = { path = "../rustc_span" }

Diff for: compiler/rustc_query_system/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rustc_feature = { path = "../rustc_feature" }
1515
rustc_hir = { path = "../rustc_hir" }
1616
rustc_index = { path = "../rustc_index" }
1717
rustc_macros = { path = "../rustc_macros" }
18-
rustc-rayon-core = { version = "0.4.0", optional = true }
18+
rustc-rayon-core = { version = "0.5.0", optional = true }
1919
rustc_serialize = { path = "../rustc_serialize" }
2020
rustc_session = { path = "../rustc_session" }
2121
rustc_span = { path = "../rustc_span" }

Diff for: compiler/rustc_query_system/src/query/job.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use std::num::NonZeroU64;
1818
#[cfg(parallel_compiler)]
1919
use {
2020
parking_lot::{Condvar, Mutex},
21+
rayon_core,
2122
rustc_data_structures::fx::FxHashSet,
2223
rustc_data_structures::sync::Lock,
2324
rustc_data_structures::sync::Lrc,
2425
rustc_data_structures::{jobserver, OnDrop},
25-
rustc_rayon_core as rayon_core,
2626
rustc_span::DUMMY_SP,
2727
std::iter,
2828
std::process,

Diff for: compiler/rustc_serialize/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
indexmap = "1.9.1"
7+
indexmap = "1.9.3"
88
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
99
thin-vec = "0.2.12"
1010

Diff for: compiler/rustc_span/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ tracing = "0.1"
1818
sha1 = "0.10.0"
1919
sha2 = "0.10.1"
2020
md5 = { package = "md-5", version = "0.10.0" }
21-
indexmap = { version = "1.9.1" }
21+
indexmap = { version = "1.9.3" }

0 commit comments

Comments
 (0)