Skip to content

Replace visit_waiters with abstracted_waiters_of#153376

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zoxc:cycle-waiters-iter
Mar 14, 2026
Merged

Replace visit_waiters with abstracted_waiters_of#153376
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Zoxc:cycle-waiters-iter

Conversation

@Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 4, 2026

This replaces visit_waiters which uses closures to visit waiters with abstracted_waiters_of which returns a list of waiters. This makes the control flow of their users a bit clearer.

Additionally abstracted_waiters_of includes non-query waiters unlike visit_waiters. This means that connected_to_root now considers resumable waiters from the compiler root as being connected to root, while previously only non-resumable waiters counted. This can result in some additional entry points being found. Similarly in the loop detecting entry points we now consider queries in the cycle with direct resumable waiters from the compiler root as being entry points.

When looking for entry points we now look at waiters until we found a query to populate the EntryPoint.waiter field instead of stopping when we determined it to be an entry point.

cc @petrochenkov @nnethercote

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 4, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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: compiler, query-system
  • compiler, query-system expanded to 69 candidates
  • Random selection from 16 candidates

@nnethercote nnethercote added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2026
@nnethercote
Copy link
Contributor

This is a smallish change to code that #153185 is proposing to completely rewrite. If that PR is accepted and merged then this one will be moot. So we need to reach a conclusion on that PR before considering this one.

@rustbot blocked

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 4, 2026

That's not how that works.

Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

I've been looking at enough of this code to have some idea of what's going on now. This new code is definitely easier to follow. E.g. the old comments at the top of visit_waiters were really hard to understand. The remaining code is still very complicated!

There are enough changes that I'm having trouble seeing the exact 1-to-1 mapping from the old control flow to the new control flow. Especially given that it seems (from the PR description) there are some deliberate changes to the control flow.

This file uses "query" in a lot of places where "job" would probably be better. (Working on the assumption that "query" the conceptual thing, like type_of, and "job" is an actively running query with a particular key.) That's beyond the scope of this PR, though.

View changes since this review

struct Waiter {
span: Span,
/// The query which we are waiting from, if none the waiter is from a compiler root.
query: Option<QueryJobId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called parent? (I have been wondering the same thing about QueryWaiter::query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do associate parent a bit more with trees than graphs, but this could have a name other than query.

/// The query which we are waiting from, if none the waiter is from a compiler root.
query: Option<QueryJobId>,
resumable: Option<ResumableWaiterLocation>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We now have QueryWaiter and Waiter. And also QueryJobInfo and QueryInfo. These structs with similar names and contents are hard to remember.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the variable name waiter now sometimes means a QueryWaiter, sometimes a Waiter, and sometimes a QueryJobId. This gets quite confusing. It would be good to have separate names. E.g. sometimes waiter_query is used for a QueryJobId that comes from waiter.query, which is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Waiter represents graph edges, so we could use graph terminology for contrast here.

result.push(Waiter {
span: waiter.span,
query: waiter.query,
resumable: Some((query, i)),
Copy link
Contributor

Choose a reason for hiding this comment

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

You're pushing the same query multiple times. I think it's possible to change ResumableWaiterLocation to just be the usize index, because the query is always available at the waiters_of call site.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I'm not sure if that works. It's still odd to see query pushed multiple times.

/// the function return true.
/// If a cycle was not found, the starting query is removed from `jobs` and
/// the function returns false.
fn remove_cycle<'tcx>(
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is a good example of confusing names: waiter appears multiple times, with a different type and meaning each time.

@rust-bors

This comment has been minimized.

@Zoxc Zoxc force-pushed the cycle-waiters-iter branch from 2049f02 to c6bc581 Compare March 12, 2026 18:51
@rustbot

This comment has been minimized.

Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

Ok, I think this is good enough. Squash the commits and I will r+, thanks.

View changes since this review

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 13, 2026
@Zoxc Zoxc force-pushed the cycle-waiters-iter branch from c6bc581 to ed07376 Compare March 13, 2026 06:44
@rustbot

This comment has been minimized.

@Zoxc Zoxc changed the title Replace visit_waiters with waiters_of Replace visit_waiters with abstracted_waiters_of Mar 13, 2026
@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Contributor

r=me once the tests are passing.

@bors delegate=Zoxc

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 13, 2026

Invalid command: Invalid delegation type Zoxc. Possible values are try/review. Run @bors help to see available commands.

@Zoxc Zoxc force-pushed the cycle-waiters-iter branch from ed07376 to 1f44a11 Compare March 13, 2026 11:58
@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2026

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.

@nnethercote
Copy link
Contributor

I don't know why delegation is no longer working.

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 13, 2026

📌 Commit 1f44a11 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 13, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 13, 2026
…cote

Replace `visit_waiters` with `abstracted_waiters_of`

This replaces `visit_waiters` which uses closures to visit waiters with `abstracted_waiters_of` which returns a list of waiters. This makes the control flow of their users a bit clearer.

Additionally `abstracted_waiters_of` includes non-query waiters unlike `visit_waiters`. This means that `connected_to_root` now considers resumable waiters from the compiler root as being connected to root, while previously only non-resumable waiters counted. This can result in some additional entry points being found. Similarly in the loop detecting entry points we now consider queries in the cycle with direct resumable waiters from the compiler root as being entry points.

When looking for entry points we now look at waiters until we found a query to populate the `EntryPoint.waiter` field instead of stopping when we determined it to be an entry point.

cc @petrochenkov @nnethercote
rust-bors bot pushed a commit that referenced this pull request Mar 14, 2026
Rollup of 4 pull requests

Successful merges:

 - #153376 (Replace `visit_waiters` with `abstracted_waiters_of`)
 - #153818 (Reimplement const closures)
 - #153774 (Fix std doctest build for SGX target.)
 - #153786 (Remove `value_from_cycle_error` specializations)
rust-bors bot pushed a commit that referenced this pull request Mar 14, 2026
Rollup of 7 pull requests

Successful merges:

 - #152621 (LinkedGraph: support adding nodes and edges in arbitrary order)
 - #153376 (Replace `visit_waiters` with `abstracted_waiters_of`)
 - #153760 (Move and expand the big `rustc_query_impl` macro into a physical `query_impl.rs`)
 - #153818 (Reimplement const closures)
 - #153774 (Fix std doctest build for SGX target.)
 - #153786 (Remove `value_from_cycle_error` specializations)
 - #153819 (delete some duplicated tests)
rust-bors bot pushed a commit that referenced this pull request Mar 14, 2026
Rollup of 7 pull requests

Successful merges:

 - #152621 (LinkedGraph: support adding nodes and edges in arbitrary order)
 - #153376 (Replace `visit_waiters` with `abstracted_waiters_of`)
 - #153760 (Move and expand the big `rustc_query_impl` macro into a physical `query_impl.rs`)
 - #153818 (Reimplement const closures)
 - #153774 (Fix std doctest build for SGX target.)
 - #153786 (Remove `value_from_cycle_error` specializations)
 - #153819 (delete some duplicated tests)
@rust-bors rust-bors bot merged commit 1d49de5 into rust-lang:main Mar 14, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 14, 2026
@Zoxc Zoxc deleted the cycle-waiters-iter branch March 14, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants