Skip to content

Conversation

@Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Jan 31, 2026

This moves the query list from rustc_middle::query into a new rustc_middle::queries module. This splits up the use of the query system from the remaining implementation of it in rustc_middle::query, which conceptually belong to rustc_query_system.

The goal is to let rustc crates define queries with their own queries module, and this makes rustc_middle also fit this pattern.

The inner queries module used by the macros are renamed to query_info, so it doesn't conflict with the new outer name.

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 31, 2026
@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc marked this pull request as ready for review January 31, 2026 21:38
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 31, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 31, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
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

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 31, 2026
@nnethercote
Copy link
Contributor

This appears to be the first step of a much larger change that would definitely need an MCP.

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 1, 2026

Just to clarify, I think this makes sense whether or not we want to let other crates define queries. It would just be additional motivation to do so.

@nnethercote
Copy link
Contributor

I don't like query_info as a name. info (or data) in a name is usuall a bad sign, because it's so generic.

Is the query_info module providing any real value? Could we eliminate it, and reduce queries::query_info::$name to just queries::$name?

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 2, 2026

Is the query_info module providing any real value? Could we eliminate it, and reduce queries::query_info::$name to just queries::$name?

It's quite useful. We'd want to keep it in an fresh submodule to avoid naming conflicts. Maybe just query would be a better name?

@nnethercote
Copy link
Contributor

What naming conflicts could occur? Isn't the point of the queries submodule to isolate all the queries (which have unique names)?

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 2, 2026

Yeah, I guess we could just keep the new top-level rustc_middle::queries module clean to avoid conflicts.

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 2, 2026

Actually the proc macro generates some modules which may conflict.

@nnethercote
Copy link
Contributor

What are the conflicting modules?

@petrochenkov
Copy link
Contributor

r? @nnethercote

@rustbot rustbot assigned nnethercote and unassigned petrochenkov Feb 2, 2026
@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 2, 2026

We have 3 modules each defining a $name item per query: query_info, descs, cached. The module wasn't as clear as I though, but we can rename the others if needed (they look like unlikely query names currently).

@rustbot

This comment has been minimized.

@nnethercote
Copy link
Contributor

The queries::$name/queries::#name stuff is good.

The queries::desc/queries::cached is less good, but probably ok.

There's also all of these:

use crate::queries::{
    ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates,
};

Is that avoidable? Ideally the queries module would only contain the individual query names...

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 3, 2026

Is that avoidable?

The macro could probably just use full paths for these instead.

@nnethercote
Copy link
Contributor

In case it wasn't clear: I would prefer ExternProviders, PerQueryVTables, etc., to not be in the queries module, if possible.

@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 3, 2026

Ah, I though at first you were referring to the extra imports in the queries module (I think those should go). The types you refer to are specific to the queries defined and do belong alongside them. Not sure why you'd want them moved?

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 3, 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 guess the argument is that ExternProviders et al. are types that have one field per query, i.e. their structure is entirely dependent on the queries list, and therefore they belong in the same module as the query functions themselves. I can live with that.

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 4, 2026

📌 Commit 9de16dd 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2026
@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 4, 2026

Conceptually the types would be defined in rustc_middle::query and be generic over the query list, which we can't practically do in Rust.

@Zalathar
Copy link
Member

Zalathar commented Feb 4, 2026

In general I think it's premature to make sweeping changes based on the ambition of splitting query declarations across multiple crates, because that's an MCP-level change that I still have a lot of reservations about.

However, in this particular case pulling the query declarations out of rustc_middle::query is a good idea anyway, because it was awkward to have those declarations in a mod.rs file mixed in with submodules full of plumbing.

So I guess this is fine?

@Zalathar
Copy link
Member

Zalathar commented Feb 4, 2026

As a matter of commit style, I generally don't like to see moves and fixups in separate commits, unless it's absolutely necessary to get Git rename-tracking to still work by default.

EDIT: Though looking at the squashed PR diff, the separation does seem to be necessary to properly preserve the move, so I guess this is one of those exceptional cases after all.

Similarly, I don't like to see unnecessary indentation changes in the fixups. While Git tools can sometimes deal with that, it still adds an unwelcome layer of noise when trying to make sense of history.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 4, 2026
Move the query list into a new `rustc_middle::queries` module

This moves the query list from `rustc_middle::query` into a new `rustc_middle::queries` module. This splits up the use of the query system from the remaining implementation of it in `rustc_middle::query`, which conceptually belong to `rustc_query_system`.

The goal is to let rustc crates define queries with their own `queries` module, and this makes `rustc_middle` also fit this pattern.

The inner `queries` module used by the macros are renamed to `query_info`, so it doesn't conflict with the new outer name.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 4, 2026
Move the query list into a new `rustc_middle::queries` module

This moves the query list from `rustc_middle::query` into a new `rustc_middle::queries` module. This splits up the use of the query system from the remaining implementation of it in `rustc_middle::query`, which conceptually belong to `rustc_query_system`.

The goal is to let rustc crates define queries with their own `queries` module, and this makes `rustc_middle` also fit this pattern.

The inner `queries` module used by the macros are renamed to `query_info`, so it doesn't conflict with the new outer name.
@Zalathar
Copy link
Member

Zalathar commented Feb 4, 2026

We have 3 modules each defining a $name item per query: query_info, descs, cached. The module wasn't as clear as I though, but we can rename the others if needed (they look like unlikely query names currently).

In #151943 I intend to rename cached to _cache_on_disk_if_fns, and I'll probably do something similar with descs in a follow-up.

Regarding the flattened queries module, in some ways I did like the explicitness of a separate submodule for the macro-generated helper items, because I think it makes the use-sites a bit clearer. But we'll see how this flatter scheme works out in practice; it could be fine.

rust-bors bot pushed a commit that referenced this pull request Feb 4, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #151893 (Move the query list into a new `rustc_middle::queries` module)
 - #152060 (ci: Optimize loongarch64-linux dist builders)
 - #151993 (Add uv to the list of possible python runners)
 - #152047 (Convert to inline diagnostics in `rustc_interface`)
 - #152053 (Avoid semicolon suggestion when tail expr is error)

Failed merges:

 - #152023 (Some `rustc_query_system` cleanups)
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.

6 participants