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

Stabilize non_null_convenience #124498

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Apr 28, 2024

Fully stabilize the following API, including const where applicable:

impl <T> NonNull<T> {
    pub const unsafe fn offset(self, count: isize) -> Self;
    pub const unsafe fn add(self, count: usize) -> Self;
    pub const unsafe fn sub(self, count: usize) -> Self;
    pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
    pub const unsafe fn read(self) -> T;
    pub unsafe fn read_volatile(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
    pub unsafe fn write_volatile(self, val: T);
    pub unsafe fn replace(self, src: T) -> T;
}

impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn byte_offset(self, count: isize) -> Self;
    pub const unsafe fn byte_add(self, count: usize) -> Self;
    pub const unsafe fn byte_sub(self, count: usize) -> Self;
    pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;
    pub unsafe fn drop_in_place(self);
}

Stabilize the following without const:

impl <T> NonNull<T> {
    // const under `const_intrinsic_copy`
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);

    // const under `const_ptr_write`
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
    pub const unsafe fn write_unaligned(self, val: T);

    // const under `const_swap`
    pub const unsafe fn swap(self, with: NonNull<T>);

    // const under `const_align_offset`
    pub const fn align_offset(self, align: usize) -> usize;

    // const under `const_pointer_is_aligned`
    pub const fn is_aligned(self) -> bool;
}

Left the following unstable:

impl <T> NonNull<T> {
    // moved gate to `ptr_sub_ptr`
    pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;
}

impl <T: ?Sized> NonNull<T> {
    // moved gate to `pointer_is_aligned_to`
    pub const fn is_aligned_to(self, align: usize) -> bool;
}

Fixes: #117691

@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2024

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2024
@tgross35
Copy link
Contributor Author

FCP complete at #117691 (comment)

@rustbot label -T-libs +T-libs-api

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2024
Fully stabilize the following API, including const where applicable:

    impl <T> NonNull<T> {
        pub const unsafe fn offset(self, count: isize) -> Self;
        pub const unsafe fn add(self, count: usize) -> Self;
        pub const unsafe fn sub(self, count: usize) -> Self;
        pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
        pub const unsafe fn read(self) -> T;
        pub unsafe fn read_volatile(self) -> T;
        pub const unsafe fn read_unaligned(self) -> T;
        pub unsafe fn write_volatile(self, val: T);
        pub unsafe fn replace(self, src: T) -> T;
    }

    impl<T: ?Sized> NonNull<T> {
        pub const unsafe fn byte_offset(self, count: isize) -> Self;
        pub const unsafe fn byte_add(self, count: usize) -> Self;
        pub const unsafe fn byte_sub(self, count: usize) -> Self;
        pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;
        pub unsafe fn drop_in_place(self);
    }

Stabilize the following without const:

    impl <T> NonNull<T> {
        // const under `const_intrinsic_copy`
        pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
        pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);
        pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
        pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);

        // const under `const_ptr_write`
        pub const unsafe fn write(self, val: T);
        pub const unsafe fn write_bytes(self, val: u8, count: usize);
        pub const unsafe fn write_unaligned(self, val: T);

        // const under `const_swap`
        pub const unsafe fn swap(self, with: NonNull<T>);

        // const under `const_align_offset`
        pub const fn align_offset(self, align: usize) -> usize;

        // const under `const_pointer_is_aligned`
        pub const fn is_aligned(self) -> bool;
    }

Left the following unstable:

    impl <T> NonNull<T> {
        // moved gate to `ptr_sub_ptr`
        pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;
    }

    impl <T: ?Sized> NonNull<T> {
        // moved gate to `pointer_is_aligned_to`
        pub const fn is_aligned_to(self, align: usize) -> bool;
    }

Fixes: rust-lang#117691
@tgross35 tgross35 force-pushed the stabilize-non_null_convenience branch from f971153 to e0f8202 Compare April 28, 2024 21:20
@jhpratt
Copy link
Member

jhpratt commented Apr 28, 2024

@rustbot claim

@bors r+

@bors
Copy link
Contributor

bors commented Apr 28, 2024

📌 Commit e0f8202 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2024
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 28, 2024
@tgross35
Copy link
Contributor Author

Thanks!

@jhpratt
Copy link
Member

jhpratt commented Apr 28, 2024

Library stabilizations are simple enough, so I figured why not review when I saw the email 😄

Comment on lines +1379 to +1380
#[inline]
#[must_use]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a preferred attribute order? I'm never sure which order people prefer, if anyone even cares. If there is preference, I'd prefer to have a tool to make it happen.

Copy link
Contributor Author

@tgross35 tgross35 Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever I touch functions I sort them from smallest to largest (exception being rustc_stable always before rustc_const_stable), which does seem a bit silly but looks nice IMO. Looking through libs, I think this is somewhat common?

Didn't actually mean to change these here since they're not related to the stabilization, but it doesn't hurt anything.

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2024
…nce, r=jhpratt

Stabilize `non_null_convenience`

Fully stabilize the following API, including const where applicable:

```rust
impl <T> NonNull<T> {
    pub const unsafe fn offset(self, count: isize) -> Self;
    pub const unsafe fn add(self, count: usize) -> Self;
    pub const unsafe fn sub(self, count: usize) -> Self;
    pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize;
    pub const unsafe fn read(self) -> T;
    pub unsafe fn read_volatile(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
    pub unsafe fn write_volatile(self, val: T);
    pub unsafe fn replace(self, src: T) -> T;
}

impl<T: ?Sized> NonNull<T> {
    pub const unsafe fn byte_offset(self, count: isize) -> Self;
    pub const unsafe fn byte_add(self, count: usize) -> Self;
    pub const unsafe fn byte_sub(self, count: usize) -> Self;
    pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize;
    pub unsafe fn drop_in_place(self);
}
```

Stabilize the following without const:

```rust
impl <T> NonNull<T> {
    // const under `const_intrinsic_copy`
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);

    // const under `const_ptr_write`
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
    pub const unsafe fn write_unaligned(self, val: T);

    // const under `const_swap`
    pub const unsafe fn swap(self, with: NonNull<T>);

    // const under `const_align_offset`
    pub const fn align_offset(self, align: usize) -> usize;

    // const under `const_pointer_is_aligned`
    pub const fn is_aligned(self) -> bool;
}
```

Left the following unstable:

```rust
impl <T> NonNull<T> {
    // moved gate to `ptr_sub_ptr`
    pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize;
}

impl <T: ?Sized> NonNull<T> {
    // moved gate to `pointer_is_aligned_to`
    pub const fn is_aligned_to(self, align: usize) -> bool;
}
```

Fixes: rust-lang#117691
@bors
Copy link
Contributor

bors commented Apr 28, 2024

⌛ Testing commit e0f8202 with merge c99bba3...

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_ast_lowering test:false 68.517
   Compiling rustc_hir_analysis v0.0.0 (/checkout/compiler/rustc_hir_analysis)
[RUSTC-TIMING] rustc_metadata test:false 69.715
   Compiling rustc_ty_utils v0.0.0 (/checkout/compiler/rustc_ty_utils)
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.

Session terminated, killing shell...::group::Clock drift check
  network time:  ...killed.
##[error]The operation was canceled.
Cleaning up orphan processes

@bors
Copy link
Contributor

bors commented Apr 29, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 29, 2024
@jhpratt
Copy link
Member

jhpratt commented Apr 29, 2024

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2024
@bors
Copy link
Contributor

bors commented Apr 29, 2024

⌛ Testing commit e0f8202 with merge 5fe8b69...

@bors
Copy link
Contributor

bors commented Apr 29, 2024

☀️ Test successful - checks-actions
Approved by: jhpratt
Pushing 5fe8b69 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 29, 2024
@bors bors merged commit 5fe8b69 into rust-lang:master Apr 29, 2024
11 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Apr 29, 2024
@tgross35 tgross35 deleted the stabilize-non_null_convenience branch April 29, 2024 02:27
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5fe8b69): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [-0.1%, 1.7%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 674.021s -> 674.79s (0.11%)
Artifact size: 316.00 MiB -> 315.95 MiB (-0.02%)

#[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved a bunch of things under different feature gates, but the corresponding tracking issues (e.g. #95892) have not been updated. Would be good to do that at some point. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I went through and think they should all be updated now.

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Sep 24, 2024
…tolnay

stabilize const_intrinsic_copy

Fixes rust-lang#80697

This stabilizes
```rust
mod ptr {
    pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
    pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

impl *const T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
}

impl *mut T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);

    pub const unsafe fn copy_from(self, src: *const T, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);

    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
}
```
In particular, this reverts rust-lang#117905, which reverted rust-lang#97276.

The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in rust-lang#124498. The existing [FCP](rust-lang#80697 (comment)) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. `@rust-lang/libs-api` please let me know if FCP will be required for the `NonNull` methods.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Sep 24, 2024
…tolnay

stabilize const_intrinsic_copy

Fixes rust-lang#80697

This stabilizes
```rust
mod ptr {
    pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
    pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

impl *const T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
}

impl *mut T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);

    pub const unsafe fn copy_from(self, src: *const T, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);

    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
}
```
In particular, this reverts rust-lang#117905, which reverted rust-lang#97276.

The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in rust-lang#124498. The existing [FCP](rust-lang#80697 (comment)) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. ``@rust-lang/libs-api`` please let me know if FCP will be required for the `NonNull` methods.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 24, 2024
Rollup merge of rust-lang#130762 - RalfJung:const_intrinsic_copy, r=dtolnay

stabilize const_intrinsic_copy

Fixes rust-lang#80697

This stabilizes
```rust
mod ptr {
    pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
    pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

impl *const T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
}

impl *mut T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);

    pub const unsafe fn copy_from(self, src: *const T, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);

    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
}
```
In particular, this reverts rust-lang#117905, which reverted rust-lang#97276.

The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in rust-lang#124498. The existing [FCP](rust-lang#80697 (comment)) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. ``@rust-lang/libs-api`` please let me know if FCP will be required for the `NonNull` methods.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 25, 2024
stabilize const_intrinsic_copy

Fixes rust-lang/rust#80697

This stabilizes
```rust
mod ptr {
    pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
    pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

impl *const T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
}

impl *mut T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);

    pub const unsafe fn copy_from(self, src: *const T, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);

    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
}
```
In particular, this reverts rust-lang/rust#117905, which reverted rust-lang/rust#97276.

The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in rust-lang/rust#124498. The existing [FCP](rust-lang/rust#80697 (comment)) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. ``@rust-lang/libs-api`` please let me know if FCP will be required for the `NonNull` methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for convenience methods on NonNull
9 participants