Skip to content

Commit

Permalink
Update some more things and improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb authored and jyn514 committed Nov 5, 2022
1 parent 0872241 commit 090bd54
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,25 @@ they define both a `provide` and a `provide_extern` function, through
How do you add a new query?
Defining a query takes place in two steps:

1. Specify the query name and its arguments.
1. Declare the query name, its arguments and description.
2. Supply query providers where needed.

To specify the query name and arguments, you simply add an entry to
the big macro invocation in
[`compiler/rustc_middle/src/query/mod.rs`][query-mod], which looks something like:
To declare the query name and arguments, you simply add an entry to
the big macro invocation in [`compiler/rustc_middle/src/query/mod.rs`][query-mod].
Then you need to add a documentation comment to it with some _internal_ description.
Then, provide the `desc` attribute which contains a short description of the query.
This description is shown to the user in query cycles.

This looks something like:

[query-mod]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/query/index.html

```rust,ignore
rustc_queries! {
/// Records the type of every item.
query type_of(key: DefId) -> Ty<'tcx> {
cache { key.is_local() }
cache_on_disk_if { key.is_local() }
desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
}
...
}
Expand Down Expand Up @@ -261,21 +266,6 @@ extra methods which are used by the query system.
[QueryConfig]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryConfig.html
[QueryDescription]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryDescription.html


Queries also have a description, which is specified using the `desc` modifier.
This description is shown to the user when cycle errors happen.

```rust,ignore
rustc_queries! {
Other {
/// Records the type of every item.
query type_of(key: DefId) -> Ty<'tcx> {
desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
}
}
}
```

## External links

Related design ideas, and tracking issues:
Expand Down

0 comments on commit 090bd54

Please sign in to comment.