Skip to content

Commit

Permalink
Merge #877
Browse files Browse the repository at this point in the history
877: Bump MSRV to Rust 1.38 r=taiki-e a=taiki-e

It was released [nearly 3 years ago](https://blog.rust-lang.org/2019/09/26/Rust-1.38.0.html) and meets our MSRV policy.

This allows using const_in_array_repeat_expressions (rust-lang/rust#49147) and `<pointer>.cast()`.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Jul 22, 2022
2 parents 99b14b1 + 6ac1232 commit c059aec
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .clippy.toml
@@ -1 +1 @@
msrv = "1.36"
msrv = "1.38"
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -30,9 +30,9 @@ jobs:
fail-fast: false
matrix:
include:
- rust: 1.36.0
- rust: '1.38'
os: ubuntu-latest
- rust: 1.36.0
- rust: '1.38'
os: windows-latest
- rust: stable
os: ubuntu-latest
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
fail-fast: false
matrix:
rust:
- 1.36.0
- '1.38'
- nightly
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -6,7 +6,7 @@ name = "crossbeam"
# - Create "crossbeam-X.Y.Z" git tag
version = "0.8.1"
edition = "2018"
rust-version = "1.36"
rust-version = "1.38"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
homepage = "https://github.com/crossbeam-rs/crossbeam"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam#license)
https://crates.io/crates/crossbeam)
[![Documentation](https://docs.rs/crossbeam/badge.svg)](
https://docs.rs/crossbeam)
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
https://www.rust-lang.org)
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)

Expand Down Expand Up @@ -94,7 +94,7 @@ crossbeam = "0.8"

Crossbeam 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.36.
version is released. Currently, the minimum supported Rust version is 1.38.

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ name = "crossbeam-channel"
# - Create "crossbeam-channel-X.Y.Z" git tag
version = "0.5.5"
edition = "2018"
rust-version = "1.36"
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-channel"
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-channel/README.md
Expand Up @@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#license)
https://crates.io/crates/crossbeam-channel)
[![Documentation](https://docs.rs/crossbeam-channel/badge.svg)](
https://docs.rs/crossbeam-channel)
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
https://www.rust-lang.org)
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)

Expand Down Expand Up @@ -48,7 +48,7 @@ crossbeam-channel = "0.5"

Crossbeam Channel 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.36.
version is released. Currently, the minimum supported Rust version is 1.38.

## License

Expand Down
4 changes: 2 additions & 2 deletions crossbeam-channel/src/flavors/array.rs
Expand Up @@ -216,7 +216,7 @@ impl<T> Channel<T> {
return Err(msg);
}

let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();

// Write the message into the slot and update the stamp.
slot.msg.get().write(MaybeUninit::new(msg));
Expand Down Expand Up @@ -307,7 +307,7 @@ impl<T> Channel<T> {
return Err(());
}

let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();

// Read the message from the slot and update the stamp.
let msg = slot.msg.get().read().assume_init();
Expand Down
18 changes: 10 additions & 8 deletions crossbeam-channel/src/flavors/list.rs
Expand Up @@ -49,6 +49,11 @@ struct Slot<T> {
}

impl<T> Slot<T> {
const UNINIT: Self = Self {
msg: UnsafeCell::new(MaybeUninit::uninit()),
state: AtomicUsize::new(0),
};

/// Waits until a message is written into the slot.
fn wait_write(&self) {
let backoff = Backoff::new();
Expand All @@ -72,13 +77,10 @@ struct Block<T> {
impl<T> Block<T> {
/// Creates an empty block.
fn new() -> Block<T> {
// SAFETY: This is safe because:
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
// [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4].
// [3] `Slot::msg` (UnsafeCell) may be safely zero initialized because it
// holds a MaybeUninit.
// [4] `Slot::state` (AtomicUsize) may be safely zero initialized.
unsafe { MaybeUninit::zeroed().assume_init() }
Self {
next: AtomicPtr::new(ptr::null_mut()),
slots: [Slot::UNINIT; BLOCK_CAP],
}
}

/// Waits until the next pointer is set.
Expand Down Expand Up @@ -283,7 +285,7 @@ impl<T> Channel<T> {
}

// Write the message into the slot.
let block = token.list.block as *mut Block<T>;
let block = token.list.block.cast::<Block<T>>();
let offset = token.list.offset;
let slot = (*block).slots.get_unchecked(offset);
slot.msg.get().write(MaybeUninit::new(msg));
Expand Down
10 changes: 5 additions & 5 deletions crossbeam-channel/src/flavors/zero.rs
Expand Up @@ -190,7 +190,7 @@ impl<T> Channel<T> {
// heap-allocated packet.
packet.wait_ready();
let msg = packet.msg.get().replace(None).unwrap();
drop(Box::from_raw(token.zero.0 as *mut Packet<T>));
drop(Box::from_raw(token.zero.0.cast::<Packet<T>>()));
Ok(msg)
}
}
Expand Down Expand Up @@ -409,15 +409,15 @@ impl<T> SelectHandle for Receiver<'_, T> {
let mut inner = self.0.inner.lock().unwrap();
inner
.receivers
.register_with_packet(oper, packet as *mut (), cx);
.register_with_packet(oper, packet.cast::<()>(), cx);
inner.senders.notify();
inner.senders.can_select() || inner.is_disconnected
}

fn unregister(&self, oper: Operation) {
if let Some(operation) = self.0.inner.lock().unwrap().receivers.unregister(oper) {
unsafe {
drop(Box::from_raw(operation.packet as *mut Packet<T>));
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
}
}
}
Expand Down Expand Up @@ -459,15 +459,15 @@ impl<T> SelectHandle for Sender<'_, T> {
let mut inner = self.0.inner.lock().unwrap();
inner
.senders
.register_with_packet(oper, packet as *mut (), cx);
.register_with_packet(oper, packet.cast::<()>(), cx);
inner.receivers.notify();
inner.receivers.can_select() || inner.is_disconnected
}

fn unregister(&self, oper: Operation) {
if let Some(operation) = self.0.inner.lock().unwrap().senders.unregister(oper) {
unsafe {
drop(Box::from_raw(operation.packet as *mut Packet<T>));
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-deque/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ name = "crossbeam-deque"
# - Create "crossbeam-deque-X.Y.Z" git tag
version = "0.8.1"
edition = "2018"
rust-version = "1.36"
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-deque"
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-deque/README.md
Expand Up @@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-deque#license)
https://crates.io/crates/crossbeam-deque)
[![Documentation](https://docs.rs/crossbeam-deque/badge.svg)](
https://docs.rs/crossbeam-deque)
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
https://www.rust-lang.org)
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)

Expand All @@ -28,7 +28,7 @@ crossbeam-deque = "0.8"

Crossbeam Deque 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.36.
version is released. Currently, the minimum supported Rust version is 1.38.

## License

Expand Down
20 changes: 11 additions & 9 deletions crossbeam-deque/src/deque.rs
Expand Up @@ -64,7 +64,7 @@ impl<T> Buffer<T> {
/// that would be more expensive and difficult to implement generically for all types `T`.
/// Hence, as a hack, we use a volatile write instead.
unsafe fn write(&self, index: isize, task: MaybeUninit<T>) {
ptr::write_volatile(self.at(index) as *mut MaybeUninit<T>, task)
ptr::write_volatile(self.at(index).cast::<MaybeUninit<T>>(), task)
}

/// Reads a task from the specified `index`.
Expand All @@ -74,7 +74,7 @@ impl<T> Buffer<T> {
/// that would be more expensive and difficult to implement generically for all types `T`.
/// Hence, as a hack, we use a volatile load instead.
unsafe fn read(&self, index: isize) -> MaybeUninit<T> {
ptr::read_volatile(self.at(index) as *mut MaybeUninit<T>)
ptr::read_volatile(self.at(index).cast::<MaybeUninit<T>>())
}
}

Expand Down Expand Up @@ -1119,6 +1119,11 @@ struct Slot<T> {
}

impl<T> Slot<T> {
const UNINIT: Self = Self {
task: UnsafeCell::new(MaybeUninit::uninit()),
state: AtomicUsize::new(0),
};

/// Waits until a task is written into the slot.
fn wait_write(&self) {
let backoff = Backoff::new();
Expand All @@ -1142,13 +1147,10 @@ struct Block<T> {
impl<T> Block<T> {
/// Creates an empty block that starts at `start_index`.
fn new() -> Block<T> {
// SAFETY: This is safe because:
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
// [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4].
// [3] `Slot::task` (UnsafeCell) may be safely zero initialized because it
// holds a MaybeUninit.
// [4] `Slot::state` (AtomicUsize) may be safely zero initialized.
unsafe { MaybeUninit::zeroed().assume_init() }
Self {
next: AtomicPtr::new(ptr::null_mut()),
slots: [Slot::UNINIT; BLOCK_CAP],
}
}

/// Waits until the next pointer is set.
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ name = "crossbeam-epoch"
# - Create "crossbeam-epoch-X.Y.Z" git tag
version = "0.9.9"
edition = "2018"
rust-version = "1.36"
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-epoch"
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-epoch/README.md
Expand Up @@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch#license)
https://crates.io/crates/crossbeam-epoch)
[![Documentation](https://docs.rs/crossbeam-epoch/badge.svg)](
https://docs.rs/crossbeam-epoch)
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
https://www.rust-lang.org)
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)

Expand All @@ -35,7 +35,7 @@ crossbeam-epoch = "0.9"

Crossbeam Epoch 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.36.
version is released. Currently, the minimum supported Rust version is 1.38.

## License

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/src/atomic.rs
Expand Up @@ -252,7 +252,7 @@ impl<T> Pointable for [MaybeUninit<T>] {
let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * len;
let align = mem::align_of::<Array<T>>();
let layout = alloc::Layout::from_size_align(size, align).unwrap();
let ptr = alloc::alloc(layout) as *mut Array<T>;
let ptr = alloc::alloc(layout).cast::<Array<T>>();
if ptr.is_null() {
alloc::handle_alloc_error(layout);
}
Expand Down
19 changes: 14 additions & 5 deletions crossbeam-epoch/src/deferred.rs
Expand Up @@ -29,6 +29,15 @@ impl fmt::Debug for Deferred {
}

impl Deferred {
pub(crate) const NO_OP: Self = {
fn no_op_call(_raw: *mut u8) {}
Self {
call: no_op_call,
data: MaybeUninit::uninit(),
_marker: PhantomData,
}
};

/// Constructs a new `Deferred` from a `FnOnce()`.
pub(crate) fn new<F: FnOnce()>(f: F) -> Self {
let size = mem::size_of::<F>();
Expand All @@ -37,10 +46,10 @@ impl Deferred {
unsafe {
if size <= mem::size_of::<Data>() && align <= mem::align_of::<Data>() {
let mut data = MaybeUninit::<Data>::uninit();
ptr::write(data.as_mut_ptr() as *mut F, f);
ptr::write(data.as_mut_ptr().cast::<F>(), f);

unsafe fn call<F: FnOnce()>(raw: *mut u8) {
let f: F = ptr::read(raw as *mut F);
let f: F = ptr::read(raw.cast::<F>());
f();
}

Expand All @@ -52,12 +61,12 @@ impl Deferred {
} else {
let b: Box<F> = Box::new(f);
let mut data = MaybeUninit::<Data>::uninit();
ptr::write(data.as_mut_ptr() as *mut Box<F>, b);
ptr::write(data.as_mut_ptr().cast::<Box<F>>(), b);

unsafe fn call<F: FnOnce()>(raw: *mut u8) {
// It's safe to cast `raw` from `*mut u8` to `*mut Box<F>`, because `raw` is
// originally derived from `*mut Box<F>`.
let b: Box<F> = ptr::read(raw as *mut Box<F>);
let b: Box<F> = ptr::read(raw.cast::<Box<F>>());
(*b)();
}

Expand All @@ -74,7 +83,7 @@ impl Deferred {
#[inline]
pub(crate) fn call(mut self) {
let call = self.call;
unsafe { call(self.data.as_mut_ptr() as *mut u8) };
unsafe { call(self.data.as_mut_ptr().cast::<u8>()) };
}
}

Expand Down

0 comments on commit c059aec

Please sign in to comment.