Skip to content

Commit 10123fb

Browse files
ojedaherrnst
authored andcommitted
*RFL import: rust: upgrade to Rust 1.75.0
This is the next upgrade to the Rust toolchain, from 1.74.1 to 1.75.0 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4 ("rust: upgrade to Rust 1.68.2"). The `const_maybe_uninit_zeroed` unstable feature [3] was stabilized in Rust 1.75.0, which we were using in the PHYLIB abstractions. The only unstable features allowed to be used outside the `kernel` crate are still `new_uninit,offset_of`, though other code to be upstreamed may increase the list. Please see [4] for details. Rust 1.75.0 stabilized `pointer_byte_offsets` [5] which we could potentially use as an alternative for `ptr_metadata` in the future. For this upgrade, no changes were required (i.e. on our side). The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1750-2023-12-28 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: rust-lang/rust#91850 [3] Link: Rust-for-Linux/linux#2 [4] Link: rust-lang/rust#96283 [5] Reviewed-by: Vincenzo Palazzo <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Tested-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 3455a8e commit 10123fb

File tree

8 files changed

+51
-25
lines changed

8 files changed

+51
-25
lines changed

Documentation/process/changes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ you probably needn't concern yourself with pcmciautils.
3131
====================== =============== ========================================
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 11.0.0 clang --version
34-
Rust (optional) 1.74.1 rustc --version
34+
Rust (optional) 1.75.0 rustc --version
3535
bindgen (optional) 0.65.1 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

rust/alloc/alloc.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,20 @@ pub const fn handle_alloc_error(layout: Layout) -> ! {
380380
panic!("allocation failed");
381381
}
382382

383+
#[inline]
383384
fn rt_error(layout: Layout) -> ! {
384385
unsafe {
385386
__rust_alloc_error_handler(layout.size(), layout.align());
386387
}
387388
}
388389

389-
unsafe { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) }
390+
#[cfg(not(feature = "panic_immediate_abort"))]
391+
unsafe {
392+
core::intrinsics::const_eval_select((layout,), ct_error, rt_error)
393+
}
394+
395+
#[cfg(feature = "panic_immediate_abort")]
396+
ct_error(layout)
390397
}
391398

392399
// For alloc test `std::alloc::handle_alloc_error` can be used directly.

rust/alloc/boxed.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ use core::marker::Tuple;
161161
use core::marker::Unsize;
162162
use core::mem::{self, SizedTypeProperties};
163163
use core::ops::{
164-
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
164+
CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DispatchFromDyn, Receiver,
165165
};
166166
use core::pin::Pin;
167167
use core::ptr::{self, NonNull, Unique};
@@ -211,7 +211,7 @@ impl<T> Box<T> {
211211
/// ```
212212
/// let five = Box::new(5);
213213
/// ```
214-
#[cfg(all(not(no_global_oom_handling)))]
214+
#[cfg(not(no_global_oom_handling))]
215215
#[inline(always)]
216216
#[stable(feature = "rust1", since = "1.0.0")]
217217
#[must_use]
@@ -2110,28 +2110,28 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A> {
21102110
#[stable(feature = "pin", since = "1.33.0")]
21112111
impl<T: ?Sized, A: Allocator> Unpin for Box<T, A> where A: 'static {}
21122112

2113-
#[unstable(feature = "generator_trait", issue = "43122")]
2114-
impl<G: ?Sized + Generator<R> + Unpin, R, A: Allocator> Generator<R> for Box<G, A>
2113+
#[unstable(feature = "coroutine_trait", issue = "43122")]
2114+
impl<G: ?Sized + Coroutine<R> + Unpin, R, A: Allocator> Coroutine<R> for Box<G, A>
21152115
where
21162116
A: 'static,
21172117
{
21182118
type Yield = G::Yield;
21192119
type Return = G::Return;
21202120

2121-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
2121+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
21222122
G::resume(Pin::new(&mut *self), arg)
21232123
}
21242124
}
21252125

2126-
#[unstable(feature = "generator_trait", issue = "43122")]
2127-
impl<G: ?Sized + Generator<R>, R, A: Allocator> Generator<R> for Pin<Box<G, A>>
2126+
#[unstable(feature = "coroutine_trait", issue = "43122")]
2127+
impl<G: ?Sized + Coroutine<R>, R, A: Allocator> Coroutine<R> for Pin<Box<G, A>>
21282128
where
21292129
A: 'static,
21302130
{
21312131
type Yield = G::Yield;
21322132
type Return = G::Return;
21332133

2134-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
2134+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
21352135
G::resume((*self).as_mut(), arg)
21362136
}
21372137
}
@@ -2448,4 +2448,8 @@ impl<T: core::error::Error> core::error::Error for Box<T> {
24482448
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
24492449
core::error::Error::source(&**self)
24502450
}
2451+
2452+
fn provide<'b>(&'b self, request: &mut core::error::Request<'b>) {
2453+
core::error::Error::provide(&**self, request);
2454+
}
24512455
}

rust/alloc/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
not(no_sync),
8282
target_has_atomic = "ptr"
8383
))]
84+
#![cfg_attr(not(bootstrap), doc(rust_logo))]
85+
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
8486
#![no_std]
8587
#![needs_allocator]
8688
// Lints:
@@ -117,7 +119,6 @@
117119
#![feature(const_eval_select)]
118120
#![feature(const_maybe_uninit_as_mut_ptr)]
119121
#![feature(const_maybe_uninit_write)]
120-
#![feature(const_maybe_uninit_zeroed)]
121122
#![feature(const_pin)]
122123
#![feature(const_refs_to_cell)]
123124
#![feature(const_size_of_val)]
@@ -143,7 +144,7 @@
143144
#![feature(maybe_uninit_uninit_array)]
144145
#![feature(maybe_uninit_uninit_array_transpose)]
145146
#![feature(pattern)]
146-
#![feature(pointer_byte_offsets)]
147+
#![feature(ptr_addr_eq)]
147148
#![feature(ptr_internals)]
148149
#![feature(ptr_metadata)]
149150
#![feature(ptr_sub_ptr)]
@@ -170,7 +171,7 @@
170171
//
171172
// Language features:
172173
// tidy-alphabetical-start
173-
#![cfg_attr(not(test), feature(generator_trait))]
174+
#![cfg_attr(not(test), feature(coroutine_trait))]
174175
#![cfg_attr(test, feature(panic_update_hook))]
175176
#![cfg_attr(test, feature(test))]
176177
#![feature(allocator_internals)]

rust/alloc/raw_vec.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,13 @@ impl<T, A: Allocator> RawVec<T, A> {
338338
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
339339
pub fn try_reserve(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
340340
if self.needs_to_grow(len, additional) {
341-
self.grow_amortized(len, additional)
342-
} else {
343-
Ok(())
341+
self.grow_amortized(len, additional)?;
342+
}
343+
unsafe {
344+
// Inform the optimizer that the reservation has succeeded or wasn't needed
345+
core::intrinsics::assume(!self.needs_to_grow(len, additional));
344346
}
347+
Ok(())
345348
}
346349

347350
/// The same as `reserve_for_push`, but returns on errors instead of panicking or aborting.
@@ -378,7 +381,14 @@ impl<T, A: Allocator> RawVec<T, A> {
378381
len: usize,
379382
additional: usize,
380383
) -> Result<(), TryReserveError> {
381-
if self.needs_to_grow(len, additional) { self.grow_exact(len, additional) } else { Ok(()) }
384+
if self.needs_to_grow(len, additional) {
385+
self.grow_exact(len, additional)?;
386+
}
387+
unsafe {
388+
// Inform the optimizer that the reservation has succeeded or wasn't needed
389+
core::intrinsics::assume(!self.needs_to_grow(len, additional));
390+
}
391+
Ok(())
382392
}
383393

384394
/// Shrinks the buffer down to the specified capacity. If the given amount
@@ -569,6 +579,7 @@ fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
569579
// ensure that the code generation related to these panics is minimal as there's
570580
// only one location which panics rather than a bunch throughout the module.
571581
#[cfg(not(no_global_oom_handling))]
582+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
572583
fn capacity_overflow() -> ! {
573584
panic!("capacity overflow");
574585
}

rust/alloc/vec/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ impl<T, A: Allocator> Vec<T, A> {
13761376
/// [`as_mut_ptr`]: Vec::as_mut_ptr
13771377
/// [`as_ptr`]: Vec::as_ptr
13781378
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
1379-
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
1379+
#[rustc_never_returns_null_ptr]
13801380
#[inline]
13811381
pub fn as_ptr(&self) -> *const T {
13821382
// We shadow the slice method of the same name to avoid going through
@@ -1436,7 +1436,7 @@ impl<T, A: Allocator> Vec<T, A> {
14361436
/// [`as_mut_ptr`]: Vec::as_mut_ptr
14371437
/// [`as_ptr`]: Vec::as_ptr
14381438
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
1439-
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
1439+
#[rustc_never_returns_null_ptr]
14401440
#[inline]
14411441
pub fn as_mut_ptr(&mut self) -> *mut T {
14421442
// We shadow the slice method of the same name to avoid going through
@@ -1565,7 +1565,8 @@ impl<T, A: Allocator> Vec<T, A> {
15651565
#[stable(feature = "rust1", since = "1.0.0")]
15661566
pub fn swap_remove(&mut self, index: usize) -> T {
15671567
#[cold]
1568-
#[inline(never)]
1568+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
1569+
#[track_caller]
15691570
fn assert_failed(index: usize, len: usize) -> ! {
15701571
panic!("swap_remove index (is {index}) should be < len (is {len})");
15711572
}
@@ -1606,7 +1607,8 @@ impl<T, A: Allocator> Vec<T, A> {
16061607
#[stable(feature = "rust1", since = "1.0.0")]
16071608
pub fn insert(&mut self, index: usize, element: T) {
16081609
#[cold]
1609-
#[inline(never)]
1610+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
1611+
#[track_caller]
16101612
fn assert_failed(index: usize, len: usize) -> ! {
16111613
panic!("insertion index (is {index}) should be <= len (is {len})");
16121614
}
@@ -1667,7 +1669,7 @@ impl<T, A: Allocator> Vec<T, A> {
16671669
#[track_caller]
16681670
pub fn remove(&mut self, index: usize) -> T {
16691671
#[cold]
1670-
#[inline(never)]
1672+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
16711673
#[track_caller]
16721674
fn assert_failed(index: usize, len: usize) -> ! {
16731675
panic!("removal index (is {index}) should be < len (is {len})");
@@ -2097,6 +2099,7 @@ impl<T, A: Allocator> Vec<T, A> {
20972099
} else {
20982100
unsafe {
20992101
self.len -= 1;
2102+
core::intrinsics::assume(self.len < self.capacity());
21002103
Some(ptr::read(self.as_ptr().add(self.len())))
21012104
}
21022105
}
@@ -2299,7 +2302,8 @@ impl<T, A: Allocator> Vec<T, A> {
22992302
A: Clone,
23002303
{
23012304
#[cold]
2302-
#[inline(never)]
2305+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
2306+
#[track_caller]
23032307
fn assert_failed(at: usize, len: usize) -> ! {
23042308
panic!("`at` split index (is {at}) should be <= len (is {len})");
23052309
}

rust/kernel/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(allocator_api)]
1616
#![feature(associated_type_defaults)]
1717
#![feature(coerce_unsized)]
18-
#![feature(const_maybe_uninit_zeroed)]
1918
#![feature(const_mut_refs)]
2019
#![feature(const_refs_to_cell)]
2120
#![feature(dispatch_from_dyn)]

scripts/min-tool-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ llvm)
3333
fi
3434
;;
3535
rustc)
36-
echo 1.74.1
36+
echo 1.75.0
3737
;;
3838
bindgen)
3939
echo 0.65.1

0 commit comments

Comments
 (0)