Skip to content

Enhance documentation on wake call memory ordering#154401

Closed
xmh0511 wants to merge 7 commits into
rust-lang:mainfrom
xmh0511:main
Closed

Enhance documentation on wake call memory ordering#154401
xmh0511 wants to merge 7 commits into
rust-lang:mainfrom
xmh0511:main

Conversation

@xmh0511

@xmh0511 xmh0511 commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

View all comments

Add documentation about memory ordering requirements for wake calls. Try to fix #128920

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 26, 2026
@rustbot

rustbot commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates

@rust-log-analyzer

This comment has been minimized.

Comment thread library/alloc/src/task.rs Outdated
@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 27, 2026
@rustbot

rustbot commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Darksonn

Copy link
Copy Markdown
Member

In general I would say that this documentation makes more sense on the Waker struct or the Future trait. The Wake trait is just a utility trait, and should not be the primary location for these kinds of docs (though it can be mentioned there too).

I would also relax the wording a bit. You use the word 'runtime must' and so on, but I think it would be useful to instead phrase it along the lines of 'to avoid missed wakeups, the runtime must' or similar to make it clear what the consequences of getting it wrong are.

@rust-log-analyzer

This comment has been minimized.

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good to me.

View changes since this review

Comment thread library/alloc/src/task.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 10, 2026
Comment thread library/core/src/task/wake.rs Outdated
Comment on lines +437 to +438
/// the beginning of the invocation of `poll`.
/// In particular, this means that if a task self-wakes (invokes `wake` on itself during `poll`),

@Darksonn Darksonn Jun 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like you intended to have a newline here, but markdown will not treat this as a newline.

Please either reflow without a line break or add an empty line if you want two paragraphs. (I probably would keep one paragraph.)

View changes since the review

Comment thread library/core/src/task/wake.rs Outdated
/// current task again.
///
/// To avoid missed wakeups, the runtime must ensure that for any call to `wake`,
/// there is a subsequent call to `poll` such that the returned `wake` _happens-before_

@Darksonn Darksonn Jun 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Saying "returned wake" sounds like a value called wake is being returned, but that is not the case. Can you reword?

View changes since the review

@xmh0511 xmh0511 Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is "returning from the wake happens-before ..." good enough? Or, option B

there is a subsequent call to poll such that the wake() return happens-before

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's probably sufficient to say that "the call to wake() happens-before the beginning of the call to poll()".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Darksonn I have closed this PR due to confliction, and created a new one, see #157694

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is generally a bad idea to create PRs from your main branch. Always create a new branch in your repo for every PR.

It is however not necessary to make a new PR, you can just force-push to that branch to remove the bad changes.

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

The run-make-support library was changed

cc @jieyouxu

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs T-clippy Relevant to the Clippy team. labels Jun 10, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 10, 2026
xmh0511 added 6 commits June 10, 2026 14:40
Add memory ordering guarantees for wake and poll calls.
Clarify wake behavior in documentation regarding missed wakeups.
Clarify wakeup requirements for the executor in documentation.
@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 10, 2026
@xmh0511 xmh0511 requested a review from Darksonn June 10, 2026 06:48
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

error: encountered diff marker
  --> compiler/rustc_middle/src/queries.rs:61:1
   |
61 | <<<<<<< HEAD
   | ^^^^^^^ between this marker and `=======` is the code that you are merging into
...
64 | =======
   | ------- between this marker and `>>>>>>>` is the incoming code
65 | use rustc_errors::ErrorGuaranteed;
66 | >>>>>>> 665bf7d3863 (revert cargo fmt)
   | ^^^^^^^ this marker concludes the conflict region
   |
   = note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts
           to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers
   = help: if you are in a merge, the top section is the code you already had checked out and the bottom section is the new code
           if you are in a rebase, the top section is the code being rebased onto and the bottom section is the code you had checked out which is being rebased
   = note: for an explanation on these markers from the `git` documentation, visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts>

[RUSTC-TIMING] rustc_middle test:false 0.087
warning: `rustc_middle` (lib) generated 1 warning
error: could not compile `rustc_middle` (lib) due to 1 previous error; 1 warning emitted
warning: build failed, waiting for other jobs to finish...

@xmh0511 xmh0511 closed this by deleting the head repository Jun 10, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs T-clippy Relevant to the Clippy team. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Happens-before relationship between wake and poll

6 participants