Skip to content

Commit 4aa62ea

Browse files
committed
Use rustc_thread_pool instead of rustc-rayon-core
1 parent 0b9b1df commit 4aa62ea

File tree

29 files changed

+86
-81
lines changed

29 files changed

+86
-81
lines changed

Cargo.lock

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,15 @@ dependencies = [
29772977
"getrandom 0.3.3",
29782978
]
29792979

2980+
[[package]]
2981+
name = "rand_xorshift"
2982+
version = "0.4.0"
2983+
source = "registry+https://github.com/rust-lang/crates.io-index"
2984+
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
2985+
dependencies = [
2986+
"rand_core 0.9.3",
2987+
]
2988+
29802989
[[package]]
29812990
name = "rand_xoshiro"
29822991
version = "0.7.0"
@@ -3176,16 +3185,6 @@ dependencies = [
31763185
"tikv-jemalloc-sys",
31773186
]
31783187

3179-
[[package]]
3180-
name = "rustc-rayon-core"
3181-
version = "0.5.1"
3182-
source = "registry+https://github.com/rust-lang/crates.io-index"
3183-
checksum = "2f42932dcd3bcbe484b38a3ccf79b7906fac41c02d408b5b1bac26da3416efdb"
3184-
dependencies = [
3185-
"crossbeam-deque",
3186-
"crossbeam-utils",
3187-
]
3188-
31893188
[[package]]
31903189
name = "rustc-semver"
31913190
version = "1.1.0"
@@ -3554,14 +3553,14 @@ dependencies = [
35543553
"parking_lot",
35553554
"portable-atomic",
35563555
"rustc-hash 2.1.1",
3557-
"rustc-rayon-core",
35583556
"rustc-stable-hash",
35593557
"rustc_arena",
35603558
"rustc_graphviz",
35613559
"rustc_hashes",
35623560
"rustc_index",
35633561
"rustc_macros",
35643562
"rustc_serialize",
3563+
"rustc_thread_pool",
35653564
"smallvec",
35663565
"stacker",
35673566
"tempfile",
@@ -3908,7 +3907,6 @@ dependencies = [
39083907
name = "rustc_interface"
39093908
version = "0.0.0"
39103909
dependencies = [
3911-
"rustc-rayon-core",
39123910
"rustc_abi",
39133911
"rustc_ast",
39143912
"rustc_ast_lowering",
@@ -3947,6 +3945,7 @@ dependencies = [
39473945
"rustc_span",
39483946
"rustc_symbol_mangling",
39493947
"rustc_target",
3948+
"rustc_thread_pool",
39503949
"rustc_trait_selection",
39513950
"rustc_traits",
39523951
"rustc_ty_utils",
@@ -4074,7 +4073,6 @@ dependencies = [
40744073
"either",
40754074
"gsgdt",
40764075
"polonius-engine",
4077-
"rustc-rayon-core",
40784076
"rustc_abi",
40794077
"rustc_apfloat",
40804078
"rustc_arena",
@@ -4098,6 +4096,7 @@ dependencies = [
40984096
"rustc_session",
40994097
"rustc_span",
41004098
"rustc_target",
4099+
"rustc_thread_pool",
41014100
"rustc_type_ir",
41024101
"smallvec",
41034102
"thin-vec",
@@ -4344,7 +4343,6 @@ version = "0.0.0"
43444343
dependencies = [
43454344
"hashbrown",
43464345
"parking_lot",
4347-
"rustc-rayon-core",
43484346
"rustc_abi",
43494347
"rustc_ast",
43504348
"rustc_attr_data_structures",
@@ -4359,6 +4357,7 @@ dependencies = [
43594357
"rustc_serialize",
43604358
"rustc_session",
43614359
"rustc_span",
4360+
"rustc_thread_pool",
43624361
"smallvec",
43634362
"tracing",
43644363
]
@@ -4520,6 +4519,18 @@ dependencies = [
45204519
"tracing",
45214520
]
45224521

4522+
[[package]]
4523+
name = "rustc_thread_pool"
4524+
version = "0.0.0"
4525+
dependencies = [
4526+
"crossbeam-deque",
4527+
"crossbeam-utils",
4528+
"libc",
4529+
"rand 0.9.1",
4530+
"rand_xorshift",
4531+
"scoped-tls",
4532+
]
4533+
45234534
[[package]]
45244535
name = "rustc_tools_util"
45254536
version = "0.4.2"

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ indexmap = "2.4.0"
1414
jobserver_crate = { version = "0.1.28", package = "jobserver" }
1515
measureme = "12.0.1"
1616
rustc-hash = "2.0.0"
17-
rustc-rayon-core = { version = "0.5.0" }
1817
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
1918
rustc_arena = { path = "../rustc_arena" }
2019
rustc_graphviz = { path = "../rustc_graphviz" }
2120
rustc_hashes = { path = "../rustc_hashes" }
2221
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2322
rustc_macros = { path = "../rustc_macros" }
2423
rustc_serialize = { path = "../rustc_serialize" }
24+
rustc_thread_pool = { path = "../rustc_thread_pool" }
2525
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
2626
stacker = "0.1.17"
2727
tempfile = "3.2"

compiler/rustc_data_structures/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
2424
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
2525
//! | | | |
26-
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
26+
//! | `ParallelIterator` | `Iterator` | `rustc_thread_pool::iter::ParallelIterator` |
2727
//!
2828
//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
2929
//! of a `RefCell`. This is appropriate when interior mutability is not

compiler/rustc_data_structures/src/sync/parallel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macro_rules! parallel {
9696
pub fn spawn(func: impl FnOnce() + DynSend + 'static) {
9797
if mode::is_dyn_thread_safe() {
9898
let func = FromDyn::from(func);
99-
rayon_core::spawn(|| {
99+
rustc_thread_pool::spawn(|| {
100100
(func.into_inner())();
101101
});
102102
} else {
@@ -107,11 +107,11 @@ pub fn spawn(func: impl FnOnce() + DynSend + 'static) {
107107
// This function only works when `mode::is_dyn_thread_safe()`.
108108
pub fn scope<'scope, OP, R>(op: OP) -> R
109109
where
110-
OP: FnOnce(&rayon_core::Scope<'scope>) -> R + DynSend,
110+
OP: FnOnce(&rustc_thread_pool::Scope<'scope>) -> R + DynSend,
111111
R: DynSend,
112112
{
113113
let op = FromDyn::from(op);
114-
rayon_core::scope(|s| FromDyn::from(op.into_inner()(s))).into_inner()
114+
rustc_thread_pool::scope(|s| FromDyn::from(op.into_inner()(s))).into_inner()
115115
}
116116

117117
#[inline]
@@ -124,7 +124,7 @@ where
124124
let oper_a = FromDyn::from(oper_a);
125125
let oper_b = FromDyn::from(oper_b);
126126
let (a, b) = parallel_guard(|guard| {
127-
rayon_core::join(
127+
rustc_thread_pool::join(
128128
move || guard.run(move || FromDyn::from(oper_a.into_inner()())),
129129
move || guard.run(move || FromDyn::from(oper_b.into_inner()())),
130130
)
@@ -158,7 +158,7 @@ fn par_slice<I: DynSend>(
158158
let (left, right) = items.split_at_mut(items.len() / 2);
159159
let mut left = state.for_each.derive(left);
160160
let mut right = state.for_each.derive(right);
161-
rayon_core::join(move || par_rec(*left, state), move || par_rec(*right, state));
161+
rustc_thread_pool::join(move || par_rec(*left, state), move || par_rec(*right, state));
162162
}
163163
}
164164

@@ -241,7 +241,7 @@ pub fn par_map<I: DynSend, T: IntoIterator<Item = I>, R: DynSend, C: FromIterato
241241
pub fn broadcast<R: DynSend>(op: impl Fn(usize) -> R + DynSync) -> Vec<R> {
242242
if mode::is_dyn_thread_safe() {
243243
let op = FromDyn::from(op);
244-
let results = rayon_core::broadcast(|context| op.derive(op(context.index())));
244+
let results = rustc_thread_pool::broadcast(|context| op.derive(op(context.index())));
245245
results.into_iter().map(|r| r.into_inner()).collect()
246246
} else {
247247
vec![op(0)]

compiler/rustc_interface/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
rustc-rayon-core = { version = "0.5.0" }
98
rustc_ast = { path = "../rustc_ast" }
109
rustc_ast_lowering = { path = "../rustc_ast_lowering" }
1110
rustc_ast_passes = { path = "../rustc_ast_passes" }
@@ -43,6 +42,7 @@ rustc_session = { path = "../rustc_session" }
4342
rustc_span = { path = "../rustc_span" }
4443
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
4544
rustc_target = { path = "../rustc_target" }
45+
rustc_thread_pool = { path = "../rustc_thread_pool" }
4646
rustc_trait_selection = { path = "../rustc_trait_selection" }
4747
rustc_traits = { path = "../rustc_traits" }
4848
rustc_ty_utils = { path = "../rustc_ty_utils" }

compiler/rustc_interface/src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
208208

209209
let proxy_ = Arc::clone(&proxy);
210210
let proxy__ = Arc::clone(&proxy);
211-
let builder = rayon_core::ThreadPoolBuilder::new()
211+
let builder = rustc_thread_pool::ThreadPoolBuilder::new()
212212
.thread_name(|_| "rustc".to_string())
213213
.acquire_thread_handler(move || proxy_.acquire_thread())
214214
.release_thread_handler(move || proxy__.release_thread())
@@ -218,7 +218,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
218218
// locals to it. The new thread runs the deadlock handler.
219219

220220
let current_gcx2 = current_gcx2.clone();
221-
let registry = rayon_core::Registry::current();
221+
let registry = rustc_thread_pool::Registry::current();
222222
let session_globals = rustc_span::with_session_globals(|session_globals| {
223223
session_globals as *const SessionGlobals as usize
224224
});
@@ -265,7 +265,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
265265
builder
266266
.build_scoped(
267267
// Initialize each new worker thread when created.
268-
move |thread: rayon_core::ThreadBuilder| {
268+
move |thread: rustc_thread_pool::ThreadBuilder| {
269269
// Register the thread for use with the `WorkerLocal` type.
270270
registry.register();
271271

@@ -274,7 +274,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
274274
})
275275
},
276276
// Run `f` on the first thread in the thread pool.
277-
move |pool: &rayon_core::ThreadPool| {
277+
move |pool: &rustc_thread_pool::ThreadPool| {
278278
pool.install(|| f(current_gcx.into_inner(), proxy))
279279
},
280280
)

compiler/rustc_middle/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ bitflags = "2.4.1"
99
either = "1.5.0"
1010
gsgdt = "0.1.2"
1111
polonius-engine = "0.13.0"
12-
rustc-rayon-core = { version = "0.5.0" }
1312
rustc_abi = { path = "../rustc_abi" }
1413
rustc_apfloat = "0.2.0"
1514
rustc_arena = { path = "../rustc_arena" }
@@ -33,6 +32,7 @@ rustc_serialize = { path = "../rustc_serialize" }
3332
rustc_session = { path = "../rustc_session" }
3433
rustc_span = { path = "../rustc_span" }
3534
rustc_target = { path = "../rustc_target" }
35+
rustc_thread_pool = { path = "../rustc_thread_pool" }
3636
rustc_type_ir = { path = "../rustc_type_ir" }
3737
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3838
thin-vec = "0.2.12"

compiler/rustc_middle/src/ty/context/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
3636
}
3737

3838
// Import the thread-local variable from Rayon, which is preserved for Rayon jobs.
39-
use rayon_core::tlv::TLV;
39+
use rustc_thread_pool::tlv::TLV;
4040

4141
#[inline]
4242
fn erase(context: &ImplicitCtxt<'_, '_>) -> *const () {

compiler/rustc_query_system/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
parking_lot = "0.12"
9-
rustc-rayon-core = { version = "0.5.0" }
109
rustc_abi = { path = "../rustc_abi" }
1110
rustc_ast = { path = "../rustc_ast" }
1211
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
@@ -21,6 +20,7 @@ rustc_macros = { path = "../rustc_macros" }
2120
rustc_serialize = { path = "../rustc_serialize" }
2221
rustc_session = { path = "../rustc_session" }
2322
rustc_span = { path = "../rustc_span" }
23+
rustc_thread_pool = { path = "../rustc_thread_pool" }
2424
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2525
tracing = "0.1"
2626
# tidy-alphabetical-end

compiler/rustc_query_system/src/query/job.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<I> QueryLatch<I> {
236236
// If this detects a deadlock and the deadlock handler wants to resume this thread
237237
// we have to be in the `wait` call. This is ensured by the deadlock handler
238238
// getting the self.info lock.
239-
rayon_core::mark_blocked();
239+
rustc_thread_pool::mark_blocked();
240240
let proxy = qcx.jobserver_proxy();
241241
proxy.release_thread();
242242
waiter.condvar.wait(&mut info);
@@ -251,9 +251,9 @@ impl<I> QueryLatch<I> {
251251
let mut info = self.info.lock();
252252
debug_assert!(!info.complete);
253253
info.complete = true;
254-
let registry = rayon_core::Registry::current();
254+
let registry = rustc_thread_pool::Registry::current();
255255
for waiter in info.waiters.drain(..) {
256-
rayon_core::mark_unblocked(&registry);
256+
rustc_thread_pool::mark_unblocked(&registry);
257257
waiter.condvar.notify_one();
258258
}
259259
}
@@ -507,7 +507,7 @@ fn remove_cycle<I: Clone>(
507507
/// all active queries for cycles before finally resuming all the waiters at once.
508508
pub fn break_query_cycles<I: Clone + Debug>(
509509
query_map: QueryMap<I>,
510-
registry: &rayon_core::Registry,
510+
registry: &rustc_thread_pool::Registry,
511511
) {
512512
let mut wakelist = Vec::new();
513513
// It is OK per the comments:
@@ -543,7 +543,7 @@ pub fn break_query_cycles<I: Clone + Debug>(
543543
// we wake the threads up as otherwise Rayon could detect a deadlock if a thread we
544544
// resumed fell asleep and this thread had yet to mark the remaining threads as unblocked.
545545
for _ in 0..wakelist.len() {
546-
rayon_core::mark_unblocked(registry);
546+
rustc_thread_pool::mark_unblocked(registry);
547547
}
548548

549549
for waiter in wakelist.into_iter() {

compiler/rustc_thread_pool/Cargo.toml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
[package]
2-
name = "rustc-rayon-core"
3-
version = "0.5.1"
2+
name = "rustc_thread_pool"
3+
version = "0.0.0"
44
authors = ["Niko Matsakis <niko@alum.mit.edu>",
55
"Josh Stone <cuviper@gmail.com>"]
66
description = "Core APIs for Rayon - fork for rustc"
77
license = "MIT OR Apache-2.0"
8-
repository = "https://github.com/rust-lang/rustc-rayon"
9-
documentation = "https://docs.rs/rustc-rayon-core/"
108
rust-version = "1.63"
119
edition = "2021"
1210
readme = "README.md"
1311
keywords = ["parallel", "thread", "concurrency", "join", "performance"]
1412
categories = ["concurrency"]
1513

16-
[lib]
17-
name = "rayon_core"
18-
19-
# Some dependencies may not be their latest version, in order to support older rustc.
2014
[dependencies]
21-
crossbeam-deque = "0.8.1"
22-
crossbeam-utils = "0.8.0"
15+
crossbeam-deque = "0.8"
16+
crossbeam-utils = "0.8"
2317

2418
[dev-dependencies]
2519
rand = "0.9"

compiler/rustc_thread_pool/src/compile_fail/quicksort_race1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
77
88
let mid = partition(v);
99
let (lo, _hi) = v.split_at_mut(mid);
10-
rayon_core::join(|| quick_sort(lo), || quick_sort(lo)); //~ ERROR
10+
rustc_thred_pool::join(|| quick_sort(lo), || quick_sort(lo)); //~ ERROR
1111
}
1212
1313
fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize {

compiler/rustc_thread_pool/src/compile_fail/quicksort_race2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
77
88
let mid = partition(v);
99
let (lo, _hi) = v.split_at_mut(mid);
10-
rayon_core::join(|| quick_sort(lo), || quick_sort(v)); //~ ERROR
10+
rustc_thred_pool::join(|| quick_sort(lo), || quick_sort(v)); //~ ERROR
1111
}
1212
1313
fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize {

compiler/rustc_thread_pool/src/compile_fail/quicksort_race3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
77
88
let mid = partition(v);
99
let (_lo, hi) = v.split_at_mut(mid);
10-
rayon_core::join(|| quick_sort(hi), || quick_sort(hi)); //~ ERROR
10+
rustc_thred_pool::join(|| quick_sort(hi), || quick_sort(hi)); //~ ERROR
1111
}
1212
1313
fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize {

compiler/rustc_thread_pool/src/compile_fail/rc_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::rc::Rc;
44
5-
rayon_core::join(|| Rc::new(22), || ()); //~ ERROR
5+
rustc_thred_pool::join(|| Rc::new(22), || ()); //~ ERROR
66
77
``` */
88
mod left {}
@@ -11,7 +11,7 @@ mod left {}
1111
1212
use std::rc::Rc;
1313
14-
rayon_core::join(|| (), || Rc::new(23)); //~ ERROR
14+
rustc_thred_pool::join(|| (), || Rc::new(23)); //~ ERROR
1515
1616
``` */
1717
mod right {}

0 commit comments

Comments
 (0)