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_maybe_uninit_assume_init #86722

Open
2 tasks done
usbalbin opened this issue Jun 29, 2021 · 17 comments
Open
2 tasks done

Tracking Issue for const_maybe_uninit_assume_init #86722

usbalbin opened this issue Jun 29, 2021 · 17 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. 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 29, 2021

Feature gate: #![feature(const_maybe_uninit_assume_init)]

This is a tracking issue for turning the methods assume_init, assume_init_ref, assume_init_mut, slice_assume_init_ref, slice_assume_init_mut of MaybeUninit into const fns. Note that the implementation of the latter two slice related methods are currently behind maybe_uninit_slice #63569, while the constness is behind const_maybe_uninit_assume_init.

Public API

impl<T> MaybeUninit<T> {
    pub const unsafe fn assume_init(self) -> T;
    pub const unsafe fn assume_init_ref(&self) -> &T;
    pub const unsafe fn assume_init_mut(&mut self) -> &mut T;
}

// These function impls are behind `maybe_uninit_slice` while the constnes is `const_maybe_uninit_assume_init` (this issue)
impl<T> MaybeUninit<T> {
    pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T];
    pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T];
}

Steps / History

Unresolved Questions

  • None yet.
@usbalbin usbalbin added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 29, 2021
@jhpratt
Copy link
Member

jhpratt commented Sep 28, 2021

@RalfJung @oli-obk there should be no issues stabilizing this, correct? I'm going through some things that can be stabilized as const and this seems like it would fall logically from the const union PR that has already been merged.

I was planning to stabilize assume_init and assume_init_ref, as assume_init_mut would be blocked on const mut refs with the two slice methods being unstable in general (the immutable one could have its rustc_const_unstable annotation removed, though).

@oli-obk
Copy link
Contributor

oli-obk commented Sep 28, 2021

we haven't stabilized transmute yet, all that is blocked on me finishing rust-lang/nomicon#221, then we can start the stabilization wave for unsafe const stuff

@jhpratt
Copy link
Member

jhpratt commented Sep 28, 2021

Was that not #85769?

@oli-obk
Copy link
Contributor

oli-obk commented Sep 28, 2021

🤦 I am completely lost at the moment on what is stabilized and what is not... I really need to update the skill tree...

Yea, those are trivial to replicate in bad ways on stable then... so we should stabilize them

@jhpratt
Copy link
Member

jhpratt commented Sep 29, 2021

It looks like a number of methods rely on dereferencing a raw pointer or reading one, all of which we don't want at compile-time for the time being due to some uncertainty, correct? If this is permissible, just say so and I can include them.

The one method that can clearly be stabilized without issue is assume_init (with array_assume_init being able to be stabilized with the method itself).

@oli-obk
Copy link
Contributor

oli-obk commented Sep 29, 2021

We should stabilize raw pointer deref, otherwise ppl will start transmuting raw pointers to references and dereferencing those

@jhpratt
Copy link
Member

jhpratt commented Sep 29, 2021

Just sent Ralf a PM on Zulip asking him to check this out. I recall him having an objection to something of the sort when stabilizing const transmutes — I believe we initially wanted a lint.

@RalfJung
Copy link
Member

Yeah there was the idea of having a lint against ptr-to-int transmutes.

My only concern with raw pointers is how and where to document that type-punning loads (i.e., raw-ptr-based transmutes) of pointers to integers are considered UB during CTFE.

@jhpratt
Copy link
Member

jhpratt commented Sep 30, 2021

So raw pointer deref could be stabilized, correct? Dereferencing raw pointers is unsafe to begin with, so documenting that shouldn't be an issue.

@RalfJung
Copy link
Member

so documenting that shouldn't be an issue.

Where would you put that documentation though? And would anyone actually read it?^^

But, yeah, just from an implementation perspective I can't think of any reason how raw ptr deref could screw us now that we have stabilized transmutes and union field accesses.

@jhpratt
Copy link
Member

jhpratt commented Sep 30, 2021

I removed bit of my comment that because I realized it was orthogonal to this issue. Sounds good though 👍

@KamilaBorowska
Copy link
Contributor

Is there anything blocking stabilization of const MaybeUninit::assume_init and const MaybeUninit::assume_init_ref at this point?

@jhpratt
Copy link
Member

jhpratt commented Nov 22, 2021

It's in FCP right now!

@KamilaBorowska
Copy link
Contributor

Oh, didn't realize the FCP is going on in #90896.

@workingjubilee workingjubilee added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 19, 2024
@workingjubilee
Copy link
Member

workingjubilee commented Sep 19, 2024

We have the option of const-stabilizing assume_init_mut: #86722

@dtolnay
Copy link
Member

dtolnay commented Sep 19, 2024

@rfcbot fcp merge

assume_init and assume_init_ref were const-stabilized already by #90896.

This FCP proposes const-stabilizing assume_init_mut, which has been unblocked by #129195.

Further, it proposes moving the const-stability of slice_assume_init_ref and slice_assume_init_mut, which are still unstable, out of this tracking issue over to those functions' main tracking issue, and this one can be closed. When or if these functions get stabilized in the future, they can be const-stabilized at the same time.

@rfcbot
Copy link

rfcbot commented Sep 19, 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 19, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants