Skip to content

Commit

Permalink
Auto merge of #131288 - matthiaskrgr:rollup-h0t0v2h, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #130428 (Stabilize `const_slice_split_at_mut` and `const_slice_first_last_chunk`)
 - #131094 (std: replace `LazyBox` with `OnceBox`)
 - #131256 (move f16/f128 const fn under f16/f128 feature gate)
 - #131278 (remove outdated contribution direction)
 - #131286 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 5, 2024
2 parents 5a4ee43 + 72acacf commit f559d61
Show file tree
Hide file tree
Showing 61 changed files with 1,516 additions and 724 deletions.
3 changes: 0 additions & 3 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
#![feature(const_size_of_val)]
#![feature(const_size_of_val_raw)]
#![feature(const_slice_from_ref)]
#![feature(const_slice_split_at_mut)]
#![feature(const_strict_overflow_ops)]
#![feature(const_swap)]
#![feature(const_try)]
Expand All @@ -158,8 +157,6 @@
#![feature(coverage_attribute)]
#![feature(do_not_recommend)]
#![feature(duration_consts_float)]
#![feature(f128_const)]
#![feature(f16_const)]
#![feature(internal_impls_macro)]
#![feature(ip)]
#![feature(is_ascii_octdigit)]
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ impl f128 {
/// ```
#[inline]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_bits(self) -> u128 {
// SAFETY: `u128` is a plain old datatype so we can always transmute to it.
Expand Down Expand Up @@ -959,7 +959,7 @@ impl f128 {
#[inline]
#[must_use]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn from_bits(v: u128) -> Self {
// It turns out the safety issues with sNaN were overblown! Hooray!
// SAFETY: `u128` is a plain old datatype so we can always transmute from it.
Expand All @@ -986,7 +986,7 @@ impl f128 {
/// ```
#[inline]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_be_bytes(self) -> [u8; 16] {
self.to_bits().to_be_bytes()
Expand All @@ -1012,7 +1012,7 @@ impl f128 {
/// ```
#[inline]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_le_bytes(self) -> [u8; 16] {
self.to_bits().to_le_bytes()
Expand Down Expand Up @@ -1049,7 +1049,7 @@ impl f128 {
/// ```
#[inline]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_ne_bytes(self) -> [u8; 16] {
self.to_bits().to_ne_bytes()
Expand Down Expand Up @@ -1077,7 +1077,7 @@ impl f128 {
#[inline]
#[must_use]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn from_be_bytes(bytes: [u8; 16]) -> Self {
Self::from_bits(u128::from_be_bytes(bytes))
}
Expand All @@ -1104,7 +1104,7 @@ impl f128 {
#[inline]
#[must_use]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn from_le_bytes(bytes: [u8; 16]) -> Self {
Self::from_bits(u128::from_le_bytes(bytes))
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ impl f128 {
#[inline]
#[must_use]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128_const", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]
pub const fn from_ne_bytes(bytes: [u8; 16]) -> Self {
Self::from_bits(u128::from_ne_bytes(bytes))
}
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ impl f16 {
/// ```
#[inline]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_bits(self) -> u16 {
// SAFETY: `u16` is a plain old datatype so we can always transmute to it.
Expand Down Expand Up @@ -944,7 +944,7 @@ impl f16 {
#[inline]
#[must_use]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
pub const fn from_bits(v: u16) -> Self {
// It turns out the safety issues with sNaN were overblown! Hooray!
// SAFETY: `u16` is a plain old datatype so we can always transmute from it.
Expand All @@ -970,7 +970,7 @@ impl f16 {
/// ```
#[inline]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_be_bytes(self) -> [u8; 2] {
self.to_bits().to_be_bytes()
Expand All @@ -995,7 +995,7 @@ impl f16 {
/// ```
#[inline]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_le_bytes(self) -> [u8; 2] {
self.to_bits().to_le_bytes()
Expand Down Expand Up @@ -1033,7 +1033,7 @@ impl f16 {
/// ```
#[inline]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "this returns the result of the operation, without modifying the original"]
pub const fn to_ne_bytes(self) -> [u8; 2] {
self.to_bits().to_ne_bytes()
Expand All @@ -1057,7 +1057,7 @@ impl f16 {
#[inline]
#[must_use]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
pub const fn from_be_bytes(bytes: [u8; 2]) -> Self {
Self::from_bits(u16::from_be_bytes(bytes))
}
Expand All @@ -1080,7 +1080,7 @@ impl f16 {
#[inline]
#[must_use]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
pub const fn from_le_bytes(bytes: [u8; 2]) -> Self {
Self::from_bits(u16::from_le_bytes(bytes))
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl f16 {
#[inline]
#[must_use]
#[unstable(feature = "f16", issue = "116909")]
#[rustc_const_unstable(feature = "f16_const", issue = "116909")]
#[rustc_const_unstable(feature = "f16", issue = "116909")]
pub const fn from_ne_bytes(bytes: [u8; 2]) -> Self {
Self::from_bits(u16::from_ne_bytes(bytes))
}
Expand Down
21 changes: 14 additions & 7 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
#[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> {
if self.len() < N {
None
Expand Down Expand Up @@ -421,7 +422,8 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
#[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn split_first_chunk_mut<const N: usize>(
&mut self,
) -> Option<(&mut [T; N], &mut [T])> {
Expand Down Expand Up @@ -491,7 +493,8 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
#[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn split_last_chunk_mut<const N: usize>(
&mut self,
) -> Option<(&mut [T], &mut [T; N])> {
Expand Down Expand Up @@ -560,7 +563,8 @@ impl<T> [T] {
/// ```
#[inline]
#[stable(feature = "slice_first_last_chunk", since = "1.77.0")]
#[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")]
#[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> {
if self.len() < N {
None
Expand Down Expand Up @@ -1903,7 +1907,8 @@ impl<T> [T] {
#[inline]
#[track_caller]
#[must_use]
#[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")]
#[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
match self.split_at_mut_checked(mid) {
Some(pair) => pair,
Expand Down Expand Up @@ -2005,7 +2010,8 @@ impl<T> [T] {
/// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
/// ```
#[stable(feature = "slice_split_at_unchecked", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")]
#[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
#[inline]
#[must_use]
pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
Expand Down Expand Up @@ -2105,7 +2111,8 @@ impl<T> [T] {
/// assert_eq!(None, v.split_at_mut_checked(7));
/// ```
#[stable(feature = "split_at_checked", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")]
#[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
#[inline]
#[must_use]
pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut [T], &mut [T])> {
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/sys/sync/condvar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ cfg_if::cfg_if! {
))] {
mod futex;
pub use futex::Condvar;
} else if #[cfg(target_family = "unix")] {
} else if #[cfg(any(
target_family = "unix",
target_os = "teeos",
))] {
mod pthread;
pub use pthread::Condvar;
} else if #[cfg(all(target_os = "windows", target_vendor = "win7"))] {
Expand All @@ -24,9 +27,6 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "solid_asp3")] {
mod itron;
pub use itron::Condvar;
} else if #[cfg(target_os = "teeos")] {
mod teeos;
pub use teeos::Condvar;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use xous::Condvar;
Expand Down
38 changes: 18 additions & 20 deletions library/std/src/sys/sync/condvar/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@ use crate::cell::UnsafeCell;
use crate::ptr;
use crate::sync::atomic::AtomicPtr;
use crate::sync::atomic::Ordering::Relaxed;
use crate::sys::sync::{Mutex, mutex};
use crate::sys::sync::{Mutex, OnceBox};
#[cfg(not(target_os = "nto"))]
use crate::sys::time::TIMESPEC_MAX;
#[cfg(target_os = "nto")]
use crate::sys::time::TIMESPEC_MAX_CAPPED;
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
use crate::time::Duration;

struct AllocatedCondvar(UnsafeCell<libc::pthread_cond_t>);

pub struct Condvar {
inner: LazyBox<AllocatedCondvar>,
inner: OnceBox<AllocatedCondvar>,
mutex: AtomicPtr<libc::pthread_mutex_t>,
}

#[inline]
fn raw(c: &Condvar) -> *mut libc::pthread_cond_t {
c.inner.0.get()
}

unsafe impl Send for AllocatedCondvar {}
unsafe impl Sync for AllocatedCondvar {}

impl LazyInit for AllocatedCondvar {
fn init() -> Box<Self> {
impl AllocatedCondvar {
fn new() -> Box<Self> {
let condvar = Box::new(AllocatedCondvar(UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER)));

cfg_if::cfg_if! {
Expand All @@ -37,7 +31,7 @@ impl LazyInit for AllocatedCondvar {
target_vendor = "apple",
))] {
// `pthread_condattr_setclock` is unfortunately not supported on these platforms.
} else if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
} else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "teeos"))] {
// NOTE: ESP-IDF's PTHREAD_COND_INITIALIZER support is not released yet
// So on that platform, init() should always be called
// Moreover, that platform does not have pthread_condattr_setclock support,
Expand Down Expand Up @@ -82,7 +76,11 @@ impl Drop for AllocatedCondvar {

impl Condvar {
pub const fn new() -> Condvar {
Condvar { inner: LazyBox::new(), mutex: AtomicPtr::new(ptr::null_mut()) }
Condvar { inner: OnceBox::new(), mutex: AtomicPtr::new(ptr::null_mut()) }
}

fn get(&self) -> *mut libc::pthread_cond_t {
self.inner.get_or_init(AllocatedCondvar::new).0.get()
}

#[inline]
Expand All @@ -98,21 +96,21 @@ impl Condvar {

#[inline]
pub fn notify_one(&self) {
let r = unsafe { libc::pthread_cond_signal(raw(self)) };
let r = unsafe { libc::pthread_cond_signal(self.get()) };
debug_assert_eq!(r, 0);
}

#[inline]
pub fn notify_all(&self) {
let r = unsafe { libc::pthread_cond_broadcast(raw(self)) };
let r = unsafe { libc::pthread_cond_broadcast(self.get()) };
debug_assert_eq!(r, 0);
}

#[inline]
pub unsafe fn wait(&self, mutex: &Mutex) {
let mutex = mutex::raw(mutex);
let mutex = mutex.get_assert_locked();
self.verify(mutex);
let r = libc::pthread_cond_wait(raw(self), mutex);
let r = libc::pthread_cond_wait(self.get(), mutex);
debug_assert_eq!(r, 0);
}

Expand All @@ -129,7 +127,7 @@ impl Condvar {
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
use crate::sys::time::Timespec;

let mutex = mutex::raw(mutex);
let mutex = mutex.get_assert_locked();
self.verify(mutex);

#[cfg(not(target_os = "nto"))]
Expand All @@ -144,7 +142,7 @@ impl Condvar {
.and_then(|t| t.to_timespec_capped())
.unwrap_or(TIMESPEC_MAX_CAPPED);

let r = libc::pthread_cond_timedwait(raw(self), mutex, &timeout);
let r = libc::pthread_cond_timedwait(self.get(), mutex, &timeout);
assert!(r == libc::ETIMEDOUT || r == 0);
r == 0
}
Expand All @@ -162,7 +160,7 @@ impl Condvar {
use crate::sys::time::SystemTime;
use crate::time::Instant;

let mutex = mutex::raw(mutex);
let mutex = mutex.get_assert_locked();
self.verify(mutex);

// OSX implementation of `pthread_cond_timedwait` is buggy
Expand All @@ -188,7 +186,7 @@ impl Condvar {
.and_then(|t| t.to_timespec())
.unwrap_or(TIMESPEC_MAX);

let r = libc::pthread_cond_timedwait(raw(self), mutex, &timeout);
let r = libc::pthread_cond_timedwait(self.get(), mutex, &timeout);
debug_assert!(r == libc::ETIMEDOUT || r == 0);

// ETIMEDOUT is not a totally reliable method of determining timeout due
Expand Down
Loading

0 comments on commit f559d61

Please sign in to comment.