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_cell #131283

Open
1 of 3 tasks
RalfJung opened this issue Oct 5, 2024 · 6 comments · May be fixed by #137928
Open
1 of 3 tasks

Tracking Issue for const_cell #131283

RalfJung opened this issue Oct 5, 2024 · 6 comments · May be fixed by #137928
Labels
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.

Comments

@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2024

Feature gate: #![feature(const_cell)]

This is a tracking issue for using Cell in a const context.

Public API

// core::cell

impl<T> Cell<T> {
    pub const fn replace(&self, val: T) -> T;
}

impl<T: Copy> Cell<T> {
    pub const fn get(&self) -> T;
}

impl<T: ?Sized> Cell<T> {
    pub const fn get_mut(&mut self) -> &mut T;
    pub const fn from_mut(t: &mut T) -> &Cell<T>;
}

impl<T> Cell<[T]> {
    pub const fn as_slice_of_cells(&self) -> &[Cell<T>];
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@RalfJung RalfJung 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 Oct 5, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 5, 2024
make Cell unstably const

Now that we can do interior mutability in `const`, most of the Cell API can be `const fn`. :)  The main exception is `set`, because it drops the old value. So from const context one has to use `replace`, which delegates the responsibility for dropping to the caller.

Tracking issue: rust-lang#131283

`as_array_of_cells` is itself still unstable to I added the const-ness to the feature gate for that function and not to `const_cell`, Cc rust-lang#88248.

r? libs-api
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 5, 2024
Rollup merge of rust-lang#131281 - RalfJung:const-cell, r=Amanieu

make Cell unstably const

Now that we can do interior mutability in `const`, most of the Cell API can be `const fn`. :)  The main exception is `set`, because it drops the old value. So from const context one has to use `replace`, which delegates the responsibility for dropping to the caller.

Tracking issue: rust-lang#131283

`as_array_of_cells` is itself still unstable to I added the const-ness to the feature gate for that function and not to `const_cell`, Cc rust-lang#88248.

r? libs-api
@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2025

@rust-lang/libs-api @rust-lang/wg-const-eval I see no reason to wait any longer, so I propose we stabilize the use of Cell in const fn -- specifically the APIs listed here:

// core::cell

impl<T> Cell<T> {
    pub const fn replace(&self, val: T) -> T;
}

impl<T: Copy> Cell<T> {
    pub const fn get(&self) -> T;
}

impl<T: ?Sized> Cell<T> {
    pub const fn get_mut(&mut self) -> &mut T;
    pub const fn from_mut(t: &mut T) -> &Cell<T>;
}

impl<T> Cell<[T]> {
    pub const fn as_slice_of_cells(&self) -> &[Cell<T>];
}

Unfortunately, set cannot be made const fn yet as it drops the old contents.

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 3, 2025
@traviscross
Copy link
Contributor

traviscross commented Mar 3, 2025

In the libs-api call last week, we (mostly @Amanieu and I) talked about and agreed on doing libs-api stabilization FCPs on the stabilization PRs rather than on the tracking issues. This lets the team look at exactly what will be stabilized, it helps avoid the skew that can sometimes happen between what gets FCPed and what goes up in the PR, and it aligns the process with what lang does. While the risk of skew seems low in this particular case, perhaps it'd be better to go ahead and put up the stabilization PR for this and nominate that.

As you say, it does seem time to do these.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2025

Okay, I will prepare a PR when I find some time.

The library tracking issue template should then be adjusted to make it clear that the FCP should happen in the stabilization PR :)

@RalfJung RalfJung linked a pull request Mar 3, 2025 that will close this issue
@RalfJung RalfJung removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Mar 3, 2025
@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2025

PR is up at #137928

@moxian
Copy link
Contributor

moxian commented Mar 6, 2025

@traviscross should the documentation at https://rustc-dev-guide.rust-lang.org/stability.html#stabilizing-a-library-feature be updated to reflect this new policy? Or is it still in the "experimental" and "on a case-by-case basis" state?

@traviscross
Copy link
Contributor

traviscross commented Mar 6, 2025

Probably it should, yes.

(It's @Amanieu's call, but he seemed settled on it when we talked. We discussed whether any documentation would need to be updated, but that page and the tracking issue template didn't immediately come to mind, so we both just agreed we'd start to tell people to do it this way.)

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 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.

3 participants