diff options
| author | Celina G. Val <celinval@amazon.com> | 2025-06-11 11:12:32 -0700 |
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2025-06-11 11:12:32 -0700 |
| commit | 0b9b1df0064396708a5e5ca27fd010ae3ad3a305 (patch) | |
| tree | c854a9e2fd775dba7f0a5e70a2c7be121b5fec0b /compiler/rustc_thread_pool/src/scope | |
| parent | 35c5144394c1b93784867d330f694fa7c8f480e3 (diff) | |
Fix format and tidy for code moved from rayon
Diffstat (limited to 'compiler/rustc_thread_pool/src/scope')
| -rw-r--r-- | compiler/rustc_thread_pool/src/scope/mod.rs | 34 | ||||
| -rw-r--r-- | compiler/rustc_thread_pool/src/scope/tests.rs (renamed from compiler/rustc_thread_pool/src/scope/test.rs) | 35 |
2 files changed, 27 insertions, 42 deletions
diff --git a/compiler/rustc_thread_pool/src/scope/mod.rs b/compiler/rustc_thread_pool/src/scope/mod.rs index 364b322baad..95a4e0b7a18 100644 --- a/compiler/rustc_thread_pool/src/scope/mod.rs +++ b/compiler/rustc_thread_pool/src/scope/mod.rs @@ -5,19 +5,19 @@ //! [`in_place_scope()`]: fn.in_place_scope.html //! [`join()`]: ../join/join.fn.html +use std::any::Any; +use std::marker::PhantomData; +use std::mem::ManuallyDrop; +use std::sync::Arc; +use std::sync::atomic::{AtomicPtr, Ordering}; +use std::{fmt, ptr}; + use crate::broadcast::BroadcastContext; use crate::job::{ArcJob, HeapJob, JobFifo, JobRef}; use crate::latch::{CountLatch, Latch}; -use crate::registry::{global_registry, in_worker, Registry, WorkerThread}; +use crate::registry::{Registry, WorkerThread, global_registry, in_worker}; use crate::tlv::{self, Tlv}; use crate::unwind; -use std::any::Any; -use std::fmt; -use std::marker::PhantomData; -use std::mem::ManuallyDrop; -use std::ptr; -use std::sync::atomic::{AtomicPtr, Ordering}; -use std::sync::Arc; #[cfg(test)] mod test; @@ -53,7 +53,7 @@ struct ScopeBase<'scope> { job_completed_latch: CountLatch, /// You can think of a scope as containing a list of closures to execute, - /// all of which outlive `'scope`. They're not actually required to be + /// all of which outlive `'scope`. They're not actually required to be /// `Sync`, but it's still safe to let the `Scope` implement `Sync` because /// the closures are only *moved* across threads to be executed. #[allow(clippy::type_complexity)] @@ -179,9 +179,9 @@ struct ScopeBase<'scope> { /// they were spawned. So in this example, absent any stealing, we can /// expect `s.2` to execute before `s.1`, and `t.2` before `t.1`. Other /// threads always steal from the other end of the deque, like FIFO -/// order. The idea is that "recent" tasks are most likely to be fresh +/// order. The idea is that "recent" tasks are most likely to be fresh /// in the local CPU's cache, while other threads can steal older -/// "stale" tasks. For an alternate approach, consider +/// "stale" tasks. For an alternate approach, consider /// [`scope_fifo()`] instead. /// /// [`scope_fifo()`]: fn.scope_fifo.html @@ -353,7 +353,7 @@ where /// /// Under `scope_fifo()`, the spawns are prioritized in a FIFO order on /// the thread from which they were spawned, as opposed to `scope()`'s -/// LIFO. So in this example, we can expect `s.1` to execute before +/// LIFO. So in this example, we can expect `s.1` to execute before /// `s.2`, and `t.1` before `t.2`. Other threads also steal tasks in /// FIFO order, as usual. Overall, this has roughly the same order as /// the now-deprecated [`breadth_first`] option, except the effect is @@ -469,7 +469,7 @@ impl<'scope> Scope<'scope> { } /// Spawns a job into the fork-join scope `self`. This job will - /// execute sometime before the fork-join scope completes. The + /// execute sometime before the fork-join scope completes. The /// job is specified as a closure, and this closure receives its /// own reference to the scope `self` as argument. This can be /// used to inject new jobs into `self`. @@ -539,7 +539,7 @@ impl<'scope> Scope<'scope> { } /// Spawns a job into every thread of the fork-join scope `self`. This job will - /// execute on each thread sometime before the fork-join scope completes. The + /// execute on each thread sometime before the fork-join scope completes. The /// job is specified as a closure, and this closure receives its own reference /// to the scope `self` as argument, as well as a `BroadcastContext`. pub fn spawn_broadcast<BODY>(&self, body: BODY) @@ -567,7 +567,7 @@ impl<'scope> ScopeFifo<'scope> { } /// Spawns a job into the fork-join scope `self`. This job will - /// execute sometime before the fork-join scope completes. The + /// execute sometime before the fork-join scope completes. The /// job is specified as a closure, and this closure receives its /// own reference to the scope `self` as argument. This can be /// used to inject new jobs into `self`. @@ -575,7 +575,7 @@ impl<'scope> ScopeFifo<'scope> { /// # See also /// /// This method is akin to [`Scope::spawn()`], but with a FIFO - /// priority. The [`scope_fifo` function] has more details about + /// priority. The [`scope_fifo` function] has more details about /// this distinction. /// /// [`Scope::spawn()`]: struct.Scope.html#method.spawn @@ -605,7 +605,7 @@ impl<'scope> ScopeFifo<'scope> { } /// Spawns a job into every thread of the fork-join scope `self`. This job will - /// execute on each thread sometime before the fork-join scope completes. The + /// execute on each thread sometime before the fork-join scope completes. The /// job is specified as a closure, and this closure receives its own reference /// to the scope `self` as argument, as well as a `BroadcastContext`. pub fn spawn_broadcast<BODY>(&self, body: BODY) diff --git a/compiler/rustc_thread_pool/src/scope/test.rs b/compiler/rustc_thread_pool/src/scope/tests.rs index 4505ba7c4fb..2df3bc67e29 100644 --- a/compiler/rustc_thread_pool/src/scope/test.rs +++ b/compiler/rustc_thread_pool/src/scope/tests.rs @@ -1,13 +1,13 @@ -use crate::unwind; -use crate::ThreadPoolBuilder; -use crate::{scope, scope_fifo, Scope, ScopeFifo}; -use rand::{Rng, SeedableRng}; -use rand_xorshift::XorShiftRng; use std::iter::once; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Barrier, Mutex}; use std::vec; +use rand::{Rng, SeedableRng}; +use rand_xorshift::XorShiftRng; + +use crate::{Scope, ScopeFifo, ThreadPoolBuilder, scope, scope_fifo, unwind}; + #[test] fn scope_empty() { scope(|_| {}); @@ -93,10 +93,7 @@ impl<T: Send> Tree<T> { where OP: Fn(&mut T) + Sync, { - let Tree { - ref mut value, - ref mut children, - } = *self; + let Tree { ref mut value, ref mut children } = *self; scope.spawn(move |scope| { for child in children { scope.spawn(move |scope| child.update_in_scope(op, scope)); @@ -124,10 +121,7 @@ fn random_tree1(depth: usize, rng: &mut XorShiftRng) -> Tree<u32> { .collect() }; - Tree { - value: rng.random_range(0..1_000_000), - children, - } + Tree { value: rng.random_range(0..1_000_000), children } } #[test] @@ -161,11 +155,7 @@ fn linear_stack_growth() { let diff_when_500 = *max_diff.get_mut().unwrap() as f64; let ratio = diff_when_5 / diff_when_500; - assert!( - ratio > 0.9 && ratio < 1.1, - "stack usage ratio out of bounds: {}", - ratio - ); + assert!(ratio > 0.9 && ratio < 1.1, "stack usage ratio out of bounds: {}", ratio); }); } @@ -366,10 +356,7 @@ fn nested_fifo_order() { fn nested_lifo_fifo_order() { // LIFO on the outside, FIFO on the inside let vec = test_nested_order!(scope => spawn, scope_fifo => spawn_fifo); - let expected: Vec<i32> = (0..10) - .rev() - .flat_map(|i| (0..10).map(move |j| i * 10 + j)) - .collect(); + let expected: Vec<i32> = (0..10).rev().flat_map(|i| (0..10).map(move |j| i * 10 + j)).collect(); assert_eq!(vec, expected); } @@ -378,9 +365,7 @@ fn nested_lifo_fifo_order() { fn nested_fifo_lifo_order() { // FIFO on the outside, LIFO on the inside let vec = test_nested_order!(scope_fifo => spawn_fifo, scope => spawn); - let expected: Vec<i32> = (0..10) - .flat_map(|i| (0..10).rev().map(move |j| i * 10 + j)) - .collect(); + let expected: Vec<i32> = (0..10).flat_map(|i| (0..10).rev().map(move |j| i * 10 + j)).collect(); assert_eq!(vec, expected); } |
