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

Tracking Issue for const_ptr_write #86302

Closed
7 of 9 tasks
usbalbin opened this issue Jun 14, 2021 · 14 comments · Fixed by #130954
Closed
7 of 9 tasks

Tracking Issue for const_ptr_write #86302

usbalbin opened this issue Jun 14, 2021 · 14 comments · Fixed by #130954
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@usbalbin
Copy link
Contributor

usbalbin commented Jun 14, 2021

Feature gate: #![feature(const_ptr_write)]

This is a tracking issue for making the functions ptr::write and ptr::write_unaligned, and the same methods on *mut T, const fn.

Public API

mod ptr {
    pub const unsafe fn write<T>(dst: *mut T, src: T);
    pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T);
    pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
}

impl<T> *mut T {
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_unaligned(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_unaligned(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
}

Steps / History

Related

Unresolved Questions

  • None yet.
@usbalbin usbalbin added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 14, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 23, 2021
Make `intrinsics::write_bytes` const

This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`.

Tracking issue: rust-lang#86302
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 11, 2021
Make `intrinsics::write_bytes` const

This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`.

Tracking issue: rust-lang#86302
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 11, 2021
Make `intrinsics::write_bytes` const

This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`.

Tracking issue: rust-lang#86302
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 12, 2021
…i-obk

Make `(*mut T)::write_bytes` `const`

Tracking issue: rust-lang#86302
@lilasta
Copy link
Contributor

lilasta commented Dec 13, 2021

core::intrinsics::write_bytes and (*mut T)::write_bytes have been constified: #90081 #91824

@SUPERCILEX
Copy link
Contributor

How does one initiate the FCP? Or are there any blockers?

@c410-f3r
Copy link
Contributor

AFAICT, there are no blockers so this feature can probably be stabilized.

@RalfJung
Copy link
Member

RalfJung commented Nov 10, 2023

How does stabilizing this help? You can't create mutable pointers in const on stable anyway...

@RalfJung
Copy link
Member

IOW, this is blocked on #57349 getting stabilized first.

@wyfo
Copy link

wyfo commented Aug 17, 2024

How does stabilizing this help? You can't create mutable pointers in const on stable anyway...

It seems you can with UnsafeCell::raw_get.

@RalfJung
Copy link
Member

Oh fun, another accidental stabilization...

Well, #57349 should be stable soon, so it's not worth de-stabilizing like we did with #80697.

@RalfJung
Copy link
Member

RalfJung commented Sep 4, 2024

@rust-lang/libs-api with #129195 in FCP, I'd like to get the ball rolling for stabilizing this feature as well, so that it can be released together with const_mut_refs. After all, what good is a mutable raw pointer if you cannot .write() it? Okay, you can use *ptr = ...;, and in const context we don't allow Drop types, so this can't cause destructor problems... but still, these functions seem like basic functionality to go with "you can have mutable pointers and references now", so would be nice to ship them all in one package.

So, can we get a t-libs-api FCP started for this? :)

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 4, 2024
@rfcbot
Copy link

rfcbot commented Sep 4, 2024

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 4, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 4, 2024
@RalfJung
Copy link
Member

@Amanieu @BurntSushi @joshtriplett @m-ou-se this proposes to stabilize some very basic *mut T operations that would be nice to ship together with the const_mut_refs stabilization. Given that these have been stable outside const since forever, it should be entirely uncontroversial. :)

@RalfJung
Copy link
Member

FYI, turns out there are three more functions under this feature gate -- NonNull has the exact same set of functions as *mut.

impl <T> NonNull<T> {
    pub const unsafe fn write(self, val: T);
    pub const unsafe fn write_unaligned(self, val: T);
    pub const unsafe fn write_bytes(self, val: u8, count: usize);
}

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 24, 2024
@rfcbot
Copy link

rfcbot commented Sep 24, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 4, 2024
@rfcbot
Copy link

rfcbot commented Oct 4, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Oct 4, 2024
tgross35 added a commit to tgross35/rust that referenced this issue Oct 12, 2024
…-fn, r=RalfJung

Stabilize const `ptr::write*` and `mem::replace`

Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we may now also stabilize the ability to write to places during const evaluation inside our library API. So, we now propose the `const fn` version of `ptr::write` and its variants. This allows us to also stabilize `mem::replace` and `ptr::replace`.
- const `mem::replace`: rust-lang#83164 (comment)
- const `ptr::write{,_bytes,_unaligned}`: rust-lang#86302 (comment)

Their implementation requires an additional internal stabilization of `const_intrinsic_forget`, which is required for `*::write*` and thus `*::replace`. Thus we const-stabilize the internal intrinsics `forget`, `write_bytes`, and `write_via_move`.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 12, 2024
Rollup merge of rust-lang#130954 - workingjubilee:stabilize-const-mut-fn, r=RalfJung

Stabilize const `ptr::write*` and `mem::replace`

Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we may now also stabilize the ability to write to places during const evaluation inside our library API. So, we now propose the `const fn` version of `ptr::write` and its variants. This allows us to also stabilize `mem::replace` and `ptr::replace`.
- const `mem::replace`: rust-lang#83164 (comment)
- const `ptr::write{,_bytes,_unaligned}`: rust-lang#86302 (comment)

Their implementation requires an additional internal stabilization of `const_intrinsic_forget`, which is required for `*::write*` and thus `*::replace`. Thus we const-stabilize the internal intrinsics `forget`, `write_bytes`, and `write_via_move`.
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants