Skip to content

Replace visit_waiters with waiters_of#153376

Open
Zoxc wants to merge 1 commit intorust-lang:mainfrom
Zoxc:cycle-waiters-iter
Open

Replace visit_waiters with waiters_of#153376
Zoxc wants to merge 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 waiters_of which returns a list of waiters. This makes the control flow of their users a bit clearer.

Additionally 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.

/// 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.

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.

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-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.

3 participants