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

Add Wake trait for safe construction of Wakers. #68700

Merged
merged 8 commits into from
Mar 23, 2020

Conversation

withoutboats
Copy link
Contributor

Currently, constructing a waker requires calling the unsafe Waker::from_raw API. This API requires the user to manually construct a vtable for the waker themself - which is both cumbersome and very error prone. This API would provide an ergonomic, straightforward and guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the Waker type essentially function as an Arc<dyn Wake>, with a Wake trait as defined here. Two considerations prevented the original API from being shipped as simply an Arc<dyn Wake>:

  • We want to support futures on embedded systems, which may not have an allocator, and in optimized executors for which this API may not be best-suited. Therefore, we have always explicitly supported the maximally-flexible (but also memory-unsafe) RawWaker API, and Waker has always lived in libcore.
  • Because Waker lives in libcore and Arc lives in liballoc, it has not been feasible to provide a constructor for Waker from Arc<dyn Wake>.

Therefore, the Wake trait was left out of the initial version of the task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan rules to implement From<Arc<W>> for Waker where W: Wake in liballoc. Therefore, we can now define this constructor even though Waker lives in libcore.

This PR adds these APIs:

  • A Wake trait, which contains two methods
    • A required method wake, which is called by Waker::wake
    • A provided method wake_by_ref, which is called by Waker::wake_by_ref and which implementors can override if they can optimize this use case.
  • An implementation of From<Arc<W>> for Waker where W: Wake + Send + Sync + 'static
  • A similar implementation of From<Arc<W>> for RawWaker.

@rust-highfive
Copy link
Collaborator

r? @rkruppe

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 31, 2020
@withoutboats
Copy link
Contributor Author

r? @cramertj (maybe?)

@withoutboats
Copy link
Contributor Author

cc @rust-lang/libs

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-31T13:37:19.7465639Z ========================== Starting Command Output ===========================
2020-01-31T13:37:19.7469338Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/8f7619dc-e4ce-40b3-814d-bc886f8689ef.sh
2020-01-31T13:37:19.7469452Z 
2020-01-31T13:37:19.7474049Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-31T13:37:19.7481127Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T13:37:19.7483103Z Task         : Get sources
2020-01-31T13:37:19.7483141Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T13:37:19.7483179Z Version      : 1.0.0
2020-01-31T13:37:19.7483277Z Author       : Microsoft
---
2020-01-31T13:37:20.7622183Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-31T13:37:20.7720875Z ##[command]git config gc.auto 0
2020-01-31T13:37:20.7803007Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-31T13:37:20.7863980Z ##[command]git config --get-all http.proxy
2020-01-31T13:37:20.8002090Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68700/merge:refs/remotes/pull/68700/merge
---
2020-01-31T13:42:29.8322883Z     Checking panic_abort v0.0.0 (/checkout/src/libpanic_abort)
2020-01-31T13:42:29.9898649Z     Checking backtrace v0.3.40
2020-01-31T13:42:31.1017403Z     Checking rustc-std-workspace-alloc v1.99.0 (/checkout/src/tools/rustc-std-workspace-alloc)
2020-01-31T13:42:31.1018368Z     Checking panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
2020-01-31T13:42:32.5862517Z error[E0658]: use of unstable library feature 'wake_trait'
2020-01-31T13:42:32.5864437Z     |
2020-01-31T13:42:32.5865385Z 479 |     pub use alloc::task::*;
2020-01-31T13:42:32.5866158Z     |             ^^^^^^^^^^^
2020-01-31T13:42:32.5866792Z     |
2020-01-31T13:42:32.5866792Z     |
2020-01-31T13:42:32.5867488Z     = help: add `#![feature(wake_trait)]` to the crate attributes to enable
2020-01-31T13:42:34.3183378Z error: aborting due to previous error
2020-01-31T13:42:34.3183536Z 
2020-01-31T13:42:34.3184007Z For more information about this error, try `rustc --explain E0658`.
2020-01-31T13:42:34.3286838Z error: could not compile `std`.
---
2020-01-31T13:42:34.3369593Z   local time: Fri Jan 31 13:42:34 UTC 2020
2020-01-31T13:42:34.6259037Z   network time: Fri, 31 Jan 2020 13:42:34 GMT
2020-01-31T13:42:34.6260389Z == end clock drift check ==
2020-01-31T13:42:35.6921663Z 
2020-01-31T13:42:35.6979058Z ##[error]Bash exited with code '1'.
2020-01-31T13:42:35.7001634Z ##[section]Finishing: Run build
2020-01-31T13:42:35.7020068Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T13:42:35.7022598Z Task         : Get sources
2020-01-31T13:42:35.7022644Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T13:42:35.7022714Z Version      : 1.0.0
2020-01-31T13:42:35.7022869Z Author       : Microsoft
2020-01-31T13:42:35.7022869Z Author       : Microsoft
2020-01-31T13:42:35.7022915Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-01-31T13:42:35.7022988Z ==============================================================================
2020-01-31T13:42:36.1698244Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-01-31T13:42:36.1736680Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T13:42:36.1848064Z Cleaning up task key
2020-01-31T13:42:36.1849172Z Start cleaning up orphan processes.
2020-01-31T13:42:36.1951436Z Terminate orphan process: pid (4404) (python)
2020-01-31T13:42:36.2173497Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

/// This trait is a memory-safe and ergonomic alternative to constructing a
/// [`RawWaker`]. It supports the common executor design in which the data
/// used to wake up a task is stored in an [`Arc`]. Some executors (especially
/// those for embedded systems) cannot use this API, which is way [`RawWaker`]
Copy link

Choose a reason for hiding this comment

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

typo way => why.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-31T13:44:57.0266080Z ========================== Starting Command Output ===========================
2020-01-31T13:44:57.0270844Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/b0500972-e0b4-45ff-bad9-8acf365b3e19.sh
2020-01-31T13:44:57.0271085Z 
2020-01-31T13:44:57.0275137Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-31T13:44:57.0281389Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T13:44:57.0283044Z Task         : Get sources
2020-01-31T13:44:57.0283078Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T13:44:57.0283108Z Version      : 1.0.0
2020-01-31T13:44:57.0283187Z Author       : Microsoft
---
2020-01-31T13:44:58.0304877Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-31T13:44:58.0319158Z ##[command]git config gc.auto 0
2020-01-31T13:44:58.0321546Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-31T13:44:58.0323464Z ##[command]git config --get-all http.proxy
2020-01-31T13:44:58.0459345Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68700/merge:refs/remotes/pull/68700/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: Arc<W> = Arc::from_raw(waker as *const W);
Wake::wake_by_ref(&waker);
mem::forget(waker);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using ManuallyDrop might be a better choice in the case waker panics.

/// [`Arc`] and calls `wake` on the clone.
#[unstable(feature = "wake_trait", issue = "0")]
fn wake_by_ref(self: &Arc<Self>) {
self.clone().wake();
Copy link
Member

Choose a reason for hiding this comment

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

futures::task::ArcWake has the opposite defaulted method. Is there a reason to assume that implementations would commonly need to own the Arc instead of being able to wake through a shared reference?

Copy link
Contributor Author

@withoutboats withoutboats Jan 31, 2020

Choose a reason for hiding this comment

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

In my experience working on romio/juliex and reading the tokio source, the standard executor model is to re-enqueue the task on some TLS or global queue (which means it must have ownership), and the standard reactor model is to store an Option<Waker> and then call .take().unwrap().wake(). IMO the default in futures is backwards, and would result in naive implementations making an additional unnecessary ref count increment.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion about this either way-- I can definitely imagine arguments on either side. The reason I did it the other way in futures-rs was that I imagined implementations which only needed by-reference waking would implement just wake not realizing that that would result in a wake_by_ref method which cloned unnecessarily. In practice, I don't think either case is too big of an issue.

Copy link
Contributor Author

@withoutboats withoutboats Feb 2, 2020

Choose a reason for hiding this comment

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

Yea, either way I think its a chance of an incorrectly implemented executor leading to one extra incr/decr on wakeup - a trivial and easily fixable problem.

But I do think the more likely scenario is that they do need ownership of the arc, rather than that they don't (the only point of it being by arc is to cheaply enqueue on wake up after all), and I thought our choice to name the fns wake and wake_by_ref was tied up in this assumption (that wake would be the default one).

@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-31T16:02:41.8900972Z ========================== Starting Command Output ===========================
2020-01-31T16:02:41.8903816Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/45971c8c-4b52-4995-b981-095186d5626f.sh
2020-01-31T16:02:41.8904013Z 
2020-01-31T16:02:41.8907594Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-31T16:02:41.8914200Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:02:41.8915954Z Task         : Get sources
2020-01-31T16:02:41.8915989Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T16:02:41.8916021Z Version      : 1.0.0
2020-01-31T16:02:41.8916054Z Author       : Microsoft
---
2020-01-31T16:02:42.9375241Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-31T16:02:42.9386411Z ##[command]git config gc.auto 0
2020-01-31T16:02:42.9389141Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-31T16:02:42.9391118Z ##[command]git config --get-all http.proxy
2020-01-31T16:02:42.9397374Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68700/merge:refs/remotes/pull/68700/merge
---
2020-01-31T16:07:37.0944373Z 
2020-01-31T16:07:37.0979986Z error: incorrect close delimiter: `)`
2020-01-31T16:07:37.0980299Z   --> src/liballoc/task.rs:86:6
2020-01-31T16:07:37.0980566Z    |
2020-01-31T16:07:37.0980896Z 58 | fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
2020-01-31T16:07:37.0981288Z    |                                                                          - un-closed delimiter
2020-01-31T16:07:37.0981799Z 86 |     ))
2020-01-31T16:07:37.0982136Z    |      ^ incorrect close delimiter
2020-01-31T16:07:37.0986490Z 
2020-01-31T16:07:37.1049187Z error: aborting due to 2 previous errors
---
2020-01-31T16:07:38.4393165Z   local time: Fri Jan 31 16:07:38 UTC 2020
2020-01-31T16:07:38.7283554Z   network time: Fri, 31 Jan 2020 16:07:38 GMT
2020-01-31T16:07:38.7284506Z == end clock drift check ==
2020-01-31T16:07:39.7393634Z 
2020-01-31T16:07:39.7483734Z ##[error]Bash exited with code '1'.
2020-01-31T16:07:39.7498098Z ##[section]Finishing: Run build
2020-01-31T16:07:39.7516226Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:07:39.7518505Z Task         : Get sources
2020-01-31T16:07:39.7518553Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T16:07:39.7518617Z Version      : 1.0.0
2020-01-31T16:07:39.7518676Z Author       : Microsoft
2020-01-31T16:07:39.7518676Z Author       : Microsoft
2020-01-31T16:07:39.7518723Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-01-31T16:07:39.7518772Z ==============================================================================
2020-01-31T16:07:40.1682207Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-01-31T16:07:40.1723981Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:07:40.1836052Z Cleaning up task key
2020-01-31T16:07:40.1836988Z Start cleaning up orphan processes.
2020-01-31T16:07:40.1951712Z Terminate orphan process: pid (3967) (python)
2020-01-31T16:07:40.2150862Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-31T16:15:05.3638631Z ========================== Starting Command Output ===========================
2020-01-31T16:15:05.3659998Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/6c9e28e6-71ba-49dd-8cd5-21242af713f0.sh
2020-01-31T16:15:05.3931565Z 
2020-01-31T16:15:05.3939622Z ##[section]Finishing: Disable git automatic line ending conversion
2020-01-31T16:15:05.3945487Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:15:05.3947192Z Task         : Get sources
2020-01-31T16:15:05.3947243Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T16:15:05.3947276Z Version      : 1.0.0
2020-01-31T16:15:05.3947310Z Author       : Microsoft
---
2020-01-31T16:15:06.4591690Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-01-31T16:15:06.4605863Z ##[command]git config gc.auto 0
2020-01-31T16:15:06.4611113Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-01-31T16:15:06.4615566Z ##[command]git config --get-all http.proxy
2020-01-31T16:15:06.4624183Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68700/merge:refs/remotes/pull/68700/merge
---
2020-01-31T16:20:46.3759933Z * 589 error codes
2020-01-31T16:20:46.3760688Z * highest error code: E0746
2020-01-31T16:20:46.4659007Z thread 'main' panicked at 'assertion failed: `(left != right)`
2020-01-31T16:20:46.4659832Z   left: `0`,
2020-01-31T16:20:46.4660767Z  right: `0`: "none" should be used when there is no issue, not "0"', src/tools/tidy/src/features.rs:417:21
2020-01-31T16:20:46.4664469Z 
2020-01-31T16:20:46.4664767Z 
2020-01-31T16:20:46.4664767Z 
2020-01-31T16:20:46.4665594Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2020-01-31T16:20:46.4666662Z 
2020-01-31T16:20:46.4666867Z 
2020-01-31T16:20:46.4675192Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2020-01-31T16:20:46.4676338Z Build completed unsuccessfully in 0:01:35
2020-01-31T16:20:46.4676338Z Build completed unsuccessfully in 0:01:35
2020-01-31T16:20:46.4726342Z == clock drift check ==
2020-01-31T16:20:46.4736787Z   local time: Fri Jan 31 16:20:46 UTC 2020
2020-01-31T16:20:46.6330126Z   network time: Fri, 31 Jan 2020 16:20:46 GMT
2020-01-31T16:20:46.6336348Z == end clock drift check ==
2020-01-31T16:20:47.3851644Z 
2020-01-31T16:20:47.3955483Z ##[error]Bash exited with code '1'.
2020-01-31T16:20:47.3968246Z ##[section]Finishing: Run build
2020-01-31T16:20:47.3983208Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:20:47.3984981Z Task         : Get sources
2020-01-31T16:20:47.3985048Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-01-31T16:20:47.3985098Z Version      : 1.0.0
2020-01-31T16:20:47.3985141Z Author       : Microsoft
2020-01-31T16:20:47.3985141Z Author       : Microsoft
2020-01-31T16:20:47.3985219Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-01-31T16:20:47.3985272Z ==============================================================================
2020-01-31T16:20:47.8399674Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-01-31T16:20:47.8442657Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-01-31T16:20:47.8561273Z Cleaning up task key
2020-01-31T16:20:47.8562356Z Start cleaning up orphan processes.
2020-01-31T16:20:47.8681815Z Terminate orphan process: pid (3896) (python)
2020-01-31T16:20:47.8893305Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@withoutboats withoutboats added A-async-await Area: Async & Await T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 2, 2020
@withoutboats
Copy link
Contributor Author

@rfcbot fcp merge See first post for a full explanation

@rfcbot
Copy link

rfcbot commented Feb 2, 2020

Team member @withoutboats 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 Feb 2, 2020
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-02-02T15:52:44.6597906Z ========================== Starting Command Output ===========================
2020-02-02T15:52:44.6599890Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/05a112d7-4169-448c-af76-ddb09955816c.sh
2020-02-02T15:52:44.6599925Z 
2020-02-02T15:52:44.6602767Z ##[section]Finishing: Disable git automatic line ending conversion
2020-02-02T15:52:44.6607658Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-02-02T15:52:44.6609808Z Task         : Get sources
2020-02-02T15:52:44.6609834Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-02T15:52:44.6609860Z Version      : 1.0.0
2020-02-02T15:52:44.6609892Z Author       : Microsoft
---
2020-02-02T15:52:45.4755220Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-02-02T15:52:45.4844260Z ##[command]git config gc.auto 0
2020-02-02T15:52:45.4897914Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-02-02T15:52:45.4944460Z ##[command]git config --get-all http.proxy
2020-02-02T15:52:45.5080201Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68700/merge:refs/remotes/pull/68700/merge
---
2020-02-02T15:57:52.1583998Z * 589 error codes
2020-02-02T15:57:52.1584962Z * highest error code: E0746
2020-02-02T15:57:52.2434408Z thread 'main' panicked at 'assertion failed: `(left != right)`
2020-02-02T15:57:52.2437304Z   left: `0`,
2020-02-02T15:57:52.2438681Z  right: `0`: "none" should be used when there is no issue, not "0"', src/tools/tidy/src/features.rs:417:21
2020-02-02T15:57:52.2446962Z 
2020-02-02T15:57:52.2447321Z 
2020-02-02T15:57:52.2447321Z 
2020-02-02T15:57:52.2448246Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2020-02-02T15:57:52.2448829Z 
2020-02-02T15:57:52.2449201Z 
2020-02-02T15:57:52.2451649Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2020-02-02T15:57:52.2452111Z Build completed unsuccessfully in 0:01:20
2020-02-02T15:57:52.2452111Z Build completed unsuccessfully in 0:01:20
2020-02-02T15:57:52.2495500Z == clock drift check ==
2020-02-02T15:57:52.2503642Z   local time: Sun Feb  2 15:57:52 UTC 2020
2020-02-02T15:57:52.4172018Z   network time: Sun, 02 Feb 2020 15:57:52 GMT
2020-02-02T15:57:52.4178376Z == end clock drift check ==
2020-02-02T15:57:53.1970241Z 
2020-02-02T15:57:53.2035649Z ##[error]Bash exited with code '1'.
2020-02-02T15:57:53.2046900Z ##[section]Finishing: Run build
2020-02-02T15:57:53.2060199Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-02-02T15:57:53.2062062Z Task         : Get sources
2020-02-02T15:57:53.2062104Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-02T15:57:53.2062161Z Version      : 1.0.0
2020-02-02T15:57:53.2062198Z Author       : Microsoft
2020-02-02T15:57:53.2062198Z Author       : Microsoft
2020-02-02T15:57:53.2062255Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-02-02T15:57:53.2062315Z ==============================================================================
2020-02-02T15:57:53.5702836Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-02-02T15:57:53.5740037Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/68700/merge to s
2020-02-02T15:57:53.5846063Z Cleaning up task key
2020-02-02T15:57:53.5847165Z Start cleaning up orphan processes.
2020-02-02T15:57:53.5955071Z Terminate orphan process: pid (3756) (python)
2020-02-02T15:57:53.6135047Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@dtolnay
Copy link
Member

dtolnay commented Feb 2, 2020

Looks great to me. Minor question: is there any use case for a Wake impl that is not Send + Sync + 'static? Did you evaluate having those as supertraits of Wake?

@rfcbot reviewed

@withoutboats
Copy link
Contributor Author

Looks great to me. Minor question: is there any use case for a Wake impl that is not Send + Sync + 'static? Did you evaluate having those as supertraits of Wake?

No there isn't, but I put them on the bound instead of as supertrait since that's my understanding of how std normally does things.

@Matthias247
Copy link
Contributor

We had this in the original proposal and removed it. What is the motivation to add it now? Who is the target user group? Wakers are part of an executor system. And building good executors (which include IO, timers, etc) is a not something a bigger group of people will do.

I don't see a lot of value in adding this. I certainly observe there is a trend of "build your own executor, because it's so neat to be able to do this in a couple lines of code". And that an addition like this would make it easier to write them. But I don't think that more toy executors really bring the ecosystem forward.

@withoutboats
Copy link
Contributor Author

@Matthias247 we removed it with the intention of always adding it once a good constructor API was possible. I don't agree that executors using this API would be "toys," in fact I would recommend this for production executor libraries in most server settings. There should be a safe way to construct a waker, period.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Feb 9, 2020
@rfcbot
Copy link

rfcbot commented Feb 9, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Feb 9, 2020
@Ixrec
Copy link
Contributor

Ixrec commented Feb 10, 2020

@Matthias247 more specifically, to quote the PR description:

However, as Rust 1.41, it is possible under the more flexible orphan rules to implement From<Arc> for Waker where W: Wake in liballoc.

So that's why it's happening now instead of in 2019.

@eddyb
Copy link
Member

eddyb commented Mar 23, 2020

@bors r- could you rebase? There's an accidental merge commit.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 23, 2020
withoutboats and others added 8 commits March 23, 2020 15:44
Currently, constructing a waker requires calling the unsafe
`Waker::from_raw` API. This API requires the user to manually construct
a vtable for the waker themself - which is both cumbersome and very
error prone. This API would provide an ergonomic, straightforward and
guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the `Waker` type essentially
function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two
considerations prevented the original API from being shipped as simply
an `Arc<dyn Wake>`:

- We want to support futures on embedded systems, which may not have an
  allocator, and in optimized executors for which this API may not be
  best-suited. Therefore, we have always explicitly supported the
  maximally-flexible (but also memory-unsafe) `RawWaker` API, and
  `Waker` has always lived in libcore.
- Because `Waker` lives in libcore and `Arc` lives in liballoc, it has
  not been feasible to provide a constructor for `Waker` from `Arc<dyn
  Wake>`.

Therefore, the Wake trait was left out of the initial version of the
task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan
rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc.
Therefore, we can now define this constructor even though `Waker` lives
in libcore.

This PR adds these APIs:

- A `Wake` trait, which contains two methods
    - A required method `wake`, which is called by `Waker::wake`
    - A provided method `wake_by_ref`, which is called by
      `Waker::wake_by_ref` and which implementors can override if they
      can optimize this use case.
- An implementation of `From<Arc<W>> for Waker where W: Wake + Send +
  Sync + 'static`
- A similar implementation of `From<Arc<W>> for RawWaker`.
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
@withoutboats
Copy link
Contributor Author

@bors r+

@bors
Copy link
Contributor

bors commented Mar 23, 2020

📌 Commit 32f5724 has been approved by withoutboats

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 23, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 23, 2020
…oats

Add Wake trait for safe construction of Wakers.

Currently, constructing a waker requires calling the unsafe `Waker::from_raw` API. This API requires the user to manually construct a vtable for the waker themself - which is both cumbersome and very error prone. This API would provide an ergonomic, straightforward and guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the `Waker` type essentially function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two considerations prevented the original API from being shipped as simply an `Arc<dyn Wake>`:

- We want to support futures on embedded systems, which may not have an allocator, and in optimized executors for which this API may not be best-suited. Therefore, we have always explicitly supported the maximally-flexible (but also memory-unsafe) `RawWaker` API, and `Waker` has always lived in libcore.
- Because `Waker` lives in libcore and `Arc` lives in liballoc, it has not been feasible to provide a constructor for `Waker` from `Arc<dyn Wake>`.

Therefore, the Wake trait was left out of the initial version of the task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc. Therefore, we can now define this constructor even though `Waker` lives in libcore.

This PR adds these APIs:

- A `Wake` trait, which contains two methods
    - A required method `wake`, which is called by `Waker::wake`
    - A provided method `wake_by_ref`, which is called by `Waker::wake_by_ref` and which implementors can override if they can optimize this use case.
- An implementation of `From<Arc<W>> for Waker where W: Wake + Send + Sync + 'static`
- A similar implementation of `From<Arc<W>> for RawWaker`.
This was referenced Mar 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2020
Rollup of 9 pull requests

Successful merges:

 - rust-lang#68700 (Add Wake trait for safe construction of Wakers.)
 - rust-lang#69494 (Stabilize --crate-version option in rustdoc)
 - rust-lang#70080 (rustc_mir: remove extra space when pretty-printing MIR.)
 - rust-lang#70195 (Add test for issue rust-lang#53275)
 - rust-lang#70199 (Revised span-to-lines conversion to produce an empty vec on DUMMY_SP.)
 - rust-lang#70299 (add err_machine_stop macro)
 - rust-lang#70300 (Reword unused variable warning)
 - rust-lang#70315 (Rename remaining occurences of Void to Opaque.)
 - rust-lang#70318 (Split long derive lists into two derive attributes.)

Failed merges:

r? @ghost
@bors bors merged commit e4d2f74 into rust-lang:master Mar 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 3, 2020
…ylan-DPC

Fix link in task::Wake docs

`task::Wake` was introduced in rust-lang#68700. While I was browsing the docs I noticed a link to `sync::Arc` wasn't resolving correctly. This patch fixes that. Thanks!

## Before

![Screenshot_2020-04-03 std task Wake - Rust](https://user-images.githubusercontent.com/2467194/78346384-466cb280-759f-11ea-97c8-aede186c674e.png)

## Proposed

![Screenshot_2020-04-03 alloc task Wake - Rust](https://user-images.githubusercontent.com/2467194/78349819-79657500-75a4-11ea-9282-16691ae2a5d4.png)
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 7, 2020
… r=Mark-Simulacrum

Add Arc::{incr,decr}_strong_count

This adds two `unsafe` methods to `Arc`: `incr_strong_count` and `decr_strong_count`. A suggestion to add methods to change the strong count in `Arc` came up in during review in rust-lang#68700 (comment), and from asking a few people this seemed like generally useful to have.

References:
- [Motivation from rust-lang#68700](rust-lang#68700 (comment))
- [Real world example in an executor](https://docs.rs/extreme/666.666.666666/src/extreme/lib.rs.html#13)
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 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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.