rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.7k stars 12.75k forks source link

Tracking Issue for `waker_getters` #96992

Closed oxalica closed 2 months ago

oxalica commented 2 years ago

Feature gate: #![feature(waker_getters)]

This is a tracking issue for getters of data and vtable pointers for RawWaker, and the method to get RawWaker from Waker.

Public API

// core::task
impl RawWaker {
    pub fn data(&self) -> *const ();
    pub fn vtable(&self) -> &'static RawWakerVTable;
}
impl Waker {
    pub fn as_raw(&self) -> &RawWaker;
}

Steps / History

Unresolved Questions

jkarneges commented 8 months ago

This will be merged soon.

It looks like there was a vote to merge, but this issue isn't a PR and it remains open. What's next here?

wyfo commented 7 months ago

As I have already mentioned, this feature is not really usable with alloc::task::Wake.

Could it be possible to add the following implementation?

impl<W: Wake + Send + Sync + 'static> Arc<W> {
    const fn waker_vtable() -> &'static RawWakerVTable { ... }
}

It would allow to match the vtable returned by RawWaker::vtable.

conradludgate commented 7 months ago

this feature is not really usable with alloc::task::Wake.

Does Waker::from(&arc_wake).as_raw().vtable() not work?

wyfo commented 7 months ago

Does Waker::from(&arc_wake).as_raw().vtable() not work?

Yes it works, but it requires to already have an allocated arc_wake, which makes the thing unusable.

The goal is to compare the vtable of a random waker to know if I can cast its data pointer to my own waker implementation. I don't want to rely for this comparison on a lazily allocated waker to get its vtable (especially as this lazy waker may requires some parameters random to be initialized). In short, this is unusable. That's too bad, because Wake is a convenient implementation shortcut, but I have to rewrite it myself to use this feature.

Hawk777 commented 5 months ago

If I understand correctly, the FCP has happened and ended with a disposition to merge. Is there some reason why the FCP checkbox in the first comment is still unticked? In terms of the stabilization PR, is that just waiting for someone to do it, or is there some missing prerequisite?

Amanieu commented 4 months ago

This is just waiting for someone to submit a stabilization PR.

kevinmehall commented 2 months ago

Submitted a stabilization PR: https://github.com/rust-lang/rust/pull/129919