summaryrefslogtreecommitdiffstats
path: root/vendor/rayon/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/rayon/src
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rayon/src')
-rw-r--r--vendor/rayon/src/iter/extend.rs10
-rw-r--r--vendor/rayon/src/iter/from_par_iter.rs51
-rw-r--r--vendor/rayon/src/iter/mod.rs10
-rw-r--r--vendor/rayon/src/iter/par_bridge.rs5
-rw-r--r--vendor/rayon/src/iter/product.rs2
-rw-r--r--vendor/rayon/src/iter/sum.rs2
-rw-r--r--vendor/rayon/src/lib.rs2
-rw-r--r--vendor/rayon/src/slice/quicksort.rs42
8 files changed, 98 insertions, 26 deletions
diff --git a/vendor/rayon/src/iter/extend.rs b/vendor/rayon/src/iter/extend.rs
index 1769d476b..a2645280f 100644
--- a/vendor/rayon/src/iter/extend.rs
+++ b/vendor/rayon/src/iter/extend.rs
@@ -500,6 +500,16 @@ impl ParallelExtend<String> for String {
}
}
+/// Extends a string with boxed strings from a parallel iterator.
+impl ParallelExtend<Box<str>> for String {
+ fn par_extend<I>(&mut self, par_iter: I)
+ where
+ I: IntoParallelIterator<Item = Box<str>>,
+ {
+ extend!(self, par_iter, string_extend);
+ }
+}
+
/// Extends a string with string slices from a parallel iterator.
impl<'a> ParallelExtend<Cow<'a, str>> for String {
fn par_extend<I>(&mut self, par_iter: I)
diff --git a/vendor/rayon/src/iter/from_par_iter.rs b/vendor/rayon/src/iter/from_par_iter.rs
index 3240f32e2..49afd6cb8 100644
--- a/vendor/rayon/src/iter/from_par_iter.rs
+++ b/vendor/rayon/src/iter/from_par_iter.rs
@@ -6,6 +6,8 @@ use std::collections::LinkedList;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::collections::{BinaryHeap, VecDeque};
use std::hash::{BuildHasher, Hash};
+use std::rc::Rc;
+use std::sync::Arc;
/// Creates an empty default collection and extends it.
fn collect_extended<C, I>(par_iter: I) -> C
@@ -31,6 +33,45 @@ where
}
}
+/// Collects items from a parallel iterator into a boxed slice.
+impl<T> FromParallelIterator<T> for Box<[T]>
+where
+ T: Send,
+{
+ fn from_par_iter<I>(par_iter: I) -> Self
+ where
+ I: IntoParallelIterator<Item = T>,
+ {
+ Vec::from_par_iter(par_iter).into()
+ }
+}
+
+/// Collects items from a parallel iterator into a reference-counted slice.
+impl<T> FromParallelIterator<T> for Rc<[T]>
+where
+ T: Send,
+{
+ fn from_par_iter<I>(par_iter: I) -> Self
+ where
+ I: IntoParallelIterator<Item = T>,
+ {
+ Vec::from_par_iter(par_iter).into()
+ }
+}
+
+/// Collects items from a parallel iterator into an atomically-reference-counted slice.
+impl<T> FromParallelIterator<T> for Arc<[T]>
+where
+ T: Send,
+{
+ fn from_par_iter<I>(par_iter: I) -> Self
+ where
+ I: IntoParallelIterator<Item = T>,
+ {
+ Vec::from_par_iter(par_iter).into()
+ }
+}
+
/// Collects items from a parallel iterator into a vecdeque.
impl<T> FromParallelIterator<T> for VecDeque<T>
where
@@ -174,6 +215,16 @@ impl FromParallelIterator<String> for String {
}
}
+/// Collects boxed strings from a parallel iterator into one large string.
+impl FromParallelIterator<Box<str>> for String {
+ fn from_par_iter<I>(par_iter: I) -> Self
+ where
+ I: IntoParallelIterator<Item = Box<str>>,
+ {
+ collect_extended(par_iter)
+ }
+}
+
/// Collects string slices from a parallel iterator into a string.
impl<'a> FromParallelIterator<Cow<'a, str>> for String {
fn from_par_iter<I>(par_iter: I) -> Self
diff --git a/vendor/rayon/src/iter/mod.rs b/vendor/rayon/src/iter/mod.rs
index e60ea1633..7b5a29aeb 100644
--- a/vendor/rayon/src/iter/mod.rs
+++ b/vendor/rayon/src/iter/mod.rs
@@ -1547,7 +1547,7 @@ pub trait ParallelIterator: Sized + Send {
/// Computes the maximum of all the items in the iterator with respect to
/// the given comparison function. If the iterator is empty, `None` is
- /// returned; otherwise, `Some(min)` is returned.
+ /// returned; otherwise, `Some(max)` is returned.
///
/// Note that the order in which the items will be reduced is not
/// specified, so if the comparison function is not associative, then
@@ -2392,7 +2392,7 @@ impl<T: ParallelIterator> IntoParallelIterator for T {
#[allow(clippy::len_without_is_empty)]
pub trait IndexedParallelIterator: ParallelIterator {
/// Collects the results of the iterator into the specified
- /// vector. The vector is always truncated before execution
+ /// vector. The vector is always cleared before execution
/// begins. If possible, reusing the vector across calls can lead
/// to better performance since it reuses the same backing buffer.
///
@@ -2401,7 +2401,7 @@ pub trait IndexedParallelIterator: ParallelIterator {
/// ```
/// use rayon::prelude::*;
///
- /// // any prior data will be truncated
+ /// // any prior data will be cleared
/// let mut vec = vec![-1, -2, -3];
///
/// (0..5).into_par_iter()
@@ -2414,7 +2414,7 @@ pub trait IndexedParallelIterator: ParallelIterator {
}
/// Unzips the results of the iterator into the specified
- /// vectors. The vectors are always truncated before execution
+ /// vectors. The vectors are always cleared before execution
/// begins. If possible, reusing the vectors across calls can lead
/// to better performance since they reuse the same backing buffer.
///
@@ -2423,7 +2423,7 @@ pub trait IndexedParallelIterator: ParallelIterator {
/// ```
/// use rayon::prelude::*;
///
- /// // any prior data will be truncated
+ /// // any prior data will be cleared
/// let mut left = vec![42; 10];
/// let mut right = vec![-1; 10];
///
diff --git a/vendor/rayon/src/iter/par_bridge.rs b/vendor/rayon/src/iter/par_bridge.rs
index 8398274b3..eb058d3e6 100644
--- a/vendor/rayon/src/iter/par_bridge.rs
+++ b/vendor/rayon/src/iter/par_bridge.rs
@@ -13,6 +13,11 @@ use crate::{current_num_threads, current_thread_index};
/// `par_iter` instead. However, it can still be useful for iterators that are difficult to
/// parallelize by other means, like channels or file or network I/O.
///
+/// Iterator items are pulled by `next()` one at a time, synchronized from each thread that is
+/// ready for work, so this may become a bottleneck if the serial iterator can't keep up with the
+/// parallel demand. The items are not buffered by `IterBridge`, so it's fine to use this with
+/// large or even unbounded iterators.
+///
/// The resulting iterator is not guaranteed to keep the order of the original iterator.
///
/// # Examples
diff --git a/vendor/rayon/src/iter/product.rs b/vendor/rayon/src/iter/product.rs
index a3d0727f9..e081be06b 100644
--- a/vendor/rayon/src/iter/product.rs
+++ b/vendor/rayon/src/iter/product.rs
@@ -13,7 +13,7 @@ where
}
fn mul<T: Product>(left: T, right: T) -> T {
- iter::once(left).chain(iter::once(right)).product()
+ [left, right].into_iter().product()
}
struct ProductConsumer<P: Send> {
diff --git a/vendor/rayon/src/iter/sum.rs b/vendor/rayon/src/iter/sum.rs
index a73e0bf3d..ddae810f9 100644
--- a/vendor/rayon/src/iter/sum.rs
+++ b/vendor/rayon/src/iter/sum.rs
@@ -13,7 +13,7 @@ where
}
fn add<T: Sum>(left: T, right: T) -> T {
- iter::once(left).chain(iter::once(right)).sum()
+ [left, right].into_iter().sum()
}
struct SumConsumer<S: Send> {
diff --git a/vendor/rayon/src/lib.rs b/vendor/rayon/src/lib.rs
index 86f997b36..dc7fcc0a7 100644
--- a/vendor/rayon/src/lib.rs
+++ b/vendor/rayon/src/lib.rs
@@ -152,7 +152,7 @@ impl<T> SendPtr<T> {
// Implement Clone without the T: Clone bound from the derive
impl<T> Clone for SendPtr<T> {
fn clone(&self) -> Self {
- Self(self.0)
+ *self
}
}
diff --git a/vendor/rayon/src/slice/quicksort.rs b/vendor/rayon/src/slice/quicksort.rs
index d71079ec3..2bfc35032 100644
--- a/vendor/rayon/src/slice/quicksort.rs
+++ b/vendor/rayon/src/slice/quicksort.rs
@@ -5,16 +5,34 @@
//! `rayon_core::join`.
use std::cmp;
+use std::marker::PhantomData;
use std::mem::{self, MaybeUninit};
use std::ptr;
/// When dropped, copies from `src` into `dest`.
-struct CopyOnDrop<T> {
+#[must_use]
+struct CopyOnDrop<'a, T> {
src: *const T,
dest: *mut T,
+ /// `src` is often a local pointer here, make sure we have appropriate
+ /// PhantomData so that dropck can protect us.
+ marker: PhantomData<&'a mut T>,
}
-impl<T> Drop for CopyOnDrop<T> {
+impl<'a, T> CopyOnDrop<'a, T> {
+ /// Construct from a source pointer and a destination
+ /// Assumes dest lives longer than src, since there is no easy way to
+ /// copy down lifetime information from another pointer
+ unsafe fn new(src: &'a T, dest: *mut T) -> Self {
+ CopyOnDrop {
+ src,
+ dest,
+ marker: PhantomData,
+ }
+ }
+}
+
+impl<T> Drop for CopyOnDrop<'_, T> {
fn drop(&mut self) {
// SAFETY: This is a helper class.
// Please refer to its usage for correctness.
@@ -54,10 +72,7 @@ where
// into the slice.
let tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(0)));
let v = v.as_mut_ptr();
- let mut hole = CopyOnDrop {
- src: &*tmp,
- dest: v.add(1),
- };
+ let mut hole = CopyOnDrop::new(&*tmp, v.add(1));
ptr::copy_nonoverlapping(v.add(1), v.add(0), 1);
for i in 2..len {
@@ -103,10 +118,7 @@ where
// into the slice.
let tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(len - 1)));
let v = v.as_mut_ptr();
- let mut hole = CopyOnDrop {
- src: &*tmp,
- dest: v.add(len - 2),
- };
+ let mut hole = CopyOnDrop::new(&*tmp, v.add(len - 2));
ptr::copy_nonoverlapping(v.add(len - 2), v.add(len - 1), 1);
for i in (0..len - 2).rev() {
@@ -510,10 +522,7 @@ where
// SAFETY: `pivot` is a reference to the first element of `v`, so `ptr::read` is safe.
let tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
- let _pivot_guard = CopyOnDrop {
- src: &*tmp,
- dest: pivot,
- };
+ let _pivot_guard = unsafe { CopyOnDrop::new(&*tmp, pivot) };
let pivot = &*tmp;
// Find the first pair of out-of-order elements.
@@ -569,10 +578,7 @@ where
// operation panics, the pivot will be automatically written back into the slice.
// SAFETY: The pointer here is valid because it is obtained from a reference to a slice.
let tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
- let _pivot_guard = CopyOnDrop {
- src: &*tmp,
- dest: pivot,
- };
+ let _pivot_guard = unsafe { CopyOnDrop::new(&*tmp, pivot) };
let pivot = &*tmp;
// Now partition the slice.