Skip to content

Conversation

@nnethercote
Copy link
Contributor

To make it more similar to rustc_middle::define_callbacks, because I think it's very helpful for the two macros to work similarly.

define_queries currently generates one module called query_impl::$name for every query, and also generates a few types/consts/funcs into crate root.

After this change, it instead generates one module called queries::$name for every query, and also generates those few types/consts/funcs into queries. This makes it much more like define_callbacks.

The commit also adjusts imports so the body of define_queries needs fewer qualifiers, and to minimize potential confusion between rustc_middle::queries and rustc_query_impl::queries. And removes some unnecessary $crate/crate qualifiers.

r? @Zalathar

To make it more similar to `rustc_middle::define_callbacks`, because I
think it's very helpful for the two macros to work similarly.

`define_queries` currently generates one module called
`query_impl::$name` for every query, and also generates a few
types/consts/funcs into crate root.

After this change, it instead generates one module called
`queries::$name` for every query, and also generates those few
types/consts/funcs into `queries`. This makes it much more like
`define_callbacks`.

The commit also adjusts imports so the body of `define_queries` needs
fewer qualifiers, and to minimize potential confusion between
`rustc_middle::queries` and `rustc_query_impl::queries`. And removes
some unnecessary `$crate`/`crate` qualifiers.
@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 Feb 10, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 11, 2026

☔ The latest upstream changes (presumably #151943) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines +969 to +970
use $name::QueryType;
plumbing::make_dep_kind_vtable_for_query::<QueryType<'tcx>, _, _>(
Copy link
Member

Choose a reason for hiding this comment

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

I find that this sort of change makes the macro code significantly harder to understand, for no real benefit.

In the old code, it's easy to see that we're referring to things defined in the current crate, inside a module with the uniquely-searchable name query_impl. I can also see that query_impl is defined by the enclosing macro, and that other parts of the macro also refer to query_impl.

In the new code, it's much harder to know what the bare $name or plumbing names refer to. IDE features don't work because this is macro code, and I can't usefully search for those names either.

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 find the opposite, that unnecessary qualification obscures. If I see $name I know it's from the current crate and module. If I see crate::query_impl::$name it seems like it must be from another module.

Copy link
Member

@Zalathar Zalathar Feb 11, 2026

Choose a reason for hiding this comment

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

When we're dealing with 3+ levels of nested macros, expanded cross-module and in some cases cross-crate, I'd prefer not to have to solve a logic puzzle to figure out what and where $name is when the source code could just tell me instead.

In trying to get my head around the query system macros, I never found myself wishing for paths to be less explicit, but very often found myself wishing that they were more explicit.

}

rustc_middle::rustc_with_all_queries! { define_queries! }
pub mod queries {
Copy link
Member

@Zalathar Zalathar Feb 11, 2026

Choose a reason for hiding this comment

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

Calling this module queries seems very bad to me, because it results in maximum confusion between rustc_middle and rustc_query_impl.

Working with macro-generated code is inherently hard, which is why I always prefer to have distinctive “landmarks” to help keep things separate in my mind.

I also don't see a benefit in moving the module declaration out of the macro, because now it's less obvious that the module's contents are defined by the macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The double use of queries has pros (symmetry) and cons (potential confusion), and I'm not wedded to it.

Moving the module declaration makes define_callbacks and define_queries more similar, which is the primary motivation of this whole PR. Does increasing similarity of the macros seem valuable to you?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants