Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax MSRV of utils to 1.38 #1156

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam <version>'
version = "0.8.4"
edition = "2021"
edition = "2018"
rust-version = "1.61"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down Expand Up @@ -47,7 +47,6 @@ rand = "0.8"
workspace = true

[workspace]
resolver = "2"
members = [
".",
"crossbeam-channel",
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam-channel"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-channel <version>'
version = "0.5.13"
edition = "2021"
edition = "2018"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "benchmarks"
version = "0.0.0"
edition = "2021"
edition = "2018"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-deque/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam-deque"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-deque <version>'
version = "0.8.5"
edition = "2021"
edition = "2018"
rust-version = "1.61"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
1 change: 1 addition & 0 deletions crossbeam-deque/src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::boxed::Box;
use std::cell::{Cell, UnsafeCell};
use std::cmp;
use std::fmt;
use std::iter::FromIterator;
use std::marker::PhantomData;
use std::mem::{self, MaybeUninit};
use std::ptr;
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam-epoch"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-epoch <version>'
version = "0.9.18"
edition = "2021"
edition = "2018"
rust-version = "1.61"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam-queue"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-queue <version>'
version = "0.3.11"
edition = "2021"
edition = "2018"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-skiplist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "crossbeam-skiplist"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-skiplist <version>'
version = "0.1.3"
edition = "2021"
edition = "2018"
rust-version = "1.61"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
1 change: 1 addition & 0 deletions crossbeam-skiplist/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::borrow::Borrow;
use std::fmt;
use std::iter::FromIterator;
use std::mem::ManuallyDrop;
use std::ops::{Bound, RangeBounds};
use std::ptr;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-skiplist/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::borrow::Borrow;
use std::fmt;
use std::iter::FromIterator;
use std::ops::Deref;
use std::ops::{Bound, RangeBounds};

Expand Down
4 changes: 2 additions & 2 deletions crossbeam-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ name = "crossbeam-utils"
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-utils <version>'
version = "0.8.20"
edition = "2021"
rust-version = "1.56"
edition = "2018"
rust-version = "1.38"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-utils"
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ crossbeam-utils = "0.8"

Crossbeam Utils supports stable Rust releases going back at least six months,
and every time the minimum supported Rust version is increased, a new minor
version is released. Currently, the minimum supported Rust version is 1.56.
version is released. Currently, the minimum supported Rust version is 1.38.

## License

Expand Down
4 changes: 4 additions & 0 deletions crossbeam-utils/src/atomic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//! * [`AtomicCell`], a thread-safe mutable memory location.
//! * [`AtomicConsume`], for reading from primitive atomic types with "consume" ordering.

// unsafe_op_in_unsafe_fn requires Rust 1.52, so cannot be used at crate-level,
// but this module requires 1.60.
#![warn(unsafe_op_in_unsafe_fn)]

#[cfg(target_has_atomic = "ptr")]
#[cfg(not(crossbeam_loom))]
// Use "wide" sequence lock if the pointer width <= 32 for preventing its counter against wrap
Expand Down
10 changes: 8 additions & 2 deletions crossbeam-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(feature = "std")]
Expand Down Expand Up @@ -65,7 +65,13 @@ mod primitive {
#[allow(unused_imports)]
mod primitive {
pub(crate) mod hint {
pub(crate) use core::hint::spin_loop;
// core::hint::spin_loop requires Rust 1.49
// pub(crate) use core::hint::spin_loop;
#[inline]
pub(crate) fn spin_loop() {
#[allow(deprecated)]
core::sync::atomic::spin_loop_hint();
}
}
pub(crate) mod sync {
pub(crate) use core::sync::atomic;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-utils/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! * [`WaitGroup`], for synchronizing the beginning or end of some computation.

#[cfg(not(crossbeam_loom))]
#[allow(unused_unsafe)] // once_lock.rs is also used from epoch which sets unsafe_op_in_unsafe_fn.
mod once_lock;
mod parker;
#[cfg(not(crossbeam_loom))]
Expand Down
21 changes: 17 additions & 4 deletions crossbeam-utils/src/sync/once_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use core::cell::UnsafeCell;
use core::mem::MaybeUninit;
use core::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;

pub(crate) struct OnceLock<T> {
once: Once,
// Once::is_completed requires Rust 1.43, so use this to track of whether they have been initialized.
is_initialized: AtomicBool,
value: UnsafeCell<MaybeUninit<T>>,
// Unlike std::sync::OnceLock, we don't need PhantomData here because
// we don't use #[may_dangle].
Expand All @@ -22,6 +25,7 @@ impl<T> OnceLock<T> {
pub(crate) const fn new() -> Self {
Self {
once: Once::new(),
is_initialized: AtomicBool::new(false),
value: UnsafeCell::new(MaybeUninit::uninit()),
}
}
Expand All @@ -46,7 +50,7 @@ impl<T> OnceLock<T> {
F: FnOnce() -> T,
{
// Fast path check
if self.once.is_completed() {
if self.is_initialized() {
// SAFETY: The inner value has been initialized
return unsafe { self.get_unchecked() };
}
Expand All @@ -56,31 +60,40 @@ impl<T> OnceLock<T> {
unsafe { self.get_unchecked() }
}

#[inline]
fn is_initialized(&self) -> bool {
self.is_initialized.load(Ordering::Acquire)
}

#[cold]
fn initialize<F>(&self, f: F)
where
F: FnOnce() -> T,
{
let slot = self.value.get();
let is_initialized = &self.is_initialized;

self.once.call_once(|| {
let value = f();
unsafe { slot.write(MaybeUninit::new(value)) }
is_initialized.store(true, Ordering::Release);
});
}

/// # Safety
///
/// The value must be initialized
unsafe fn get_unchecked(&self) -> &T {
debug_assert!(self.once.is_completed());
unsafe { (*self.value.get()).assume_init_ref() }
debug_assert!(self.is_initialized());
// assume_init_drop requires Rust 1.55
// unsafe { (*self.value.get()).assume_init_ref() }
unsafe { &*self.value.get().cast::<T>() }
}
}

impl<T> Drop for OnceLock<T> {
fn drop(&mut self) {
if self.once.is_completed() {
if self.is_initialized() {
// SAFETY: The inner value has been initialized
// assume_init_drop requires Rust 1.60
// unsafe { (*self.value.get()).assume_init_drop() };
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-utils/src/sync/parker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Parker {
/// ```
pub unsafe fn from_raw(ptr: *const ()) -> Self {
Self {
unparker: unsafe { Unparker::from_raw(ptr) },
unparker: Unparker::from_raw(ptr),
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl Unparker {
/// ```
pub unsafe fn from_raw(ptr: *const ()) -> Self {
Self {
inner: unsafe { Arc::from_raw(ptr.cast::<Inner>()) },
inner: Arc::from_raw(ptr.cast::<Inner>()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-utils/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
//! tricky because argument `s` lives *inside* the invocation of `thread::scope()` and as such
//! cannot be borrowed by scoped threads:
//!
//! ```compile_fail,E0521
//! ```compile_fail,E0373,E0521
//! use crossbeam_utils::thread;
//!
//! thread::scope(|s| {
Expand Down
Loading