Skip to content

Conversation

@xizheyin
Copy link
Member

Refined some vague concepts and pseudo-code in Query System

In the past, we only used vague concepts like local and extern to differentiate between different queries. however the code has more detailed Providers and ExternProviders to differentiate between them, so we should mention both of them in the documentation as well.

It is also important to indicate that rustc_middle::util::Providers is made up of Providers and ExternProviders in the query mod.

This PR also updates the example of registering a new Provider to consider ExternProviders.

r? @tshepang

@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Jun 15, 2025
@xizheyin xizheyin marked this pull request as draft June 15, 2025 12:47
@xizheyin xizheyin marked this pull request as ready for review June 15, 2025 12:52
@xizheyin
Copy link
Member Author

first commit for ExternProviders, second commit for the nit in #2465.

@BoxyUwU BoxyUwU self-assigned this Dec 11, 2025
@BoxyUwU BoxyUwU added S-waiting-on-author Status: this PR is waiting for additional action by the OP A-query-system Area: query system and removed S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content labels Dec 11, 2025
@rustbot

This comment has been minimized.

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>

Co-authored-by: Boxy <rust@boxyuwu.dev>
#### Adding a new provider

Suppose you want to add a new query called `fubar`. You would:
Suppose you want to add a new query called `fubar`. This section focuses on wiring up the providers; for how to declare the query itself in the big `rustc_queries!` macro, see [Adding a new query](#adding-a-new-query) below.
Copy link
Member Author

Choose a reason for hiding this comment

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

Here, I add some explanations to hint that how to add a query is put below.

Comment on lines +180 to +187
1. Decide which crate "owns" the query (for example `rustc_hir_analysis`, `rustc_mir_build`, or another `rustc_*` crate).
2. In that crate, look for an existing `provide` function:
```rust,ignore
pub fn provide(providers: &mut query::Providers) {
// existing assignments
}
```
If it exists, you will extend it to set the field for your new query. If the crate does not yet have a `provide` function, add one and make sure it is included in `DEFAULT_QUERY_PROVIDERS` in the `rustc_interface` crate so that it actually gets called during initialization (see the discussion above).
Copy link
Member Author

Choose a reason for hiding this comment

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

Some more deatils: if there is a existing..., else ...

@xizheyin
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content and removed S-waiting-on-author Status: this PR is waiting for additional action by the OP labels Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: query system S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants