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

Implements the changes for Wakers that are currently discussed in the tracking issue for stabilization #1340

Closed
wants to merge 3 commits into from

Conversation

Matthias247
Copy link
Contributor

@Matthias247 Matthias247 commented Nov 19, 2018

This depends on changes to libcore and libstd to work.

See discussion in rust-lang/rfcs#2592 and proposed update in
aturon/rfcs#15

This depends on changes to libcore and libstd to work.
@Matthias247
Copy link
Contributor Author

I already upload it here, so that people can take a look on the impact of the API changes.
I would especially like to get the parts around FuturesUnordered and LocalWakerRef reviewed, since those were pretty hard to understand. I have changed LocalWakerRef now to produce some very special LocalWaker which doesn't care about refcounts, but which changes it's vtable when it gets cloned. That should be correct.

However I'm not sure why currently local_waker_ref_from_nonlocal is used instead of local_waker_ref.

@Matthias247 Matthias247 changed the title Implements the changes for Wakers that are currently discussed. Implements the changes for Wakers that are currently discussed in the tracking issue for stabilization Nov 19, 2018
Copy link

@Centril Centril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assorted places I think unsafe is unneeded. While skimming this PR I noticed that there are places where unsafe { ... } is used; I think generally, uses of unsafe { ... } should come with a comment containing an informal proof of safety. This is especially true for bits and pieces that are going to be included in the standard library.

pub fn new() -> Self {
Self { _reserved: () }
}
unsafe fn noop(_data: *const()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop(_data: *const()) {
fn noop(_data: *const()) {

You should be able to remove unsafe here because of this coercion between fn and unsafe fn:

fn noop(_data: *const()) {}
const PTR: unsafe fn(*const ()) = noop;

Copy link
Member

@Nemo157 Nemo157 Dec 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, so there’s a coercion from fn to unsafe fn and from environment-less-closure to fn, but not the combined environment-less-closure to unsafe fn: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eaec9c9f080c999a55a08dd2184d8669. Has there been any discussion of adding the latter?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's just due to the lack of transitive coercions in general. It is not particular to this case AFAIK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally accept PRs for these without FCP since the original RFC specified that we should include all transitive coercions, but there isn't a mechanism in the compiler for that today.

#[derive(Debug)]
pub struct PanicWake {
_reserved: (),
unsafe fn noop_clone(_data: *const()) -> RawWaker {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop_clone(_data: *const()) -> RawWaker {
fn noop_clone(_data: *const()) -> RawWaker {

ditto

fn default() -> Self {
Self::new()
}
unsafe fn wake_panic(_data: *const()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn wake_panic(_data: *const()) {
fn wake_panic(_data: *const()) {

ditto

fn wake(_arc_self: &Arc<Self>) {
panic!("should not be woken")
}
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
fn noop_into_waker(_data: *const()) -> Option<RawWaker> {

ditto

LocalWakerRef::new(local_waker)
}

unsafe fn noop(_data: *const()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop(_data: *const()) {
fn noop(_data: *const()) {

ditto

#[derive(Debug)]
struct NoopWake {
_reserved: (),
unsafe fn noop_clone(_data: *const()) -> RawWaker {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop_clone(_data: *const()) -> RawWaker {
fn noop_clone(_data: *const()) -> RawWaker {

ditto

unsafe fn drop_raw(&self) {}

unsafe fn wake(&self) {}
unsafe fn noop(_data: *const()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop(_data: *const()) {
fn noop(_data: *const()) {

ditto

fn noop_unsafe_wake() -> NonNull<dyn UnsafeWake> {
static mut INSTANCE: NoopWake = NoopWake { _reserved: () };
unsafe { NonNull::new_unchecked(&mut INSTANCE as *mut dyn UnsafeWake) }
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsafe fn noop_into_waker(_data: *const()) -> Option<RawWaker> {
fn noop_into_waker(_data: *const()) -> Option<RawWaker> {

@Nemo157
Copy link
Member

Nemo157 commented Feb 20, 2019

@Matthias247 can be closed now?

@Matthias247
Copy link
Contributor Author

Merged in a different CR

@Matthias247 Matthias247 deleted the waker_changes branch February 21, 2019 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants