-
Notifications
You must be signed in to change notification settings - Fork 543
Instructions for adding a new query #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Someone from @rust-lang/wg-incr-comp might be able to help here. |
See also rust-lang/rust#94097. |
This comment was marked as outdated.
This comment was marked as outdated.
The The name
There is only one per crate. Use the one for the crate where you define the query provider.
You should reuse the provide function for the current crate if it exists. A question you didn't ask, but I think we should answer, is when to use a query instead of a normal function. Some examples:
Note that all queries must be idempotent and cannot change (and preferably, not even access) global state. Failure to do so will cause ICEs at best and silently miscompile code at worst. Be extremely cautious about using any function named @michaelwoerister @cjgillot does that sound roughly right? |
@Nilstrieb mentions "projection queries" are also a good reason for using a query instead of a function, for better caching. https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation-in-detail.html#the-projection-query-pattern |
Most rustc code runs inside some form of query provider (for example the entirety of the borrow checker in the |
@jyn514, sounds right to me.
I think there are some instances where there's more than one |
Summary of issue
We have a good start on documenting adding a new query: https://rustc-dev-guide.rust-lang.org/query.html#adding-a-new-kind-of-query. However, I think there's room for greater clarity.
☞ After reading this section, I know where to define a query. I want to know where and how to implement one.
Details
Currently, this section of the guide has two summaries of the process:
and
Where are these providers?
How do I find "the appropriate
provide
method" for a new query? Do I always need to create a new one for a new query? Or can I sometimes reuse ("modify") an existing one?The section immediately before this one gives information on Providers, but does not say how to add a new one.
The text was updated successfully, but these errors were encountered: