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_waker #102012

Closed
1 of 3 tasks
y86-dev opened this issue Sep 19, 2022 · 8 comments · Fixed by #128228
Closed
1 of 3 tasks

Tracking Issue for const_waker #102012

y86-dev opened this issue Sep 19, 2022 · 8 comments · Fixed by #128228
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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. I-async-nominated Nominated for discussion during an async working group meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. WG-async Working group: Async & await

Comments

@y86-dev
Copy link
Contributor

y86-dev commented Sep 19, 2022

Feature gate: #![feature(const_waker)]

This is a tracking issue for constifying the following functions:

  • Context::from_waker
  • Context::waker
  • Waker::from_raw

Public API

// core::task
impl<'a> Context<'a> {
    pub const fn from_waker(waker: &'a Waker) -> Self;
    pub const fn waker(&self) -> &'a Waker;
}

impl Waker {
    pub const unsafe fn from_raw(waker: RawWaker) -> Waker;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

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

@y86-dev y86-dev 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 Sep 19, 2022
@y86-dev

This comment was marked as off-topic.

@dtolnay
Copy link
Member

dtolnay commented Jan 2, 2023

The const on Context::from_waker and Context::waker require revisiting after #95985, since static CONTEXT: Context<'static> = Context::from_waker(&WAKER) is no longer legal.

Before stabilizing those consts, we should have a real-world use case in mind, and a new test that is representative of that use case.

@traviscross
Copy link
Contributor

@rustbot labels +I-libs-api-nominated

We discussed this in the WG-async call today. We observed there was a request for a use case here. We propose this one:

#![feature(const_waker)]

// ###################################################################
// Supporting code.

pub use nop_waker::*;
mod nop_waker {
    use core::{
        future::Future,
        pin::Pin,
        task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
    };
    pub const NOP_RAWWAKER: RawWaker = {
        fn nop(_: *const ()) {}
        const VTAB: RawWakerVTable =
            RawWakerVTable::new(|_| NOP_RAWWAKER, nop, nop, nop);
        RawWaker::new(&() as *const (), &VTAB)
    };
    pub const NOP_WAKER: &Waker =
        &unsafe { Waker::from_raw(NOP_RAWWAKER) };
    pub const NOP_CONTEXT: Context<'static> =
        Context::from_waker(NOP_WAKER);
    pub fn poll_once<T, F>(f: &mut F) -> Poll<T>
    where
        F: Future<Output = T> + ?Sized + Unpin,
    {
        let mut cx = NOP_CONTEXT;
        Pin::new(f).as_mut().poll(&mut cx)
    }
}

This is code that's been copy-and-pasted into a number of places recently to support tests.

More generally, in any context where one might want a noop Waker or a greater-than-noop but similarly trivial Waker, one probably also wants these methods to be const stable. Even if we were to separately stabilize Waker::noop(), it could still make sense to stabilize const_waker in the spirit of stabilizing primitives where possible.

We agreed that the above is a valid use case for const_waker and that WG-async is in favor of stabilizing const_waker subject to better understanding the concerns @dtolnay raised with regard to #95985.

Nominating as WG-async would like to see this move forward or hear more details about those concerns.

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jan 29, 2024
@traviscross traviscross added WG-async Working group: Async & await I-async-nominated Nominated for discussion during an async working group meeting. A-async-await Area: Async & Await labels Jan 29, 2024
@dtolnay
Copy link
Member

dtolnay commented Jan 30, 2024

Thanks Travis! Looks good.

Prior to #95985, the tests related to this feature involved static Context<'static> and static &'static Waker, which no longer works and those tests were deleted. If putting those types into const instead of static is useful too, this seems fine to move forward. Let's add the code from #102012 (comment) as a test as part of the stabilization PR.

@rust-lang/libs-api:
@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Jan 30, 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 Jan 30, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jan 30, 2024
@traviscross traviscross added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Feb 26, 2024
@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 Jul 2, 2024
@rfcbot
Copy link

rfcbot commented Jul 2, 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 Jul 12, 2024
@rfcbot
Copy link

rfcbot commented Jul 12, 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 Jul 12, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jul 22, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 28, 2024
Stabilize `const_waker`

Closes: rust-lang#102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under rust-lang#102012 from the beginning IMO.)~~ reused their own feature gates as suggested by `@tgross35.`

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

r? libs-api
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 28, 2024
…li-obk

Stabilize `const_waker`

Closes: rust-lang#102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under rust-lang#102012 from the beginning IMO.)~~ reused their own feature gates as suggested by `@tgross35.`

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

r? libs-api
@rakshith-ravi
Copy link
Contributor

Curious question: is this a step towards async const fns?

@bors bors closed this as completed in ee5956f Jul 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 28, 2024
Rollup merge of rust-lang#128228 - slanterns:const_waker, r=dtolnay,oli-obk

Stabilize `const_waker`

Closes: rust-lang#102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under rust-lang#102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.``

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

r? libs-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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. I-async-nominated Nominated for discussion during an async working group meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants